javax.constraints.impl
Class AbstractProblem

java.lang.Object
  extended by javax.constraints.impl.AbstractProblem
All Implemented Interfaces:
Problem

public abstract class AbstractProblem
extends java.lang.Object
implements Problem

Problem - a placeholder for all components used to represent and resolve a constraint satisfaction problem (Problem). A Problem usually consists of two parts:

  1. Problem Definition: contains all constrained objects and constraints that define and control relationships between constrained objects
  2. Problem Resolution: contains search algorithm (goals) that allows to solve the problem
The decision variables are represented in form of Java objects which may use the predefined constrained variables types such as Var, VarReal, VarSet. The constraints themselves are objects inherited from a generic class Constraint. The interface covers major binary and global constraints required for the practical CP programming. It is possible to define and add new constraints.

To find the problem solutions, javax.constraints uses search algorithms presented using objects of the predefined type Goal. Goals are building blocks to define different search algorithms.

See Also:
Var, Constraint, Goal

Field Summary
 
Fields inherited from interface javax.constraints.Problem
JSR331_VERSION
 
Constructor Summary
AbstractProblem(java.lang.String name)
           
 
Method Summary
 Constraint add(Constraint constraint)
          Adds a Constraint "constraint" to the problem, then returns the constraint.
 Constraint add(java.lang.String name, Constraint constraint)
          Gives a Constraint "constraint" a new name "name", adds the Constraint to the problem and returns the newly added Constraint.
 Var add(java.lang.String name, Var var)
          Gives the Var variable "var" a new name "name", adds it to the problem, and returns the newly added Var.
 VarReal add(java.lang.String name, VarReal var)
          Gives the VarReal variable "var" a new name "name", adds it to the problem, and returns the newly added VarReal.
 Var add(Var var)
          Adds a Var variable "var" to the problem, and returns the newly added Var.
 VarBool add(VarBool varBool)
          Adds a VarBool variable "var" to the problem, and returns the newly added Var.
 VarReal add(VarReal var)
          Adds a VarReal variable "var" to the problem, and returns the newly added VarReal.
 void add(VarString var)
           
 Reversible addReversible(java.lang.String name, int value)
          Creates a Reversible integer with the name "name" and value "value" and returns the newly added Reversible.
 Var[] addVarArray(java.lang.String arrayName, java.lang.String[] varNames)
          Creates an array of Var variables with name "arrayName".
 Var[] addVarArray(java.lang.String name, Var[] vars)
          Gives the array of Var variables "vars" a new name "name", adds the array of variables to the problem, and returns the newly added Var array.
 Constraint allDiff(VarList vars)
          This method create a new Constraint stating that all of the elements of the list of variables "vars" must take different values from each other.
 Constraint and(Constraint[] array)
          Returns an "AND" Constraint.
abstract  Var createVariable(java.lang.String name, int min, int max)
          Creates a Var with the name "name" and domain [min;max] of the default domain type, and returns the newly added Var.
abstract  void debug(java.lang.String text)
          Log the String parameter "text"
 Var element(int[] array, Var indexVar)
          Returns a constrained integer variable that is an element of the integer "array" with index defined as another constrained integer variable "indexVar".
 VarSet element(java.util.Set<java.lang.Integer>[] sets, Var indexVar)
          Creates a set variable that corresponds to sets[index]
 Var element(Var[] array, Var indexVar)
          Returns a constrained integer variable that is an element of the "array" of variables with index defined as another constrained integer variable "indexVar".
 Var element(VarList list, Var indexVar)
           
abstract  void error(java.lang.String text)
          Log the String parameter "text"
 java.lang.String getAPIVersion()
          Returns JSR331 API version number
 Constraint getConstraint(java.lang.String name)
          Returns the Constraint the name "name", or null if no such constraints exists in the problem.
 Constraint[] getConstraints()
          Returns an array of Objects containing the Constraints previously added to the problem.
 DomainType getDomainType()
           
 Constraint getFalseConstraint()
          Returns the constant constraint that always will fail when it is posted or executed.
abstract  java.lang.String getImplVersion()
          Returns JSR331 Implementation version number
 java.lang.String getName()
          Returns the problem name
 double getRealPrecision()
          Returns the precision for VarReals
 Solver getSolver()
          Returns an instance of a Solver associated with this problem.
 Constraint getTrueConstraint()
          Returns the constant constraint that always succeeds when it is posted or executed.
 Var getVar(java.lang.String name)
          Returns the Var variable with the name "name", or null if no such variable exists in the problem.
 Var[] getVarArray(java.lang.String name)
          Returns the array of Var variables with the name "name", or null if no such array exists in the problem.
 VarBool[] getVarBools()
          Returns an array containing the VarBool variables previously added to the problem.
 VarMatrix getVarMatrix(java.lang.String name)
           
 VarReal getVarReal(java.lang.String name)
          Returns the VarReal variable with the name "name", or null if no such variable exists in the problem.
 VarReal[] getVarReals()
          Returns an array containing the VarReal variables previously added to the problem.
 Var[] getVars()
          Returns an array containing the Var variables previously added to the problem.
 VarReal[] getVarSets()
          Returns an array containing the VarSet variables previously added to the problem.
 VarString getVarString(java.lang.String name)
           
 VarString[] getVarStrings()
           
 boolean isSolverCreated()
           
 Constraint linear(VarString var, java.lang.String oper, java.lang.String value)
           
 void log(Constraint[] constraints)
          Logs all Constraints contained in the array "constraints".
abstract  void log(java.lang.String text)
          Log the String parameter "text"
 void log(java.lang.String text, Var[] vars)
          Logs the String "text" and then all integer constrained variables added to the problem.
 void log(java.lang.String text, VarReal[] vars)
          Logs the String "text" and then all real constrained variables contained in the array "vars".
 void log(java.lang.String text, VarSet[] vars)
          Logs the String "text" and then all constrained set variables contained in the array "vars".
 void log(Var[] vars)
          Logs the integer constrained variables contained in the array "vars".
 void log(VarList vars)
           
 void log(VarReal[] vars)
          Logs the real constrained variables contained in the array "vars".
 void log(VarSet[] vars)
          Logs the constrained set variables contained in the array "vars".
 Var max(Var[] vars)
          Returns a constrained integer variable that is equal to the maximal variable in the array "arrayOfVariables" when they are all instantiated.
 Var max(VarList listOfVariables)
           
 Var max(Var var1, Var var2)
          Returns a constrained integer variable that is equal to the maximal of two variablea var1 or var 2 when they are both instantiated.
 Var min(Var[] vars)
          Returns a constrained integer variable that is equal to the minimal variable in the array "arrayOfVariables" when they are all instantiated.
 Var min(VarList listOfVariables)
           
 Var min(Var var1, Var var2)
          Returns a constrained integer variable that is equal to the minimal of two variablea var1 or var 2 when they are both instantiated.
 void notImplementedException(java.lang.String feature)
           
