-
Notifications
You must be signed in to change notification settings - Fork 4
/
model_expression_unary.go
88 lines (72 loc) · 1.68 KB
/
model_expression_unary.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// © 2019-present nextmv.io inc
package nextroute
import (
"fmt"
)
// TermExpression is an expression that returns the product of the given factor
// and the value of the given expression.
type TermExpression interface {
ModelExpression
// Expression returns the expression.
Expression() ModelExpression
// Factor returns the factor.
Factor() float64
}
// NewTermExpression returns a new TermExpression.
func NewTermExpression(
factor float64,
expression ModelExpression,
) TermExpression {
return &termExpression{
index: NewModelExpressionIndex(),
expression: expression,
factor: factor,
name: fmt.Sprintf("%f * %s", factor, expression),
}
}
type termExpression struct {
expression ModelExpression
name string
index int
factor float64
}
func (t *termExpression) HasNegativeValues() bool {
if t.factor < 0 {
return t.expression.HasPositiveValues()
}
return t.expression.HasNegativeValues()
}
func (t *termExpression) HasPositiveValues() bool {
if t.factor < 0 {
return t.expression.HasNegativeValues()
}
return t.expression.HasPositiveValues()
}
func (t *termExpression) String() string {
return fmt.Sprintf("Term[%v] %v * %v",
t.index,
t.factor,
t.expression,
)
}
func (t *termExpression) Index() int {
return t.index
}
func (t *termExpression) Name() string {
return t.name
}
func (t *termExpression) SetName(n string) {
t.name = n
}
func (t *termExpression) Factor() float64 {
return t.factor
}
func (t *termExpression) Expression() ModelExpression {
return t.expression
}
func (t *termExpression) Value(
vehicle ModelVehicleType,
from, to ModelStop,
) float64 {
return t.factor * t.expression.Value(vehicle, from, to)
}