Class BavetConstraintFactory<Solution_>
- All Implemented Interfaces:
ConstraintFactory
-
Constructor Summary
ConstructorsConstructorDescriptionBavetConstraintFactory(SolutionDescriptor<Solution_> solutionDescriptor, EnvironmentMode environmentMode) -
Method Summary
Modifier and TypeMethodDescription<A> @NonNull UniConstraintStream<A>Start aConstraintStreamof all instances of the sourceClass that are known asproblem factsorplanning entities.<A> @NonNull UniConstraintStream<A>forEachIncludingUnassigned(@NonNull Class<A> sourceClass) As defined byConstraintFactory.forEach(Class), but without any filtering of unassignedplanning entities(forPlanningVariable.allowsUnassigned()) or shadow entities not assigned to any applicable list variable (forPlanningListVariable.allowsUnassignedValues()).<A> @NonNull UniConstraintStream<A>This method is deprecated.<A> @NonNull UniConstraintStream<A>fromUnfiltered(@NonNull Class<A> fromClass) This method is deprecated.@NonNull String<Stream_ extends BavetAbstractConstraintStream<Solution_>>
Stream_share(Stream_ stream) <Stream_ extends BavetAbstractConstraintStream<Solution_>>
Stream_Enables node sharing.Methods inherited from class ai.timefold.solver.core.impl.score.stream.common.InnerConstraintFactory
assertValidFromType, buildConstraints, forEachUniquePair, fromUniquePairMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ai.timefold.solver.core.api.score.stream.ConstraintFactory
forEachIncludingNullVars, forEachUniquePair, forEachUniquePair, forEachUniquePair, forEachUniquePair, forEachUniquePair, fromUniquePair, fromUniquePair, fromUniquePair, fromUniquePair, fromUniquePair
-
Constructor Details
-
BavetConstraintFactory
public BavetConstraintFactory(SolutionDescriptor<Solution_> solutionDescriptor, EnvironmentMode environmentMode)
-
-
Method Details
-
forEach
Description copied from interface:ConstraintFactoryStart aConstraintStreamof all instances of the sourceClass that are known asproblem factsorplanning entities.If the sourceClass is a
PlanningEntity, then it is automaticallyfilteredto only contain entities for which each genuinePlanningVariable(of the sourceClass or a superclass thereof) has a non-null value.If the sourceClass is a shadow entity (an entity without any genuine planning variables), and if there exists a genuine
PlanningEntitywith aPlanningListVariablewhich accepts instances of this shadow entity as values in that list, and if that list variableallows unassigned values, then this stream will filter out all sourceClass instances which are not present in any instances of that list variable. This is achieved in one of two ways:- If the sourceClass has
InverseRelationShadowVariablefield referencing instance of an entity with the list variable, the value of that field will be used to determine if the value is assigned. Null in that field means the instance of sourceClass is unassigned. - As fallback, the value is considered assigned if there exists
an instance of the entity where its list variable contains the value.
This will perform significantly worse and only exists
so that using the
InverseRelationShadowVariablecan remain optional. Adding the field is strongly recommended.
- Type Parameters:
A- the type of the matched problem fact orplanning entity
- If the sourceClass has
-
forEachIncludingUnassigned
public <A> @NonNull UniConstraintStream<A> forEachIncludingUnassigned(@NonNull Class<A> sourceClass) Description copied from interface:ConstraintFactoryAs defined byConstraintFactory.forEach(Class), but without any filtering of unassignedplanning entities(forPlanningVariable.allowsUnassigned()) or shadow entities not assigned to any applicable list variable (forPlanningListVariable.allowsUnassignedValues()).- Type Parameters:
A- the type of the matched problem fact orplanning entity
-
from
Description copied from interface:ConstraintFactoryThis method is deprecated. Migrate uses of this method toConstraintFactory.forEach(Class), but first understand this:- If none of your planning variables
allow unassigned values, then the replacement byConstraintFactory.forEach(Class)has little to no impact. Subsequent conditional propagation calls (UniConstraintStream.ifExists(java.lang.Class<B>, ai.timefold.solver.core.api.score.stream.bi.BiJoiner<A, B>)etc.) will now also filter out planning entities with null variables, consistently withConstraintFactory.forEach(Class)family of methods and with joining. - If any of your planning variables
allow unassigned values, then there is severe impact. Calls to theConstraintFactory.forEach(Class)family of methods will now filter out planning entities with null variables, so most constraints no longer need to do null checks, but the constraint that penalizes unassigned entities (typically a medium constraint) must now useConstraintFactory.forEachIncludingUnassigned(Class)instead. Subsequent joins and conditional propagation calls will now also consistently filter out planning entities with null variables.
The original Javadoc of this method follows:
Start a
ConstraintStreamof all instances of the fromClass that are known asproblem factsorplanning entities.If the fromClass is a
PlanningEntity, then it is automaticallyfilteredto only contain fully initialized entities, for which each genuinePlanningVariable(of the fromClass or a superclass thereof) is initialized. This filtering will NOT automatically apply to genuine planning variables of subclass planning entities of the fromClass.- Type Parameters:
A- the type of the matched problem fact orplanning entity
- If none of your planning variables
-
fromUnfiltered
Description copied from interface:ConstraintFactoryThis method is deprecated. Migrate uses of this method toConstraintFactory.forEachIncludingUnassigned(Class), but first understand that subsequent joins and conditional propagation calls (UniConstraintStream.ifExists(java.lang.Class<B>, ai.timefold.solver.core.api.score.stream.bi.BiJoiner<A, B>)etc.) will now also consistently filter out planning entities with null variables.The original Javadoc of this method follows:
As defined by
ConstraintFactory.from(Class), but without any filtering of uninitializedplanning entities.- Type Parameters:
A- the type of the matched problem fact orplanning entity
-
getSolutionDescriptor
- Specified by:
getSolutionDescriptorin classInnerConstraintFactory<Solution_,BavetConstraint<Solution_>> - Returns:
- never null
-
getEnvironmentMode
-
getDefaultConstraintPackage