abstract  void post(Constraint constraint)
          This method takes a constraint's implementation and uses its own implementation-specific post-method.
 Constraint post(int[] array, VarList vars, java.lang.String oper, int value)
           
 Constraint post(int[] array, VarList vars, java.lang.String oper, Var var)
           
 Constraint post(java.lang.String name, java.lang.String symbolicExpression)
          Creates a Constraint based on the symbolicExpression such as "x*y-z<3*r", adds this constraint to the problem, and returns the newly added Constraint.
 Constraint post(VarList vars, java.lang.String oper, int value)
          Creates and posts a constraint: sum of vars value
 Constraint post(VarList vars, java.lang.String oper, Var var)
          Creates and posts a constraint: sum of vars "oper" var
 Constraint post(VarString var, java.lang.String oper, java.lang.String value)
           
 Constraint post(VarString var1, java.lang.String oper, VarString var2)
           
 Constraint post(Var var1, Var var2, java.lang.String oper, int value)
          Creates and posts a constraint: (var1 + var2) "oper" value
 Constraint post(Var var1, Var var2, java.lang.String oper, Var var)
          Creates and posts a constraint: (var1 + var2) "oper" var
 Constraint postAllDiff(java.util.ArrayList<Var> vars)
          Similar to postAllDiff for variables saved in the ArrayList vars
 Constraint postAllDiff(Var[] vars)
          This constraint is a synonym for constraintAllDifferent
 Constraint postAllDifferent(java.util.ArrayList<Var> vars)
          Similar to postAllDifferent for variables saved in the ArrayList vars
 Constraint postAllDifferent(java.util.List vars)
           
 Constraint postAllDifferent(Var[] vars)
          Creates and posts a new Constraint stating that all of the elements of the array of variables "vars" must take different values from each other.
 Constraint postAllDifferent(VarList vars)
           
 Constraint postAnd(Constraint c1, Constraint c2)
          Creates and posts a constraint an "AND" Constraint.
 Constraint postCardinality(Var[] vars, Var cardVar, java.lang.String oper, int value)
          This method is similar to the one above but instead of “var” it uses "value"
 Constraint postCardinality(Var[] vars, Var cardVar, java.lang.String oper, Var var)
          This method creates a new cardinality constraint “cardinality(vars,cardVar) < value”.
 Constraint postCardinality(VarList vars, int cardValue, java.lang.String oper, int value)
           
 Constraint postCardinality(VarList vars, int cardValue, java.lang.String oper, Var var)
           
 Constraint postCardinality(VarList vars, Var cardVar, java.lang.String oper, int value)
           
 Constraint postCardinality(VarList vars, Var cardVar, java.lang.String oper, Var var)
           
 Constraint postElement(java.util.Set[] arrayOfSets, Var indexVar, java.lang.String oper, VarSet var)
          Creates and posts a constraint: arrayOfSets[indexVar] setVar Here "arrayOfSets[indexVar]" denotes a constrained set variable, which domain consists of sets of integers arrayOfSets[i] where i is within domain of the "indexVar".
 Constraint postGlobalCardinality(Var[] vars, int[] values, int[] cardMin, int[] cardMax)
          For each index i the number of times the value "values[i]" occurs in the array "vars" should be cardMin[i] and cardMax[i] (inclusive)
 Constraint postGlobalCardinality(Var[] vars, int[] values, Var[] cardinalityVars)
          Creates and posts a new global cardinality constraint that states:
 Constraint postGlobalCardinality(VarList vars, int[] values, int[] cardMin, int[] cardMax)
           
 Constraint postGlobalCardinality(VarList vars, int[] values, Var[] cardinalityVars)
           
 Constraint postIfThen(Constraint constraint1, Constraint constraint2)
          Creates and posts a constraint that states the implication: constraint1 => constraint2.
 Constraint postLinear(int[] array, Var[] vars, java.lang.String oper, int value)
          Synonym for constraint(int[] array, Var[] vars, String oper, int value)
 Constraint postLinear(int[] array, Var[] vars, java.lang.String oper, Var var)
          Synonym for constraint(int[] array, Var[] vars, String oper, Var var)
 Constraint postLinear(int[] array, VarList vars, java.lang.String oper, int value)
           
 Constraint postLinear(int[] array, VarList vars, java.lang.String oper, Var var)
           
 Constraint postLinear(Var[] vars, java.lang.String oper, int value)
          Synonym for constraint(Var[] vars, String oper, int value)
 Constraint postLinear(Var[] vars, java.lang.String oper, Var var)
          Synonym for constraint(Var[] vars, String oper, Var var)
 Constraint postLinear(Var var, java.lang.String oper, int value)
          Synonym for constraint(Var var, String oper, int value)
 Constraint postLinear(Var var1, java.lang.String oper, Var var2)
          Synonym for constraint(Var var1, String oper, Var var2)
 Constraint postMax(Var[] vars, java.lang.String oper, int value)
          Creates and posts a constraint: max(vars) "oper" value where max(vars) is a maximal variable in the array "vars" when they are all instantiated.
 Constraint postMax(Var[] vars, java.lang.String oper, Var var)
          Creates and posts a constraint: max(vars) "oper" var where max(vars) is a maximal variable in the array "vars" when they are all instantiated.
 Constraint postMin(Var[] vars, java.lang.String oper, int value)
          Creates and posts a constraint: min(vars) "oper" value where max(vars) is a minimal variable in the array "vars" when they are all instantiated.
 Constraint postMin(Var[] vars, java.lang.String oper, Var var)
          Creates and posts a constraint: min(vars) "oper" var where max(vars) is a minimal variable in the array "vars" when they are all instantiated.
 Constraint postOr(Constraint c1, Constraint c2)
          Creates and posts a constraint an "OR" Constraint.
 void remove(java.lang.String varName)
          Removes a Var variable by "name".
 Var scalProd(int[] arrayOfValues, VarList vars)
           
 void setDomainType(DomainType domainType)
          Sets the domain type that will be used as the default for subsequent creation of variables using addVar-methods
 void setName(java.lang.String name)
          Sets the problem name
 void setRealPrecision(double value)
          Sets the precision for VarReals
 void setSolver(Solver solver)
          Associates a "solver" with the problem making it available through the method "getSolver()".
 Var sum(Var[] vars)
          Returns a constrained integer variable that is constrained to be the sum of the variables in the array "vars".
 Var sum(VarList vars)
          Returns a constrained integer variable that is constrained to be the sum of the variables in the VarList "vars".
 Var var(java.lang.String name, java.lang.String symbolicExpression)
          Creates a Var variable based on the symbolicExpression, adds this variable to the problem, and returns the newly added Var.
 Var variable(int[] domain)
          An equivalent of var("",domain)
 Var variable(int min, int max)
          Creates a Var with domain [min;max].
 Var variable(java.lang.String name, int[] domain)
          Creates a Var with the name "name", and domain int[]
 Var variable(java.lang.String name, int min, int max)
          Creates a Var by calling createVariable(name,min,max) and adds this variable to the problem.
 Var variable(java.lang.String name, int min, int max, DomainType domainType)
          Similar to variable(String name, int min, int max) but also has one more parameter that defines the default domain type
 Var[] variableArray(java.lang.String name, int min, int max, int size)
          Adds an array of Var variables with the name "name" and domains [min;max] of domain type "type", adds this array of variables to the problem, and returns the newly added Var array.
 VarBool variableBool()
          Creates a bool var not added to the problem.
