Decision Optimization

Decision Optimization

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

 View Only
Expand all | Collapse all

Get a solutionhttp://www.ibm.com/developerworks/forums/post!default.jspa?fo

  • 1.  Get a solutionhttp://www.ibm.com/developerworks/forums/post!default.jspa?fo

    Posted Mon April 12, 2010 04:20 PM

    Originally posted by: anamaria.anayaarenas


    Hello,

    I'm trying to create an application with Java for create and solve a MIP with Cplex. I'll already create the model and solve it. But now i want to be able to post the value of the Objective Function at different times of the solution process (say every minute or every 30 seconds).. Is that possible? I find the function TuningDisplay (int).. is this the one? how can i enter the parameters??

    I some one can help me I will really appreciate it... I'm new at Java and Cplex! :s

    Thanks a lot!!!

    A.Anaya
    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Get a solutionhttp://www.ibm.com/developerworks/forums/post!default.jspa?fo

    Posted Mon April 12, 2010 04:32 PM

    Originally posted by: SystemAdmin


    If you just want to see the progress on your screen, you can set some CPLEX parameters to display a log file. In the C API the relevant parameters are CPX_PARAM_SCRIND, CPX_PARAM_MIPDISPLAY, and CPX_PARAM_MIPINTERVAL. I don't know how these parameters are called in Jave, but they probably have similar names. Consult the manual to find them.

    If you want to query the incumbent and best bound values to do something fancy in your Java application (like printing a graph with the primal and dual bounds, or displaying some kind of progress bar), then you need to use an "informational callback". Please see the manual how to do this. There is also the "MIPex4.java" example in your CPLEX distribution in the "examples/java" subdirectory. This uses an informational callback, so you can see how to do it.

    Tobias
    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Get a solutionhttp://www.ibm.com/developerworks/forums/post!default.jspa?fo

    Posted Mon April 12, 2010 04:42 PM

    Originally posted by: anamaria.anayaarenas


    Well, thanks a lot for your answer.. im gonna look for the parameters in Java... the informational callback is a good idea, but for now i just want to be able to see the value of the objective function and the gap.

    Thanks anyway,

    A.Anaya
    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: Get a solutionhttp://www.ibm.com/developerworks/forums/post!default.jspa?fo

    Posted Tue April 13, 2010 01:25 AM

    Originally posted by: SystemAdmin


    There is no such parameter for Java. Don't you see an output like this:
    Selected objective sense:  MINIMIZE
    Selected objective  name:  total_costs
    Selected RHS        name:  rhs        
    Selected bound      name:  bnd        
    Tried aggregator 1 time.              
    Aggregator did 24 substitutions.      
    Reduced MIP has 455 rows, 818 columns, and 2043 nonzeros.
    Reduced MIP has 397 binaries, 0 generals, 0 SOSs, and 0 indicators.
    Presolve time =    0.00 sec.                                       
    Clique table members: 29.                                          
    MIP emphasis: balance optimality and feasibility.                  
    MIP search method: dynamic search.                                 
    Parallel mode: deterministic, using up to 2 threads.               
    Root relaxation solution time =    0.00 sec.                       
     
            Nodes                                         Cuts/ 
       Node  Left     Objective  IInf  Best Integer     Best Node    ItCnt     Gap
     
          0     0      983.1674    24                    983.1674      106         
          0     0     1030.7685    27                    Cuts: 61      182         
          0     0     1045.1624    34                    Cuts: 33      234         
          0     0     1056.9364    37                    Cuts: 16      289         
          0     0     1059.5056    42                    Cuts: 11      314         
          0     0     1061.1749    46                    Cuts: 10      347         
          0     0     1063.4669    44                    Cuts: 12      389         
          0     0     1066.7358    42                    Cuts: 12      441         
          0     0     1074.6732    46                    Cuts: 13      489         
          0     0     1075.4509    47                     Cuts: 3      517         
          0     0     1078.0319    47                    Cuts: 11      569         
          0     0     1081.0944    47                    Cuts: 10      615         
          0     0     1083.9145    55                     Cuts: 7      668         
          0     0     1085.2013    54                    Cuts: 12      713         
          0     0     1086.7665    53                     Cuts: 8      758         
          0     0     1087.8046    55                    Cuts: 12      793         
          0     0     1088.0676    58                   Covers: 1      813         
          0     0     1088.3318    53                     Cuts: 7      838         
          0     0     1088.4547    60                     Cuts: 4      849         
          0     0     1088.7303    56                     Cuts: 9      868         
    *     0+    0                         1431.0000     1088.7303      868   23.92%
    *     0+    0                         1384.0000     1088.7303      868   21.33%
    *     0+    0                         1170.0000     1088.7303      868    6.95%
    *     0+    0                         1158.0000     1088.7303      868    5.98%
          0     2     1088.7303    56     1158.0000     1088.7303      868    5.98%
        100    56     1156.8831     3     1158.0000     1090.4565     3505    5.83%
        200   107     1121.2216    38     1158.0000     1105.6505     7087    4.52%
        300   159     1116.5026    30     1158.0000     1106.9100     9122    4.41%
        400   195     1137.7402    27     1158.0000     1113.6844    11898    3.83%
        500   261     1140.6393    20     1158.0000     1115.4560    14176    3.67%
        600   253     1136.0688    14     1158.0000     1115.4560    18054    3.67%
        700   243     1151.7777    24     1158.0000     1115.4560    20592    3.67%
        800   248        cutoff           1158.0000     1115.4560    23267    3.67%
        900   263     1142.2662    10     1158.0000     1118.1157    26494    3.44%
       1000   273     1140.5885    30     1158.0000     1121.5396    30585    3.15%
    Elapsed real time =   6.84 sec. (tree size =  0.08 MB, solutions = 4)          
       1100   316     1145.1445    14     1158.0000     1123.7826    34276    2.95%
       1200   367     1132.4366    25     1158.0000     1125.5038    37183    2.81%
       1300   401        cutoff           1158.0000     1127.7763    40855    2.61%
       1400   450     1149.6268    28     1158.0000     1129.8826    44054    2.43%
       1500   471        cutoff           1158.0000     1132.9375    47827    2.16%
       1600   474     1151.4207    20     1158.0000     1135.1903    51481    1.97%
       1700   485     1156.8374    20     1158.0000     1137.2711    55209    1.79%
       1800   466        cutoff           1158.0000     1139.0625    58372    1.64%
       1900   429        cutoff           1158.0000     1140.9689    61897    1.47%
       2000   439     1152.9333    11     1158.0000     1142.2017    64273    1.36%
    Elapsed real time =   7.80 sec. (tree size =  0.14 MB, solutions = 4)          
       2100   427     1154.1556     9     1158.0000     1143.6801    66944    1.24%
       2200   417     1151.6467     8     1158.0000     1144.9936    69311    1.12%
       2300   364     1155.2372    29     1158.0000     1146.2315    71677    1.02%
       2400   302     1150.0974    17     1158.0000     1148.0016    73449    0.86%
       2500   221        cutoff           1158.0000     1149.7803    75082    0.71%
       2600   145        cutoff           1158.0000     1151.5869    76925    0.55%
       2700    57    infeasible           1158.0000     1153.9186    78206    0.35%
     
    Cover cuts applied:  33
    Implied bound cuts applied:  67
    Flow cuts applied:  35
    Mixed integer rounding cuts applied:  29
    Flow path cuts applied:  18
    Zero-half cuts applied:  1
    Multi commodity flow cuts applied:  20
    Gomory fractional cuts applied:  5
     
    Root node processing (before b&c):
      Real time             =    2.27
    Parallel b&c, 2 threads:
      Real time             =    6.08
      Sync time (average)   =    0.13
      Wait time (average)   =    0.47
                              -------
    Total (root+branch&cut) =    8.35 sec.
    

    This is the output that Tobias meant to enable by setting CPX_PARAM_SCRIND.
    However, as I said there is no such parameter in Java. Instead the output is enabled by default and if you want to disable it you have to call
    IloCplex cplex = new IloCplex();
    ...
    cplex.setOut(null);
    

    By default an output line is printed every 100 nodes. You can change that interval by
    cplex.setParam(IloCplex.IntParam.MIPInterval, N); // Output a log line every N nodes (N is an integer)
    

    If that is not enough you will need to use the info callback as suggested by Tobias.
    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: Get a solutionhttp://www.ibm.com/developerworks/forums/post!default.jspa?fo

    Posted Tue April 13, 2010 06:04 PM

    Originally posted by: anamaria.anayaarenas


    Hi! Daniel thank you for your help! mm ok, yes i get all the output that you mention. but i get it in the Java Consol. Is it possible to have it in an output file like the log file for Cplex? and if i want to limit the optimization time? i found the parameter is TiLim, is that right??

    Thanks for your answer. :)

    Ana Maria Anaya
    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  Re: Get a solutionhttp://www.ibm.com/developerworks/forums/post!default.jspa?fo

    Posted Wed April 14, 2010 01:15 AM

    Originally posted by: SystemAdmin


    To redirect CPLEX output to a file use IloCplex.setOut(java.io.OutputStream out):
    IloCplex cplex = new IloCplex();
    cplex.setOut(new FileOutputStream("logfile"));
    

    If you also want to redirect warnings use IloCplex.setWarning(java.io.OutputStream out):

    Yes, TiLim limits the time CPLEX spends on optimizing the problem. There are also other parameters to limit the work CPLEX does. For example,
    • NodeLim limits the number of nodes that are explored,
    • ItLim limits the number of simplex iterations,
    • IntSolLim stops after a specified number of solutions where found,
    • EpAGap/EpGap stops if a solution of sufficient quality is found.

    #CPLEXOptimizers
    #DecisionOptimization


  • 7.  Re: Get a solutionhttp://www.ibm.com/developerworks/forums/post!default.jspa?fo

    Posted Wed April 14, 2010 10:53 AM

    Originally posted by: anamaria.anayaarenas


    Hey thanks again, you are really helpful! this is my first time in java and in Cplex so im having all kinds of trouble... i try to add the time limit function but i dont know why it doesnt work.. do you think that you could give me a hand with the code line?? :s i write inside of

    IloCplex cplex = new IloCplex();
    cplex.setParam(IloCplex.TiLim (0.05));

    but he says that the function is not right. What is the right path for this kind of parameters?

    Anyway, if you or someone else could give me a hand i will really appreciate it!! :)

    thanks!
    #CPLEXOptimizers
    #DecisionOptimization


  • 8.  Re: Get a solutionhttp://www.ibm.com/developerworks/forums/post!default.jspa?fo

    Posted Wed April 14, 2010 10:57 AM

    Originally posted by: SystemAdmin


    It is
    cplex.setParam(IloCplex.DoubleParam.TiLim, 0.05);
    

    Note that some other parameters are in IloCplex.IntParam or IloCplex.BoolParam.
    #CPLEXOptimizers
    #DecisionOptimization


  • 9.  Re: Get a solutionhttp://www.ibm.com/developerworks/forums/post!default.jspa?fo

    Posted Thu April 15, 2010 02:05 PM

    Originally posted by: anamaria.anayaarenas


    Hey Daniel, thanks a lot for your help, i did check the examples but not all the functions are in there.. anyway i still have a bug in this part of my code.. now the line of the parameter set is not showing any errors, but when i execute, he does the first loop with out any problems, but in the second one he shows this error:

    Exception in thread "main" java.lang.NullPointerException

    and he says that is in the line of cplex.setParam like I put it here.. this is my loop code

    while (totaltime <= timeLimit){

    cplex.setParam(IloCplex.DoubleParam.TiLim, 60 );

    if (cplex.solve()){

    ......
    ......
    ......

    totaltime=totaltime+0.05;
    }

    Thanks again for your help!

    Ana
    #CPLEXOptimizers
    #DecisionOptimization


  • 10.  Re: Get a solutionhttp://www.ibm.com/developerworks/forums/post!default.jspa?fo

    Posted Fri April 16, 2010 12:25 AM

    Originally posted by: SystemAdmin


    The call to cplex.solve() completes without exception?
    What do you do after this? Do you happen to call cplex.end()? I'd need more code to tell you what is going wrong. Can you post your complete code here? If you don't want to or are not allowed to you can also send it directly to me: daniel(dot)junglas(at)de(dot)ibm(dot)com.
    And if you have the time, could you make a list of functions that are not in the examples and for which an example would have helped you? This could help us to improve our examples.
    #CPLEXOptimizers
    #DecisionOptimization


  • 11.  Re: Get a solutionhttp://www.ibm.com/developerworks/forums/post!default.jspa?fo

    Posted Wed April 14, 2010 10:58 AM

    Originally posted by: SystemAdmin


    By the way, have you looked at the examples that come with CPLEX? If you are new to CPLEX and Java it might be the easiest way to start from an example you know that works and change that one bit at a time.
    #CPLEXOptimizers
    #DecisionOptimization