Skip to content

Commit

Permalink
improve reading duration matrices from input
Browse files Browse the repository at this point in the history
  • Loading branch information
nilsbeck committed Oct 31, 2024
1 parent 6f99e4a commit fa1c31c
Showing 1 changed file with 4 additions and 15 deletions.
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

0 comments on commit fa1c31c

Please sign in to comment.