Package com.artelys.kalis
Class KGlobalCardinalityConstraint
- java.lang.Object
-
- com.artelys.kalis.KConstraint
-
- com.artelys.kalis.KGlobalCardinalityConstraint
-
public class KGlobalCardinalityConstraint extends KConstraint
This class implements a Global Cardinality Constraint.
A GCC (Global Cardinality Constraint) over a set of variables is defined by three arrays called
values,
lowerBound, and upperBound. The constraint is satisfied if and only if the number of
variables of the given set which are assigned to values[i] is greater or equal to lowerBound[i],
and lower or equal to upperBound[i] for all i, and if no variable of the given set is assigned
to a value which does not belong to values.
Posting a KGlobalCardinalityConstraint to a problem is equivalent, from a modelisation point of view,
to posting two instances of {KOccurence} for each value. But this is absolutely not equivalent from
a propagation point of view : GCC acquires a far better propagation, using the Regin algorithm.
Example.
A group of tourists have to be transported from a point to another one, using a fleet of buses. The objective
is to find the assignment which maximize a satisfaction of tourists, depending of their affinities.
The bus capacity constraint can me modelized by the following code :
Bus [] fleet = // something ; Tourist [] tourists = // something ; KIntVarArray assignment = new KIntVarArray (problem, tourists.length, 0, fleet.length-1, "TouristBusesAssignment"); int [] capacity = new int [fleet.length]; // Capacities of the buses for (int i=0; i < fleet.length; i++) capacity[i] = fleet[i].capacity; KGlobalCardinalityConstraint gcc = new KGlobalCardinalityConstraint ("Buses Capacity constraint", assignment.getVars(), capacity);
- See Also:
KOccurence
-
-
Field Summary
-
Fields inherited from class com.artelys.kalis.KConstraint
swigCMemOwn
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
KGlobalCardinalityConstraint(long cPtr, boolean cMemoryOwn)
KGlobalCardinalityConstraint(KGlobalCardinalityConstraint toCopy)
Copy constructorKGlobalCardinalityConstraint(java.lang.String name, KIntVarArray vars, KIntArray vals, KIntArray low, KIntArray upp, int k)
Builds a GCC
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description int
askIfEntailed()
void
delete()
protected void
finalize()
protected static long
getCPtr(KGlobalCardinalityConstraint obj)
-
Methods inherited from class com.artelys.kalis.KConstraint
getArity, getCopyPtr, getCPtr, getInstance, getInstanceCopyPtr, getLinearRelaxation, getLinearRelaxation, getName, getPriority, getProblem, getTag, getTypeInfo, isGetLinearRelaxationImplemented, print, print, setName, setPriority, setTag
-
-
-
-
Constructor Detail
-
KGlobalCardinalityConstraint
protected KGlobalCardinalityConstraint(long cPtr, boolean cMemoryOwn)
-
KGlobalCardinalityConstraint
public KGlobalCardinalityConstraint(java.lang.String name, KIntVarArray vars, KIntArray vals, KIntArray low, KIntArray upp, int k)
Builds a GCC
- Parameters:
name
- The name of the constraintvars
- The set of variables involved by the GCCvals
- The set of values involved by the GCClow
- The minimum number of variables assigned to each valueupp
- The maximum number of variables assigned to each valuek
- The number of values. Arrays vals, low, upp, must be of length k.
-
KGlobalCardinalityConstraint
public KGlobalCardinalityConstraint(KGlobalCardinalityConstraint toCopy)
Copy constructor
-
-
Method Detail
-
getCPtr
protected static long getCPtr(KGlobalCardinalityConstraint obj)
-
finalize
protected void finalize()
- Overrides:
finalize
in classKConstraint
-
delete
public void delete()
- Overrides:
delete
in classKConstraint
-
askIfEntailed
public int askIfEntailed()
- Overrides:
askIfEntailed
in classKConstraint
-
-