abstract  VarBool variableBool(java.lang.String name)
          Creates a boolean constrained variable with the name "name" and adds this variable to the problem, and returns the newly added VarBool.
 VarList variableList()
           
 VarMatrix variableMatrix(java.lang.String name, int min, int max, int rows, int columns)
           
 VarReal variableReal(java.lang.String name)
          Creates a VarReal with the name "name" and default domain [Double.MIN_VALUE+1;Double.MAX_VALUE-1], adds this variable to the problem, and returns the newly added VarReal.
 VarReal variableReal(java.lang.String name, double min, double max)
          Creates a VarReal with the name "name" and domain [min;max], adds this variable to the problem, and returns the newly added VarReal.
 VarSet variableSet(java.lang.String name, int[] values)
          Creates a constrained set variable VarSet with the name "name" and which domain consists of integer values from the array "value".
 VarSet variableSet(java.lang.String name, int min, int max)
          Creates a constrained set variable VarSet with the name "name" and domain of integer values from "min" to "max" inclusive.
 VarSet variableSet(java.lang.String name, java.util.Set set)
          Creates a constrained set variable VarSet with the name "name" and which domain consists of integer values from the Set "set".
 VarString variableString(java.lang.String name, java.lang.String[] allStrings)
           
 Var[] varSquare(java.lang.String name, int min, int max, int size)
          Creates a 2-dimensional array of Var variables, with dimensions "size"x"size".
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.constraints.Problem
allDiff, linear, linear, loadFromXML, post, post, post, post, post, post, postCardinality, postCardinality, postElement, postElement, postElement, postElement, scalProd, storeToXML
 

Constructor Detail

AbstractProblem

public AbstractProblem(java.lang.String name)
Method Detail

add

public Constraint add(Constraint constraint)
Adds a Constraint "constraint" to the problem, then returns the constraint. The Constraint is not posted.

Specified by:
add in interface Problem
Parameters:
constraint - the constraint to add to the problem.
Returns:
the Constraint added to the problem.

add

public Constraint add(java.lang.String name,
                      Constraint constraint)
Gives a Constraint "constraint" a new name "name", adds the Constraint to the problem and returns the newly added Constraint. The Constraint is not posted.

Parameters:
name - the new name for the Constraint.
constraint - the Constraint to add to the problem
Returns:
the Constraint added to the problem.

add

public Var add(java.lang.String name,
               Var var)
Gives the Var variable "var" a new name "name", adds it to the problem, and returns the newly added Var.

Specified by:
add in interface Problem
Parameters:
name - the new name for var.
var - the variable to add to the problem.
Returns:
the Var variable added to the problem.

add

public VarReal add(java.lang.String name,
                   VarReal var)
Gives the VarReal variable "var" a new name "name", adds it to the problem, and returns the newly added VarReal.

Parameters:
name - the new name for var.
var - the real variable to add to the problem.
Returns:
the VarReal variable added to the problem.

add

public Var add(Var var)
Adds a Var variable "var" to the problem, and returns the newly added Var.

Specified by:
add in interface Problem
Parameters:
var - the variable to add to the problem.
Returns:
the Var variable added to the problem.

add

public VarBool add(VarBool varBool)
Adds a VarBool variable "var" to the problem, and returns the newly added Var.

Specified by:
add in interface Problem
Parameters:
varBool - the bolean variable to add to the problem.
Returns:
the VarBool variable added to the problem.

add

public VarReal add(VarReal var)
Adds a VarReal variable "var" to the problem, and returns the newly added VarReal.

Specified by:
add in interface Problem
Parameters:
var - the real variable to add to the problem.
Returns:
the VarReal variable added to the problem.

add

public void add(VarString var)
Specified by:
add in interface Problem

addReversible

public Reversible addReversible(java.lang.String name,
                                int value)
Creates a Reversible integer with the name "name" and value "value" and returns the newly added Reversible.

Parameters:
name - the name for the new reversible.
value - the initial value
Returns:
the reversible integer

addVarArray

public Var[] addVarArray(java.lang.String arrayName,
                         java.lang.String[] varNames)
Creates an array of Var variables with name "arrayName". The variables to be contained in the array must have already been added to the problem, and their names are specified in "varNames".

