Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Gap in Progress Report

    Posted 01/22/13 09:46 AM

    Originally posted by: LRAU


    Hello,

    I have a question concerning the gap in the progress report. The conventional way to show the development of the gaps is to use the x-axis for the time and the y-axis for the corresponding gap value. The progress report only shows the gap values and the iteration count. Is there any way to show the elapsed time for each gap value as well?

    Thank you very much for your help!
    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Gap in Progress Report

    Posted 01/22/13 10:06 AM

    Originally posted by: SystemAdmin


    Are you running the interactive or are you using any of the programming APIs (which one)?
    There is no explicit parameter or such thing to add the requested time stamps to the output. However, in the programming APIs you can register a function that is invoked every time CPLEX prints something to the log. In this function you could print time stamps.
    In the interactive things will be a little more complicated since you cannot register such a function but there may still be ways to get those timestamps (depending on the OS, which OS do you use?).
    Another option would be to use an info callback and explicitly print time and gap from that callback (which would give you the advantage that you can print in any format and don't need to parse the log file afterwards).
    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Gap in Progress Report

    Posted 01/22/13 10:42 AM

    Originally posted by: LRAU


    Hi Daniel,

    thank you for your reply!
    I'm using the interactive in Windows7.
    Do you know which info callback I could use? Because I only find callbacks that report the end time, and I already have that information.
    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: Gap in Progress Report

    Posted 01/22/13 10:55 AM

    Originally posted by: SystemAdmin


    You cannot use callbacks with the interactive. If you want to use callbacks you will have to use one of the programming APIs. Which of those APIs would you be willing to use (C, C++, Java, C#, Python)? And which version of CPLEX do you use?
    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: Gap in Progress Report

    Posted 01/22/13 11:03 AM

    Originally posted by: LRAU


    I'm using ILOG CPLEX Optimization Studio.12.4.0 and Java
    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  Re: Gap in Progress Report

    Posted 01/22/13 11:29 AM

    Originally posted by: LRAU


    Oh, I guess I'm using the programming API after all
    #CPLEXOptimizers
    #DecisionOptimization


  • 7.  Re: Gap in Progress Report

    Posted 01/22/13 11:43 AM

    Originally posted by: SystemAdmin


    OK, in Java the quickest thing to do is to use IloCplex.setOut() and redirect output to a stream that adds time stamps:
    
    
    
    import ilog.cplex.*; 
    
    import ilog.concert.*;   
    
    public 
    
    final 
    
    class Timestamp 
    { 
    /** A java.io.OutputStream that prints to stdout and prepends each line * with a timestamp. * The implementation is utterly ineffecient but should illustrate how * to get timestamps on CPLEX output. */ 
    
    private 
    
    static 
    
    final 
    
    class TimestampOutput 
    
    extends java.io.OutputStream 
    { 
    /** Time when this instance was created. */ 
    
    private 
    
    final 
    
    long start; 
    
    public TimestampOutput() 
    { start = System.currentTimeMillis(); 
    } 
    /** Write <code>character</code> to stdout and print a timestamp * when we started a new line. */ 
    
    public 
    
    void write(
    
    int character) 
    { System.out.print((
    
    char)character); 
    
    if (character == 
    '\n') 
    { 
    // We just started a new line, so print out the number of 
    // elapsed seconds. 
    
    final 
    
    long elapsed = System.currentTimeMillis() - start; System.out.print(String.format(
    "%10.2f", 1e-3 * elapsed) + 
    ": "); 
    } 
    } 
    }   
    
    public 
    
    static 
    
    void main(String[] args) 
    { 
    // Solve all models that were specifiy on the command line. 
    
    for (String model : args) 
    { 
    
    try 
    { 
    // Load the model. IloCplex cplex = 
    
    new IloCplex(); cplex.importModel(model); 
    // Redirect output to a stream that adds timestamps. cplex.setOut(
    
    new TimestampOutput()); 
    // Solve the model. cplex.solve(); cplex.end(); 
    } 
    
    catch (IloException e) 
    { System.err.println(e.getMessage()); System.exit(-1); 
    } 
    } 
    } 
    }
    

    Another option would be to use a MIPInfoCallback and print timestamp and progress from this callback. Starting with CPLEX 12.5 this callback provides a getCplexTime() member. So you could write:
    
    
    
    import ilog.cplex.*; 
    
    import ilog.concert.*;   
    
    public 
    
    final 
    
    class TimestampCB 
    { 
    
    private 
    
    static 
    
    final 
    
    class TimestampOutput 
    
    extends IloCplex.MIPInfoCallback 
    { 
    
    private 
    
    final Double start; 
    
    public TimestampOutput(Double start) 
    { this.start = start; 
    } 
    
    public 
    
    void main() 
    
    throws IloException 
    { System.out.println(
    "Elapsed: " + (getCplexTime() - start) + 
    " Gap: " + getMIPRelativeGap()); 
    } 
    }   
    
    public 
    
    static 
    
    void main(String[] args) 
    { 
    // Solve all models that were specifiy on the command line. 
    
    for (String model : args) 
    { 
    
    try 
    { 
    // Load the model. IloCplex cplex = 
    
    new IloCplex(); cplex.importModel(model); cplex.use(
    
    new TimestampOutput(cplex.getCplexTime())); 
    // Solve the model. cplex.solve(); cplex.end(); 
    } 
    
    catch (IloException e) 
    { System.err.println(e.getMessage()); System.exit(-1); 
    } 
    } 
    } 
    }
    

    Prior to version 12.5 this getCplexTime() function does not exist but you could use System.getCurrentTimeMillis() instead.
    #CPLEXOptimizers
    #DecisionOptimization


  • 8.  Re: Gap in Progress Report

    Posted 01/23/13 05:46 AM

    Originally posted by: LRAU


    Thank you so much! You helped a lot!
    #CPLEXOptimizers
    #DecisionOptimization