Class DefaultProblemChangeDirector<Solution_>
java.lang.Object
ai.timefold.solver.core.impl.solver.change.DefaultProblemChangeDirector<Solution_>
- All Implemented Interfaces:
ProblemChangeDirector
public final class DefaultProblemChangeDirector<Solution_>
extends Object
implements ProblemChangeDirector
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<Entity> voidAdd a newPlanningEntityinstance into theworking solution.<ProblemFact>
voidaddProblemFact(@NonNull ProblemFact problemFact, @NonNull Consumer<ProblemFact> problemFactConsumer) Add a new problem fact into theworking solution.<EntityOrProblemFact>
voidchangeProblemProperty(@NonNull EntityOrProblemFact problemFactOrEntity, @NonNull Consumer<EntityOrProblemFact> problemFactOrEntityConsumer) Change a property of either aPlanningEntityor a problem fact.<Entity> voidchangeVariable(@NonNull Entity entity, @NonNull String variableName, @NonNull Consumer<Entity> entityConsumer) Change aPlanningVariablevalue of aPlanningEntity.<EntityOrProblemFact>
Optional<EntityOrProblemFact>lookUpWorkingObject(EntityOrProblemFact externalObject) As defined byProblemChangeDirector.lookUpWorkingObjectOrFail(Object), but doesn't fail fast if no workingObject was ever added for the externalObject.<EntityOrProblemFact>
@Nullable EntityOrProblemFactlookUpWorkingObjectOrFail(@Nullable EntityOrProblemFact externalObject) Translate an entity or fact instance (often from anotherThreador JVM) to thisProblemChangeDirector's internal working instance.<Entity> voidremoveEntity(@NonNull Entity entity, @NonNull Consumer<Entity> entityConsumer) Remove an existingPlanningEntityinstance from theworking solution.<ProblemFact>
voidremoveProblemFact(@NonNull ProblemFact problemFact, @NonNull Consumer<ProblemFact> problemFactConsumer) Remove an existing problem fact from theworking solution.voidCalls variable listeners on the external changes submitted so far.
-
Constructor Details
-
DefaultProblemChangeDirector
-
-
Method Details
-
addEntity
Description copied from interface:ProblemChangeDirectorAdd a newPlanningEntityinstance into theworking solution.- Specified by:
addEntityin interfaceProblemChangeDirector- Type Parameters:
Entity- the planning entity object type- Parameters:
entity- thePlanningEntityinstanceentityConsumer- adds the entity to theworking solution
-
removeEntity
Description copied from interface:ProblemChangeDirectorRemove an existingPlanningEntityinstance from theworking solution. Translates the entity to a working planning entity by performing a lookup as defined byProblemChangeDirector.lookUpWorkingObjectOrFail(Object).- Specified by:
removeEntityin interfaceProblemChangeDirector- Type Parameters:
Entity- the planning entity object type- Parameters:
entity- thePlanningEntityinstanceentityConsumer- removes the working entity from theworking solution
-
changeVariable
public <Entity> void changeVariable(@NonNull Entity entity, @NonNull String variableName, @NonNull Consumer<Entity> entityConsumer) Description copied from interface:ProblemChangeDirectorChange aPlanningVariablevalue of aPlanningEntity. Translates the entity to a working planning entity by performing a lookup as defined byProblemChangeDirector.lookUpWorkingObjectOrFail(Object).- Specified by:
changeVariablein interfaceProblemChangeDirector- Type Parameters:
Entity- the planning entity object type- Parameters:
entity- thePlanningEntityinstancevariableName- name of thePlanningVariableentityConsumer- updates the value of thePlanningVariableinside thePlanningEntity
-
addProblemFact
public <ProblemFact> void addProblemFact(@NonNull ProblemFact problemFact, @NonNull Consumer<ProblemFact> problemFactConsumer) Description copied from interface:ProblemChangeDirectorAdd a new problem fact into theworking solution.- Specified by:
addProblemFactin interfaceProblemChangeDirector- Type Parameters:
ProblemFact- the problem fact object type- Parameters:
problemFact- the problem fact instanceproblemFactConsumer- removes the working problem fact from theworking solution
-
removeProblemFact
public <ProblemFact> void removeProblemFact(@NonNull ProblemFact problemFact, @NonNull Consumer<ProblemFact> problemFactConsumer) Description copied from interface:ProblemChangeDirectorRemove an existing problem fact from theworking solution. Translates the problem fact to a working problem fact by performing a lookup as defined byProblemChangeDirector.lookUpWorkingObjectOrFail(Object).- Specified by:
removeProblemFactin interfaceProblemChangeDirector- Type Parameters:
ProblemFact- the problem fact object type- Parameters:
problemFact- the problem fact instanceproblemFactConsumer- removes the working problem fact from theworking solution
-
changeProblemProperty
public <EntityOrProblemFact> void changeProblemProperty(@NonNull EntityOrProblemFact problemFactOrEntity, @NonNull Consumer<EntityOrProblemFact> problemFactOrEntityConsumer) Description copied from interface:ProblemChangeDirectorChange a property of either aPlanningEntityor a problem fact. Translates the entity or the problem fact to itsworking solutioncounterpart by performing a lookup as defined byProblemChangeDirector.lookUpWorkingObjectOrFail(Object).- Specified by:
changeProblemPropertyin interfaceProblemChangeDirector- Type Parameters:
EntityOrProblemFact- the planning entity or problem fact object type- Parameters:
problemFactOrEntity- thePlanningEntityor the problem fact instanceproblemFactOrEntityConsumer- updates the property of thePlanningEntityor the problem fact
-
lookUpWorkingObjectOrFail
public <EntityOrProblemFact> @Nullable EntityOrProblemFact lookUpWorkingObjectOrFail(@Nullable EntityOrProblemFact externalObject) Description copied from interface:ProblemChangeDirectorTranslate an entity or fact instance (often from anotherThreador JVM) to thisProblemChangeDirector's internal working instance.Matching is determined by the
LookUpStrategyTypeonPlanningSolution. Matching uses aPlanningIdby default.- Specified by:
lookUpWorkingObjectOrFailin interfaceProblemChangeDirector- Type Parameters:
EntityOrProblemFact- the object type- Returns:
- null if externalObject is null
-
lookUpWorkingObject
public <EntityOrProblemFact> Optional<EntityOrProblemFact> lookUpWorkingObject(EntityOrProblemFact externalObject) Description copied from interface:ProblemChangeDirectorAs defined byProblemChangeDirector.lookUpWorkingObjectOrFail(Object), but doesn't fail fast if no workingObject was ever added for the externalObject. It's recommended to useProblemChangeDirector.lookUpWorkingObjectOrFail(Object)instead.- Specified by:
lookUpWorkingObjectin interfaceProblemChangeDirector- Type Parameters:
EntityOrProblemFact- the object type- Returns:
Optional.empty()if externalObject is null or if there is no workingObject for externalObject
-
updateShadowVariables
public void updateShadowVariables()Description copied from interface:ProblemChangeDirectorCalls variable listeners on the external changes submitted so far.This happens automatically after the entire
ProblemChangehas been processed, but this method allows the user to specifically request it in the middle of theProblemChange.- Specified by:
updateShadowVariablesin interfaceProblemChangeDirector
-