Parameters:
arrayName - the name for the new Var array.
varNames - an array of names of already added variables, which are to form the new array.
Returns:
the array of Var variables created and added to the problem.

addVarArray

public Var[] addVarArray(java.lang.String name,
                         Var[] vars)
Gives the array of Var variables "vars" a new name "name", adds the array of variables to the problem, and returns the newly added Var array.

Parameters:
name - the new name for the array "vars".
vars - the array of Var variables to add to the problem.
Returns:
the array of Var variables added to the problem.

allDiff

public Constraint allDiff(VarList vars)
Description copied from interface: Problem
This method create a new Constraint stating that all of the elements of the list of variables "vars" must take different values from each other. To have an effect the constraint should be posted using Constraint's methods post() or post(ConsistencyLevel consistencyLevel)

Specified by:
allDiff in interface Problem
Parameters:
vars - the VarList which must all take different values.
Returns:
a newly created constraint

and

public Constraint and(Constraint[] array)
Returns an "AND" Constraint. The Constraint "AND" is satisfied if all of the Constraints in the array "array" are satisfied. The Constraint "AND" is not satisfied if at least one of the Constraints in "array" is not satisfied.

Parameters:
array - the array of constraints forming the new "AND" Constraint.
Returns:
a Constraint "AND" between all the Constraints in the array "array".

createVariable

public abstract Var createVariable(java.lang.String name,
                                   int min,
                                   int max)
Description copied from interface: Problem
Creates a Var with the name "name" and domain [min;max] of the default domain type, and returns the newly added Var. The variable will be created with the default domain type or by the latest call of the method setDomainType().

Specified by:
createVariable in interface Problem
Parameters:
name - the name for the new Var.
min - the minimum value in the domain for the new Var.
max - the maximum value in the domain for the new Var.
Returns:
the Var variable created and added to the problem.

debug

public abstract void debug(java.lang.String text)
Log the String parameter "text"


element

public Var element(int[] array,
                   Var indexVar)
Returns a constrained integer variable that is an element of the integer "array" with index defined as another constrained integer variable "indexVar". When index is bound to the value i, the value of the resulting variable is array[i]. More generally, the domain of the returned variable is the set of values array[i] where the i are in the domain of index.

Specified by:
element in interface Problem
Parameters:
array - an array of integers
indexVar - a constrained integer variable whose domain serves as an index into the array.
Returns:
a constrained integer variable whose domain is the set of values array[i] where each i is in the domain of "indexVar".

element

public VarSet element(java.util.Set<java.lang.Integer>[] sets,
                      Var indexVar)
               throws java.lang.Exception
Creates a set variable that corresponds to sets[index]

Specified by:
element in interface Problem
Parameters:
sets -
indexVar -
Returns:
a set variable
Throws:
java.lang.Exception

element

public Var element(Var[] array,
                   Var indexVar)
Returns a constrained integer variable that is an element of the "array" of variables with index defined as another constrained integer variable "indexVar". When index is bound to the value i, the value of the resulting variable is array[i]. More generally, the domain of the returned variable is the set of values array[i] where the i are in the domain of index.

Specified by:
element in interface Problem
Parameters:
array - an array of Var variables.
indexVar - a constrained integer variable whose domain serves as an index into the array.
Returns:
a constrained integer variable whose domain is the set of values array[i] where each i is in the domain of "indexVar".

element

public Var element(VarList list,
                   Var indexVar)
Specified by:
element in interface Problem

error

public abstract void error(java.lang.String text)
Log the String parameter "text"


getAPIVersion

public java.lang.String getAPIVersion()
Description copied from interface: Problem
Returns JSR331 API version number

Specified by:
getAPIVersion in interface Problem
Returns:
JSR331 API version number

getConstraint

public final Constraint getConstraint(java.lang.String name)
Description copied from interface: Problem
Returns the Constraint the name "name", or null if no such constraints exists in the problem.

Specified by:
getConstraint in interface Problem
Parameters:
name - the name of the desired constraint.
Returns:
the Constraint the name "name", or null if no such constraints exists in the problem.

getConstraints

public Constraint[] getConstraints()
Returns an array of Objects containing the Constraints previously added to the problem.

Specified by:
getConstraints in interface Problem
Returns:
an array of Objects containing the Constraints previously added to the problem.

getDomainType

public final DomainType getDomainType()

getFalseConstraint

public Constraint getFalseConstraint()
Returns the constant constraint that always will fail when it is posted or executed.

Specified by:
getFalseConstraint in interface Problem
Returns:
the False Constraint

getImplVersion

public abstract java.lang.String getImplVersion()
Description copied from interface: Problem
Returns JSR331 Implementation version number

Specified by:
getImplVersion in interface Problem
Returns:
JSR331 Implementation version number

getName

public final java.lang.String getName()
Description copied from interface: Problem
Returns the problem name

Specified by:
getName in interface Problem
Returns:
the problem name

getRealPrecision

public double getRealPrecision()
Returns the precision for VarReals

Specified by:
getRealPrecision in interface Problem
Returns:
the precision for VarReals

getSolver

public Solver getSolver()
Returns an instance of a Solver associated with this problem. If a solver is not defined yet, creates a new Solver and associates it with the problem.

Specified by:
getSolver in interface Problem
Returns:
a solver

getTrueConstraint

public Constraint getTrueConstraint()
Returns the constant constraint that always succeeds when it is posted or executed.

Specified by:
getTrueConstraint in interface Problem
Returns:
the True Constraint

getVar

public Var getVar(java.lang.String name)
Returns the Var variable with the name "name", or null if no such variable exists in the problem.

Specified by:
getVar in interface Problem
Parameters:
name - the name of the desired variable.
Returns:
the Var variable with the name "name", or null if no such variable exists in the problem.

getVarArray

public Var[] getVarArray(java.lang.String name)
Returns the array of Var variables with the name "name", or null if no such array exists in the problem.

Specified by:
getVarArray in interface Problem
Parameters:
name - the name of the desired array of Var variables.
Returns:
the array of Var variables with the name "name", or null if no such array exists in the problem.

getVarBools

public VarBool[] getVarBools()
Returns an array containing the VarBool variables previously added to the problem.

Specified by:
getVarBools in interface Problem
Returns:
an array containing the VarBool variables previously added to the problem.

