From 989ada43cbd2f17fb9dfe5b325bbf4da6e162f43 Mon Sep 17 00:00:00 2001 From: David Rijsman Date: Mon, 18 Mar 2024 09:32:15 +0100 Subject: [PATCH] Runtime check on at least one operator that checks for improvements. --- solve_solver.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/solve_solver.go b/solve_solver.go index ba0e3a2..313357b 100644 --- a/solve_solver.go +++ b/solve_solver.go @@ -5,6 +5,7 @@ package nextroute import ( "context" "fmt" + "github.com/nextmv-io/nextroute/common" "math/rand" "slices" "time" @@ -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