choco.cp.solver.constraints.global.pack
Class PackSConstraint

java.lang.Object
  extended by choco.kernel.solver.propagation.Propagator
      extended by choco.kernel.solver.constraints.AbstractSConstraint<Var>
          extended by choco.kernel.solver.constraints.set.AbstractMixedSetIntSConstraint
              extended by choco.kernel.solver.constraints.set.AbstractLargeSetIntSConstraint
                  extended by choco.cp.solver.constraints.global.pack.PackSConstraint
All Implemented Interfaces:
IPackSConstraint, IExtensionnable, IPretty, SConstraint<Var>, IntPropagator, SetPropagator, ISolutionDisplay, Cloneable, EventListener

public class PackSConstraint
extends AbstractLargeSetIntSConstraint
implements IPackSConstraint, ISolutionDisplay

Pack which maintains a primal-dual packing model.
The primal model consists of bins variables. bins[item] = bin means that item is packed into bin.
The dual model consists of svars variables. item is in svars[bin] also means that item is packed into bin.

Since:
5 déc. 2008 version 2.0.1
Version:
2.1.0
Author:
Arnaud Malapert

Nested Class Summary
protected  class PackSConstraint.BoundNumberOfBins
           
 
Field Summary
static StringMask ADDITIONAL_RULES
           
protected  IntDomainVar[] bins
          The bin of each item.
protected  PackSConstraint.BoundNumberOfBins bounds
           
static StringMask DYNAMIC_LB
           
static StringMask FILL_BIN
           
 PackFiltering filtering
           
 BitMask flags
           
static StringMask LAST_BINS_EMPTY
           
protected  IntDomainVar[] loads
          The loads of the bins.
protected  int[] sizes
          The sizes of the items.
 
Fields inherited from class choco.kernel.solver.constraints.set.AbstractLargeSetIntSConstraint
ivars, svars
 
Fields inherited from class choco.kernel.solver.constraints.AbstractSConstraint
cIndices, constraintType, extensions, vars
 
Fields inherited from class choco.kernel.solver.propagation.Propagator
active, constAwakeEvent, priority, propagationEngine
 
Fields inherited from interface choco.kernel.solver.constraints.SConstraint
LOGGER
 
Constructor Summary
PackSConstraint(IEnvironment environment, SetVar[] itemSets, IntDomainVar[] loads, IntDomainVar[] sizes, IntDomainVar[] bins, IntDomainVar nbNonEmpty)
           
 
Method Summary
 void awake()
          Propagation: Propagating the constraint for the very first time until local consistency is reached.
 void awakeOnBounds(int varIndex)
           
 void awakeOnEnv(int varIdx, int x)
          Default propagation on enveloppe modification: propagation on removing a value from the enveloppe.
 void awakeOnInf(int varIdx)
          Default propagation on improved lower bound: propagation on domain revision.
 void awakeOnInst(int varIdx)
          Default propagation on instantiation.
 void awakeOnKer(int varIdx, int x)
          Default propagation on kernel modification: propagation on adding a value to the kernel.
 void awakeOnRem(int varIdx, int val)
          Default propagation on one value removal: propagation on domain revision.
 void awakeOnSup(int varIdx)
          Default propagation on improved upper bound: propagation on domain revision.
protected  void checkBounds(int item)
           
protected  void checkDeltaDomain(int item)
           
protected  void checkEnveloppes()
           
 void fireAvailableBins()
           
 IStateIntVector getAvailableBins()
           
 IntDomainVar[] getBins()
           
protected  int getItemIndex(int varIdx)
           
 IntDomainVar[] getLoads()
           
 int getNbBins()
           
 int getNbItems()
           
 int getRemainingSpace(int bin)
           
 int getRequiredSpace(int bin)
           
 int[] getSizes()
           
 NoSumList getStatus(int bin)
           
 boolean isConsistent()
          tests if the constraint is consistent with respect to the current state of domains
 boolean isEmpty(int bin)
           
protected  boolean isItemEvent(int varIdx)
           
 boolean isSatisfied()
          Semantic: Testing if the constraint is satisfied.
protected  boolean isSetEvent(int varIdx)
           
 boolean pack(int item, int bin)
          Pack an item into a bin
 void propagate()
          Propagation: Propagating the constraint until local consistency is reached.
 void readOptions(List<String> options)
           
 boolean remove(int item, int bin)
          Remove a possible assignment of an item into a bin.
 String solutionToString()
           
 boolean updateInfLoad(int bin, int load)
          Update the minimal load of a given bin.
 boolean updateNbNonEmpty(int min, int max)
          update the number of non empty bins.
 boolean updateSupLoad(int bin, int load)
          Update the maximal load of a given bin.
 
