Decision Optimization

Decision Optimization

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

 View Only
  • 1.  Python + CPLEX: Elapsed Time

    Posted Tue March 19, 2013 02:52 PM

    Originally posted by: SystemAdmin


    Hello,

    I'm currently trying to solve a mixed integer programs with Python and CPLEX.
    With the following code, I am able to solve my problem and I also get the correct result.

    > import cplex
    >
    > c = cplex.Cplex()
    > c.read("MasterBIP.txt")
    > c.solve()
    > x = c.solution.get_values()

    In the output, I can see the elapsed time but since I want to solve the problem in a subroutine without output, I wanted to ask how I can access the solution time.

    I am happy for every answer,
    Best regards,
    BobGr
    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Python + CPLEX: Elapsed Time

    Posted Wed March 20, 2013 01:53 AM

    Originally posted by: SystemAdmin


    If your CPLEX version is recent enough then the Cplex class has a method get_time() that returns a timestamp and you can get the solve time like this:
    import cplex
     
    c = cplex.Cplex()
    c.read("MasterBIP.txt")
    start = c.get_time()
    c.solve()
    end = c.get_time()
    elapsed = end - start
    x = c.solution.get_values()
    


    In any case, Python has a time module that is more flexible, so you may want to use that instead.
    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Python + CPLEX: Elapsed Time

    Posted Wed March 20, 2013 04:29 AM

    Originally posted by: SystemAdmin


    Thanks for your answer.
    • My CPLEX version seems to to be old, since the get_time() is not available.
    • I already know the time module, but I planned to use the CPLEX time.

    Until I found a better solution, I will use the following workaround:

    c.set_results_stream("Test.log")
    


    From the "Test.log", I will read the necessary times-

    Thank you for your help,
    BobGr
    #CPLEXOptimizers
    #DecisionOptimization