Decision Optimization

Decision Optimization

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

 View Only
Expand all | Collapse all

LP relaxation time > MIP solve time

  • 1.  LP relaxation time > MIP solve time

    Posted Mon August 18, 2014 03:29 PM

    Originally posted by: flo12392


    Hi guys,

    I have a small problem which I hope someone can help me with, or tell me which way I should look for a solution. 

    I have implemented a pretty large MIP in Cplex 12.5 in Java, and I want to obtain the LP objective and the LP solving time. I have therefore implemented the LP relaxation twice (once by manually converting integer variables to floats and linearIntExprs to linarNumexprs, and once by adding IloConversion Objects). However, there are some small instances where the LP relaxation takes longer to solve then the MIP (1.4 seconds vs 1.2 seconds). The objective values are the same.

    I presume this has something to do with presolving. The MIP presolve eliminates much more rows and columns than the LP presolve.

    Now my question is: Does anyone have an idea how I could obtain the correct LP solving time?

    Kind regards,
    Florian


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: LP relaxation time > MIP solve time

    Posted Tue August 19, 2014 01:43 AM

    What exactly do you mean by "correct" LP solving time?

    If you mean the time it requires CPLEX to solve the initial LP relaxation then one simple way to get that would be to just grab it from the log output. After solving the root relaxation, CPLEX prints a line like this:

    Root relaxation solution time = 0.00 sec. (1.64 ticks)

    If you register an output stream with IloCplex.setOut() then you can just parse CPLEX log output for this line. This is the least intrusive way to get this time. It also does not require you to build your model twice. Here is a simple example:



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

    import java.io.IOException;
    import java.io.OutputStream;
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;

    public class RootTime {
      public static final class Stream extends OutputStream {
        private static final Pattern pattern = Pattern.compile("^Root relaxation solution time = *([0-9e.+-]+) sec\\. *\\(([0-9.e+-]+) ticks\\)");
        private final StringBuffer buffer = new StringBuffer();
        private double rootTime = Double.NaN;
        private double rootTicks = Double.NaN;
        
        @Override
        public void write(int b) throws IOException {
          final char c = (char)b;
          buffer.append(c);
          if (c == '\r' || c == '\n') {
            final String line = buffer.toString();
            buffer.setLength(0);
            System.out.print(line);
            final Matcher m = pattern.matcher(line);
            if (m.find()) {
              rootTime = Double.parseDouble(m.group(1));
              rootTicks = Double.parseDouble(m.group(2));
            }
          }
        }
        
        public double getRootTime() { return rootTime; }
        public double getRootTicks() { return rootTicks; }
      }

      public static void main(String[] args) {
        for (final String model : args) {
          try {
            final Stream stream = new Stream();
            final IloCplex cplex = new IloCplex();
            cplex.importModel(model);
            cplex.setOut(stream);
            cplex.setParam(IloCplex.IntParam.NodeLim, 1);
            cplex.solve();
            System.out.println("Root relaxation time: " + stream.getRootTime() + "/" + stream.getRootTicks());
            cplex.end();
          }
          catch (IloException e) {
            System.err.println(e.getMessage());
            System.exit(-1);
          }
        }
      }
    }

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: LP relaxation time > MIP solve time

    Posted Tue August 19, 2014 04:14 AM

    Originally posted by: flo12392


    Thanks very much for the extensive answer, this was indeed what I was looking for. 

    Regards,
    Florian


    #CPLEXOptimizers
    #DecisionOptimization