public class Model extends Object implements IModel
Model
is the header component of Constraint Programming.
It embeds the list of Variable
(and their Domain
), the Constraint
's network,
and a IPropagationEngine
to pilot the propagation.Model
includes a AbstractSearchLoop
to guide the search loop: applying decisions and propagating,
running backups and rollbacks and storing solutions.Variable
,
Constraint
Modifier and Type | Field and Description |
---|---|
static String |
IBEX_HOOK_NAME |
static boolean |
MAXIMIZE |
static boolean |
MINIMIZE |
static String |
MINISAT_HOOK_NAME |
static String |
NOGOODS_HOOK_NAME |
static String |
TASK_SET_HOOK_NAME
Name of internal hook dedicated to store declared
Task . |
CSTE_NAME
Constructor and Description |
---|
Model()
Creates a Model object to formulate a decision problem by declaring variables and posting constraints.
|
Model(IEnvironment environment,
String name)
Creates a Model object to formulate a decision problem by declaring variables and posting constraints.
|
Model(IEnvironment environment,
String name,
Settings settings)
Creates a Model object to formulate a decision problem by declaring variables and posting constraints.
|
Model(Settings settings)
Creates a Model object to formulate a decision problem by declaring variables and posting constraints.
|
Model(String name)
Creates a Model object to formulate a decision problem by declaring variables and posting constraints.
|
Model(String name,
Settings settings)
Creates a Model object to formulate a decision problem by declaring variables and posting constraints.
|
Modifier and Type | Method and Description |
---|---|
void |
addHook(String hookName,
Object hookObject)
Adds the
hookObject to store in this model, associated with the name hookName . |
void |
associates(Variable variable)
Link a variable to
this . |
void |
clearObjective()
Removes any objective and set problem to a satisfaction problem
|
Constraint |
falseConstraint()
The basic "false" constraint, which is always violated
|
gnu.trove.map.hash.TIntObjectHashMap<IntVar> |
getCachedConstants()
Get the map of constant IntVar the have default names to avoid creating multiple identical constants.
|
long |
getCreationTime()
Get the creation time (in milliseconds) of the model (to estimate modeling duration)
|
Constraint[] |
getCstrs()
Returns the array of
Constraint objects posted in this Model . |
IEnvironment |
getEnvironment()
Return the backtracking environment of
this model. |
Object |
getHook(String hookName)
Returns the object associated with the named
hookName |
protected Map<String,Object> |
getHooks()
Returns the map containing declared hooks.
|
Ibex |
getIbex()
Deprecated.
see
getIbexHandler() ()}` |
IbexHandler |
getIbexHandler()
Return a constraint embedding an instance of Ibex (continuous solver).
|
SatConstraint |
getMinisat()
Returns the unique constraint embedding a minisat model.
|
String |
getName()
Return the name of
this model. |
int |
getNbBoolVar()
Returns the number of
BoolVar of the model involved in this ,
It also counts FIXED variables and VIEWS, if any. |
int |
getNbCstrs()
Return the number of constraints posted in
this . |
int |
getNbIntVar(boolean includeBoolVar)
|
int |
getNbRealVar()
Returns the number of
RealVar of the model involved in this ,
It also counts FIXED variables and VIEWS, if any. |
int |
getNbSetVar()
Returns the number of
SetVar of the model involved in this ,
It also counts FIXED variables and VIEWS, if any. |
int |
getNbVars()
Returns the number of variables involved in
this . |
NogoodConstraint |
getNogoodStore()
Return a constraint embedding a nogood store (based on a sat model).
|
Variable |
getObjective()
Return the (possibly null) objective variable
|
double |
getPrecision()
In case of real variable(s) to optimize, a precision is required.
|
ResolutionPolicy |
getResolutionPolicy()
Get the resolution policy of the model
|
Settings |
getSettings()
Return the current settings for the solver
|
Solver |
getSolver()
Returns the unique and internal propagation and search object to solve this model.
|
Variable |
getVar(int i)
Returns the ith variable within the array of variables defined in
this . |
Variable[] |
getVars()
Returns the array of
Variable objects declared in this Model . |
int |
nextId()
Get a free single-use id to identify a new variable.
|
int |
nextNameId()
Get a free single-use name id to identify a variable created internally.
|
void |
post(Constraint... cs)
Posts constraints
cs permanently in the constraints network of this :
- add them to the data structure,
- set the fixed idx,
- checks for restrictions |
void |
postTemp(Constraint... cs)
Posts constraints
cs temporary, that is, they will be unposted upon backtrack. |
Model |
ref() |
void |
removeAllHooks()
Empties the hooks attached to this model.
|
void |
removeHook(String hookName)
Removes the hook named
hookName |
void |
removeMinisat()
Unpost minisat constraint from model, if any.
|
void |
removeNogoodStore()
Unpost nogood store constraint from model, if any.
|
BoolVar[] |
retrieveBoolVars()
Iterate over the variable of
this and build an array that contains the BoolVar only. |
IntVar[] |
retrieveIntVars(boolean includeBoolVar)
Iterate over the variable of
this and build an array that contains all the IntVar of the model. |
RealVar[] |
retrieveRealVars()
Iterate over the variable of
this and build an array that contains the RealVar only. |
SetVar[] |
retrieveSetVars()
Iterate over the variable of
this and build an array that contains the SetVar only. |
void |
set(Settings defaults)
Deprecated.
will be removed in version > 4.0.7
|
void |
setName(String name)
Changes the name of this model to be equal to the argument
name . |
void |
setObjective(boolean maximize,
Variable objective)
|
void |
setPrecision(double p)
In case of real variable to optimize, a precision is required.
|
String |
toString()
Return a string describing the CSP defined in
this model. |
Constraint |
trueConstraint()
The basic "true" constraint, which is always satisfied
|
void |
unassociates(Variable variable)
Unlink the variable from
this . |
void |
unpost(Constraint... constraints)
Remove permanently the constraint
c from the constraint network. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
boolVar, boolVar, boolVar, boolVar, boolVarArray, boolVarArray, boolVarMatrix, boolVarMatrix, checkIntDomainRange, checkRealDomainRange, generateName, generateName, intVar, intVar, intVar, intVar, intVar, intVar, intVar, intVar, intVarArray, intVarArray, intVarArray, intVarArray, intVarArray, intVarArray, intVarMatrix, intVarMatrix, intVarMatrix, intVarMatrix, intVarMatrix, intVarMatrix, realVar, realVar, realVar, realVar, realVar, realVarArray, realVarArray, realVarMatrix, realVarMatrix, setVar, setVar, setVar, setVar, setVarArray, setVarArray, setVarMatrix, setVarMatrix, taskVar, taskVar, taskVar, taskVarArray, taskVarMatrix, toBoolVar
boolNotView, intAbsView, intAffineView, intMinusView, intOffsetView, intScaleView, realIntView, realIntViewArray, realIntViewMatrix
absolute, allDifferent, allDifferent, allDifferentExcept0, allDifferentUnderCondition, allEqual, among, and, and, arithm, arithm, arithm, arithm, atLeastNValues, atMostNValues, binPacking, bitsIntChanneling, boolsIntChanneling, circuit, circuit, circuit, clausesIntChanneling, costRegular, count, count, cumulative, cumulative, cumulative, cumulative, diffN, distance, distance, div, element, element, element, getDomainUnion, globalCardinality, intValuePrecedeChain, intValuePrecedeChain, inverseChanneling, inverseChanneling, keySort, knapsack, lexChainLess, lexChainLessEq, lexLess, lexLessEq, max, max, max, mddc, member, member, min, min, min, mod, multiCostRegular, multiCostRegular, not, notAllEqual, notMember, notMember, nValues, or, or, path, path, regular, scalar, scalar, scalar, scalar, sort, square, subCircuit, subPath, sum, sum, sum, sum, sum, sum, sum, table, table, table, table, times, times, times, tree, tree
ibex, realIbexGenericConstraint, scalar
allDifferent, allDisjoint, allEqual, disjoint, element, element, intersection, intersection, inverseSet, max, max, member, member, member, min, min, nbEmpty, nbEmpty, notEmpty, notMember, notMember, offSet, partition, setBoolsChanneling, setBoolsChanneling, setsIntsChanneling, setsIntsChanneling, subsetEq, sum, sumElements, sumElements, symmetric, symmetric, union, union
addClauseFalse, addClauses, addClauses, addClausesAtMostNMinusOne, addClausesAtMostOne, addClausesBoolAndArrayEqualFalse, addClausesBoolAndArrayEqVar, addClausesBoolAndEqVar, addClausesBoolEq, addClausesBoolIsEqVar, addClausesBoolIsLeVar, addClausesBoolIsLtVar, addClausesBoolIsNeqVar, addClausesBoolLe, addClausesBoolLt, addClausesBoolNot, addClausesBoolOrArrayEqualTrue, addClausesBoolOrArrayEqVar, addClausesBoolOrEqVar, addClausesBoolXorEqVar, addClausesMaxBoolArrayLessEqVar, addClausesSumBoolArrayGreaterEqVar, addClausesSumBoolArrayLessEqVar, addClauseTrue, addConstructiveDisjunction
ifOnlyIf, ifThen, ifThen, ifThenElse, ifThenElse, reification, reifyXeqC, reifyXeqY, reifyXgtC, reifyXinS, reifyXleY, reifyXltC, reifyXltY, reifyXltYC, reifyXneC, reifyXneY
regularDec
public static boolean MAXIMIZE
public static boolean MINIMIZE
public static final String TASK_SET_HOOK_NAME
Task
.public static final String MINISAT_HOOK_NAME
public static final String NOGOODS_HOOK_NAME
public static final String IBEX_HOOK_NAME
public Model(IEnvironment environment, String name, Settings settings)
name
and it uses a specific backtracking environment
.environment
- a backtracking environment to allow searchname
- The name of the model (for logging purpose)settings
- settings to usepublic Model(IEnvironment environment, String name)
name
and it uses a specific backtracking environment
.environment
- a backtracking environment to allow searchname
- The name of the model (for logging purpose)public Model(String name, Settings settings)
name
and it uses a specific backtracking environment
.name
- The name of the model (for logging purpose)settings
- settings to usepublic Model(String name)
name
and uses the default (trailing) backtracking environment.name
- The name of the model (for logging purpose)Model(org.chocosolver.memory.IEnvironment, String, Settings)
public Model(Settings settings)
settings
- settings to useModel(org.chocosolver.memory.IEnvironment, String, Settings)
public Model()
Model(String)
public long getCreationTime()
public ResolutionPolicy getResolutionPolicy()
ResolutionPolicy
public gnu.trove.map.hash.TIntObjectHashMap<IntVar> getCachedConstants()
public Constraint trueConstraint()
public Constraint falseConstraint()
public Solver getSolver()
Resolver
object.public Variable[] getVars()
Variable
objects declared in this Model
.public int getNbVars()
this
.public Variable getVar(int i)
this
.i
- index of the variable to return.public int getNbIntVar(boolean includeBoolVar)
public IntVar[] retrieveIntVars(boolean includeBoolVar)
public int getNbBoolVar()
BoolVar
of the model involved in this
,
It also counts FIXED variables and VIEWS, if any.BoolVar
of the model involved in this
public BoolVar[] retrieveBoolVars()
this
and build an array that contains the BoolVar
only.
It also contains FIXED variables and VIEWS, if any.BoolVar
in this
modelpublic int getNbSetVar()
SetVar
of the model involved in this
,
It also counts FIXED variables and VIEWS, if any.SetVar
of the model involved in this
public SetVar[] retrieveSetVars()
this
and build an array that contains the SetVar
only.
It also contains FIXED variables and VIEWS, if any.this
modelpublic int getNbRealVar()
RealVar
of the model involved in this
,
It also counts FIXED variables and VIEWS, if any.RealVar
of the model involved in this
public RealVar[] retrieveRealVars()
this
and build an array that contains the RealVar
only.
It also contains FIXED variables and VIEWS, if any.RealVar
in this
modelpublic Constraint[] getCstrs()
Constraint
objects posted in this Model
.public int getNbCstrs()
this
.public String getName()
this
model.public IEnvironment getEnvironment()
this
model.public Variable getObjective()
public double getPrecision()
public Object getHook(String hookName)
hookName
hookName
- the name of the hook to returnhookName
protected Map<String,Object> getHooks()
public SatConstraint getMinisat()
public void removeMinisat()
public NogoodConstraint getNogoodStore()
public void removeNogoodStore()
public IbexHandler getIbexHandler()
public Settings getSettings()
Settings
public void setObjective(boolean maximize, Variable objective)
maximize
- whether to maximize (true) or minimize (false) the objectiveobjective
- variable to optimizeIObjectiveManager.setStrictDynamicCut()
,
IObjectiveManager.setWalkingDynamicCut()
,
IObjectiveManager.setCutComputer(Function)
public void clearObjective()
public void setPrecision(double p)
p
- the precision (default is 0.0001D)@Deprecated public void set(Settings defaults)
public void addHook(String hookName, Object hookObject)
hookObject
to store in this model, associated with the name hookName
.
A hook is a simple map "hookName" <-> hookObject.hookName
- name of the hookhookObject
- hook to storepublic void removeHook(String hookName)
hookName
hookName
- name of the hookObject to removepublic void removeAllHooks()
public void setName(String name)
name
.name
- the new name of this model.public void associates(Variable variable)
this
. This is executed AUTOMATICALLY in variable constructor,
so no checked are done on multiple occurrences of the very same variable.
Should not be called by the user.variable
- a newly created variable, not already addedpublic void unassociates(Variable variable)
this
.
Should not be called by the user.variable
- variable to un-associatepublic int nextId()
public int nextNameId()
public void post(Constraint... cs) throws SolverException
cs
permanently in the constraints network of this
:
- add them to the data structure,
- set the fixed idx,
- checks for restrictionscs
- ConstraintsSolverException
- if the constraint is posted twice, posted although reified or reified twice.public void postTemp(Constraint... cs) throws ContradictionException
cs
temporary, that is, they will be unposted upon backtrack.
The unpost instruction is defined by an IOperation
saved in the IEnvironment
cs
- a set of constraints to addContradictionException
- if the addition of constraints cs
detects inconsistency.SolverException
- if a constraint is posted twice, posted although reified or reified twice.public void unpost(Constraint... constraints) throws SolverException
c
from the constraint network.constraints
- the constraints to removeSolverException
- if a constraint is unknown from the modelpublic String toString()
this
model.@Deprecated public Ibex getIbex()
getIbexHandler()
()}`Copyright © 2018. All rights reserved.