Class KRelaxationSolver

  • Direct Known Subclasses:
    KLinearRelaxationSolver

    public class KRelaxationSolver
    extends java.lang.Object
    This class is intended as a superclass for linear relaxation solvers.

    Such a solver must be provided with
    - a linear relaxation (KLinearRelaxation)
    - an objective variable (KNumVar)
    - a sense for optimization (KProblem::Sense).

    It relies on a LP/MIP solver to provide the following information:
    - a value (a bound for the relaxed problem, cf method getBound())
    - a solution, possibly not feasible for the original problem, but which can be used to guide the search for a feasible solution
    - if the problem is LP, reduced costs (that can be used for instance in the "reduced cost fixing" procedure).

    Since:
    2016.1
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected boolean swigCMemOwn  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected KRelaxationSolver​(long cPtr, boolean cMemoryOwn)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      void delete()  
      protected void finalize()  
      void generateCuts​(KLinearRelaxation relaxation)
      Cut generation
      int getAlgorithm()
      Get the resolution algorithm
      double getBestBound()  
      double getBound()
      Get the (lower for minimization, upper for maximization) bound computed by solve().

      Note that :
      - solve() method must be called before the getBound() method
      - moreover, the return code provided by solve() must be checked before using the value
      returned by getBound().
      KRelaxationSolverConfigurator getConfigurator()
      Get the configurator of a KRelaxationSolver
      protected static long getCPtr​(KRelaxationSolver obj)  
      com.artelys.kalis.SWIGTYPE_p_KRelaxationSolver_I getInternalPtr()  
      double getLPSolution​(KAuxVar var)
      Get the current relaxed solution for a given KAuxVar variable.

      double getLPSolution​(KNumVar var)
      Get the current LP solution for a given KNumVar variable.

      double getMIPSolution​(KAuxVar var)
      Get the current MIP solution for a given KAuxVar variable.

      double getMIPSolution​(KNumVar var)
      Get the current MIP solution for a given KNumVar variable.

      int getNumberGlobals()
      Get the total number of global variables.
      double getTimeSpentInLastComputation()
      Get the amount of time spent during the last call to solve().
      double getTotalTimeSpentInComputation()
      Get the total amount of time spent in computations since the object was built.
      void instantiateNumVarsToCurrentSol()
      Instantiate variables to current solution obtained by linear relaxation solver
      void instantiateNumVarToCurrentSol​(KNumVar var)
      Instantiate a variables to current solution obtained by linear relaxation solver
      boolean isGlobal​(KAuxVar arg0)
      Return true if the given variable is set as global
      boolean isGlobal​(KIntVar arg0)
      Return true if the given variable is set as global
      void print()  
      void setAlgorithm​(int alg)
      Set the resolution algorithm
      void setAllGlobal​(boolean isGlobal)
      (Un)set variables as global.

      Set or unset as "global" all KIntVar and KAuxVar with global type (note
      that a KFloatVar variables are not modified, since it would make little
      sense to set them global.)

      void setConfigurator​(KRelaxationSolverConfigurator configurator)
      Set the configurator of a KRelaxationSolver
      void setGlobal​(KAuxVar var, boolean isGlobal)
      Set (or unset) a KAuxVar global.

      void setGlobal​(KIntVar var, boolean isGlobal)
      Set (or unset) a KIntVar as global.

      void setIndicatorsGlobal​(boolean isGlobal)
      Set all indicator auxiliary variables global.

      void setMaxMIPSol​(int arg0)
      Stop global search after maxMIPSol feasible solutions found.

      0 for no limit, this is the default.
      If the limit is low, this is likely to cause optimization to end before
      optimality.
      void setObjective​(KNumVar var)
      Set objective variable.

      void setSense​(int arg0)
      Set the sense of optimization (maximize, minimize).

      void setSolveAsMIP​(boolean flag)
      Deprecated.
      The new way of doing this is to use a configurator
      int solve()
      Solve the relaxed optimization problem.

      This methods returns the following error codes :
      - 0 : optimal
      - 1 : infeasible
      - 2 : search interrupted prematurely, a solution was found
      - 3 : search interrupted prematurely, no solution was found
      - 4 : other problem
      boolean solveAsMIP()
      Return true if the flag "solveAsMIP" is set
      • Methods inherited from class java.lang.Object

        clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • swigCMemOwn

        protected transient boolean swigCMemOwn
    • Constructor Detail

      • KRelaxationSolver

        protected KRelaxationSolver​(long cPtr,
                                    boolean cMemoryOwn)
    • Method Detail

      • finalize

        protected void finalize()
        Overrides:
        finalize in class java.lang.Object
      • delete

        public void delete()
      • getInternalPtr

        public com.artelys.kalis.SWIGTYPE_p_KRelaxationSolver_I getInternalPtr()
      • setObjective

        public void setObjective​(KNumVar var)
        Set objective variable.

        Parameters:
        var - the new objective variable
      • solve

        public int solve()
        Solve the relaxed optimization problem.

        This methods returns the following error codes :
        - 0 : optimal
        - 1 : infeasible
        - 2 : search interrupted prematurely, a solution was found
        - 3 : search interrupted prematurely, no solution was found
        - 4 : other problem
      • getBound

        public double getBound()
        Get the (lower for minimization, upper for maximization) bound computed by solve().

        Note that :
        - solve() method must be called before the getBound() method
        - moreover, the return code provided by solve() must be checked before using the value
        returned by getBound().
      • getBestBound

        public double getBestBound()
      • print

        public void print()
      • isGlobal

        public boolean isGlobal​(KIntVar arg0)
        Return true if the given variable is set as global
      • isGlobal

        public boolean isGlobal​(KAuxVar arg0)
        Return true if the given variable is set as global
      • setGlobal

        public void setGlobal​(KIntVar var,
                              boolean isGlobal)
        Set (or unset) a KIntVar as global.

        Parameters:
        var - variable to modify
        isGlobal - new global status
      • setGlobal

        public void setGlobal​(KAuxVar var,
                              boolean isGlobal)
        Set (or unset) a KAuxVar global.

        Parameters:
        var - variable to check
        isGlobal - new global status
      • setAllGlobal

        public void setAllGlobal​(boolean isGlobal)
        (Un)set variables as global.

        Set or unset as "global" all KIntVar and KAuxVar with global type (note
        that a KFloatVar variables are not modified, since it would make little
        sense to set them global.)

        Parameters:
        isGlobal - new global status
      • setIndicatorsGlobal

        public void setIndicatorsGlobal​(boolean isGlobal)
        Set all indicator auxiliary variables global.

        Parameters:
        isGlobal - new global status
      • setSense

        public void setSense​(int arg0)
        Set the sense of optimization (maximize, minimize).

      • getMIPSolution

        public double getMIPSolution​(KNumVar var)
        Get the current MIP solution for a given KNumVar variable.

        Parameters:
        var - variable whose solution is checked
        Returns:
        value of var in the current MIP solution
      • getMIPSolution

        public double getMIPSolution​(KAuxVar var)
        Get the current MIP solution for a given KAuxVar variable.

        Parameters:
        var - variable whose solution is checked
        Returns:
        value of var in the current MIP solution
      • getLPSolution

        public double getLPSolution​(KNumVar var)
        Get the current LP solution for a given KNumVar variable.

        Parameters:
        var - variable whose value is checked
        Returns:
        value of var in the current MIP solution
      • getLPSolution

        public double getLPSolution​(KAuxVar var)
        Get the current relaxed solution for a given KAuxVar variable.

        Parameters:
        var - variable whose value is checked
        Returns:
        value of var in the current solution
      • getNumberGlobals

        public int getNumberGlobals()
        Get the total number of global variables.
      • getTotalTimeSpentInComputation

        public double getTotalTimeSpentInComputation()
        Get the total amount of time spent in computations since the object was built.
      • getTimeSpentInLastComputation

        public double getTimeSpentInLastComputation()
        Get the amount of time spent during the last call to solve().
      • setSolveAsMIP

        public void setSolveAsMIP​(boolean flag)
        Deprecated.
        The new way of doing this is to use a configurator
        Set this flag to 0 if you want to solve as LP a linear relaxation
        containing global entities (1 is the default).

        Parameters:
        flag - New flag value

      • solveAsMIP

        public boolean solveAsMIP()
        Return true if the flag "solveAsMIP" is set
      • setMaxMIPSol

        public void setMaxMIPSol​(int arg0)
        Stop global search after maxMIPSol feasible solutions found.

        0 for no limit, this is the default.
        If the limit is low, this is likely to cause optimization to end before
        optimality.
      • setAlgorithm

        public void setAlgorithm​(int alg)
        Set the resolution algorithm
      • getAlgorithm

        public int getAlgorithm()
        Get the resolution algorithm
      • instantiateNumVarsToCurrentSol

        public void instantiateNumVarsToCurrentSol()
        Instantiate variables to current solution obtained by linear relaxation solver
      • instantiateNumVarToCurrentSol

        public void instantiateNumVarToCurrentSol​(KNumVar var)
        Instantiate a variables to current solution obtained by linear relaxation solver
      • generateCuts

        public void generateCuts​(KLinearRelaxation relaxation)
        Cut generation