Decision Optimization

 View Only
Expand all | Collapse all

Print/save solutions

  • 1.  Print/save solutions

    Posted Thu December 23, 2021 02:03 AM
    Hi I have a model in which I am running a LP file. How can I print or save the solutions (values of decision variables)

    /*********************************************
    * OPL 12.10.0.0 Model
    *********************************************/
    main
    {
    cplex.importModel("DPRT.lp");
    cplex.solve();
    writeln(cplex.getObjValue());
    }

    ------------------------------
    sandeep singh chauhan
    ------------------------------


  • 2.  RE: Print/save solutions

    Posted Mon December 27, 2021 04:16 AM
    Hi,

    you could use writeMIPStarts from Making Optimization Simple

    With zoo.lp

    \ENCODING=ISO-8859-1
    \Problem name: Configuration1
    
    Minimize
     obj1: 500 nbBus40 + 400 nbBus30
    Subject To
     c1: 40 nbBus40 + 30 nbBus30 >= 300
    Bounds
          nbBus40 >= 0
          nbBus30 >= 0
    Generals
     nbBus40  nbBus30 
    End
    ​


    main
    {
      cplex.importModel("zoo.lp");
      
      cplex.solve();
      writeln("objective = ",cplex.getObjValue());
      cplex.writeMIPStarts("c:/temp/zoo.mst", 0, 1);
      
    }​

    gives

    <?xml version = "1.0" encoding="UTF-8" standalone="yes"?>
    <CPLEXSolutions version="1.2">
     <CPLEXSolution version="1.2">
      <header
        problemName="C:\zoo.lp"
        solutionName="m1"
        solutionIndex="0"
        MIPStartEffortLevel="0"
        writeLevel="2"/>
      <variables>
       <variable name="nbBus40" index="0" value="6"/>
       <variable name="nbBus30" index="1" value="2"/>
      </variables>
     </CPLEXSolution>
    </CPLEXSolutions>​


    ------------------------------
    [Alex] [Fleischer]
    [EMEA CPLEX Optimization Technical Sales]
    [IBM]
    ------------------------------