Class InnerConstraintFactory<Solution_,Constraint_ extends Constraint>
- java.lang.Object
-
- org.optaplanner.core.impl.score.stream.InnerConstraintFactory<Solution_,Constraint_>
-
- All Implemented Interfaces:
ConstraintFactory
- Direct Known Subclasses:
BavetConstraintFactory
,DroolsConstraintFactory
public abstract class InnerConstraintFactory<Solution_,Constraint_ extends Constraint> extends Object implements ConstraintFactory
-
-
Constructor Summary
Constructors Constructor Description InnerConstraintFactory()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description <A> void
assertValidFromType(Class<A> fromType)
List<Constraint_>
buildConstraints(ConstraintProvider constraintProvider)
<A> UniConstraintStream<A>
forEach(Class<A> sourceClass)
Start aConstraintStream
of all instances of the sourceClass that are known asproblem facts
orplanning entities
.<A> BiConstraintStream<A,A>
forEachUniquePair(Class<A> sourceClass, BiJoiner<A,A> joiner)
Create a newBiConstraintStream
for every unique combination of A and another A with a higherPlanningId
for which theBiJoiner
is true (for the properties it extracts from both facts).<A> UniConstraintStream<A>
from(Class<A> fromClass)
This method is deprecated.<A> BiConstraintStream<A,A>
fromUniquePair(Class<A> fromClass, BiJoiner<A,A> joiner)
This method is deprecated.<A> Predicate<A>
getNullityFilter(Class<A> fromClass)
abstract SolutionDescriptor<Solution_>
getSolutionDescriptor()
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.optaplanner.core.api.score.stream.ConstraintFactory
forEachIncludingNullVars, forEachUniquePair, forEachUniquePair, forEachUniquePair, forEachUniquePair, forEachUniquePair, fromUnfiltered, fromUniquePair, fromUniquePair, fromUniquePair, fromUniquePair, fromUniquePair, getDefaultConstraintPackage
-
-
-
-
Method Detail
-
forEach
public <A> UniConstraintStream<A> forEach(Class<A> sourceClass)
Description copied from interface:ConstraintFactory
Start aConstraintStream
of all instances of the sourceClass that are known asproblem facts
orplanning entities
.If the sourceClass is a
PlanningEntity
, then it is automaticallyfiltered
to only contain entities for which each genuinePlanningVariable
(of the sourceClass or a superclass thereof) has a non-null value.- Specified by:
forEach
in interfaceConstraintFactory
- Type Parameters:
A
- the type of the matched problem fact orplanning entity
- Parameters:
sourceClass
- never null- Returns:
- never null
-
forEachUniquePair
public <A> BiConstraintStream<A,A> forEachUniquePair(Class<A> sourceClass, BiJoiner<A,A> joiner)
Description copied from interface:ConstraintFactory
Create a newBiConstraintStream
for every unique combination of A and another A with a higherPlanningId
for which theBiJoiner
is true (for the properties it extracts from both facts).Important: This is faster and more scalable than not using a
ConstraintFactory.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 alessThan
joiner on thePlanningId
of A.This method has overloaded methods with multiple
BiJoiner
parameters.- Specified by:
forEachUniquePair
in interfaceConstraintFactory
- Type Parameters:
A
- the type of the matched problem fact orplanning entity
- Parameters:
sourceClass
- never nulljoiner
- never null- Returns:
- a stream that matches every unique combination of A and another A for which the
BiJoiner
is true
-
from
public <A> UniConstraintStream<A> from(Class<A> fromClass)
Description copied from interface:ConstraintFactory
This method is deprecated. Migrate uses of this method toConstraintFactory.forEach(Class)
, but first understand this:- If none of your
planning variables
are explicitly set to nullable=true, then the replacement byConstraintFactory.forEach(Class)
has little to no impact. Subsequent conditional propagation calls (UniConstraintStream.ifExists(java.lang.Class<B>, org.optaplanner.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
are nullable=true, 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.forEachIncludingNullVars(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
ConstraintStream
of all instances of the fromClass that are known asproblem facts
orplanning entities
.If the fromClass is a
PlanningEntity
, then it is automaticallyfiltered
to 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.- Specified by:
from
in interfaceConstraintFactory
- Type Parameters:
A
- the type of the matched problem fact orplanning entity
- Parameters:
fromClass
- never null- Returns:
- never null
- If none of your
-
fromUniquePair
public <A> BiConstraintStream<A,A> fromUniquePair(Class<A> fromClass, BiJoiner<A,A> joiner)
Description copied from interface:ConstraintFactory
This method is deprecated. Migrate uses of this method toConstraintFactory.forEachUniquePair(Class, BiJoiner)
, but first understand that the same precautions apply as with the use ofConstraintFactory.from(Class)
.The original Javadoc of this method follows:
Create a new
BiConstraintStream
for every unique combination of A and another A with a higherPlanningId
for which theBiJoiner
is true (for the properties it extracts from both facts).Important: This is faster and more scalable than not using a
ConstraintFactory.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 alessThan
joiner on thePlanningId
of A.This method has overloaded methods with multiple
BiJoiner
parameters.- Specified by:
fromUniquePair
in interfaceConstraintFactory
- Type Parameters:
A
- the type of the matched problem fact orplanning entity
- Parameters:
fromClass
- never nulljoiner
- never null- Returns:
- a stream that matches every unique combination of A and another A for which the
BiJoiner
is true
-
assertValidFromType
public <A> void assertValidFromType(Class<A> fromType)
-
buildConstraints
public List<Constraint_> buildConstraints(ConstraintProvider constraintProvider)
-
getSolutionDescriptor
public abstract SolutionDescriptor<Solution_> getSolutionDescriptor()
- Returns:
- never null
-
-