getVarMatrix

public VarMatrix getVarMatrix(java.lang.String name)
Specified by:
getVarMatrix in interface Problem

getVarReal

public VarReal getVarReal(java.lang.String name)
Returns the VarReal variable with the name "name", or null if no such variable exists in the problem.

Specified by:
getVarReal in interface Problem
Parameters:
name - the name of the desired variable.
Returns:
the VarReal variable with the name "name", or null if no such variable exists in the problem.

getVarReals

public VarReal[] getVarReals()
Returns an array containing the VarReal variables previously added to the problem.

Specified by:
getVarReals in interface Problem
Returns:
an array containing the VarReal variables previously added to the problem.

getVars

public Var[] getVars()
Returns an array containing the Var variables previously added to the problem.

Specified by:
getVars in interface Problem
Returns:
an array containing the Var variables previously added to the problem.

getVarSets

public VarReal[] getVarSets()
Returns an array containing the VarSet variables previously added to the problem.

Specified by:
getVarSets in interface Problem
Returns:
an array containing the VarSet variables previously added to the problem.

getVarString

public VarString getVarString(java.lang.String name)
Specified by:
getVarString in interface Problem

getVarStrings

public VarString[] getVarStrings()
Specified by:
getVarStrings in interface Problem

isSolverCreated

public boolean isSolverCreated()

linear

public Constraint linear(VarString var,
                         java.lang.String oper,
                         java.lang.String value)
Specified by:
linear in interface Problem

log

public void log(Constraint[] constraints)
Logs all Constraints contained in the array "constraints".


log

public abstract void log(java.lang.String text)
Log the String parameter "text"

Specified by:
log in interface Problem

log

public void log(java.lang.String text,
                Var[] vars)
Logs the String "text" and then all integer constrained variables added to the problem.

Parameters:
text - the text to log prior to logging all the integer constrained variables added to the problem.

log

public void log(java.lang.String text,
                VarReal[] vars)
Logs the String "text" and then all real constrained variables contained in the array "vars".

Parameters:
text - the text to log prior to logging all the real constrained variables added to the problem.

log

public void log(java.lang.String text,
                VarSet[] vars)
Logs the String "text" and then all constrained set variables contained in the array "vars".

Parameters:
text - the text to log prior to logging all the constrained set variables added to the problem.

log

public void log(Var[] vars)
Logs the integer constrained variables contained in the array "vars".

Specified by:
log in interface Problem
Parameters:
vars - the array of Vars to log.

log

public void log(VarList vars)
Specified by:
log in interface Problem

log

public void log(VarReal[] vars)
Logs the real constrained variables contained in the array "vars".

Parameters:
vars - the array of VarReals to log.

log

public void log(VarSet[] vars)
Logs the constrained set variables contained in the array "vars".

Parameters:
vars - the array of VarSets to log.

max

public Var max(Var[] vars)
Returns a constrained integer variable that is equal to the maximal variable in the array "arrayOfVariables" when they are all instantiated.

Specified by:
max in interface Problem
Parameters:
vars - the array of variables from which we desire the maximal variable.
Returns:
a constrained integer variable that is equal to the maximal variable in the array "arrayOfVariables" when they are all instantiated.

max

public Var max(VarList listOfVariables)
Specified by:
max in interface Problem

max

public Var max(Var var1,
               Var var2)
Description copied from interface: Problem
Returns a constrained integer variable that is equal to the maximal of two variablea var1 or var 2 when they are both instantiated.

Specified by:
max in interface Problem
Parameters:
var1 - integer variable
var2 - integer variable
Returns:
maximum of two variables: var1 and var2

min

public Var min(Var[] vars)
Returns a constrained integer variable that is equal to the minimal variable in the array "arrayOfVariables" when they are all instantiated.

Specified by:
min in interface Problem
Parameters:
vars - the array of variables from which we desire the minimal variable.
Returns:
a constrained integer variable that is equal to the minimal variable in the array "arrayOfVariables" when they are all instantiated.

min

public Var min(VarList listOfVariables)
Specified by:
min in interface Problem

min

public Var min(Var var1,
               Var var2)
Description copied from interface: Problem
Returns a constrained integer variable that is equal to the minimal of two variablea var1 or var 2 when they are both instantiated.

Specified by:
min in interface Problem
Parameters:
var1 - integer variable
var2 - integer variable
Returns:
minimum of two variables: var1 and var2

notImplementedException

public void notImplementedException(java.lang.String feature)

post

public abstract void post(Constraint constraint)
This method takes a constraint's implementation and uses its own implementation-specific post-method.

Specified by:
post in interface Problem
Parameters:
constraint - the constraint to post.
Throws:
java.lang.RuntimeException - if a failure happened during the posting

post

public Constraint post(int[] array,
                       VarList vars,
                       java.lang.String oper,
                       int value)
Specified by:
post in interface Problem

post

public Constraint post(int[] array,
                       VarList vars,
                       java.lang.String oper,
                       Var var)

post

public Constraint post(java.lang.String name,
                       java.lang.String symbolicExpression)
Creates a Constraint based on the symbolicExpression such as "x*y-z<3*r", adds this constraint to the problem, and returns the newly added Constraint. It is assumed that all variables in the expression were previously created under names used within this expression. If the returned Constraint is null, there is either an error inside the symbolicExpression or there is no concrete solver implementation of this method. In either case, the constraint will not have been added to the problem.

Specified by:
post in interface Problem
Parameters:
name - the name for a new constraint
symbolicExpression - a string that defines a constrained expression that uses already defined variables, e.g. "x*y-z<3*r"
Returns:
the constraint created and added to the problem, or null if there is an error inside the symbolicExpression or if this method is not defined by a concrete solver implementation.

post

public Constraint post(VarList vars,
                       java.lang.String oper,
                       int value)
Description copied from interface: Problem
Creates and posts a constraint: sum of vars value

Specified by:
post in interface Problem
Returns:
a newly created constraint

post

public Constraint post(VarList vars,
                       java.lang.String oper,
                       Var var)
Description copied from interface: Problem
Creates and posts a constraint: sum of vars "oper" var

Specified by:
post in interface Problem
Returns:
a newly created constraint

post

