Decision Optimization

Decision Optimization

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


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

Time for user cut generation

  • 1.  Time for user cut generation

    Posted 08/21/13 12:10 PM

    Originally posted by: mrmag


    Dear all,
     
    How to get the whole time for the user cuts generation + the time for resolution of the LP afterwards?
     
    Thank you in advance!
    Marat
     

    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Time for user cut generation

    Posted 08/22/13 04:53 AM

    There is no direct way to do that. One option would be to do your own timing in the user cut callback (this gives you the time spent for creating user cuts) and also use a solve callback to time the LP (re)solves.


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Time for user cut generation

    Posted 08/22/13 05:11 AM

    Originally posted by: mrmag


    Dear Daniel, thank you for the response. I realized the timing in the user callback. But if I do the same in the solve callback it will compute the time for all LP resolutions also with those after branches without generation of user cuts. Do you have any idea how to compute the time only for LP resolutions after a user cut addition?

    Marat


    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: Time for user cut generation

    Posted 08/22/13 05:19 AM

    It should be possible to do that using a node's user data. Assume you have two markers, TIME and NOTIME.

    In the solve callback you only measure the time if the current node's user data is TIME. Before the solve callback returns you always set the current node's user data to NOTIME.

    After adding cuts in the cut callback add/change the current node's user data to TIME.

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: Time for user cut generation

    Posted 08/22/13 05:40 AM

    Originally posted by: mrmag


    That is a good idea. I will report the results after implementation.

    The problem could of course occur if i solve the program in parallel. Then the markers will be mixed.


    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  Re: Time for user cut generation

    Posted 08/22/13 05:47 AM

    Why would the markers be mixed? Multiple threads may process different nodes simultaneously but multiple threads will never process the same node simultaneously. I don't see how the markers could get mixed up.


    #CPLEXOptimizers
    #DecisionOptimization


  • 7.  Re: Time for user cut generation

    Posted 08/22/13 05:55 AM

    Originally posted by: mrmag


    Sorry, I thought about a global variable... Can you give me a hint about a node's user data? Where can I find the info about them?


    #CPLEXOptimizers
    #DecisionOptimization


  • 8.  Re: Time for user cut generation

    Posted 08/22/13 06:06 AM

    I would do it like this:

    static int mark_time = 0; /* We don't use that, we only use its address. */
    #define TIME &mark_time
    #define NOTIME NULL

    Then use CPXcallbacksetuserhandle() to get and/or change the current node's user data. As user data just use TIME and NOTIME. You can also use CPXgetcallbacknodeinfo() with CPX_CALLBACK_INFO_NODE_USERHANDLE to get a node's data.


    #CPLEXOptimizers
    #DecisionOptimization


  • 9.  Re: Time for user cut generation

    Posted 08/22/13 08:14 AM

    Originally posted by: mrmag


    Dear Daniel,

    everything with the user data in the nodes looks to be appeared in the recent versions of CPLEX. Is there a more detailed description for "cpp + concert" of the user data?
     
    How can I calculate the solution time in ILOSOLVECALLBACKN? How do I set the value for the node's data in ILOUSERCUTCALLBACKN?
     
    ILOSOLVECALLBACK1(UserSolve,
                      outStructure &, nfo)
    {
       // If TIME then calculate the time
       // update nfo
       // else do nothing
    }
     
    ILOUSERCUTCALLBACK2
    (UserCut, 
                      two_cont&, M,
                      outStructure &, nfo
    ) {
    // generate cut
     
    // set user data to TIME
    }
     

    #CPLEXOptimizers
    #DecisionOptimization


  • 10.  Re: Time for user cut generation

    Posted 08/23/13 03:15 AM

    In C++ something like this should do the trick:

    struct TimeDummy : public IloCplex::MIPCallbackI::NodeData {
      // Just an empty class.
    };
    ILOSOLVECALLBACK1(UserSolve, outStructure &, nfo) {
       // If TIME then calculate the time
       IloCplex::MIPCallbackI::NodeData *mark = getNodeData();
       if ( mark ) {
         // update nfo
         setNodeData(0);
         delete mark;
       }
       // else do nothing
    }
    ILOUSERCUTCALLBACK2(UserCut, two_cont&, M, outStructure &, nfo) {
      // generate cut
      // set user data to TIME
      setNodeData(new TimeDummy());
    }

     

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 11.  Re: Time for user cut generation

    Posted 08/23/13 04:18 AM

    Originally posted by: mrmag


    Dear Daniel, thank you for the answer. I have the last two questions concerning the code.
     
    Is there any way to append user info into nodes not dynamically (without using "new" operator), i.e., in the model preparation phase? It could save the running time.
     
    What is the proper way now to report CPLEX to do the same stuff it does for resolution of the LP. And where should I put my timing routine?
     
    IloNum startTime=getCplexTime();
     
    // resolve the LP
     
    nfo.cutTime += getCplexTime() - startTime;
     

    Marat


    #CPLEXOptimizers
    #DecisionOptimization


  • 12.  Re: Time for user cut generation

    Posted 08/23/13 10:18 AM

    Originally posted by: mrmag


    I solved the problem by the follwing code.

    But I observe a very strange effect. For example, for the root node 10000 cuts are generated. The total time for the root node relaxation with cuts is 30 sec (in real), but the value of nfo.cutTime is only 4 sec. What else does CPLEX in the root node reoptimization?

     

    ILOSOLVECALLBACK1(UserSolve,

                      outStructure &, nfo)
    {
      IloCplex::MIPCallbackI::NodeData *mark = getNodeData();
      if ( mark ) {
         IloNum startTime=getCplexTime();
     
         solve(IloCplex::Dual);
         useSolution();
     
         setNodeData(0);
         delete mark;
     
         nfo.cutTime += getCplexTime() - startTime;
      }
    }

    #CPLEXOptimizers
    #DecisionOptimization


  • 13.  Re: Time for user cut generation

    Posted 08/29/13 02:44 AM

    CPLEX may invoke heuristics during the root node. Do the timings look better if you disable heuristics (IloCplex::HeurFreq = -1)?


    #CPLEXOptimizers
    #DecisionOptimization


  • 14.  Re: Time for user cut generation

    Posted 08/29/13 02:50 AM

    Originally posted by: mrmag


    I initiated a new topic on this: https://www.ibm.com/developerworks/community/forums/html/topic?id=2ccc9f85-ba4a-4e01-bfb3-5119293dd797&ps=25

     

    I turned the primal heuristic off by: 
    cplex.setParam(IloCplex::HeurFreq, -1);
     
    The timing has improved, but I still get 18 seconds for the root node and 4-5 seconds (in total) for the cuts' generation+addition+resolution. What else can consume the time between ILOUSERCUTCALLBACK and ILOSOLVECALLBACK?

    #CPLEXOptimizers
    #DecisionOptimization