Class SolverConfigOverride<Solution_>
- Type Parameters:
Solution_- the solution type, the class with thePlanningSolutionannotation
Solver configuration.
This class provides an API to override solver termination settings. The following options are available:
- Use
withTerminationConfig(TerminationConfig)to set a complete termination configuration - Use
withTerminationSpentLimit(Duration)and/orwithTerminationUnimprovedSpentLimit(Duration)to set specific time limits independently or in combination
Important ordering constraint: If withTerminationConfig(TerminationConfig) is used,
it must be called before any specific termination methods like withTerminationSpentLimit(Duration)
or withTerminationUnimprovedSpentLimit(Duration). This prevents accidental override of previously
set specific configurations.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription@NonNull SolverConfigOverride<Solution_>withTerminationConfig(@NonNull TerminationConfig terminationConfig) Sets the solverTerminationConfig, providing a base configuration that can be further customized with specific termination methods.@NonNull SolverConfigOverride<Solution_>withTerminationSpentLimit(@NonNull Duration spentLimit) Sets a time limit for the solver to run, creating or updating the default termination configuration.@NonNull SolverConfigOverride<Solution_>withTerminationUnimprovedSpentLimit(@NonNull Duration unimprovedSpentLimit) Sets a time limit for the solver to run without finding an improved solution, creating or updating the default termination configuration.
-
Constructor Details
-
SolverConfigOverride
public SolverConfigOverride()
-
-
Method Details
-
getTerminationConfig
-
withTerminationConfig
public @NonNull SolverConfigOverride<Solution_> withTerminationConfig(@NonNull TerminationConfig terminationConfig) Sets the solverTerminationConfig, providing a base configuration that can be further customized with specific termination methods.After calling this method, additional specific termination methods can be chained to further customize the configuration:
new SolverConfigOverride<MySolution>() .withTerminationConfig(new TerminationConfig()) .withTerminationSpentLimit(Duration.ofMinutes(5)) .withTerminationUnimprovedSpentLimit(Duration.ofMinutes(2));Important: This method must be called before any specific termination methods like
withTerminationSpentLimit(Duration)orwithTerminationUnimprovedSpentLimit(Duration).Calling this method after specific termination settings have been applied will throw an exception to prevent accidental override of those settings.
new SolverConfigOverride<MySolution>() .withTerminationSpentLimit(Duration.ofMinutes(5)) .withTerminationConfig(new TerminationConfig()); // Will throw exception- Parameters:
terminationConfig- allows overriding the default termination config ofSolver- Returns:
- this
- Throws:
IllegalStateException- if specific termination settings have already been applied
-
withTerminationSpentLimit
public @NonNull SolverConfigOverride<Solution_> withTerminationSpentLimit(@NonNull Duration spentLimit) Sets a time limit for the solver to run, creating or updating the default termination configuration.This method sets the maximum duration the solver is allowed to run before terminating. It can be used independently or in combination with
withTerminationUnimprovedSpentLimit(Duration).If no
TerminationConfighas been set viawithTerminationConfig(TerminationConfig), this method will create a new one. If a TerminationConfig already exists, this method will update its spent limit setting.Usage examples:
// Set only spent limit new SolverConfigOverride<MySolution>() .withTerminationSpentLimit(Duration.ofMinutes(10)); // Combine with unimproved spent limit new SolverConfigOverride<MySolution>() .withTerminationSpentLimit(Duration.ofMinutes(10)) .withTerminationUnimprovedSpentLimit(Duration.ofMinutes(3)); // Use with base config new SolverConfigOverride<MySolution>() .withTerminationConfig(new TerminationConfig()) .withTerminationSpentLimit(Duration.ofMinutes(10));- Parameters:
spentLimit- the maximum duration the solver is allowed to run- Returns:
- this
-
withTerminationUnimprovedSpentLimit
public @NonNull SolverConfigOverride<Solution_> withTerminationUnimprovedSpentLimit(@NonNull Duration unimprovedSpentLimit) Sets a time limit for the solver to run without finding an improved solution, creating or updating the default termination configuration.This method sets the maximum duration the solver is allowed to run without improvement before terminating. The solver will stop if it hasn't found a better solution within this time limit, even if the total spent limit (if set) hasn't been reached yet.
This method can be used independently or in combination with
withTerminationSpentLimit(Duration). When used together, the solver will terminate when either condition is met (whichever comes first).If no
TerminationConfighas been set viawithTerminationConfig(TerminationConfig), this method will create a new one. If a TerminationConfig already exists, this method will update its unimproved spent limit setting.Usage examples:
// Set only unimproved spent limit new SolverConfigOverride<MySolution>() .withTerminationUnimprovedSpentLimit(Duration.ofMinutes(2)); // Combine with total spent limit new SolverConfigOverride<MySolution>() .withTerminationSpentLimit(Duration.ofMinutes(10)) .withTerminationUnimprovedSpentLimit(Duration.ofMinutes(2)); // Use with base config new SolverConfigOverride<MySolution>() .withTerminationConfig(new TerminationConfig()) .withTerminationUnimprovedSpentLimit(Duration.ofMinutes(2));- Parameters:
unimprovedSpentLimit- the maximum duration the solver is allowed to run without improvement- Returns:
- this
-