Class 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
    • Field Detail

      • swigCMemOwn

        protected transient boolean swigCMemOwn
    • 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 KSession
        name - the name of the problem
        n - 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 KSession
        name - the name of the problem
        n - 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 KSession
        name - the name of the problem
        n - 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 KSession
        name - 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 class java.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()
      • getVariableCopyPtr

        public KIntVar getVariableCopyPtr​(KIntVar intVar,
                                          int pb)
      • getVariableCopyPtr

        public KFloatVar getVariableCopyPtr​(KFloatVar floatVar,
                                            int pb)
      • getVariableCopyPtr

        public KNumVar getVariableCopyPtr​(KNumVar numVar,
                                          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.
      • 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 context
        pfp - 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 context
        pfp - 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