Interface SolutionManager<Solution_,Score_ extends Score<Score_>>
- Type Parameters:
Solution_- the solution type, the class with thePlanningSolutionannotationScore_- the actual score type
- All Known Implementing Classes:
DefaultSolutionManager
Score, ConstraintMatchTotal,
Indictment, etc.
To create a SolutionManager instance, use create(SolverFactory).
These methods are thread-safe unless explicitly stated otherwise.
-
Method Summary
Modifier and TypeMethodDescriptiondefault ScoreAnalysis<Score_>default ScoreAnalysis<Score_>analyze(Solution_ solution, ScoreAnalysisFetchPolicy fetchPolicy) analyze(Solution_ solution, ScoreAnalysisFetchPolicy fetchPolicy, SolutionUpdatePolicy solutionUpdatePolicy) Calculates and retrieves information about which constraints contributed to the solution's score.static <Solution_,Score_ extends Score<Score_>>
SolutionManager<Solution_,Score_> create(SolverFactory<Solution_> solverFactory) Uses aSolverFactoryto build aSolutionManager.static <Solution_,Score_ extends Score<Score_>, ProblemId_>
SolutionManager<Solution_,Score_> create(SolverManager<Solution_, ProblemId_> solverManager) Uses aSolverManagerto build aSolutionManager.default ScoreExplanation<Solution_,Score_> As defined byexplain(Object, SolutionUpdatePolicy), usingSolutionUpdatePolicy.UPDATE_ALL.explain(Solution_ solution, SolutionUpdatePolicy solutionUpdatePolicy) Calculates and retrievesConstraintMatchTotals andIndictments necessary for describing the quality of a particular solution.default <EntityOrElement_,Proposition_>
List<RecommendedAssignment<Proposition_,Score_>> recommendAssignment(Solution_ solution, EntityOrElement_ evaluatedEntityOrElement, Function<EntityOrElement_, Proposition_> propositionFunction) <EntityOrElement_,Proposition_>
List<RecommendedAssignment<Proposition_,Score_>> recommendAssignment(Solution_ solution, EntityOrElement_ evaluatedEntityOrElement, Function<EntityOrElement_, Proposition_> propositionFunction, ScoreAnalysisFetchPolicy fetchPolicy) Quickly runs through all possible options of assigning a given entity or element in a given solution, and returns a list of recommendations sorted by score, with most favorable score first.default <EntityOrElement_,Proposition_>
List<RecommendedFit<Proposition_,Score_>> recommendFit(Solution_ solution, EntityOrElement_ fittedEntityOrElement, Function<EntityOrElement_, Proposition_> propositionFunction) Deprecated, for removal: This API element is subject to removal in a future version.<EntityOrElement_,Proposition_>
List<RecommendedFit<Proposition_,Score_>> recommendFit(Solution_ solution, EntityOrElement_ fittedEntityOrElement, Function<EntityOrElement_, Proposition_> propositionFunction, ScoreAnalysisFetchPolicy fetchPolicy) Deprecated, for removal: This API element is subject to removal in a future version.default Score_As defined byupdate(Object, SolutionUpdatePolicy), usingSolutionUpdatePolicy.UPDATE_ALL.update(Solution_ solution, SolutionUpdatePolicy solutionUpdatePolicy) Updates the given solution according to theSolutionUpdatePolicy.
-
Method Details
-
create
static <Solution_,Score_ extends Score<Score_>> SolutionManager<Solution_,Score_> create(SolverFactory<Solution_> solverFactory) Uses aSolverFactoryto build aSolutionManager.- Type Parameters:
Solution_- the solution type, the class with thePlanningSolutionannotationScore_- the actual score type- Parameters:
solverFactory- never null- Returns:
- never null
-
create
static <Solution_,Score_ extends Score<Score_>, SolutionManager<Solution_,ProblemId_> Score_> create(SolverManager<Solution_, ProblemId_> solverManager) Uses aSolverManagerto build aSolutionManager.- Type Parameters:
Solution_- the solution type, the class with thePlanningSolutionannotationScore_- the actual score typeProblemId_- the ID type of a submitted problem, such asLongorUUID- Parameters:
solverManager- never null- Returns:
- never null
-
update
As defined byupdate(Object, SolutionUpdatePolicy), usingSolutionUpdatePolicy.UPDATE_ALL. -
update
Updates the given solution according to theSolutionUpdatePolicy.- Parameters:
solution- never nullsolutionUpdatePolicy- never null; if unsure, pickSolutionUpdatePolicy.UPDATE_ALL- Returns:
- possibly null if already null and
SolutionUpdatePolicydidn't cause its update - See Also:
-
explain
As defined byexplain(Object, SolutionUpdatePolicy), usingSolutionUpdatePolicy.UPDATE_ALL. -
explain
ScoreExplanation<Solution_,Score_> explain(Solution_ solution, SolutionUpdatePolicy solutionUpdatePolicy) Calculates and retrievesConstraintMatchTotals andIndictments necessary for describing the quality of a particular solution. For a simplified, faster and JSON-friendly alternative, seeanalyze(Object)}.- Parameters:
solution- never nullsolutionUpdatePolicy- never null; if unsure, pickSolutionUpdatePolicy.UPDATE_ALL- Returns:
- never null
- Throws:
IllegalStateException- when constraint matching is disabled or not supported by the underlying score calculator, such asEasyScoreCalculator.- See Also:
-
analyze
-
analyze
-
analyze
ScoreAnalysis<Score_> analyze(Solution_ solution, ScoreAnalysisFetchPolicy fetchPolicy, SolutionUpdatePolicy solutionUpdatePolicy) Calculates and retrieves information about which constraints contributed to the solution's score. This is a faster, JSON-friendly version ofexplain(Object).- Parameters:
solution- never null, must be fully initialized otherwise an exception is thrownfetchPolicy- never null; if unsure, pickScoreAnalysisFetchPolicy.FETCH_ALLsolutionUpdatePolicy- never null; if unsure, pickSolutionUpdatePolicy.UPDATE_ALL- Returns:
- never null
- Throws:
IllegalStateException- when constraint matching is disabled or not supported by the underlying score calculator, such asEasyScoreCalculator.- See Also:
-
recommendAssignment
default <EntityOrElement_,Proposition_> List<RecommendedAssignment<Proposition_,Score_>> recommendAssignment(Solution_ solution, EntityOrElement_ evaluatedEntityOrElement, Function<EntityOrElement_, Proposition_> propositionFunction) -
recommendAssignment
<EntityOrElement_,Proposition_> List<RecommendedAssignment<Proposition_,Score_>> recommendAssignment(Solution_ solution, EntityOrElement_ evaluatedEntityOrElement, Function<EntityOrElement_, Proposition_> propositionFunction, ScoreAnalysisFetchPolicy fetchPolicy) Quickly runs through all possible options of assigning a given entity or element in a given solution, and returns a list of recommendations sorted by score, with most favorable score first. The input solution must either be fully initialized, or have a single entity or element unassigned.For problems with only basic planning variables or with chained planning variables, the fitted element is a planning entity of the problem. Each available planning value will be tested by setting it to the planning variable in question. For problems with a list variable, the evaluated element may be a shadow entity, and it will be tested in each position of the planning list variable.
The score returned by
RecommendedAssignment.scoreAnalysisDiff()is the difference between the score of the solution before and after fitting. Every recommendation will be in a state as if the solution was never changed; if it references entities, none of their genuine planning variables or shadow planning variables will be initialized. The input solution will be unchanged.This method does not call local search, it runs a fast greedy algorithm instead. The construction heuristic configuration from the solver configuration is used. If not present, the default construction heuristic configuration is used. This means that the API will fail if the solver config requires custom initialization phase. In this case, it will fail either directly by throwing an exception, or indirectly by not providing correct data.
When an element is tested, a score is calculated over the entire solution with the element in place, also called a placement. The proposition function is also called at that time, allowing the user to extract any information from the current placement; the extracted information is called the proposition. After the proposition is extracted, the solution is returned to its original state, resetting all changes made by the fitting. This has a major consequence for the proposition, if it is a planning entity: planning entities contain live data in their planning variables, and that data will be erased when the next placement is tested for fit. In this case, the proposition function needs to make defensive copies of everything it wants to return, such as values of shadow variables etc.
Example: Consider a planning entity Shift, with a variable "employee". Let's assume we have two employees to test for fit, Ann and Bob, and a single Shift instance to fit them into,
mondayShift. The proposition function will be called twice, once asmondayShift@Annand once asmondayShift@Bob. Let's assume the proposition function returns the Shift instance in its entirety. This is what will happen:- Calling propositionFunction on
mondayShift@Annresults in proposition P1:mondayShift@Ann - Placement is cleared,
mondayShift@Bobis now tested for fit. - Calling propositionFunction on
mondayShift@Bobresults in proposition P2:mondayShift@Bob - Proposition P1 and P2 are now both the same
mondayShift, which means Bob is now assigned to both of them. This is because both propositions operate on the same entity, and therefore share the same state. - The placement is then cleared again,
both elements have been tested,
and solution is returned to its original order.
The propositions are then returned to the user,
who notices that both P1 and P2 are
mondayShift@null. This is because they shared state, and the original state of the solution was for Shift to be unassigned.
- Type Parameters:
EntityOrElement_- generic type of the evaluated entity or elementProposition_- generic type of the user-provided proposition; if it is a planning entity, it is recommended to make a defensive copy inside the proposition function.- Parameters:
solution- never null; for basic variable, must be fully initialized or have a single entity unassigned. For list variable, all values must be assigned to some list, with the optional exception of one.evaluatedEntityOrElement- never null; must be part of the solution. For basic variable, it is a planning entity and may have one or more variables unassigned. For list variable, it is a shadow entity and need not be present in any list variable.propositionFunction- never nullfetchPolicy- never null;ScoreAnalysisFetchPolicy.FETCH_ALLwill include more data withinRecommendedAssignment, but will also take more time to gather that data.- Returns:
- never null, sorted from best to worst;
designed to be JSON-friendly, see
RecommendedAssignmentJavadoc for more. - See Also:
- Calling propositionFunction on
-
recommendFit
@Deprecated(forRemoval=true, since="1.15.0") default <EntityOrElement_,Proposition_> List<RecommendedFit<Proposition_,Score_>> recommendFit(Solution_ solution, EntityOrElement_ fittedEntityOrElement, Function<EntityOrElement_, Proposition_> propositionFunction) Deprecated, for removal: This API element is subject to removal in a future version. -
recommendFit
@Deprecated(forRemoval=true, since="1.15.0") <EntityOrElement_,Proposition_> List<RecommendedFit<Proposition_,Score_>> recommendFit(Solution_ solution, EntityOrElement_ fittedEntityOrElement, Function<EntityOrElement_, Proposition_> propositionFunction, ScoreAnalysisFetchPolicy fetchPolicy) Deprecated, for removal: This API element is subject to removal in a future version.
-
recommendAssignment(Object, Object, Function, ScoreAnalysisFetchPolicy).