Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
Expand all | Collapse all

Cplex API vs Cplex Interactive

  • 1.  Cplex API vs Cplex Interactive

    Posted 09/26/11 09:38 PM

    Originally posted by: Dursun


    I am using the dual simplex algorithm to solve LP relaxations
    in an Integer Linear Program (ILP) with 176 binary variables.
    The number of LP relaxations
    solved per second on average is 350 if I call p.lp_solver->resolve() in the Cplex library by using API.

    If Cplex is used interactively on the same problem the number
    of LP relaxations solved per second on average is about 1150.
    I observed a similar phenomenon on different problems with different
    number of variables as well.

    The search trees generated by API and Cplex Interactive are different.
    However this still does not explain the consistent difference in performance
    between the two solvers in terms of the number of LP relaxations that they can
    process per second. I was wondering whether Cplex Interactive is inherently 3 times
    faster than API for solving LP relaxations.

    The order of the variables are the same for both solvers.
    However the order of the constraints might be different.

    Thanks in advance for your attention.
    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Cplex API vs Cplex Interactive

    Posted 09/27/11 12:27 AM

    Originally posted by: EdKlotz


    > Dursun wrote:
    > I am using the dual simplex algorithm to solve LP relaxations
    > in an Integer Linear Program (ILP) with 176 binary variables.
    > The number of LP relaxations
    > solved per second on average is 350 if I call p.lp_solver->resolve()

    This p.lp_solver->resolve() is not a CPLEX API function call. This must
    be part of your program, apparently written in C++, right? But, are calling
    CPLEX's C or C++ API?

    in the Cplex library by using API.
    >
    > If Cplex is used interactively on the same problem the number
    > of LP relaxations solved per second on average is about 1150.
    > I observed a similar phenomenon on different problems with different
    > number of variables as well.
    >
    > The search trees generated by API and Cplex Interactive are different.
    > However this still does not explain the consistent difference in performance
    > between the two solvers in terms of the number of LP relaxations that they can
    > process per second. I was wondering whether Cplex Interactive is inherently 3 times
    > faster than API for solving LP relaxations.
    >
    > The order of the variables are the same for both solvers.
    > However the order of the constraints might be different.
    >
    > Thanks in advance for your attention.
    I think your post consists of two separate questions.

    1. The easier one: Can CPLEX take a different path when run interactively?
    This can happen for numerous reasons. For starters, if you write out the model
    from your program in LP or MPS format and read it into interactive CPLEX, that will
    be enough to alter the path CPLEX takes. As you mention, changing the order of
    constraints or variables suffices to alter the path. In addition, the finite precision
    of the text format MPS and LP files also is enough to change the path. Try writing
    out a binary SAV file instead and reading that into interactive CPLEX. That will
    preserve the ordering of variables and constraints, and also represent the numeric
    values with the same precision as in your program. There is still some potential for
    different paths to occur, but at least you have reduced the number of ways that it
    can happen.

    2. The harder one: the significant difference in node throughput for the same model.
    While the paths could change, I wouldn't expect that to alter the node throughput
    by a factor of 3. However, if your program used significantly more memory before
    calling CPLEX, then perhaps the CPLEX solve occurs when the program uses virtual
    memory; the associated swapping to disk could indeed result in a slowdown by a
    factor of 3 or more.

    With this as background, I recommend the following to help diagnose the issue.

    1) Check the memory usage of your application. Make sure you aren't at the limit of
    available RAM on the machine. If you are, that would explain the behavior you see.

    2) Compare the node logs of interactive CPLEX and your program. Look for differences
    that might explain the situation. For example, if the average simplex iteration count
    per node is much larger in your application

    3) Check to make sure that your application and interactive CPLEX use the same
    parameter settings.

    4) Does you application use callbacks from C++? If so, that could explain the situation,
    as those callbacks disable certain presolve reductions that remain active with interactive CPLEX.

    I hope this helps. If you are still having trouble explaining it, try posting the
    node logs from interactive CPLEX and your application to this thread.
    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Cplex API vs Cplex Interactive

    Posted 09/27/11 01:05 AM

    Originally posted by: Dursun


    Thanks for answering my question.
    First of all I am just using a C++ code that calls functions from CPLEX's library. I did not write the C++ code.
    You are right, the code is calling CPLEX's C++ API.

    I meant to ask the second question.
    I tried to make sure that that my application and interactive CPLEX use the same
    parameter settings.

    There is no presolve in CPLEX's C++ API. It is simply making calls to dual simplex resolve.
    I turned off presolve completely for the interactive CPLEX by changing parameter settings.
    Does it still do some presolve reductions?

    How do I determine whether my application is using callbacks from C++?

    Also how can I print out the node logs from my application?
    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: Cplex API vs Cplex Interactive

    Posted 10/07/11 02:14 PM

    Originally posted by: Dursun


    I compared the node logs of interactive CPLEX and my program and found out that the average simplex iteration count
    per node in my application is 3 times that of Interactive Cplex.

    I made sure that all the presolve options in interactive Cplex were turned off.

    I also checked that my application is not using callbacks from C++.

    I was told that interactive version uses shortcuts that can not be used when the user calls Cplex LP solver externally.
    I was wondering whether this is true and be a sufficient explanation for the 3-fold increase in the average simplex iteration count
    per node when Cplex is called externally.

    Thanks in advance for your attention.

    Dursun.
    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: Cplex API vs Cplex Interactive

    Posted 10/07/11 02:54 PM

    Originally posted by: EdKlotz


    > Dursun wrote:
    > I compared the node logs of interactive CPLEX and my program and found out that the average simplex iteration count
    > per node in my application is 3 times that of Interactive Cplex.
    >
    > I made sure that all the presolve options in interactive Cplex were turned off.
    >
    > I also checked that my application is not using callbacks from C++.
    >
    > I was told that interactive version uses shortcuts that can not be used when the user calls Cplex LP solver externally.
    > I was wondering whether this is true and be a sufficient explanation for the 3-fold increase in the average simplex iteration count
    > per node when Cplex is called externally.

    No, this is not true. Interactive CPLEX ultimately uses the same code that the
    CPLEX libraries use to optimize the problem.

    When calling CPLEX from C++, you do have additional C++ modeling code to translate
    the model from the object oriented modeling objects you see in your C++ program
    (e.g. IloNumVar, IloModel, etc.) to the array oriented data structures that interactive
    CPLEX and the C API use. If that extra layer results in additional memory usage
    that forces your application to use virtual memory while interactive CPLEX need not
    do so, that could explain the difference. This is why I previously recommended that
    you check the memory usage of your application and compare it to interactive CPLEX.

    Regarding your previous question about printing out node logs from a C++ application,
    use the IloAlgorithm::setOut() function to do this. However, by default, the output
    from the node log should go to the screen, so you can just capture it from there.
    >
    > Thanks in advance for your attention.
    >
    > Dursun.
    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  Re: Cplex API vs Cplex Interactive

    Posted 10/07/11 07:13 PM

    Originally posted by: Dursun


    Dear Ed,
    Then, what would be a good explanation for the 3-fold increase in the average simplex iteration count
    per node when Cplex is called from C++ vs if Interactive Cplex is used?
    This could not have been caused by virtual memory usage.

    The 3-fold increase in the average simplex iteration count
    per node explains the 3-fold speed degradation.

    Dursun.
    #CPLEXOptimizers
    #DecisionOptimization


  • 7.  Re: Cplex API vs Cplex Interactive

    Posted 10/07/11 07:29 PM

    Originally posted by: EdKlotz


    Dursun,

    > Dursun wrote:
    > Dear Ed,
    > Then, what would be a good explanation for the 3-fold increase in the average simplex iteration count
    > per node when Cplex is called from C++ vs if Interactive Cplex is used?
    > This could not have been caused by virtual memory usage.
    >
    > The 3-fold increase in the average simplex iteration count
    > per node explains the 3-fold speed degradation.
    >
    > Dursun.

    So it sounds like you've ruled out virtual memory and callbacks. That leaves, from my previous post, the following to try

    2) Compare the node logs of interactive CPLEX and your program. Look for differences
    that might explain the situation. For example, if the average simplex iteration count
    per node is much larger in your application

    3) Check to make sure that your application and interactive CPLEX use the same
    parameter settings.

    Let's see what those tell us.
    #CPLEXOptimizers
    #DecisionOptimization


  • 8.  Re: Cplex API vs Cplex Interactive

    Posted 10/08/11 01:44 AM

    Originally posted by: Dursun


    2) Compare the node logs of interactive CPLEX and your program. Look for differences
    that might explain the situation. For example, if the average simplex iteration count
    per node is much larger in your application

    As I stated in my previous post I already compared the node logs of interactive CPLEX and my program and the difference did explain the situation. The average simplex iteration count
    per node is 3 times larger in my application and this explains the 3 fold speed degradation.

    My question is why would the average simplex iteration count
    per node is 3 times larger in my application where I call Cplex LP
    solver from C++ than in Interactive Cplex.
    3) Check to make sure that your application and interactive CPLEX use the same
    parameter settings.
    I already checked that my application and CPLEX use the same
    parameter settings.
    #CPLEXOptimizers
    #DecisionOptimization


  • 9.  Re: Cplex API vs Cplex Interactive

    Posted 10/08/11 05:39 AM

    Originally posted by: SystemAdmin


    I think we have to take a step back and start with the more basic stuff to understand your issue. I may have missed something in this thread, so please don't be mad at me if I ask the same questions again...

    As far as I understand, you compare the C++ API cplex.solve() call to the interactive CPLEX "optimize" command and observe that in the interactive the model solves much faster.

    I guess you are generating the model in C++ through the typical model building facilities of Concert. But how do you get the problem into the interactive? Are you using cplex.exportModel()? If so, then you should definitely use the .sav file format in order to get a bit-wise equivalent representation of what is stored in memory. If you use the .lp file you will very often get different results in the interactive. Several other threads discuss this issue.
    Tobias
    #CPLEXOptimizers
    #DecisionOptimization


  • 10.  Re: Cplex API vs Cplex Interactive

    Posted 10/09/11 11:59 AM

    Originally posted by: Dursun


    >As far as I understand, you compare the C++ API cplex.solve() call to the interactive CPLEX "optimize" command and >observe that in the interactive the model solves much faster.

    Actually I am comparing p.lp_solver->resolve() to the interactive CPLEX "populate" command

    >I guess you are generating the model in C++ through the typical model building facilities of Concert.

    No, I have been using a C++ code based on the code Cbc found at COIN-OR repisitory and OSIcplex that interfaces the Cplex LP solver with Cbc.

    >But how do you get the problem into the interactive? Are you using cplex.exportModel()? If so, then you should >definitely use the .sav file format in order to get a bit-wise equivalent representation of what is stored in >memory.

    The code I am using has its own format for inputing problems and I am using that format. However, I was told by the author of the code that the order of the variables and the order of the constraints are preserved when the problem is loaded in memory and Cbc starts working on it.

    Also, I have been using the .mps format to input the same problem to interactive CPLEX. I was wondering whether the order of the constraints is preserved if a problem is loaded into Cplex from a .mps file. If not, is there a random or a consistent change in the order of the constraints? (I know that the order of the variables are preserved if the .mps file format is used.)

    If the differnces in the order of the constraints is causing the speed up these differences can not be random, because I have been observing this speed up over a large number of Integer programs.

    Dursun
    #CPLEXOptimizers
    #DecisionOptimization


  • 11.  Re: Cplex API vs Cplex Interactive

    Posted 10/09/11 05:18 PM

    Originally posted by: EdKlotz


    > Dursun wrote:
    > >As far as I understand, you compare the C++ API cplex.solve() call to the interactive CPLEX "optimize" command and >observe that in the interactive the model solves much faster.
    >
    > Actually I am comparing p.lp_solver->resolve() to the interactive CPLEX "populate" command
    >
    > >I guess you are generating the model in C++ through the typical model building facilities of Concert.
    >
    > No, I have been using a C++ code based on the code Cbc found at COIN-OR repisitory and OSIcplex that interfaces the Cplex LP solver with Cbc.

    OK, that adds another layer that could somehow create some sort of deviation
    in behavior.
    >
    > >But how do you get the problem into the interactive? Are you using cplex.exportModel()? If so, then you should >definitely use the .sav file format in order to get a bit-wise equivalent representation of what is stored in >memory.
    >
    > The code I am using has its own format for inputing problems and I am using that format. However, I was told by the author of the code that the order of the variables and the order of the constraints are preserved when the problem is loaded in memory and Cbc starts working on it.
    >
    > Also, I have been using the .mps format to input the same problem to interactive CPLEX. I was wondering whether the order of the constraints is preserved if a problem is loaded into Cplex from a .mps file. If not, is there a random or a consistent change in the order of the constraints? (I know that the order of the variables are preserved if the .mps file format is used.)
    >
    > If the differnces in the order of the constraints is causing the speed up these differences can not be random, because I have been observing this speed up over a large number of Integer programs.
    >
    > Dursun
    MPS format will preserve the ordering of both variables and constraints. However,
    it can differ from the representation of the model in your program because its text
    format can truncate numeric values at the lower order decimal places. That in turn
    can change the path CPLEX takes, which in turn can change the iteration count.
    However, I wouldn't expect such differences in the lower order decimal places to
    have such a consistent, profound impact on simplex method iteration counts. If that
    were true, however, I would expect to see that the additional iteration counts in your
    program all occurred at the end of the optimization, i.e. that the optimizer got close
    to optimal at the node LPs quite quickly, then spent a huge amount of time trying
    to finish up. If the MPS format truncated those low order value that contributed
    to the long tail of iterations, then I suppose this profound difference in iteration
    counts is possible. But, I must say I haven't seen anything like this in the past.

    With this as background, I recommend the following additional tests.

    1) Run both interactive CPLEX and your C++ program with feasibility and optimality
    tolerances of 1e-3 instead of the defaults of 1e-6. If the issue really involves
    truncation in MPS format, then I think the difference in iteration counts will
    disappear or diminish significantly with these larger tolerances.

    2) Run both your program and interactive CPLEX with the MIP display parameter set
    to 5, so we can see the simplex iteration logs of the various node LP solves. Maybe
    that will shed some light on the difference.

    3) Run the ilomipex2.cpp program that we provide with your MPS file. If you can
    reproduce the difference in iteration counts with that program, then you've taken
    the OSI API out of the picture. On the other hand, if the difference disappears,
    then additional investigation of how OSI operates is in order. In particular, check
    whether it quietly sets some CPLEX parameters to non default values, and check whether
    it quietly uses some CPLEX callbacks that force CPLEX to restrict presolve reductions,
    change the MIP search, or do something else to cause CPLEX to use different parameter
    settings in your program as compared to in interactive CPLEX.

    4) Compare the presolved model sizes in your program in iteractive CPLEX. Are they
    the same? If not, do they differ dramatically, or just by a little bit.
    If these don't help you resolve this, please include some node log info for both
    your program and interactive CPLEX in your next post.
    #CPLEXOptimizers
    #DecisionOptimization


  • 12.  Re: Cplex API vs Cplex Interactive

    Posted 10/10/11 04:50 AM

    Originally posted by: SystemAdmin


    Do I understand you correctly that you are comparing
    1. a CBC based code that uses CPLEX as LP solver, with
    2. CPLEX interactive?

    If this is true then there is clearly no reason to think that the iteration counts per node should be similar. First, CBC may use completely different cutting planes and branching decisions than CPLEX and thus in the CPLEX MIP solve you may end up with solving completely different LP relaxations. Second, CPLEX may use a different dual simplex pricing rule than what CBC is setting for the CPLEX LP solver. For example, it may be that CPLEX MIP uses steepest edge pricing for solving the LPs while CBC uses devex pricing. Finally, the CPLEX MIP solver can take some short cuts when interacting with its LP solver component that are not available through the OSI that is used by CBC.

    But from all these items, the dual simplex pricing rule would be my first guess...
    Tobias
    #CPLEXOptimizers
    #DecisionOptimization