Methods inherited from class choco.kernel.solver.constraints.set.AbstractLargeSetIntSConstraint
getIntVarIndex, getNbIntVars, getNbSetVars, isIntVarIndex, isSetVarIndex
 
Methods inherited from class choco.kernel.solver.constraints.set.AbstractMixedSetIntSConstraint
awakeOnEnvRemovals, awakeOnkerAdditions, awakeOnRemovals, getConstraintType, isSatisfied
 
Methods inherited from class choco.kernel.solver.constraints.AbstractSConstraint
addExtension, addListener, clone, getAbstractSConstraintExtensionNumber, getConstraintIdx, getExtension, getFineDegree, getNbVarNotInst, getNbVars, getVar, getVarQuick, isCompletelyInstantiated, isEntailed, opposite, pretty, setConstraintIndex, setExtension, setVar, toString
 
Methods inherited from class choco.kernel.solver.propagation.Propagator
activate, constAwake, fail, getEvent, getFilteredEventMask, getPriority, isActive, setActive, setActiveSilently, setEntailed, setPassive, setPropagationEngine
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface choco.cp.solver.constraints.global.pack.IPackSConstraint
fail
 

Field Detail

ADDITIONAL_RULES

public static final StringMask ADDITIONAL_RULES

DYNAMIC_LB

public static final StringMask DYNAMIC_LB

FILL_BIN

public static final StringMask FILL_BIN

LAST_BINS_EMPTY

public static final StringMask LAST_BINS_EMPTY

flags

public final BitMask flags

filtering

public final PackFiltering filtering

bounds

protected final PackSConstraint.BoundNumberOfBins bounds

sizes

protected final int[] sizes
The sizes of the items.


loads

protected final IntDomainVar[] loads
The loads of the bins.


bins

protected final IntDomainVar[] bins
The bin of each item.

Constructor Detail

PackSConstraint

public PackSConstraint(IEnvironment environment,
                       SetVar[] itemSets,
                       IntDomainVar[] loads,
                       IntDomainVar[] sizes,
                       IntDomainVar[] bins,
                       IntDomainVar nbNonEmpty)
Method Detail

readOptions

public void readOptions(List<String> options)

isEmpty

public final boolean isEmpty(int bin)

fireAvailableBins

public void fireAvailableBins()
Specified by:
fireAvailableBins in interface IPackSConstraint

getAvailableBins

public final IStateIntVector getAvailableBins()
Specified by:
getAvailableBins in interface IPackSConstraint

getRequiredSpace

public final int getRequiredSpace(int bin)

getRemainingSpace

public final int getRemainingSpace(int bin)

isSetEvent

protected final boolean isSetEvent(int varIdx)

isItemEvent

protected final boolean isItemEvent(int varIdx)

getItemIndex

protected final int getItemIndex(int varIdx)

getBins

public final IntDomainVar[] getBins()
Specified by:
getBins in interface IPackSConstraint

getNbBins

public final int getNbBins()
Specified by:
getNbBins in interface IPackSConstraint

getNbItems

public final int getNbItems()
Specified by:
getNbItems in interface IPackSConstraint

getLoads

public final IntDomainVar[] getLoads()
Specified by:
getLoads in interface IPackSConstraint

getSizes

public final int[] getSizes()
Specified by:
getSizes in interface IPackSConstraint

getStatus

public final NoSumList getStatus(int bin)
Specified by:
getStatus in interface IPackSConstraint

pack

public final boolean pack(int item,
                          int bin)
                   throws ContradictionException
Description copied from interface: IPackSConstraint
Pack an item into a bin

Specified by:
pack in interface IPackSConstraint
Returns:
true, if successful
Throws:
ContradictionException - the contradiction exception

remove

public final boolean remove(int item,
                            int bin)
                     throws ContradictionException
Description copied from interface: IPackSConstraint
Remove a possible assignment of an item into a bin.

Specified by:
remove in interface IPackSConstraint
Returns:
true, if successful
Throws:
ContradictionException - the contradiction exception

updateInfLoad

public final boolean updateInfLoad(int bin,
                                   int load)
                            throws ContradictionException
Description copied from interface: IPackSConstraint
Update the minimal load of a given bin.

Specified by:
updateInfLoad in interface IPackSConstraint
Parameters:
bin - the index of bin
load - the new load
Throws:
ContradictionException - the contradiction exception

updateNbNonEmpty

public final boolean updateNbNonEmpty(int min,
                                      int max)
                               throws ContradictionException
