-
Notifications
You must be signed in to change notification settings - Fork 4
/
model_expression_measure_bypoint.go
61 lines (49 loc) · 1.35 KB
/
model_expression_measure_bypoint.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
// © 2019-present nextmv.io inc
package nextroute
import (
"fmt"
"github.com/nextmv-io/sdk/measure"
)
// NewMeasureByPointExpression returns a new MeasureByPointExpression.
// A MeasureByPointExpression is a ModelExpression that uses a measure.ByPoint to
// calculate the cost between two stops.
func NewMeasureByPointExpression(measure measure.ByPoint) ModelExpression {
return &measureByPointExpression{
index: NewModelExpressionIndex(),
measure: measure,
name: "measure_by_point",
}
}
type measureByPointExpression struct {
measure measure.ByPoint
name string
index int
}
func (m *measureByPointExpression) HasNegativeValues() bool {
return false
}
func (m *measureByPointExpression) HasPositiveValues() bool {
return true
}
func (m *measureByPointExpression) String() string {
return fmt.Sprintf("measure_by_point[%v]",
m.index,
)
}
func (m *measureByPointExpression) Index() int {
return m.index
}
func (m *measureByPointExpression) Name() string {
return m.name
}
func (m *measureByPointExpression) SetName(n string) {
m.name = n
}
func (m *measureByPointExpression) Value(_ ModelVehicleType, from, to ModelStop) float64 {
locFrom, locTo := from.Location(), to.Location()
value := m.measure.Cost(
measure.Point{locFrom.Longitude(), locFrom.Latitude()},
measure.Point{locTo.Longitude(), locTo.Latitude()},
)
return value
}