-
Notifications
You must be signed in to change notification settings - Fork 4
/
model_expression.go
41 lines (31 loc) · 1.22 KB
/
model_expression.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// © 2019-present nextmv.io inc
package nextroute
import "sync/atomic"
var expressionIndex uint32
// NewModelExpressionIndex returns the next unique expression index.
func NewModelExpressionIndex() int {
return int(atomic.AddUint32(&expressionIndex, 1) - 1)
}
// ModelExpression is an expression that can be used in a model to define
// values for constraints and objectives. The expression is evaluated for
// each stop in the solution by invoking the Value() method. The value of
// the expression is then used in the constraints and objective.
type ModelExpression interface {
// Index returns the unique index of the expression.
Index() int
// Name returns the name of the expression.
Name() string
// Value returns the value of the expression for the given vehicle type,
// from stop and to stop.
Value(ModelVehicleType, ModelStop, ModelStop) float64
// HasNegativeValues returns true if the expression contains negative
// values.
HasNegativeValues() bool
// HasPositiveValues returns true if the expression contains positive
// values.
HasPositiveValues() bool
// SetName sets the name of the expression.
SetName(string)
}
// ModelExpressions is a slice of ModelExpression.
type ModelExpressions []ModelExpression