Decision Optimization

Decision Optimization

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

 View Only
Expand all | Collapse all

Using SOL-File/ MST-File as MIP-Start in CPLEX Optimization Studio 12.5.1

  • 1.  Using SOL-File/ MST-File as MIP-Start in CPLEX Optimization Studio 12.5.1

    Posted Mon November 18, 2013 06:48 AM

    Originally posted by: svojoe


    Im working on a rather complex MIP Problem, that i need to solve using the CPLEX Interactive Optimizer (working on an external server). To wirk with the solution I have CPLEX returning a .sol File as well as an .mst MIP-Start. 

    Now I need to read either file into my model or run-configuration as a feasible solution to to run the model of off.

    The reason I am trying to to this is, that I have a number of expression specified in my model to which I need the resulting values (which I would then like to write to Excel using commands in my .dat File). The interactive Optimizer obviously does not specify my expressions in the solution file. 

    Is there any way to do this, to read a .sol file (or .mst file i suppose) into a run-configuration in IBM ILOG Cplex Optimization Studio 12.5.1?

     

    Any sort of help would be greatly appreciated!


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: Using SOL-File/ MST-File as MIP-Start in CPLEX Optimization Studio 12.5

    Posted Mon November 18, 2013 11:00 AM

    Hi,

    in the 12.5.1 release notes

    you can read

    The ILOG Script class IloCplex contains the following new methods:

    • addMIPStart
    • changeMIPStart
    • deleteMIPStarts
    • getNMIPStarts
    • getMIPStart
    • getMIPStartName
    • getMIPStartIndex
    • readBasis
    • writeBasis

    This should help

     

    Regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: Using SOL-File/ MST-File as MIP-Start in CPLEX Optimization Studio 12.5

    Posted Mon November 18, 2013 11:58 AM

    Originally posted by: svojoe


    Hi, 

    thanks a lot for the reply!

    If I understand correctly, this is a class from the JAVA API. I am using OPL within my .mod file in a main block.

    Therefore i get the error "undefined method". Can i somehow incorporate Java into my main-block in OPL?

    Or am I missing something here?

    Best regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 4.  Re: Using SOL-File/ MST-File as MIP-Start in CPLEX Optimization Studio 12.5

    Posted Mon November 18, 2013 02:17 PM

    Those are methods that are available in OPL (scripting part). But you should make sure that you use 12.5.1, do you ?

     

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 5.  Re: Using SOL-File/ MST-File as MIP-Start in CPLEX Optimization Studio 12.5

    Posted Fri November 22, 2013 06:19 AM

    Originally posted by: svojoe


    I double checked and downloaded the latest version again. I am using 12.5.1.0 but I still get the same error message:

    "undefined method addMIPStart"

    my main block looks like this:

    main {

    thisOplModel.generate();

    IloCplex.addMIPStart("MyMIPStart.mst");

    cplex.solve();

    };

    Any Ideas? Could there be a problem regarding Java?

    Best regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 6.  Re: Using SOL-File/ MST-File as MIP-Start in CPLEX Optimization Studio 12.5

    Posted Fri November 22, 2013 09:24 AM

    Hi

     

    instead of

    IloCplex.addMIPStart("MyMIPStart.mst");

    can you try

    cplex.addMIPStart("MyMIPStart.mst");

    ?

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 7.  Re: Using SOL-File/ MST-File as MIP-Start in CPLEX Optimization Studio 12.5

    Posted Fri November 22, 2013 10:04 AM

    Originally posted by: svojoe


    Hi, 

    thanks a lot for the answer!

    I have tried that as well, I get an error as well:

    "Array argument expected"

    OPL does not seem to know the method addMIPStart. Is there anything i need to import? 

     

    best regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 8.  Re: Using SOL-File/ MST-File as MIP-Start in CPLEX Optimization Studio 12.5

    Posted Fri November 22, 2013 11:03 AM

    Hi,

    as written in IDE and OPL > Optimization Programming Language (OPL) > IBM ILOG Script Reference Manual > OPL Classes

    the syntax is

    addMIPStart(vars, vals, effort, name)
    Adds Adds a named MIP start with the specified level of effort defined by the specified variables and their corresponding values to the current problem


    or maybe you should try

    readBasis


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 9.  Re: Using SOL-File/ MST-File as MIP-Start in CPLEX Optimization Studio 12.5

    Posted Fri November 22, 2013 11:57 AM

    Originally posted by: svojoe


    Hi 

    Thanks a lot for taking the time to read my answer.

    I am entirely unsure of how to specify the necessary parameters for addMIPStart(vars, vals, effort, name).All I have is a .mst File and a .sol File. I am dealing with 40000 variables so no way to specify them directly as mostly done in examples.

    ​Could you maybe provide some sample code?

    Thanks a lot!!

    PS: cplex.readBasis does work, but does not accept any other format than .bas

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 10.  Re: Using SOL-File/ MST-File as MIP-Start in CPLEX Optimization Studio 12.5

    Posted Mon November 25, 2013 05:08 AM

    The function to read .mst files is IloCplex.readMIPStart(). Unfortunately, this function is currently not supported for the OPL scripting class.

    Here is a scripting block that reads and parses an .mst file and adds the MIP starts defined in that file to the IloCplex instance. The parser is not perfect and not very robust but it has worked for me so far.

    main {
      thisOplModel.generate();
     
      // The code below implements a simple parser for MST files.
      // The parser assumes that the MST files are well-formed and are
      // generated by CPLEX. In particular, they assume that there are
      // line breaks between certain tags (just as CPLEX outputs them).
      var mstFile = new IloOplInputFile("/path/to/start.mst");
      var inStart = false; // Is the parser currently in a MIP start?
      var vars = null;     // Variables in the current MIP start
      var vals = null;     // Values in the current MIP start (1:1 with vars)
      var count;           // Current length of vars and vals
      var m = 0;           // Number of MIP starts added.
      while (!mstFile.eof) {
        var line = mstFile.readline(); // Get next line
        if (line.indexOf("CPLEXSolutions") < 0 && line.indexOf("<CPLEXSolution") >= 0) {
          // This is a line like
          //    <CPLEXSolution version="1.2">
          // which starts a new MIP start.
          inStart = true;
          count = 0;
          vars = new Array();
          vals = new Array();   
        }
        else if (line.indexOf("CPLEXSolutions") < 0 && line.indexOf("</CPLEXSolution") >= 0) {
          // This is a line like
          //    </CPLEXSolution>
          // which terminates a MIP start
          var startname = "mipstart" + m;     
          writeln("Add mip start " + startname + " with " + count + " values");
          cplex.addMIPStart(vars, vals, 0, startname);
          inStart = false;
          vars = null;
          vals = null;
          count = 0;
          m = m + 1;     
        }
        else if (inStart) {
          if (line.indexOf("<variable") >= 0) {
            // This is a line like
            //     <variable name="x(0)" index="6" value="0"/>
            // which defines a single variable setting in a MIP start.
            // We extract the 'name' and 'value' attributes from this line
            // to add the respective variable to the MIP start.
            var start = line.indexOf("name=\"");
            if (start >= 0) {
              var s = line.substring(start + 6);
              var end = s.indexOf("\"");
              if (end >= 0) {
                var name = s.substring(0, end);
                start = line.indexOf("value=\"");
                if (start >= 0) {
                  s = line.substring(start + 7);
                  end = s.indexOf("\"");
                  if (end >= 0) {
                    var value = s.substring(0, end);
                    // We need to set name to the vars array and value to the vals array.
                    // In MIP start files variable names look like x(0)(1)(2) while in the
                    // scripting code they look like x[0][1][2], so we have to replace
                    // parentheses by square brackets. We use an eval() block here to avoid
                    // having to look up variables explicitly by name.               
                    eval("vars[" + count + "] = thisOplModel." + name.split("(").join("[").split(")").join("]") + ";");
                    vals[count] = value;
                    count = count + 1;
                  }
                }
              }
            }
          }
        }
      }                                                                                                             
      cplex.solve();
    }

    I hope this helps.


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 11.  Re: "Array argument expected"

    Posted Tue February 04, 2014 10:03 AM

    Originally posted by: Mondano


    I think I have the same problem as above, i.e. getting the error "Array argument expected" when calling

    cplex.addMIPStart(thisOplModel.x, xh);

    cplex.addMIPStart(thisOplModel.q, qh);

    (I suppose I can just ommit effort and name, as I don't think I need to use them)

    where thisOplModel.x is a 3-dimensional decision variable x[][][] defined in the model that has previously been generated with thisOplModel.generate()

    I have two separate CPLEX-models which calculate xh and qh and I want to give those as a starting solution to an integrated model with x and q. Therefore, I cannot use readBasis (as far as I know).

    Can you help me, how to give xh and qh as starting solution to x and q?

     

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 12.  Re: "Array argument expected"

    Posted Tue February 04, 2014 03:31 PM

    Originally posted by: Mondano


    I found the solution for the correct syntax myself, it's quite intuitive actually:

    You need to enter all values right in the corresponding field of the array (as the error suggests), so something like

    cplex.addMIPStart(thisOplModel.q[i][j][k], qh[i][j][k]);

    should work.


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 13.  Re: "Array argument expected"

    Posted Sun August 10, 2014 04:28 PM

    Originally posted by: _Hadi_


    I am encountering the same issue and when  I used indexes of i,j,k still I was getting  "Array argument expected"

    Then I changed my code to 

    cplex.addMIPStart(thisOplModel.move[thisOplModel.sites.][thisOplModel.sites][thisOplModel.combines], thisOplModel.rHS[thisOplModel.sites][thisOplModel.sites][thisOplModel.combines]);
     and it gave me "not of type 'Ilo Tuple'"

    sites and combines are all tuples abd move is a dvar defined based on the tuples. rHS is an array defined based on the tuples. Any thoughts on this?


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 14.  Re: "Array argument expected"