Skip to content

Commit

Permalink
Merge pull request #75 from nextmv-io/nilsbeck/fix-output-improve-dat…
Browse files Browse the repository at this point in the history
…a-reading

Nilsbeck/fix output improve data reading
  • Loading branch information
nilsbeck authored Oct 31, 2024
2 parents 2826705 + 2f06d19 commit 37870d5
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 22 deletions.
5 changes: 3 additions & 2 deletions check/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -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].
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions check/schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
19 changes: 4 additions & 15 deletions factory/vehicles.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
package factory

import (
"encoding/json"
"errors"
"fmt"

Expand Down Expand Up @@ -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
}
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down

0 comments on commit 37870d5

Please sign in to comment.