Interface ConstraintFactory
- All Known Implementing Classes:
BavetConstraintFactory,InnerConstraintFactory
ConstraintStream (for example with forEach(Class))
which ends in a Constraint returned by ConstraintProvider.defineConstraints(ConstraintFactory).-
Method Summary
Modifier and TypeMethodDescription<A> @NonNull UniConstraintStream<A>Start aConstraintStreamof all instances of the sourceClass that are known asproblem factsorplanning entities.default <A> @NonNull UniConstraintStream<A>forEachIncludingNullVars(@NonNull Class<A> sourceClass) Deprecated, for removal: This API element is subject to removal in a future version.<A> @NonNull UniConstraintStream<A>forEachIncludingUnassigned(@NonNull Class<A> sourceClass) As defined byforEach(Class), but without any filtering of unassignedplanning entities(forPlanningVariable.allowsUnassigned()) or shadow entities not assigned to any applicable list variable (forPlanningListVariable.allowsUnassignedValues()).default <A> @NonNull BiConstraintStream<A,A> forEachUniquePair(@NonNull Class<A> sourceClass) Create a newBiConstraintStreamfor every unique combination of A and another A with a higherPlanningId.default <A> @NonNull BiConstraintStream<A,A> forEachUniquePair(@NonNull Class<A> sourceClass, @NonNull BiJoiner<A, A> joiner) Create a newBiConstraintStreamfor every unique combination of A and another A with a higherPlanningIdfor which theBiJoineris true (for the properties it extracts from both facts).<A> @NonNull BiConstraintStream<A,A> forEachUniquePair(@NonNull Class<A> sourceClass, @NonNull BiJoiner<A, A>... joiners) As defined byforEachUniquePair(Class, BiJoiner).default <A> @NonNull BiConstraintStream<A,A> forEachUniquePair(@NonNull Class<A> sourceClass, @NonNull BiJoiner<A, A> joiner1, @NonNull BiJoiner<A, A> joiner2) As defined byforEachUniquePair(Class, BiJoiner).default <A> @NonNull BiConstraintStream<A,A> forEachUniquePair(@NonNull Class<A> sourceClass, @NonNull BiJoiner<A, A> joiner1, @NonNull BiJoiner<A, A> joiner2, @NonNull BiJoiner<A, A> joiner3) As defined byforEachUniquePair(Class, BiJoiner).default <A> @NonNull BiConstraintStream<A,A> forEachUniquePair(@NonNull Class<A> sourceClass, @NonNull BiJoiner<A, A> joiner1, @NonNull BiJoiner<A, A> joiner2, @NonNull BiJoiner<A, A> joiner3, @NonNull BiJoiner<A, A> joiner4) As defined byforEachUniquePair(Class, BiJoiner).<A> @NonNull UniConstraintStream<A>Deprecated, for removal: This API element is subject to removal in a future version.This method is deprecated in favor offorEach(Class), which exhibits the same behavior for planning variables which both allow and don't allow unassigned values.<A> @NonNull UniConstraintStream<A>fromUnfiltered(@NonNull Class<A> fromClass) Deprecated, for removal: This API element is subject to removal in a future version.default <A> @NonNull BiConstraintStream<A,A> fromUniquePair(@NonNull Class<A> fromClass) Deprecated, for removal: This API element is subject to removal in a future version.PreferforEachUniquePair(Class), which exhibits the same behavior for planning variables which both allow and don't allow unassigned values.default <A> @NonNull BiConstraintStream<A,A> fromUniquePair(@NonNull Class<A> fromClass, @NonNull BiJoiner<A, A> joiner) Deprecated, for removal: This API element is subject to removal in a future version.PreferforEachUniquePair(Class, BiJoiner), which exhibits the same behavior for planning variables which both allow and don't allow unassigned values.<A> @NonNull BiConstraintStream<A,A> fromUniquePair(@NonNull Class<A> fromClass, @NonNull BiJoiner<A, A>... joiners) Deprecated, for removal: This API element is subject to removal in a future version.PreferforEachUniquePair(Class, BiJoiner...), which exhibits the same behavior for planning variables which both allow and don't allow unassigned values.default <A> @NonNull BiConstraintStream<A,A> fromUniquePair(@NonNull Class<A> fromClass, @NonNull BiJoiner<A, A> joiner1, @NonNull BiJoiner<A, A> joiner2) Deprecated, for removal: This API element is subject to removal in a future version.PreferforEachUniquePair(Class, BiJoiner, BiJoiner), which exhibits the same behavior for planning variables which both allow and don't allow unassigned values.default <A> @NonNull BiConstraintStream<A,A> fromUniquePair(@NonNull Class<A> fromClass, @NonNull BiJoiner<A, A> joiner1, @NonNull BiJoiner<A, A> joiner2, @NonNull BiJoiner<A, A> joiner3) Deprecated, for removal: This API element is subject to removal in a future version.PreferforEachUniquePair(Class, BiJoiner, BiJoiner, BiJoiner), which exhibits the same behavior for planning variables which both allow and don't allow unassigned values.default <A> @NonNull BiConstraintStream<A,A> fromUniquePair(@NonNull Class<A> fromClass, @NonNull BiJoiner<A, A> joiner1, @NonNull BiJoiner<A, A> joiner2, @NonNull BiJoiner<A, A> joiner3, @NonNull BiJoiner<A, A> joiner4) Deprecated, for removal: This API element is subject to removal in a future version.PreferforEachUniquePair(Class, BiJoiner, BiJoiner, BiJoiner, BiJoiner), which exhibits the same behavior for planning variables which both allow and don't allow unassigned values.@NonNull StringDeprecated, for removal: This API element is subject to removal in a future version.Do not rely on any constraint package in user code.
-
Method Details
-
getDefaultConstraintPackage
Deprecated, for removal: This API element is subject to removal in a future version.Do not rely on any constraint package in user code. -
forEach
Start 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
-
forEachIncludingNullVars
@Deprecated(forRemoval=true, since="1.8.0") default <A> @NonNull UniConstraintStream<A> forEachIncludingNullVars(@NonNull Class<A> sourceClass) Deprecated, for removal: This API element is subject to removal in a future version.UseforEachIncludingUnassigned(Class)instead.As defined byforEachIncludingUnassigned(Class). -
forEachIncludingUnassigned
As defined byforEach(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
-
forEachUniquePair
Create a newBiConstraintStreamfor every unique combination of A and another A with a higherPlanningId.Important:
Filteringthis is slower and less scalable than using ajoiner, because it barely applies hashing and/or indexing on the properties, so it creates and checks almost every combination of A and A.This method is syntactic sugar for
UniConstraintStream.join(Class). It automatically adds alessThanjoiner on thePlanningIdof A.- Type Parameters:
A- the type of the matched problem fact orplanning entity- Returns:
- a stream that matches every unique combination of A and another A
-
forEachUniquePair
default <A> @NonNull BiConstraintStream<A,A> forEachUniquePair(@NonNull Class<A> sourceClass, @NonNull BiJoiner<A, A> joiner) Create a newBiConstraintStreamfor every unique combination of A and another A with a higherPlanningIdfor which theBiJoineris true (for the properties it extracts from both facts).Important: This is faster and more scalable than not using a
forEachUniquePair(Class)joiner} followed by afilter, because it applies hashing and/or indexing on the properties, so it doesn't create nor checks almost every combination of A and A.This method is syntactic sugar for
UniConstraintStream.join(Class, BiJoiner). It automatically adds alessThanjoiner on thePlanningIdof A.This method has overloaded methods with multiple
BiJoinerparameters.- Type Parameters:
A- the type of the matched problem fact orplanning entity- Returns:
- a stream that matches every unique combination of A and another A for which the
BiJoineris true
-
forEachUniquePair
default <A> @NonNull BiConstraintStream<A,A> forEachUniquePair(@NonNull Class<A> sourceClass, @NonNull BiJoiner<A, A> joiner1, @NonNull BiJoiner<A, A> joiner2) As defined byforEachUniquePair(Class, BiJoiner).- Type Parameters:
A- the type of the matched problem fact orplanning entity- Returns:
- a stream that matches every unique combination of A and another A for which all the
joinersare true
-
forEachUniquePair
default <A> @NonNull BiConstraintStream<A,A> forEachUniquePair(@NonNull Class<A> sourceClass, @NonNull BiJoiner<A, A> joiner1, @NonNull BiJoiner<A, A> joiner2, @NonNull BiJoiner<A, A> joiner3) As defined byforEachUniquePair(Class, BiJoiner).- Type Parameters:
A- the type of the matched problem fact orplanning entity- Returns:
- a stream that matches every unique combination of A and another A for which all the
joinersare true
-
forEachUniquePair
default <A> @NonNull BiConstraintStream<A,A> forEachUniquePair(@NonNull Class<A> sourceClass, @NonNull BiJoiner<A, A> joiner1, @NonNull BiJoiner<A, A> joiner2, @NonNull BiJoiner<A, A> joiner3, @NonNull BiJoiner<A, A> joiner4) As defined byforEachUniquePair(Class, BiJoiner).- Type Parameters:
A- the type of the matched problem fact orplanning entity- Returns:
- a stream that matches every unique combination of A and another A for which all the
joinersare true
-
forEachUniquePair
<A> @NonNull BiConstraintStream<A,A> forEachUniquePair(@NonNull Class<A> sourceClass, @NonNull BiJoiner<A, A>... joiners) As defined byforEachUniquePair(Class, BiJoiner).This method causes Unchecked generics array creation for varargs parameter warnings, but we can't fix it with a
SafeVarargsannotation because it's an interface method. Therefore, there are overloaded methods with up to 4BiJoinerparameters.- Type Parameters:
A- the type of the matched problem fact orplanning entity- Returns:
- a stream that matches every unique combination of A and another A for which all the
joinersare true
-
from
Deprecated, for removal: This API element is subject to removal in a future version.This method is deprecated in favor offorEach(Class), which exhibits the same behavior for planning variables which both allow and don't allow unassigned values.This method is deprecated. Migrate uses of this method toforEach(Class), but first understand this:- If none of your planning variables
allow unassigned values, then the replacement byforEach(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 withforEach(Class)family of methods and with joining. - If any of your planning variables
allow unassigned values, then there is severe impact. Calls to theforEach(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 useforEachIncludingUnassigned(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
@Deprecated(forRemoval=true) <A> @NonNull UniConstraintStream<A> fromUnfiltered(@NonNull Class<A> fromClass) Deprecated, for removal: This API element is subject to removal in a future version.This method is deprecated. Migrate uses of this method toforEachIncludingUnassigned(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
from(Class), but without any filtering of uninitializedplanning entities.- Type Parameters:
A- the type of the matched problem fact orplanning entity
-
fromUniquePair
@Deprecated(forRemoval=true) default <A> @NonNull BiConstraintStream<A,A> fromUniquePair(@NonNull Class<A> fromClass) Deprecated, for removal: This API element is subject to removal in a future version.PreferforEachUniquePair(Class), which exhibits the same behavior for planning variables which both allow and don't allow unassigned values.This method is deprecated. Migrate uses of this method toforEachUniquePair(Class), but first understand that the same precautions apply as with the use offrom(Class).The original Javadoc of this method follows:
Create a new
BiConstraintStreamfor every unique combination of A and another A with a higherPlanningId.Important:
Filteringthis is slower and less scalable than using ajoiner, because it barely applies hashing and/or indexing on the properties, so it creates and checks almost every combination of A and A.This method is syntactic sugar for
UniConstraintStream.join(Class). It automatically adds alessThanjoiner on thePlanningIdof A.- Type Parameters:
A- the type of the matched problem fact orplanning entity- Returns:
- a stream that matches every unique combination of A and another A
-
fromUniquePair
@Deprecated(forRemoval=true) default <A> @NonNull BiConstraintStream<A,A> fromUniquePair(@NonNull Class<A> fromClass, @NonNull BiJoiner<A, A> joiner) Deprecated, for removal: This API element is subject to removal in a future version.PreferforEachUniquePair(Class, BiJoiner), which exhibits the same behavior for planning variables which both allow and don't allow unassigned values.This method is deprecated. Migrate uses of this method toforEachUniquePair(Class, BiJoiner), but first understand that the same precautions apply as with the use offrom(Class).The original Javadoc of this method follows:
Create a new
BiConstraintStreamfor every unique combination of A and another A with a higherPlanningIdfor which theBiJoineris true (for the properties it extracts from both facts).Important: This is faster and more scalable than not using a
fromUniquePair(Class)joiner} followed by afilter, because it applies hashing and/or indexing on the properties, so it doesn't create nor checks almost every combination of A and A.This method is syntactic sugar for
UniConstraintStream.join(Class, BiJoiner). It automatically adds alessThanjoiner on thePlanningIdof A.This method has overloaded methods with multiple
BiJoinerparameters.- Type Parameters:
A- the type of the matched problem fact orplanning entity- Returns:
- a stream that matches every unique combination of A and another A for which the
BiJoineris true
-
fromUniquePair
@Deprecated(forRemoval=true) default <A> @NonNull BiConstraintStream<A,A> fromUniquePair(@NonNull Class<A> fromClass, @NonNull BiJoiner<A, A> joiner1, @NonNull BiJoiner<A, A> joiner2) Deprecated, for removal: This API element is subject to removal in a future version.PreferforEachUniquePair(Class, BiJoiner, BiJoiner), which exhibits the same behavior for planning variables which both allow and don't allow unassigned values.This method is deprecated. Migrate uses of this method toforEachUniquePair(Class, BiJoiner, BiJoiner), but first understand that the same precautions apply as with the use offrom(Class).The original Javadoc of this method follows:
As defined by
fromUniquePair(Class, BiJoiner).- Type Parameters:
A- the type of the matched problem fact orplanning entity- Returns:
- a stream that matches every unique combination of A and another A for which all the
joinersare true
-
fromUniquePair
@Deprecated(forRemoval=true) default <A> @NonNull BiConstraintStream<A,A> fromUniquePair(@NonNull Class<A> fromClass, @NonNull BiJoiner<A, A> joiner1, @NonNull BiJoiner<A, A> joiner2, @NonNull BiJoiner<A, A> joiner3) Deprecated, for removal: This API element is subject to removal in a future version.PreferforEachUniquePair(Class, BiJoiner, BiJoiner, BiJoiner), which exhibits the same behavior for planning variables which both allow and don't allow unassigned values.This method is deprecated. Migrate uses of this method toforEachUniquePair(Class, BiJoiner, BiJoiner, BiJoiner), but first understand that the same precautions apply as with the use offrom(Class).The original Javadoc of this method follows:
As defined by
fromUniquePair(Class, BiJoiner).- Type Parameters:
A- the type of the matched problem fact orplanning entity- Returns:
- a stream that matches every unique combination of A and another A for which all the
joinersare true
-
fromUniquePair
@Deprecated(forRemoval=true) default <A> @NonNull BiConstraintStream<A,A> fromUniquePair(@NonNull Class<A> fromClass, @NonNull BiJoiner<A, A> joiner1, @NonNull BiJoiner<A, A> joiner2, @NonNull BiJoiner<A, A> joiner3, @NonNull BiJoiner<A, A> joiner4) Deprecated, for removal: This API element is subject to removal in a future version.PreferforEachUniquePair(Class, BiJoiner, BiJoiner, BiJoiner, BiJoiner), which exhibits the same behavior for planning variables which both allow and don't allow unassigned values.This method is deprecated. Migrate uses of this method toforEachUniquePair(Class, BiJoiner, BiJoiner, BiJoiner, BiJoiner), but first understand that the same precautions apply as with the use offrom(Class).The original Javadoc of this method follows:
As defined by
fromUniquePair(Class, BiJoiner).- Type Parameters:
A- the type of the matched problem fact orplanning entity- Returns:
- a stream that matches every unique combination of A and another A for which all the
joinersare true
-
fromUniquePair
@Deprecated(forRemoval=true) <A> @NonNull BiConstraintStream<A,A> fromUniquePair(@NonNull Class<A> fromClass, @NonNull BiJoiner<A, A>... joiners) Deprecated, for removal: This API element is subject to removal in a future version.PreferforEachUniquePair(Class, BiJoiner...), which exhibits the same behavior for planning variables which both allow and don't allow unassigned values.This method is deprecated. Migrate uses of this method toforEachUniquePair(Class, BiJoiner...), but first understand that the same precautions apply as with the use offrom(Class).The original Javadoc of this method follows:
As defined by
fromUniquePair(Class, BiJoiner).This method causes Unchecked generics array creation for varargs parameter warnings, but we can't fix it with a
SafeVarargsannotation because it's an interface method. Therefore, there are overloaded methods with up to 4BiJoinerparameters.- Type Parameters:
A- the type of the matched problem fact orplanning entity- Returns:
- a stream that matches every unique combination of A and another A for which all the
joinersare true
-
forEachIncludingUnassigned(Class)instead.