Decision Optimization

Decision Optimization

Delivers prescriptive analytics capabilities and decision intelligence to improve decision-making.


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Accessing int values from solution pool's solution.

    Posted 02/20/12 05:52 AM

    Originally posted by: UU24_Sergej_Andrejev


    I'm using populate method in cplex 12.3 to solve MILP problem.

    The problem is I want to access int variables from solution pool, but even though there is getValues(val, var, sln) method, there is no analogous getIntValues(var, val, sln) method. I was thinking I could convert values from getValues() method, but I can't figure out the correct way to convert them. Casting doesn't work consistently with getIntValues() results and getObjValue(), so do val >= 1e-04 or val <= 1 - 1e-07 conditions. I ended up with val > 0.5 check to convert to boolean variable, but I'm not sure that is the correct way.

    I also found this unanswered question (https://www.ibm.com/developerworks/forums/thread.jspa?messageID=14605244) which I think might be the same problem.

    Any help appreciated
    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Accessing int values from solution pool's solution.

    Posted 02/20/12 06:06 AM

    Originally posted by: T_O


    As a quick and dirty fix, it should be sufficient to add 0.5 to the values and then cast to int, because casting truncates e.g. 0.999 to 0.
    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Accessing int values from solution pool's solution.

    Posted 02/20/12 06:44 AM

    Originally posted by: SystemAdmin


    I think casting a floating point number to an integer is more or less the same as calling trunc(), so no rounding will occur, instead the value will just be truncated. This will turn 0.9999 into 0, probably exactly what you just observed.
    In Java it should be sufficient to use Math.round() to convert the floating point value to the nearest int.
    In C++ you could use IloRound() (which is the same as round() on most platforms) and then cast the result. That should avoid truncation issues. In my opinion the best way for C++ is to use lrint if you can make sure that the current floating point rounding direction is as required. Unfortunately not all libraries have this function.
    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: Accessing int values from solution pool's solution.

    Posted 02/20/12 01:50 PM

    Originally posted by: UU24_Sergej_Andrejev


    Do you know how it is done in cplex and whether comparing results to 0.5 like I do is correct? Actually I forgot to mention.

    My first intention was to use IloNumArray.toIntArray() method, but it was failing with some arrays even though all the variables used to getValues() where boolean.
    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: Accessing int values from solution pool's solution.

    Posted 02/21/12 02:26 AM

    Originally posted by: SystemAdmin


    toIntArray() is not going to help you since it throws an exception as soon as floor(val) != val for any value in the input array.

    Internally CPLEX uses an integrality tolerance to determine which values are integer and which not. For example, if the tolerance is T then any value in 1-T,1+T is considered integral. You could set this tolerance ( IloCplex::EpInt) to 0 but this may increase solving time and is no guarantee to get non-fractional values for all integer variables. Numerical round-off may still yield slightly fractional values for integer variables.

    It is definitely OK to do
    int intValue = (cplex.getValue(x) > 0.5) ? 1 : 0;
    

    for a boolean variable x. This is exactly what using round() or IloRound() would do.
    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  Re: Accessing int values from solution pool's solution.

    Posted 02/21/12 03:17 AM

    Originally posted by: UU24_Sergej_Andrejev


    Do you think if I find a solution with boolean variables inside T, 1 - T which doesn't satisfy tolerance I should discards the answer completely? That is considering that I want to list all answers or it shouldn't happen at all because solutions in solution space are already in agreement with tolerance values?
    #CPLEXOptimizers
    #DecisionOptimization


  • 7.  Re: Accessing int values from solution pool's solution.

    Posted 02/24/12 10:35 AM

    Originally posted by: SystemAdmin


    I think that highly depends on the value of T and the numerics of your problem. If T is reasonably small then there is no reason to reject the solution.
    If you don't trust the solution returned by CPLEX then you could round it, plug it into your problem and see if it is feasible or not.
    #CPLEXOptimizers
    #DecisionOptimization