public Constraint post(VarString var,
                       java.lang.String oper,
                       java.lang.String value)
Specified by:
post in interface Problem

post

public Constraint post(VarString var1,
                       java.lang.String oper,
                       VarString var2)
Specified by:
post in interface Problem

post

public Constraint post(Var var1,
                       Var var2,
                       java.lang.String oper,
                       int value)
Creates and posts a constraint: (var1 + var2) "oper" value

Specified by:
post in interface Problem
Returns:
a newly created constraint

post

public Constraint post(Var var1,
                       Var var2,
                       java.lang.String oper,
                       Var var)
Creates and posts a constraint: (var1 + var2) "oper" var

Specified by:
post in interface Problem
Returns:
a newly created constraint

postAllDiff

public Constraint postAllDiff(java.util.ArrayList<Var> vars)
Description copied from interface: Problem
Similar to postAllDiff for variables saved in the ArrayList vars

Specified by:
postAllDiff in interface Problem

postAllDiff

public Constraint postAllDiff(Var[] vars)
This constraint is a synonym for constraintAllDifferent

Specified by:
postAllDiff in interface Problem

postAllDifferent

public Constraint postAllDifferent(java.util.ArrayList<Var> vars)
Description copied from interface: Problem
Similar to postAllDifferent for variables saved in the ArrayList vars

Specified by:
postAllDifferent in interface Problem

postAllDifferent

public Constraint postAllDifferent(java.util.List vars)
Specified by:
postAllDifferent in interface Problem

postAllDifferent

public Constraint postAllDifferent(Var[] vars)
Creates and posts a new Constraint stating that all of the elements of the array of variables "vars" must take different values from each other.

Specified by:
postAllDifferent in interface Problem
Parameters:
vars - the array of Vars which must all take different values.
Returns:
the all-different Constraint on the array of Vars.

postAllDifferent

public Constraint postAllDifferent(VarList vars)
Specified by:
postAllDifferent in interface Problem

postAnd

public Constraint postAnd(Constraint c1,
                          Constraint c2)
Creates and posts a constraint an "AND" Constraint. The Constraint "AND" is satisfied if both of the Constraints "c1" and "c2" are satisfied. The Constraint "AND" is not satisfied if at least one of the Constraints "c1" or "c2" are not satisfied.

Specified by:
postAnd in interface Problem
Parameters:
c1 - a Constraint
c2 - a Constraint
Returns:
a Constraint "AND" between the Constraints "c1" and "c2".

postCardinality

public Constraint postCardinality(Var[] vars,
                                  Var cardVar,
                                  java.lang.String oper,
                                  int value)
This method is similar to the one above but instead of “var” it uses "value"

Specified by:
postCardinality in interface Problem

postCardinality

public Constraint postCardinality(Var[] vars,
                                  Var cardVar,
                                  java.lang.String oper,
                                  Var var)
This method creates a new cardinality constraint “cardinality(vars,cardVar) < value”. Here “cardinality(vars,cardVar)” denotes a constrained integer variable that is equal to the number of those elements in the array "vars" that are bound to the value of the variable "cardVar" when it is instantiated. For example, if “oper” is "<" it means that the variable “cardinality(vars,cardValue)” must be less than the “var”. This constraint does NOT assume a creation of an intermediate variable "cardinality(vars,cardValue)".

Specified by:
postCardinality in interface Problem

postCardinality

public Constraint postCardinality(VarList vars,
                                  int cardValue,
                                  java.lang.String oper,
                                  int value)
Specified by:
postCardinality in interface Problem

postCardinality

public Constraint postCardinality(VarList vars,
                                  int cardValue,
                                  java.lang.String oper,
                                  Var var)
Specified by:
postCardinality in interface Problem

postCardinality

public Constraint postCardinality(VarList vars,
                                  Var cardVar,
                                  java.lang.String oper,
                                  int value)
Specified by:
postCardinality in interface Problem

postCardinality

public Constraint postCardinality(VarList vars,
                                  Var cardVar,
                                  java.lang.String oper,
                                  Var var)
Specified by:
postCardinality in interface Problem

postElement

public Constraint postElement(java.util.Set[] arrayOfSets,
                              Var indexVar,
                              java.lang.String oper,
                              VarSet var)
Creates and posts a constraint: arrayOfSets[indexVar] setVar Here "arrayOfSets[indexVar]" denotes a constrained set variable, which domain consists of sets of integers arrayOfSets[i] where i is within domain of the "indexVar". When indexVar is bound to the value v, the value of the resulting variable is arrayOfSets[v]. The operator "oper" defines the type of relationships between "arrayOfSets[indexVar]" and "setVar"

Specified by:
postElement in interface Problem
Parameters:
arrayOfSets - an array of integer sets.
indexVar - a constrained integer variable whose domain serves as an index into the "arrayOfSets".
Returns:
a newly created constraint
Throws:
java.lang.RuntimeException - if the posting fails

postGlobalCardinality

public Constraint postGlobalCardinality(Var[] vars,
                                        int[] values,
                                        int[] cardMin,
                                        int[] cardMax)
For each index i the number of times the value "values[i]" occurs in the array "vars" should be cardMin[i] and cardMax[i] (inclusive)

Specified by:
postGlobalCardinality in interface Problem
Parameters:
vars - array of constrained integer variables
values - array of integer values within domain of all vars
cardMin - array of integers that serves as lower bounds for values[i]
cardMax - array of integers that serves as upper bounds for values[i] Note that arrays values, cardMin, and cardMax should have the same size otherwise a RuntimeException will be thrown

postGlobalCardinality

public Constraint postGlobalCardinality(Var[] vars,
                                        int[] values,
                                        Var[] cardinalityVars)
Description copied from interface: Problem
Creates and posts a new global cardinality constraint that states:

For each index i the number of times the value "values[i]" occurs in the array "vars" is exactly "cardinalityVars[i]"

Specified by:
postGlobalCardinality in interface Problem
Parameters:
vars - array of constrained integer variables
values - array of integer values
cardinalityVars - array of constrained integer variables (cardinality variables)
Returns:
a newly created constraint

postGlobalCardinality

public Constraint postGlobalCardinality(VarList vars,
                                        int[] values,
                                        int[] cardMin,
                                        int[] cardMax)
