Skip to content

Commit

Permalink
Merge pull request #34 from nextmv-io/feature/eng-5080-nextroute-addi…
Browse files Browse the repository at this point in the history
…ng-initial-stops-to-a-solution-constraint

Nextroute adding initial stops to a solution constraint check
  • Loading branch information
davidrijsman authored Apr 29, 2024
2 parents 8f5ec34 + 6382b82 commit 0003d5d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion solution.go
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ func (s *solutionImpl) addInitialSolution(m Model) error {
)
}
}
move, err := NewMoveStops(planUnit, stopPositions)
move, err := newMoveStops(planUnit, stopPositions, false)
if err != nil {
return err
}
Expand Down
23 changes: 17 additions & 6 deletions solution_move_stops.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,11 +459,20 @@ func (m *solutionMoveStopsImpl) deltaTravelDurationValue() float64 {
return travelDuration
}

// NewMoveStops creates a new move. Exported to be used in tests not be used in
// SDK.
// NewMoveStops creates a new move and checks if the move is allowed and if so
// estimates the delta score.
func NewMoveStops(
planUnit SolutionPlanStopsUnit,
stopPositions StopPositions,
) (SolutionMoveStops, error) {
return newMoveStops(planUnit, stopPositions, true)
}

// newMoveStops creates a new move.
func newMoveStops(
planUnit SolutionPlanStopsUnit,
stopPositions StopPositions,
checkConstraintsAndEstimateDeltaScore bool,
) (SolutionMoveStops, error) {
if planUnit == nil {
return nil, fmt.Errorf("planUnit is nil")
Expand Down Expand Up @@ -631,9 +640,11 @@ func NewMoveStops(
valueSeen: 0,
allowed: true,
}
value, allowed, _ := planUnit.(*solutionPlanStopsUnitImpl).solution().checkConstraintsAndEstimateDeltaScore(move)
move.value = value
move.allowed = allowed
move.valueSeen = 1
if checkConstraintsAndEstimateDeltaScore {
value, allowed, _ := planUnit.(*solutionPlanStopsUnitImpl).solution().checkConstraintsAndEstimateDeltaScore(move)
move.value = value
move.allowed = allowed
move.valueSeen = 1
}
return move, nil
}

0 comments on commit 0003d5d

Please sign in to comment.