Class Model

    • Constructor Detail

      • Model

        public Model​(IEnvironment environment,
                     String name,
                     Settings settings)
        Creates a Model object to formulate a decision problem by declaring variables and posting constraints. The model is named name and it uses a specific backtracking environment.
        Parameters:
        environment - a backtracking environment to allow search
        name - The name of the model (for logging purpose)
        settings - settings to use
      • Model

        public Model​(IEnvironment environment,
                     String name)
        Creates a Model object to formulate a decision problem by declaring variables and posting constraints. The model is named name and it uses a specific backtracking environment.
        Parameters:
        environment - a backtracking environment to allow search
        name - The name of the model (for logging purpose)
      • Model

        public Model​(String name,
                     Settings settings)
        Creates a Model object to formulate a decision problem by declaring variables and posting constraints. The model is named name and it uses a specific backtracking environment.
        Parameters:
        name - The name of the model (for logging purpose)
        settings - settings to use
      • Model

        public Model​(String name)
        Creates a Model object to formulate a decision problem by declaring variables and posting constraints. The model is named name and uses the default (trailing) backtracking environment.
        Parameters:
        name - The name of the model (for logging purpose)
        See Also:
        Model(org.chocosolver.memory.IEnvironment, String, Settings)
      • Model

        public Model()
        Creates a Model object to formulate a decision problem by declaring variables and posting constraints. The model uses the default (trailing) backtracking environment.
        See Also:
        Model(String)
    • Method Detail

      • getCreationTime

        public long getCreationTime()
        Get the creation time (in milliseconds) of the model (to estimate modeling duration)
        Returns:
        the time (in ms) of the creation of the model
      • getResolutionPolicy

        public ResolutionPolicy getResolutionPolicy()
        Get the resolution policy of the model
        Returns:
        the resolution policy of the model
        See Also:
        ResolutionPolicy
      • getCachedConstants

        public gnu.trove.map.hash.TIntObjectHashMap<IntVar> getCachedConstants()
        Get the map of constant IntVar the have default names to avoid creating multiple identical constants. Should not be called by the user.
        Returns:
        the map of constant IntVar having default names.
      • trueConstraint

        public Constraint trueConstraint()
        The basic "true" constraint, which is always satisfied
        Returns:
        a "true" constraint
      • falseConstraint

        public Constraint falseConstraint()
        The basic "false" constraint, which is always violated
        Returns:
        a "false" constraint
      • getSolver

        public Solver getSolver()
        Returns the unique and internal propagation and search object to solve this model.
        Returns:
        the unique and internal Resolver object.
      • getVars

        public Variable[] getVars()
        Returns the array of Variable objects declared in this Model.
        Returns:
        array of all variables in this model
      • getNbVars

        public int getNbVars()
        Returns the number of variables involved in this.
        Returns:
        number of variables in this model
      • getVar

        public Variable getVar​(int i)
        Returns the ith variable within the array of variables defined in this.
        Parameters:
        i - index of the variable to return.
        Returns:
        the ith variable of this model
      • getNbIntVar

        public int getNbIntVar​(boolean includeBoolVar)
        Returns the number of IntVar of the model involved in this, excluding BoolVar if includeBoolVar=false. It also counts FIXED variables and VIEWS, if any.
        Parameters:
        includeBoolVar - indicates whether or not to include BoolVar
        Returns:
        the number of IntVar of the model involved in this
      • retrieveIntVars

        public IntVar[] retrieveIntVars​(boolean includeBoolVar)
        Iterate over the variable of this and build an array that contains all the IntVar of the model. excludes BoolVar if includeBoolVar=false. It also contains FIXED variables and VIEWS, if any.
        Parameters:
        includeBoolVar - indicates whether or not to include BoolVar
        Returns:
        array of IntVar in this model
      • getNbBoolVar

        public int getNbBoolVar()
        Returns the number of BoolVar of the model involved in this, It also counts FIXED variables and VIEWS, if any.
        Returns:
        the number of BoolVar of the model involved in this
      • retrieveBoolVars

        public BoolVar[] retrieveBoolVars()
        Iterate over the variable of this and build an array that contains the BoolVar only. It also contains FIXED variables and VIEWS, if any.
        Returns:
        array of BoolVar in this model
      • getNbSetVar

        public int getNbSetVar()
        Returns the number of SetVar of the model involved in this, It also counts FIXED variables and VIEWS, if any.
        Returns:
        the number of SetVar of the model involved in this
      • retrieveSetVars

        public SetVar[] retrieveSetVars()
        Iterate over the variable of this and build an array that contains the SetVar only. It also contains FIXED variables and VIEWS, if any.
        Returns:
        array of SetVars in this model
      • getNbRealVar

        public int getNbRealVar()
        Returns the number of RealVar of the model involved in this, It also counts FIXED variables and VIEWS, if any.
        Returns:
        the number of RealVar of the model involved in this
      • retrieveRealVars

        public RealVar[] retrieveRealVars()
        Iterate over the variable of this and build an array that contains the RealVar only. It also contains FIXED variables and VIEWS, if any.
        Returns:
        array of RealVar in this model
      • getCstrs

        public Constraint[] getCstrs()
        Returns the array of Constraint objects posted in this Model.
        Returns:
        array of posted constraints
      • getNbCstrs

        public int getNbCstrs()
        Return the number of constraints posted in this.
        Returns:
        number of posted constraints.
      • getName

        public String getName()
        Return the name of this model.
        Returns:
        this model's name
      • getEnvironment

        public IEnvironment getEnvironment()
        Return the backtracking environment of this model.
        Returns:
        the backtracking environment of this model
      • getObjective

        public Variable getObjective()
        Return the (possibly null) objective variable
        Returns:
        a variable (null for satisfaction problems)
      • getPrecision

        public double getPrecision()
        In case of real variable(s) to optimize, a precision is required.
        Returns:
        the precision used
      • getHook

        public Object getHook​(String hookName)
        Returns the object associated with the named hookName
        Parameters:
        hookName - the name of the hook to return
        Returns:
        the object associated to the name hookName
      • getHooks

        protected Map<String,​Object> getHooks()
        Returns the map containing declared hooks. This map is mutable.
        Returns:
        the map of hooks.
      • getMinisat

        public SatConstraint getMinisat()
        Returns the unique constraint embedding a minisat model. A call to this method will create and post the constraint if it does not exist already.
        Returns:
        the minisat constraint
      • removeMinisat

        public void removeMinisat()
        Unpost minisat constraint from model, if any.
      • getNogoodStore

        public NogoodConstraint getNogoodStore()
        Return a constraint embedding a nogood store (based on a sat model). A call to this method will create and post the constraint if it does not exist already.
        Returns:
        the no good constraint
      • removeNogoodStore

        public void removeNogoodStore()
        Unpost nogood store constraint from model, if any.
      • getClauseConstraint

        public ClauseConstraint getClauseConstraint()
        Return a constraint embedding a signed-clauses store. A call to this method will create and post the constraint if it does not exist already.
        Returns:
        the signed-clauses store constraint
      • getClauseBuilder

        public ClauseBuilder getClauseBuilder()
        Returns:
        an instance of ClauseBuilder that helps creating clause during resolution.
      • getIbexHandler

        public IbexHandler getIbexHandler()
        Return a constraint embedding an instance of Ibex (continuous solver). A call to this method will create and post the constraint if it does not exist already.
        Returns:
        the Ibex constraint
      • getSettings

        public Settings getSettings()
        Return the current settings for the solver
        Returns:
        a Settings
      • clearObjective

        public void clearObjective()
        Removes any objective and set problem to a satisfaction problem
      • setPrecision

        public void setPrecision​(double p)
        In case of real variable to optimize, a precision is required.
        Parameters:
        p - the precision (default is 0.0001D)
      • addHook

        public void addHook​(String hookName,
                            Object hookObject)
        Adds the hookObject to store in this model, associated with the name hookName. A hook is a simple map "hookName" <-> hookObject.
        Parameters:
        hookName - name of the hook
        hookObject - hook to store
      • removeHook

        public void removeHook​(String hookName)
        Removes the hook named hookName
        Parameters:
        hookName - name of the hookObject to remove
      • removeAllHooks

        public void removeAllHooks()
        Empties the hooks attached to this model.
      • setName

        public void setName​(String name)
        Changes the name of this model to be equal to the argument name.
        Parameters:
        name - the new name of this model.
      • associates

        public void associates​(Variable variable)
        Link a variable to 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.
        Parameters:
        variable - a newly created variable, not already added
      • unassociates

        public void unassociates​(Variable variable)
        Unlink the variable from this. Should not be called by the user.
        Parameters:
        variable - variable to un-associate
      • nextId

        public int nextId()
        Get a free single-use id to identify a new variable. Should not be called by the user.
        Returns:
        a free id to use
      • nextNameId

        public int nextNameId()
        Get a free single-use name id to identify a variable created internally. Should not be called by the user.
        Returns:
        a free id to use
      • post

        public void post​(Constraint... cs)
                  throws SolverException
        Posts constraints cs permanently in the constraints network of this: - add them to the data structure, - set the fixed idx, - checks for restrictions
        Parameters:
        cs - Constraints
        Throws:
        SolverException - if the constraint is posted twice, posted although reified or reified twice.
      • postTemp

        public void postTemp​(Constraint... cs)
                      throws ContradictionException
        Posts constraints cs temporary, that is, they will be unposted upon backtrack. The unpost instruction is defined by an IOperation saved in the IEnvironment
        Parameters:
        cs - a set of constraints to add
        Throws:
        ContradictionException - if the addition of constraints cs detects inconsistency.
        SolverException - if a constraint is posted twice, posted although reified or reified twice.
      • unpost

        public void unpost​(Constraint... constraints)
                    throws SolverException
        Remove permanently the constraint c from the constraint network.
        Parameters:
        constraints - the constraints to remove
        Throws:
        SolverException - if a constraint is unknown from the model
      • toString

        public String toString()
        Return a string describing the CSP defined in this model.
        Overrides:
        toString in class Object
      • ref

        public Model ref()
        Specified by:
        ref in interface ISelf<Model>
        Returns:
        the encapsulated type