KProblem¶

class KProblem : public KPtrArray<KProblem>¶
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 objectmySession
. Since
2016.1
Public Types

enum LogLevel¶
Ouput log level.
Values:

enumerator LOW¶
Display errors and basic search information.

enumerator MEDIUM¶
Display errors, warnings and detailed search information.

enumerator HIGH¶
Display all information.

enumerator INTERNALDEBUG¶
Display all information (including internal debug information)

enumerator LOW¶

enum Sense¶
Sense for optimization
Values:

enumerator Minimize¶
Minimize objective variable.

enumerator Maximize¶
Maximize objective variable.

enumerator Minimize¶

enum constraintClass¶
Constraint classes for which an automatic relaxation is available.
Values:

enumerator KAbs¶

enumerator KAllDifferent¶

enumerator KEqualXc¶

enumerator KNotEqualXc¶

enumerator KGreaterOrEqualXc¶

enumerator KLessOrEqualXc¶

enumerator KEqualXyc¶

enumerator KNotEqualXyc¶

enumerator KGreaterOrEqualXyc¶

enumerator KDistanceLowerThanXyc¶

enumerator KDistanceGreaterThanXyc¶

enumerator KDistanceEqualXyc¶

enumerator KDistanceNotEqualXyc¶

enumerator KXEqualYMinusZ¶

enumerator KLinComb¶

enumerator KElement¶

enumerator KElement2D¶

enumerator KOccurenceVal¶

enumerator KOccurence¶

enumerator KGlobalCardinalityConstraint¶

enumerator KDisjunction¶

enumerator KConjunction¶

enumerator KGuard¶

enumerator KEquiv¶

enumerator KNumLinComb¶

enumerator OtherConstraints¶

enumerator KAbs¶
Public Functions

KProblem()¶
Default constructor.

KProblem(const KSession &session, const char *name, int n = 1, unsigned int initialSize = 1024 * 1024, unsigned int initialRegisterSize = 1000)¶
Main problem constructor
If
n
= 0, a multiinstance KProblem object is created with as many instances as the number of available coresIf
n
< 0, a singleinstance KProblem object is created Parameters
session – the KSession
name – the name of the problem
n – the number of problem instances

void setPrintFunctionPointer(void *ctx, PrintFunctionPtr *pfp)¶
Set the print function pointer.

int getNumberOfVariables()¶
return the number of variables in the problem

int getNumberOfConstraints()¶
return the number of constraints in the problem

void collectAllSolutions()¶
Collects all solutions from subproblem instances.

KSolutionContainer &getSolutionContainer()¶
Get solution container.

int getNumberOfSolutions() const¶
Return the number of solutions already found for this problem.

bool problemIsSolved() const¶
Returns true iff at least one solution was found for this problem.

KSolution &getBestSolution() const¶
Returns best solution found if problem has an objective, last solution found otherwise.

void post(const KConstraint &constraint)¶
Post a constraint to the problem.

void post(const KUserConstraint &constraint)¶
Post a user constraint to the problem.

void post(const KUserNumConstraint &constraint)¶
Post a user num constraint to the problem.

void post(const KConstraint *constraint)¶
Post a constraint given as a pointer to the problem. Caution: the pointer must be managed by the user and remain alive during optimization.

void setObjective(KFloatVar &objective)¶
Set the objective function to the problem as an continuous variable.

void setSense(int sense)¶
Sets optimization sense
 Parameters
sense – Maximization or Minimization

bool propagate(void)¶
Propagate changes in the problem, returns true if the problem is proved inconsistent, false otherwise.

void print() const¶
pretty printing of the problem

void printVariablesStates(void) const¶
pretty printing of the variables of the problem

void printDisjunctionsStates(void) const¶
pretty printing of the disjunctions involved in the problem

void optimizeInternalRepresentation()¶
Do some internal optimization to solve faster the problem.

KIntVar *getInstanceOf(const KIntVar *intVar) const¶
Returns monoinstance copy of multiinstance KIntVar object. The copy is already managed.

KFloatVar *getInstanceOf(const KFloatVar *floatVar) const¶
Returns monoinstance copy of multiinstance KFloatVar object. The copy is already managed.

KIntVarArray *getInstanceOf(const KIntVarArray *intVarArray) const¶
Returns monoinstance copy of multiinstance KIntVarArray object. The copy is already managed.

KNumVarArray *getInstanceOf(const KNumVarArray *numVarArray) const¶
Returns monoinstance copy of multiinstance KNumVarArray object. The copy is already managed.

KTaskArray *getInstanceOf(const KTaskArray *taskArray) const¶
Returns monoinstance copy of multiinstance KTaskArray object. The copy is already managed.

KDisjunctionArray *getInstanceOf(const KDisjunctionArray *disjunctionArray) const¶
Returns monoinstance copy of multiinstance KDisjunctionArray object. The copy is already managed.

KBranchingSchemeGroupArray *getInstanceOf(const KBranchingSchemeGroupArray *branchingSchemeGroupArray) const¶
Returns monoinstance copy of multiinstance KBranchingSchemeGroupArray object. The copy is already managed.

KLinearRelaxation *getLinearRelaxation(int strategy = 0)¶
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.

KLinearRelaxation *getLinearRelaxation(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

KLinearRelaxation *getSimpleLinearRelaxation(int rtype)¶
Get an automatic relaxation of all the constraints in the array provided as an argument.
 Parameters
constraintArray – 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

bool hasObjective() const¶
Returns true is the problem has an objective.

KNumVar getObjective() const¶
Return the Objective variable.
Throws an ArtelysException if the problem has no objective.

void printMinimalConflictSet(void *ctx = nullptr, PrintFunctionPtr *pfp = nullptr, int verboseLebel = 1) const¶
Print a minimal conflict set for this problem.
 Parameters
ctx – printing context
pfp – pointer to a printing function
verboseLevel – verbosity level of the calculations

KConstraintArray computeMinimalConflictSet()¶
Return the minimal conflict set for this problem.

double getProblemSize()¶
Return a measure of the problem size.