From 6382b8293996216d259c22695e2bdcfba64af057 Mon Sep 17 00:00:00 2001 From: David Rijsman Date: Mon, 29 Apr 2024 12:23:38 +0200 Subject: [PATCH] Allow the creation of a move within nextroute without checking all the constraints. --- solution.go | 2 +- solution_move_stops.go | 23 +++++++++++++++++------ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/solution.go b/solution.go index 75d5710..145846c 100644 --- a/solution.go +++ b/solution.go @@ -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 } diff --git a/solution_move_stops.go b/solution_move_stops.go index bbb62a8..731ff45 100644 --- a/solution_move_stops.go +++ b/solution_move_stops.go @@ -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") @@ -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 }