Description copied from interface: IPackSConstraint
update the number of non empty bins.

Specified by:
updateNbNonEmpty in interface IPackSConstraint
Throws:
ContradictionException

updateSupLoad

public final boolean updateSupLoad(int bin,
                                   int load)
                            throws ContradictionException
Description copied from interface: IPackSConstraint
Update the maximal load of a given bin.

Specified by:
updateSupLoad in interface IPackSConstraint
Parameters:
bin - the index of bin
load - the new load
Throws:
ContradictionException - the contradiction exception

isConsistent

public boolean isConsistent()
Description copied from class: AbstractMixedSetIntSConstraint
tests if the constraint is consistent with respect to the current state of domains

Overrides:
isConsistent in class AbstractMixedSetIntSConstraint
Returns:
wether the constraint is consistent

checkBounds

protected final void checkBounds(int item)
                          throws ContradictionException
Throws:
ContradictionException

checkEnveloppes

protected final void checkEnveloppes()
                              throws ContradictionException
Throws:
ContradictionException

awake

public void awake()
           throws ContradictionException
Description copied from class: Propagator
Propagation: Propagating the constraint for the very first time until local consistency is reached.

Overrides:
awake in class Propagator
Throws:
ContradictionException - contradiction exception

awakeOnEnv

public void awakeOnEnv(int varIdx,
                       int x)
                throws ContradictionException
Description copied from interface: SetPropagator
Default propagation on enveloppe modification: propagation on removing a value from the enveloppe.

Specified by:
awakeOnEnv in interface SetPropagator
Overrides:
awakeOnEnv in class AbstractMixedSetIntSConstraint
Throws:
ContradictionException

checkDeltaDomain

protected void checkDeltaDomain(int item)
                         throws ContradictionException
Throws:
ContradictionException

awakeOnBounds

public void awakeOnBounds(int varIndex)
                   throws ContradictionException
Specified by:
awakeOnBounds in interface IntPropagator
Overrides:
awakeOnBounds in class AbstractMixedSetIntSConstraint
Throws:
ContradictionException

awakeOnInf

public void awakeOnInf(int varIdx)
                throws ContradictionException
Description copied from class: AbstractMixedSetIntSConstraint
Default propagation on improved lower bound: propagation on domain revision.

Specified by:
awakeOnInf in interface IntPropagator
Overrides:
awakeOnInf in class AbstractMixedSetIntSConstraint
Throws:
ContradictionException

awakeOnInst

public void awakeOnInst(int varIdx)
                 throws ContradictionException
Description copied from interface: SetPropagator
Default propagation on instantiation.

Specified by:
awakeOnInst in interface IntPropagator
Specified by:
awakeOnInst in interface SetPropagator
Overrides:
awakeOnInst in class AbstractMixedSetIntSConstraint
Throws:
ContradictionException

awakeOnKer

public void awakeOnKer(int varIdx,
                       int x)
                throws ContradictionException
Description copied from interface: SetPropagator
Default propagation on kernel modification: propagation on adding a value to the kernel.

Specified by:
awakeOnKer in interface SetPropagator
Overrides:
awakeOnKer in class AbstractMixedSetIntSConstraint
Throws:
ContradictionException

awakeOnRem

public void awakeOnRem(int varIdx,
                       int val)
                throws ContradictionException
Description copied from class: AbstractMixedSetIntSConstraint
Default propagation on one value removal: propagation on domain revision.

Specified by:
awakeOnRem in interface IntPropagator
Overrides:
awakeOnRem in class AbstractMixedSetIntSConstraint
Throws:
ContradictionException

awakeOnSup

public void awakeOnSup(int varIdx)
                throws ContradictionException
Description copied from class: AbstractMixedSetIntSConstraint
Default propagation on improved upper bound: propagation on domain revision.

Specified by:
awakeOnSup in interface IntPropagator
Overrides:
awakeOnSup in class AbstractMixedSetIntSConstraint
Throws:
ContradictionException

propagate

public void propagate()
               throws ContradictionException
Description copied from class: Propagator
Propagation: Propagating the constraint until local consistency is reached.

Specified by:
propagate in class Propagator
Throws:
ContradictionException - contradiction exception

isSatisfied

public boolean isSatisfied()
Description copied from interface: SConstraint
Semantic: Testing if the constraint is satisfied. Note that all variables involved in the constraint must be instantiated when this method is called.

Specified by:
isSatisfied in interface SConstraint<Var>
Returns:
true if the constraint is satisfied

solutionToString

public final String solutionToString()
Specified by:
solutionToString in interface ISolutionDisplay


Copyright © 2012. All Rights Reserved.