Skip to content

Commit

Permalink
Runtime check on at least one operator that checks for improvements.
Browse files Browse the repository at this point in the history
  • Loading branch information
David Rijsman committed Mar 18, 2024
1 parent c5d3ba2 commit 989ada4
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions solve_solver.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package nextroute
import (
"context"
"fmt"
"github.com/nextmv-io/nextroute/common"
"math/rand"
"slices"
"time"
Expand Down Expand Up @@ -231,6 +232,16 @@ func (s *solveImpl) Solve(
if len(s.solveOperators) == 0 {
return nil, fmt.Errorf("solver is empty, no solve operators provided")
}

if !common.HasTrue(s.solveOperators, func(operator SolveOperator) bool {
return operator.CanResultInImprovement()
}) {
return nil, fmt.Errorf(
"no solve operator can result in improvement," +
" enable CanResultInImprovement on at least one solve operator",
)
}

newWorkSolution := startSolutions[0].Copy()
s.bestSolution = startSolutions[0].Copy()
s.workSolution = newWorkSolution
Expand Down

0 comments on commit 989ada4

Please sign in to comment.