|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectomnics.Problem
public class Problem
Represents a constraint satisfaction problem. Constraint satisfaction problems are used to represent any type of situation where it is necessary to find a state for some objects that satifies a given set of restrictions, called constraints. The objects of the initial problem are modelled as variables having specified domains and a solution is an assignment of these variables with values from their domains that does not violate any constraint. Formally, such a problem will be represented as a constrained network. A constraint network is a triplet (X,D,C) where:
Var,
Domain,
Constraint,
Serialized Form| Field Summary | |
|---|---|
protected ConstraintSet |
constraints
|
protected java.lang.String |
description
|
static int |
INCONSISTENT
|
protected java.lang.String |
name
|
protected int |
optimum
|
static int |
SIMPLE
|
static int |
SOLVED
|
protected Solver |
solver
|
static int |
UNKNOWN
|
protected ValuationStructure |
valuation
|
protected VarSet |
variables
|
| Constructor Summary | |
|---|---|
Problem()
Creates a new instance of Problem, having no name. |
|
Problem(java.lang.String name)
Creates a new instance of Problem, having a specified name. |
|
| Method Summary | |
|---|---|
void |
addConstraint(Constraint constraint)
Adds a new constraint to the problem. |
int |
addVariable(Var var)
Adds a variable to the problem. |
SystematicSolver |
createSolver()
Creates and sets a default solver for this problem. |
SystematicSolver |
createSolver(java.lang.String filename)
Creates and sets a solver for this problem, whose state is retrieved from an external file. |
Var[] |
createVariables(int n)
Creates and returns n variables for this problem having no domain (the domain of each variable is null). |
Var[] |
createVariables(int n,
Domain domain)
Creates and returns n variables for this problem. |
ConstraintSet |
getConstraints()
Gets a reference to the collection of constraints of this problem. |
ConstraintSet |
getConstraints(VarSet someVars)
Creates and returns a set of constraints which are defined on variables containing one or more of the variables received as argument. |
java.lang.String |
getDescription()
Gets the description of this problem. |
java.lang.String |
getName()
Gets the name of this problem. |
int |
getOptimum()
Gets the known optimum of this problem. |
Solver |
getSolver()
Gets the solver which was associated to this problem. |
ValuationStructure |
getValuationStructure()
Gets the valuation structure of this problem. |
Var[] |
getVarArray()
Creates and returns an array (Var[]) containing the variables of the problem. |
VarSet |
getVariables()
Gets a reference to the collection of variables of this problem. |
VarSet |
getVariables(Var var)
Creates and returns a VarSet consisting of the variables of the
problem which participate, together with the argument variable,
in some constraint of the problem
(we say that these variables depend on each other). |
void |
reduce()
Attempts to reduce the problem, eliminating all values that are not good. |
void |
removeConstraint(Constraint constraint)
Removes a constraint from the problem. |
void |
removeConstraints(ConstraintSet constraintSet)
Removes a set of constraints from the problem. |
void |
removeVariable(Var var)
Removes a variable from the problem. |
void |
removeVariables(VarSet vars)
Removes a set of variables from the problem. |
long |
searchSpaceSize()
Computes the size of the problem search space. |
void |
setConstraints(Constraint... constraints)
Sets the constraints of the problem, copying the constraints given as parameters in a ConstraintSet. |
void |
setConstraints(ConstraintSet constraints)
Sets the constraints of the problem. |
void |
setDescription(java.lang.String description)
Sets the description of this problem. |
void |
setName(java.lang.String name)
Sets the name of this problem. |
void |
setOptimum(int optimum)
Sets the known optimum of this problem. |
protected void |
setSolver(Solver solver)
Sets a solver to this problem. |
void |
setValuationStructure(ValuationStructure valuation)
Sets the valuation structure of this problem. |
void |
setVariables(Var... vars)
Sets the variables of the problem, copying the variables given as parameters in a VarSet. |
void |
setVariables(VarSet variables)
Sets the variables of the problem. |
int |
size()
Returns the size of the problem, i.e. |
void |
sortVariables(java.util.Comparator<Var> comparator)
Sorts the variable according to a comparator. |
java.lang.String |
toString()
Gets a string representation of this problem. |
Var |
variable(int index)
Returns the variable having the specified index. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
protected java.lang.String name
protected java.lang.String description
protected VarSet variables
protected ConstraintSet constraints
protected ValuationStructure valuation
protected Solver solver
protected int optimum
public static final int UNKNOWN
public static final int SIMPLE
public static final int SOLVED
public static final int INCONSISTENT
| Constructor Detail |
|---|
public Problem()
public Problem(java.lang.String name)
name - the name of the problem| Method Detail |
|---|
public java.lang.String getName()
public void setName(java.lang.String name)
name - the name of the problempublic java.lang.String getDescription()
public void setDescription(java.lang.String description)
description - the description of the problempublic VarSet getVariables()
VarSet.
public VarSet getVariables(Var var)
VarSet consisting of the variables of the
problem which participate, together with the argument variable,
in some constraint of the problem
(we say that these variables depend on each other).
var - a variable of the problem
public Var[] getVarArray()
public void setVariables(VarSet variables)
VarSet.
The method stores the reference and does not create a copy of the
corresponding object.
variables - a set of variablesVarSetpublic void setVariables(Var... vars)
vars - an array of variables
public Var[] createVariables(int n,
Domain domain)
n - the number of variables to be createddomain - the domain which will be set for each variable
Domainpublic Var[] createVariables(int n)
n - the number of variables to be created
public Var variable(int index)
index - index of the variable to return
public int addVariable(Var var)
var - the variable to be added
public void removeVariable(Var var)
var - the variable to be removedpublic void removeVariables(VarSet vars)
vars - the variables to be removedpublic int size()
public ConstraintSet getConstraints()
ConstraintSet.
public ConstraintSet getConstraints(VarSet someVars)
someVars - a set of variables
public void setConstraints(ConstraintSet constraints)
ConstraintSet.
The method stores the reference and does not create a copy of the
corresponding object.
constraints - a set of constraintspublic void setConstraints(Constraint... constraints)
constraints - an array of constraintspublic void addConstraint(Constraint constraint)
constraint - the constraint to be addedpublic void removeConstraint(Constraint constraint)
constraint - the constraint to be removedpublic void removeConstraints(ConstraintSet constraintSet)
constraintSet - the variables to be removedpublic long searchSpaceSize()
|D_1| * |D_2| * ... * |D_n|
public ValuationStructure getValuationStructure()
ValuationStructurepublic void setValuationStructure(ValuationStructure valuation)
valuation - the valuation structure to be usedValuationStructurepublic Solver getSolver()
Solverprotected void setSolver(Solver solver)
solver - the solver which will be used to solve this problemSolverpublic SystematicSolver createSolver()
Backtracking.
Backtrackingpublic SystematicSolver createSolver(java.lang.String filename)
filename - a file containing the serialized state of a solver
public int getOptimum()
public void setOptimum(int optimum)
optimum - a value between ValuationStructure.MIN and
ValuationStructure.MAX representing the known optimum
IllegalArgumentException - if the value is not in
the specified interval.public void reduce()
public java.lang.String toString()
toString in class java.lang.Objectpublic void sortVariables(java.util.Comparator<Var> comparator)
comparator - a comparator for variables
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||