Skip to content

Commit

Permalink
Fix direct precedence constraint violation in model_constraint_direct…
Browse files Browse the repository at this point in the history
…_precedences.go
  • Loading branch information
larsbeck committed Apr 22, 2024
1 parent 8e601f4 commit de045c8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
1 change: 0 additions & 1 deletion model_constraint_direct_precedence_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,4 @@ func TestDirectPrecedenceConstraint_EstimateIsViolated(t *testing.T) {
if planned {
t.Error("expected move to not be planned")
}

}
19 changes: 16 additions & 3 deletions model_constraint_direct_precedences.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,13 @@ func (l *directPrecedencesConstraintImpl) EstimateIsViolated(
modelImpl := move.PlanStopsUnit().Solution().Model().(*modelImpl)
stopPositions := move.StopPositions()
for _, stopPosition := range stopPositions {
stop := stopPosition.Stop().ModelStop()
modelStop := stopPosition.Stop().ModelStop()
previousModelStop := stopPosition.Previous().ModelStop()
if disallowed := modelImpl.disallowedSuccessors[previousModelStop.Index()][modelStop.Index()]; disallowed {
return true, noPositionsHint()
}
nextModelStop := stopPosition.Next().ModelStop()
if disallowed := modelImpl.disallowedSuccessors[stop.Index()][nextModelStop.Index()]; disallowed {
if disallowed := modelImpl.disallowedSuccessors[modelStop.Index()][nextModelStop.Index()]; disallowed {
return true, noPositionsHint()
}
}
Expand All @@ -89,8 +93,17 @@ func (l *directPrecedencesConstraintImpl) DoesStopHaveViolations(
) bool {
modelImpl := stop.Solution().Model().(*modelImpl)
stopImpl := stop.(solutionStopImpl)
if !stop.IsFirst() {
previousModelStop := stopImpl.previous().modelStop()
if disallowed := modelImpl.disallowedSuccessors[previousModelStop.Index()][stop.ModelStopIndex()]; disallowed {
return true
}
}
if stop.IsLast() {
return false
}
nextModelStop := stopImpl.next().modelStop()
if disallowed := modelImpl.disallowedSuccessors[stop.Index()][nextModelStop.Index()]; disallowed {
if disallowed := modelImpl.disallowedSuccessors[stop.ModelStopIndex()][nextModelStop.Index()]; disallowed {
return true
}
return false
Expand Down
4 changes: 2 additions & 2 deletions solution.go
Original file line number Diff line number Diff line change
Expand Up @@ -821,9 +821,9 @@ func resetStopInterfaceCache(solution *solutionImpl) {
[]SolutionStop,
len(solution.stop),
)
for idx, value := range solution.stop {
for idx := range solution.stop {
solution.stopByIndexCache[idx] = solutionStopImpl{
index: value,
index: idx,
solution: solution,
}
}
Expand Down

0 comments on commit de045c8

Please sign in to comment.