Specified by:
postGlobalCardinality in interface Problem

postGlobalCardinality

public Constraint postGlobalCardinality(VarList vars,
                                        int[] values,
                                        Var[] cardinalityVars)
Specified by:
postGlobalCardinality in interface Problem

postIfThen

public Constraint postIfThen(Constraint constraint1,
                             Constraint constraint2)
Creates and posts a constraint that states the implication: constraint1 => constraint2. In other words, if this constraint is satisfied, then constraint "c" should also be satisfied.

Specified by:
postIfThen in interface Problem
Parameters:
constraint1 - If-Constraint in the implication.
constraint2 - Then-Constraint in the implication.
Returns:
a Constraint that means: if constraint1 then constraint2

postLinear

public Constraint postLinear(int[] array,
                             Var[] vars,
                             java.lang.String oper,
                             int value)
Description copied from interface: Problem
Synonym for constraint(int[] array, Var[] vars, String oper, int value)

Specified by:
postLinear in interface Problem

postLinear

public Constraint postLinear(int[] array,
                             Var[] vars,
                             java.lang.String oper,
                             Var var)
Description copied from interface: Problem
Synonym for constraint(int[] array, Var[] vars, String oper, Var var)

Specified by:
postLinear in interface Problem

postLinear

public Constraint postLinear(int[] array,
                             VarList vars,
                             java.lang.String oper,
                             int value)
Specified by:
postLinear in interface Problem

postLinear

public Constraint postLinear(int[] array,
                             VarList vars,
                             java.lang.String oper,
                             Var var)

postLinear

public Constraint postLinear(Var[] vars,
                             java.lang.String oper,
                             int value)
Description copied from interface: Problem
Synonym for constraint(Var[] vars, String oper, int value)

Specified by:
postLinear in interface Problem

postLinear

public Constraint postLinear(Var[] vars,
                             java.lang.String oper,
                             Var var)
Description copied from interface: Problem
Synonym for constraint(Var[] vars, String oper, Var var)

Specified by:
postLinear in interface Problem

postLinear

public Constraint postLinear(Var var,
                             java.lang.String oper,
                             int value)
Description copied from interface: Problem
Synonym for constraint(Var var, String oper, int value)

Specified by:
postLinear in interface Problem

postLinear

public Constraint postLinear(Var var1,
                             java.lang.String oper,
                             Var var2)
Description copied from interface: Problem
Synonym for constraint(Var var1, String oper, Var var2)

Specified by:
postLinear in interface Problem

postMax

public Constraint postMax(Var[] vars,
                          java.lang.String oper,
                          int value)
Creates and posts a constraint: max(vars) "oper" value where max(vars) is a maximal variable in the array "vars" when they are all instantiated.

Specified by:
postMax in interface Problem
Parameters:
vars -
oper -
value -

postMax

public Constraint postMax(Var[] vars,
                          java.lang.String oper,
                          Var var)
Creates and posts a constraint: max(vars) "oper" var where max(vars) is a maximal variable in the array "vars" when they are all instantiated.

Specified by:
postMax in interface Problem
Parameters:
vars -
oper -
var -

postMin

public Constraint postMin(Var[] vars,
                          java.lang.String oper,
                          int value)
Creates and posts a constraint: min(vars) "oper" value where max(vars) is a minimal variable in the array "vars" when they are all instantiated.

Specified by:
postMin in interface Problem
Parameters:
vars -
oper -
value -

postMin

public Constraint postMin(Var[] vars,
                          java.lang.String oper,
                          Var var)
Creates and posts a constraint: min(vars) "oper" var where max(vars) is a minimal variable in the array "vars" when they are all instantiated.

Specified by:
postMin in interface Problem
Parameters:
vars -
oper -
var -

postOr

public Constraint postOr(Constraint c1,
                         Constraint c2)
Creates and posts a constraint an "OR" Constraint. The Constraint "OR" is satisfied if at least one of constraints "c1" or "c2" are satisfied. The Constraint "OR" is not satisfied if both constraints "c1" or "c2" are not satisfied.

Specified by:
postOr in interface Problem
Parameters:
c1 - a Constraint
c2 - a Constraint
Returns:
a Constraint "OR" between the Constraints "c1" and "c2".

remove

public void remove(java.lang.String varName)
Removes a Var variable by "name".

Parameters:
varName - the name of the variable to be removed from the problem.

scalProd

public Var scalProd(int[] arrayOfValues,
                    VarList vars)
Specified by:
scalProd in interface Problem

setDomainType

public final void setDomainType(DomainType domainType)
Description copied from interface: Problem
Sets the domain type that will be used as the default for subsequent creation of variables using addVar-methods

Specified by:
setDomainType in interface Problem

setName

public final void setName(java.lang.String name)
Sets the problem name

Specified by:
setName in interface Problem
Parameters:
name -

setRealPrecision

public void setRealPrecision(double value)
Sets the precision for VarReals

Specified by:
setRealPrecision in interface Problem
Parameters:
value - the new precision for VarReals

setSolver

public void setSolver(Solver solver)
Associates a "solver" with the problem making it available through the method "getSolver()".

Specified by:
setSolver in interface Problem
Parameters:
solver -

sum

public Var sum(Var[] vars)
Returns a constrained integer variable that is constrained to be the sum of the variables in the array "vars".

Specified by:
sum in interface Problem
Parameters:
vars - the array of variables from which we desire the sum.
Returns:
a constrained integer variable that is equal to the sum of the variables in the array "var".

sum

public Var sum(VarList vars)
Returns a constrained integer variable that is constrained to be the sum of the variables in the VarList "vars".

Specified by:
sum in interface Problem
Parameters:
vars - the list of variables from which we desire the sum.
Returns:
a constrained integer variable that is equal to the sum of the variables in the array "var".

var

public Var var(java.lang.String name,
               java.lang.String symbolicExpression)
Creates a Var variable based on the symbolicExpression, adds this variable to the problem, and returns the newly added Var. If the returned Var is null, there is either an error inside the symbolicExpression or there is no concrete solver implementation of this method. In either case, the constraint will not have been added to the problem.

Parameters:
symbolicExpression - a string that defines a constrained expression that uses already defined variables.
Returns:
the Var variable created and added to the problem, or null if there is an error inside the symbolicExpression or if this method is not defined by a concrete solver implementation.

