diff --git a/check/check.go b/check/check.go index 74c1182..8fe4f1a 100644 --- a/check/check.go +++ b/check/check.go @@ -11,6 +11,7 @@ import ( "github.com/nextmv-io/nextroute" "github.com/nextmv-io/nextroute/check/schema" "github.com/nextmv-io/nextroute/common" + "github.com/nextmv-io/sdk/run/statistics" ) // ModelCheck is the check of a model returning a [Output]. @@ -222,7 +223,7 @@ SolutionPlanUnitLoop: *m.output.PlanUnits[solutionPlanUnitIdx].VehiclesHaveMoves++ } - value := bestMove.Value() + value := statistics.Float64(bestMove.Value()) vehicleDetails := &schema.VehiclesWithMovesDetail{ VehicleID: solutionVehicle.ModelVehicle().ID(), DeltaObjectiveEstimate: &value, @@ -268,7 +269,7 @@ SolutionPlanUnitLoop: if planned { moveIsImprovement = true vehicleDetails.WasPlannable = true - deltaObjective := m.solution.Score() - actualScoreBeforeMove + deltaObjective := statistics.Float64(m.solution.Score() - actualScoreBeforeMove) vehicleDetails.DeltaObjective = &deltaObjective m.output.PlanUnits[solutionPlanUnitIdx].HasPlannableBestMove = true diff --git a/check/schema/schema.go b/check/schema/schema.go index b875816..7d74fb8 100644 --- a/check/schema/schema.go +++ b/check/schema/schema.go @@ -3,6 +3,8 @@ // Package schema contains the core schemas for nextroute. package schema +import "github.com/nextmv-io/sdk/run/statistics" + // Output is the output of the check. type Output struct { // Error is the error raised during the check. @@ -119,10 +121,10 @@ type VehiclesWithMovesDetail struct { VehicleID string `json:"vehicle_id"` // DeltaObjectiveEstimate is the estimate of the delta of the objective of // that will be incurred by the move. - DeltaObjectiveEstimate *float64 `json:"delta_objective_estimate,omitempty"` + DeltaObjectiveEstimate *statistics.Float64 `json:"delta_objective_estimate,omitempty"` // DeltaObjective is the actual delta of the objective of that will be // incurred by the move. - DeltaObjective *float64 `json:"delta_objective,omitempty"` + DeltaObjective *statistics.Float64 `json:"delta_objective,omitempty"` // FailedConstraints are the constraints that are violated for the move. FailedConstraints []string `json:"failed_constraints,omitempty"` // WasPlannable is true if the move was plannable, false otherwise. diff --git a/factory/vehicles.go b/factory/vehicles.go index be98a02..5cf18c0 100644 --- a/factory/vehicles.go +++ b/factory/vehicles.go @@ -3,7 +3,6 @@ package factory import ( - "encoding/json" "errors" "fmt" @@ -45,16 +44,11 @@ func addVehicles( } } case map[string]any: - var durationMatrices schema.TimeDependentMatrix - jsonData, err := json.Marshal(matrix) + timeDependentMatrix, err := convertToTimeDependentMatrix(matrix) if err != nil { return nil, err } - err = json.Unmarshal(jsonData, &durationMatrices) - if err != nil { - return nil, err - } - travelDuration, err = dependentTravelDurationExpression(durationMatrices, model) + travelDuration, err = dependentTravelDurationExpression(timeDependentMatrix, model) if err != nil { return nil, err } @@ -64,16 +58,11 @@ func addVehicles( travelDuration = travelDurationExpression(floatMatrix) } else { // If it's not [][]float64, try to assert it as []schema.DurationMatrices - var durationMatrices []schema.TimeDependentMatrix - jsonData, err := json.Marshal(matrix) - if err != nil { - return nil, err - } - err = json.Unmarshal(jsonData, &durationMatrices) + timeDependentMatrices, err := convertToTimeDependentMatrices(matrix) if err != nil { return nil, err } - for _, durationMatrix := range durationMatrices { + for _, durationMatrix := range timeDependentMatrices { m, err := dependentTravelDurationExpression(durationMatrix, model) if err != nil { return nil, err diff --git a/go.mod b/go.mod index 27c1c95..556a09d 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/nextmv-io/nextroute go 1.21 require ( - github.com/nextmv-io/sdk v1.8.0 + github.com/nextmv-io/sdk v1.8.1 gonum.org/v1/gonum v0.14.0 ) diff --git a/go.sum b/go.sum index d7b2267..029c8a1 100644 --- a/go.sum +++ b/go.sum @@ -301,8 +301,8 @@ github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lN github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= -github.com/nextmv-io/sdk v1.8.0 h1:EqYibIyeaFRc9zgyPUUwbD2nx9z37l18YfJfVe1wHCU= -github.com/nextmv-io/sdk v1.8.0/go.mod h1:Y48XLPcIOOxRgO86ICNpqGrH2N5+dd1TDNvef/FD2Kc= +github.com/nextmv-io/sdk v1.8.1 h1:CYhhDtd4ZeFYfHXSinVQpvH4mIPJHOqtQGUaSwBfpp8= +github.com/nextmv-io/sdk v1.8.1/go.mod h1:Y48XLPcIOOxRgO86ICNpqGrH2N5+dd1TDNvef/FD2Kc= github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc= github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= github.com/pascaldekloe/goe v0.1.0/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=