Package com.artelys.kalis
Class KProblem
- java.lang.Object
-
- com.artelys.kalis.KProblem
-
public class KProblem extends java.lang.Object
Constraint satisfaction and optimization problems include variables,
constraints ( modeling entities ) and might have solutions after search.
Such problems are represented in Artelys Kalis by objects of the class
KProblem. These objects are holding the modeling entities objects, the
solutions objects and the objective variable object and the sense of the
optimization.
These elements are store in a KProblem object which is declared as follows :
KProblem myProblem(mySession,"myProblem");
This statement creates a KProblem object named myProblem and held by
the KSession object mySession.
For using Kalis parallel search algorithms, it is necessary to create
multiple instances of the problem to be solved.
This can be done by using the following KProblem declaration :
KProblem myProblem(mySession,"myProblem", n);
This statement creates a KProblem object named myProblem, storing
n problem instances and held by the KSession object
mySession.
- Since:
- 2016.1
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
KProblem.constraintClass
Constraint classes for which an automatic relaxation is availablestatic class
KProblem.LogLevel
Ouput log levelstatic class
KProblem.Sense
Sense for optimization
-
Field Summary
Fields Modifier and Type Field Description protected boolean
swigCMemOwn
-
Constructor Summary
Constructors Modifier Constructor Description KProblem()
Default constructorprotected
KProblem(long cPtr, boolean cMemoryOwn)
KProblem(KProblem problemToCopy)
KProblem(KSession session, java.lang.String name)
Main problem constructor
If n = 0, a multi-instance KProblem object is created with as many instances as the number of available cores
If n < 0, a single-instance KProblem object is created
KProblem(KSession session, java.lang.String name, int n)
Main problem constructor
If n = 0, a multi-instance KProblem object is created with as many instances as the number of available cores
If n < 0, a single-instance KProblem object is created
KProblem(KSession session, java.lang.String name, int n, long initialSize)
Main problem constructor
If n = 0, a multi-instance KProblem object is created with as many instances as the number of available cores
If n < 0, a single-instance KProblem object is created
KProblem(KSession session, java.lang.String name, int n, long initialSize, long initialRegisterSize)
Main problem constructor
If n = 0, a multi-instance KProblem object is created with as many instances as the number of available cores
If n < 0, a single-instance KProblem object is created
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addReference(java.lang.Object obj)
void
clearReferences()
void
collectAllSolutions()
Collects all solutions from subproblem instancesKConstraintArray
computeMinimalConflictSet()
Return the minimal conflict set for this problemvoid
delete()
void
destroy()
void
finalize()
KSolution
getBestSolution()
Returns best solution found if problem has an objective, last solution found otherwiseKProblem
getCopyPtr()
protected static long
getCPtr(KProblem obj)
int
getCurrentInstance()
com.artelys.kalis.SWIGTYPE_p_void
getFirstConstraint()
com.artelys.kalis.SWIGTYPE_p_void
getFirstVariable()
KBranchingScheme
getInstanceCopyPtr(KBranchingScheme branchingScheme, int pb)
KConstraint
getInstanceCopyPtr(KConstraint constraint, int pb)
KBranchingSchemeGroupArray
getInstanceOf(KBranchingSchemeGroupArray branchingSchemeGroupArray)
Returns mono-instance copy of multi-instance KBranchingSchemeGroupArray object.
The copy is already managed.KDisjunctionArray
getInstanceOf(KDisjunctionArray disjunctionArray)
Returns mono-instance copy of multi-instance KDisjunctionArray object.
The copy is already managed.KFloatVar
getInstanceOf(KFloatVar floatVar)
Returns mono-instance copy of multi-instance KFloatVar object.
The copy is already managed.KIntVar
getInstanceOf(KIntVar intVar)
Returns mono-instance copy of multi-instance KIntVar object.
The copy is already managed.KIntVarArray
getInstanceOf(KIntVarArray intVarArray)
Returns mono-instance copy of multi-instance KIntVarArray object.
The copy is already managed.KNumVarArray
getInstanceOf(KNumVarArray numVarArray)
Returns mono-instance copy of multi-instance KNumVarArray object.
The copy is already managed.KTaskArray
getInstanceOf(KTaskArray taskArray)
Returns mono-instance copy of multi-instance KTaskArray object.
The copy is already managed.KLinearRelaxation
getLinearRelaxation()
Get an automatic relaxation of all the posted constraints (if relaxation
available).
See the reference manual page of a constraint to check the available
options.KLinearRelaxation
getLinearRelaxation(int strategy)
Get an automatic relaxation of all the posted constraints (if relaxation
available).
See the reference manual page of a constraint to check the available
options.KLinearRelaxation
getLinearRelaxation(com.artelys.kalis.SWIGTYPE_p_KProblem__constraintClass constraintClassArray, int[] strategyArray, int nbElem)
Get an automatic relaxation of all the constraints in the array provided
as an argument.
com.artelys.kalis.SWIGTYPE_p_void
getNextConstraint()
com.artelys.kalis.SWIGTYPE_p_void
getNextVariable()
int
getNumberOfConstraints()
return the number of constraints in the problemint
getNumberOfSolutions()
Return the number of solutions already found for this problemint
getNumberOfVariables()
return the number of variables in the problemKNumVar
getObjective()
Return the Objective variable.
Throws an ArtelysException if the problem has no objective.double
getProblemSize()
Return a measure of the problem sizeint
getSense()
KLinearRelaxation
getSimpleLinearRelaxation(int rtype)
Get an automatic relaxation of all the constraints in the array provided
as an argument.
KSolution
getSolution()
Returns last solution foundKSolution
getSolution(int index)
Returns the solution numbered 'index'KSolutionContainer
getSolutionContainer()
Get solution containerboolean
getUse3BConsistency()
boolean
getUsePathConsistency()
KFloatVar
getVariableCopyPtr(KFloatVar floatVar, int pb)
KIntVar
getVariableCopyPtr(KIntVar intVar, int pb)
KNumVar
getVariableCopyPtr(KNumVar numVar, int pb)
boolean
hasObjective()
Returns true is the problem has an objectivevoid
optimizeInternalRepresentation()
Do some internal optimization to solve faster the problemvoid
popWorld()
void
post(KConstraint constraint)
Post a constraint to the problemvoid
post(KUserConstraint constraint)
Post a user constraint to the problemvoid
post(KUserNumConstraint constraint)
Post a user num constraint to the problemvoid
print()
pretty printing of the problemvoid
print(boolean satisfied, boolean violated, boolean unknown)
void
print(com.artelys.kalis.SWIGTYPE_p_void ctx, com.artelys.kalis.SWIGTYPE_p_f_p_void_p_q_const__char__int pfp)
void
printDisjunctionsStates()
pretty printing of the disjunctions involved in the problemvoid
printMinimalConflictSet()
Print a minimal conflict set for this problem.
void
printMinimalConflictSet(com.artelys.kalis.SWIGTYPE_p_void ctx)
Print a minimal conflict set for this problem.
void
printMinimalConflictSet(com.artelys.kalis.SWIGTYPE_p_void ctx, com.artelys.kalis.SWIGTYPE_p_f_p_void_p_q_const__char__int pfp)
Print a minimal conflict set for this problem.
void
printMinimalConflictSet(com.artelys.kalis.SWIGTYPE_p_void ctx, com.artelys.kalis.SWIGTYPE_p_f_p_void_p_q_const__char__int pfp, int verboseLebel)
Print a minimal conflict set for this problem.
void
printVariablesStates()
pretty printing of the variables of the problemboolean
problemIsSolved()
Returns true iff at least one solution was found for this problemboolean
propagate()
Propagate changes in the problem, returns true if the problem is proved inconsistent, false otherwisevoid
pushWorld()
void
setAllVariablesUseShaving(boolean use)
void
setCurrentInstance(int pb)
void
setLogLevel(int logLevel)
Set the output log levelvoid
setObjective(KFloatVar objective)
Set the objective function to the problem as an continuous variablevoid
setObjective(KIntVar objective)
Set the objective function to the problemvoid
setPrintFunctionPointer(com.artelys.kalis.SWIGTYPE_p_void ctx, com.artelys.kalis.SWIGTYPE_p_f_p_void_p_q_const__char__int pfp)
Set the print function pointervoid
setSense(int sense)
Sets optimization sense
void
setUse3BConsistency(boolean use)
void
setUsePathConsistency(boolean use)
boolean
shaveAndpropagate()
void
trace(int logLevel, java.lang.String format)
Trace 'printf' style function
-
-
-
Constructor Detail
-
KProblem
protected KProblem(long cPtr, boolean cMemoryOwn)
-
KProblem
public KProblem()
Default constructor
-
KProblem
public KProblem(KSession session, java.lang.String name, int n, long initialSize, long initialRegisterSize)
Main problem constructor
If n = 0, a multi-instance KProblem object is created with as many instances as the number of available cores
If n < 0, a single-instance KProblem object is created
- Parameters:
session
- the KSessionname
- the name of the problemn
- the number of problem instances
-
KProblem
public KProblem(KSession session, java.lang.String name, int n, long initialSize)
Main problem constructor
If n = 0, a multi-instance KProblem object is created with as many instances as the number of available cores
If n < 0, a single-instance KProblem object is created
- Parameters:
session
- the KSessionname
- the name of the problemn
- the number of problem instances
-
KProblem
public KProblem(KSession session, java.lang.String name, int n)
Main problem constructor
If n = 0, a multi-instance KProblem object is created with as many instances as the number of available cores
If n < 0, a single-instance KProblem object is created
- Parameters:
session
- the KSessionname
- the name of the problemn
- the number of problem instances
-
KProblem
public KProblem(KSession session, java.lang.String name)
Main problem constructor
If n = 0, a multi-instance KProblem object is created with as many instances as the number of available cores
If n < 0, a single-instance KProblem object is created
- Parameters:
session
- the KSessionname
- the name of the problem
-
KProblem
public KProblem(KProblem problemToCopy)
-
-
Method Detail
-
getCPtr
protected static long getCPtr(KProblem obj)
-
finalize
public void finalize()
- Overrides:
finalize
in classjava.lang.Object
-
delete
public void delete()
-
addReference
public void addReference(java.lang.Object obj)
-
clearReferences
public void clearReferences()
-
destroy
public void destroy()
-
getCopyPtr
public KProblem getCopyPtr()
-
getCurrentInstance
public int getCurrentInstance()
-
setCurrentInstance
public void setCurrentInstance(int pb)
-
setLogLevel
public void setLogLevel(int logLevel)
Set the output log level
-
setPrintFunctionPointer
public void setPrintFunctionPointer(com.artelys.kalis.SWIGTYPE_p_void ctx, com.artelys.kalis.SWIGTYPE_p_f_p_void_p_q_const__char__int pfp)
Set the print function pointer
-
trace
public void trace(int logLevel, java.lang.String format)
Trace 'printf' style function
-
getNumberOfVariables
public int getNumberOfVariables()
return the number of variables in the problem
-
getNumberOfConstraints
public int getNumberOfConstraints()
return the number of constraints in the problem
-
getFirstVariable
public com.artelys.kalis.SWIGTYPE_p_void getFirstVariable()
-
getNextVariable
public com.artelys.kalis.SWIGTYPE_p_void getNextVariable()
-
getFirstConstraint
public com.artelys.kalis.SWIGTYPE_p_void getFirstConstraint()
-
getNextConstraint
public com.artelys.kalis.SWIGTYPE_p_void getNextConstraint()
-
collectAllSolutions
public void collectAllSolutions()
Collects all solutions from subproblem instances
-
getSolutionContainer
public KSolutionContainer getSolutionContainer()
Get solution container
-
getNumberOfSolutions
public int getNumberOfSolutions()
Return the number of solutions already found for this problem
-
problemIsSolved
public boolean problemIsSolved()
Returns true iff at least one solution was found for this problem
-
getBestSolution
public KSolution getBestSolution()
Returns best solution found if problem has an objective, last solution found otherwise
-
getSolution
public KSolution getSolution()
Returns last solution found
-
getSolution
public KSolution getSolution(int index)
Returns the solution numbered 'index'
-
post
public void post(KConstraint constraint)
Post a constraint to the problem
-
post
public void post(KUserConstraint constraint)
Post a user constraint to the problem
-
post
public void post(KUserNumConstraint constraint)
Post a user num constraint to the problem
-
setObjective
public void setObjective(KIntVar objective)
Set the objective function to the problem
-
setObjective
public void setObjective(KFloatVar objective)
Set the objective function to the problem as an continuous variable
-
setSense
public void setSense(int sense)
Sets optimization sense
- Parameters:
sense
- Maximization or Minimization
-
getSense
public int getSense()
-
propagate
public boolean propagate()
Propagate changes in the problem, returns true if the problem is proved inconsistent, false otherwise
-
shaveAndpropagate
public boolean shaveAndpropagate()
-
print
public void print()
pretty printing of the problem
-
print
public void print(boolean satisfied, boolean violated, boolean unknown)
-
print
public void print(com.artelys.kalis.SWIGTYPE_p_void ctx, com.artelys.kalis.SWIGTYPE_p_f_p_void_p_q_const__char__int pfp)
-
printVariablesStates
public void printVariablesStates()
pretty printing of the variables of the problem
-
printDisjunctionsStates
public void printDisjunctionsStates()
pretty printing of the disjunctions involved in the problem
-
optimizeInternalRepresentation
public void optimizeInternalRepresentation()
Do some internal optimization to solve faster the problem
-
setUse3BConsistency
public void setUse3BConsistency(boolean use)
-
getUse3BConsistency
public boolean getUse3BConsistency()
-
setUsePathConsistency
public void setUsePathConsistency(boolean use)
-
getUsePathConsistency
public boolean getUsePathConsistency()
-
getInstanceCopyPtr
public KConstraint getInstanceCopyPtr(KConstraint constraint, int pb)
-
getInstanceCopyPtr
public KBranchingScheme getInstanceCopyPtr(KBranchingScheme branchingScheme, int pb)
-
getInstanceOf
public KIntVar getInstanceOf(KIntVar intVar)
Returns mono-instance copy of multi-instance KIntVar object.
The copy is already managed.
-
getInstanceOf
public KFloatVar getInstanceOf(KFloatVar floatVar)
Returns mono-instance copy of multi-instance KFloatVar object.
The copy is already managed.
-
getInstanceOf
public KIntVarArray getInstanceOf(KIntVarArray intVarArray)
Returns mono-instance copy of multi-instance KIntVarArray object.
The copy is already managed.
-
getInstanceOf
public KNumVarArray getInstanceOf(KNumVarArray numVarArray)
Returns mono-instance copy of multi-instance KNumVarArray object.
The copy is already managed.
-
getInstanceOf
public KTaskArray getInstanceOf(KTaskArray taskArray)
Returns mono-instance copy of multi-instance KTaskArray object.
The copy is already managed.
-
getInstanceOf
public KDisjunctionArray getInstanceOf(KDisjunctionArray disjunctionArray)
Returns mono-instance copy of multi-instance KDisjunctionArray object.
The copy is already managed.
-
getInstanceOf
public KBranchingSchemeGroupArray getInstanceOf(KBranchingSchemeGroupArray branchingSchemeGroupArray)
Returns mono-instance copy of multi-instance KBranchingSchemeGroupArray object.
The copy is already managed.
-
pushWorld
public void pushWorld()
-
popWorld
public void popWorld()
-
getLinearRelaxation
public KLinearRelaxation getLinearRelaxation(int strategy)
Get an automatic relaxation of all the posted constraints (if relaxation
available).
See the reference manual page of a constraint to check the available
options. All constraints for which a relaxation is available provide at
least strategies 0 and 1 : "0" is supposed to be tighter and "1" lighter.
Automatic relaxation 0 is LP by default and automatic relaxation 1 is MIP
by default, but you can change the type (global / continuous) of the
variables using setGlobal and setAllGlobal of KLinearRelaxation.
- Parameters:
strategy
- parameter to choose the relaxation you want to use.
-
getLinearRelaxation
public KLinearRelaxation getLinearRelaxation()
Get an automatic relaxation of all the posted constraints (if relaxation
available).
See the reference manual page of a constraint to check the available
options. All constraints for which a relaxation is available provide at
least strategies 0 and 1 : "0" is supposed to be tighter and "1" lighter.
Automatic relaxation 0 is LP by default and automatic relaxation 1 is MIP
by default, but you can change the type (global / continuous) of the
variables using setGlobal and setAllGlobal of KLinearRelaxation.
-
getLinearRelaxation
public KLinearRelaxation getLinearRelaxation(com.artelys.kalis.SWIGTYPE_p_KProblem__constraintClass constraintClassArray, int[] strategyArray, int nbElem)
Get an automatic relaxation of all the constraints in the array provided
as an argument.
- Parameters:
constraintClassArray
- types of constraints you want to relax (must have nbElem elements)strategyArray
- strategy for each constraint (must have nbElem elements)nbElem
- number of elements in the arrays
-
getSimpleLinearRelaxation
public KLinearRelaxation getSimpleLinearRelaxation(int rtype)
Get an automatic relaxation of all the constraints in the array provided
as an argument.
-
setAllVariablesUseShaving
public void setAllVariablesUseShaving(boolean use)
-
hasObjective
public boolean hasObjective()
Returns true is the problem has an objective
-
getObjective
public KNumVar getObjective()
Return the Objective variable.
Throws an ArtelysException if the problem has no objective.
-
printMinimalConflictSet
public void printMinimalConflictSet(com.artelys.kalis.SWIGTYPE_p_void ctx, com.artelys.kalis.SWIGTYPE_p_f_p_void_p_q_const__char__int pfp, int verboseLebel)
Print a minimal conflict set for this problem.
- Parameters:
ctx
- printing contextpfp
- pointer to a printing function
-
printMinimalConflictSet
public void printMinimalConflictSet(com.artelys.kalis.SWIGTYPE_p_void ctx, com.artelys.kalis.SWIGTYPE_p_f_p_void_p_q_const__char__int pfp)
Print a minimal conflict set for this problem.
- Parameters:
ctx
- printing contextpfp
- pointer to a printing function
-
printMinimalConflictSet
public void printMinimalConflictSet(com.artelys.kalis.SWIGTYPE_p_void ctx)
Print a minimal conflict set for this problem.
- Parameters:
ctx
- printing context
-
printMinimalConflictSet
public void printMinimalConflictSet()
Print a minimal conflict set for this problem.
-
computeMinimalConflictSet
public KConstraintArray computeMinimalConflictSet()
Return the minimal conflict set for this problem
-
getProblemSize
public double getProblemSize()
Return a measure of the problem size
-
-