variable

public Var variable(int[] domain)
Description copied from interface: Problem
An equivalent of var("",domain)

Specified by:
variable in interface Problem
Parameters:
domain - an array specifying the values in the domain for the new Var.
Returns:
the Var variable created and added to the problem.

variable

public Var variable(int min,
                    int max)
Description copied from interface: Problem
Creates a Var with domain [min;max]. The variable will be created with the default domain type or by the latest call of the method setDomainType(). This variable has an empty name and is not added to the problem.

Specified by:
variable in interface Problem
Parameters:
min - the minimum value in the domain for the new Var.
max - the maximum value in the domain for the new Var.
Returns:
the Var created variable

variable

public Var variable(java.lang.String name,
                    int[] domain)
Creates a Var with the name "name", and domain int[]

Specified by:
variable in interface Problem
Parameters:
name - a string
domain - an array of integers
Returns:
the created variable

variable

public Var variable(java.lang.String name,
                    int min,
                    int max)
Description copied from interface: Problem
Creates a Var by calling createVariable(name,min,max) and adds this variable to the problem. The variable will be created with the default domain type or by the latest call of the method setDomainType().

Specified by:
variable in interface Problem
Parameters:
name - the name for the new Var.
min - the minimum value in the domain for the new Var.
max - the maximum value in the domain for the new Var.
Returns:
the Var variable created and added to the problem.

variable

public Var variable(java.lang.String name,
                    int min,
                    int max,
                    DomainType domainType)
Similar to variable(String name, int min, int max) but also has one more parameter that defines the default domain type

Specified by:
variable in interface Problem
Parameters:
name - the name for the new Var
min - the minimum value in the domain for the new Var
max - the maximum value in the domain for the new Var
domainType - DomainType
Returns:
the Var variable created and added to the problem

variableArray

public Var[] variableArray(java.lang.String name,
                           int min,
                           int max,
                           int size)
Adds an array of Var variables with the name "name" and domains [min;max] of domain type "type", adds this array of variables to the problem, and returns the newly added Var array. The "size" parameter specifies how many Var variables are contained in this new array.

Specified by:
variableArray in interface Problem
Parameters:
name - the name for the new Var array.
min - the minimum value in the domains for the new Vars in the new Var array.
max - the maximum value in the domain for the new Vars in the new Var array.
size - the number of Vars in the new Var array.
Returns:
the array of Var variables created and added to the problem.

variableBool

public VarBool variableBool()
Creates a bool var not added to the problem.

Specified by:
variableBool in interface Problem
Returns:
the Var variable created

variableBool

public abstract VarBool variableBool(java.lang.String name)
Creates a boolean constrained variable with the name "name" and adds this variable to the problem, and returns the newly added VarBool.

Specified by:
variableBool in interface Problem
Parameters:
name - the name for the new Var.
Returns:
the Var variable created and added to the problem.

variableList

public VarList variableList()
Specified by:
variableList in interface Problem

variableMatrix

public VarMatrix variableMatrix(java.lang.String name,
                                int min,
                                int max,
                                int rows,
                                int columns)
Specified by:
variableMatrix in interface Problem

variableReal

public VarReal variableReal(java.lang.String name)
Creates a VarReal with the name "name" and default domain [Double.MIN_VALUE+1;Double.MAX_VALUE-1], adds this variable to the problem, and returns the newly added VarReal.

Specified by:
variableReal in interface Problem
Parameters:
name - the name for the new VarReal.
Returns:
the VarReal variable created and added to the problem.

variableReal

public VarReal variableReal(java.lang.String name,
                            double min,
                            double max)
Creates a VarReal with the name "name" and domain [min;max], adds this variable to the problem, and returns the newly added VarReal.

Specified by:
variableReal in interface Problem
Parameters:
name - the name for the new VarReal.
min - the minimum value in the domain for the new VarReal.
max - the maximum value in the domain for the new VarReal.
Returns:
the VarReal variable created and added to the problem.

variableSet

public VarSet variableSet(java.lang.String name,
                          int[] values)
                   throws java.lang.Exception
Creates a constrained set variable VarSet with the name "name" and which domain consists of integer values from the array "value".

Specified by:
variableSet in interface Problem
Parameters:
name -
values -
Returns:
the VarSet variable created and added to the problem.
Throws:
java.lang.Exception

variableSet

public VarSet variableSet(java.lang.String name,
                          int min,
                          int max)
                   throws java.lang.Exception
Creates a constrained set variable VarSet with the name "name" and domain of integer values from "min" to "max" inclusive. This interface show how to create a new constrained set variable which, when bound, is equal to a set of elements. The domain of a constrained set variable is a set of Sets that consist of regular integers.The cardinality of a set constrained variable is an integer constrained variable.

Specified by:
variableSet in interface Problem
Parameters:
name -
min -
max -
Returns:
a new VarSet variable
Throws:
java.lang.Exception

variableSet

public VarSet variableSet(java.lang.String name,
                          java.util.Set set)
                   throws java.lang.Exception
Creates a constrained set variable VarSet with the name "name" and which domain consists of integer values from the Set "set".

Specified by:
variableSet in interface Problem
Parameters:
name -
set -
Returns:
the VarSet variable created and added to the problem.
Throws:
java.lang.Exception

variableString

public VarString variableString(java.lang.String name,
                                java.lang.String[] allStrings)
Specified by:
variableString in interface Problem

varSquare

public Var[] varSquare(java.lang.String name,
                       int min,
                       int max,
                       int size)
Creates a 2-dimensional array of Var variables, with dimensions "size"x"size". The array has name "name" and each Var in the array has domain[min;max] of default domain type. The array is added to the problem, and then the array is returned. If "name" is a non-null string "X" then each element [i,j] can be found by using Problem method getInt("X[i,j]"). The default domain type is Var.DOMAIN_SMALL, but the chosen implementation may override this default with its own default.

Parameters:
min - the minimum value in the domains for the new Vars in the new Var array.
max - the maximum value in the domain for the new Vars in the new Var array.
size - the dimensions of the new 2-dimensional array. The array contains size*size elements.
Returns:
the array of Var variables created and added to the problem.