Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  engine log to database

    Posted 11/07/13 09:27 AM

    Originally posted by: gargius


    Hallo,

    I use CPLEX with Java. Now I'd like to transfer the engine log informations into one table in SQL. I know how to produce a text file with:

    String name= DATADIR+ "/EngineLog.txt";
    FileOutputStream log = new FileOutputStream (new File(name));
    opl.getCplex().setOut(log);

    But I want to create queries in SQL.

    Is there a standard command to do this? Or is it possible to access some values of the engine log? Should I word with callbacks?

     

    Thanks in advance

     

    Best regards

     

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: engine log to database

    Posted 11/07/13 09:54 AM

    Instead of using a FileOutputStream you can use any OutputStream. So you can subclass java.io.OutputStream and parse the log lines that CPLEX sends.

    Like this (which is probably not the most efficient way to do this):

    import ilog.cplex.IloCplex;
    import ilog.concert.IloException;

    import java.io.OutputStream;
    import java.io.IOException;

    public final class Redirect {
       private static final class MyStream extends OutputStream {
          private final StringBuffer buffer = new StringBuffer();
          @Override
          public void write(int c) throws IOException {
             if (c == '\n') {
                // We got a full line. Print it and start a new line.
                final String line = buffer.toString();
                buffer.setLength(0);
                // Print out the line. We prefix each line with "X".
                System.out.println("X" + line);
             }
             else {
                // Line not complete yet. Just append the character.
                buffer.append((char)c);
             }
          }
       }
       public static void main(String[] args) {
          try {
             for (String model : args) {
                IloCplex cplex = new IloCplex();
                cplex.importModel(model);
                cplex.setOut(new MyStream());
                cplex.solve();
                cplex.end();
             }
          } catch (IloException e) {
             System.err.println(e.getMessage());
             e.printStackTrace();
             System.exit(-1);
          }
       }
    }


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: engine log to database

    Posted 11/08/13 04:59 AM

    Originally posted by: gargius


    Thank you.

     

    I forgot to write that I want to access the time stamp for every row in the engine log.

    My aim is to draw a graph: On the x-axis the time and on the y-axis the MIP gap (or objective value).

    Is there no standard command to access this information?

     

    Thanks in advance

    regards


    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: engine log to database

    Posted 11/09/13 02:14 AM

    No, there is no way to directly get this information. There are two things you can do:

    1. Extend my example code to extracted the desired information from log lines and use System.currentTimeMillis() to get a timestamp when a line is complete.
    2. Use an info callback and query the desired information from that callback.

    #CPLEXOptimizers
    #DecisionOptimization