Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
Expand all | Collapse all

Displaying solution after solving model using "oplrun" from command line

  • 1.  Displaying solution after solving model using "oplrun" from command line

    Posted 10/18/11 03:07 PM

    Originally posted by: BCDS_Daniel_Underwood


    Suppose a file named myProblem.mod exists with the following contents:
    range N = 1..4;
     
    int c[N][N]= [[99999, 7, 6, 3],
                  [3, 99999, 6, 9],
                  [2, 3, 99999, 1],
                  [7, 9, 4, 99999]];
     
    dvar boolean x[N][N];
     
    minimize sum(i in N) sum(j in N) c[i][j]*x[i][j];
    subject to {
     
     forall(i in N) sum(j in N) x[i][j]==1;
     forall(j in N) sum(i in N) x[i][j]==1;
    }
    


    To solve the model, I enter the following at the command line:

    $ oplrun myProblem.mod
    


    This solves my model and displays, among other information, the optimal objective value. However, this does not display the optimal solution. How can I modify the above command, or the code inside myProblem.mod, such that the optimal solution (the optimal values of the decision variables) is also displayed on the screen (standard output)?
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: Displaying solution after solving model using "oplrun" from command line

    Posted 10/18/11 04:33 PM

    Originally posted by: SystemAdmin


    You could do so by adding a post-processing block at the end of the mod file after the 'subject to' block, which can include the required print statements:
    execute DISPLAY_RESULTS{
      writeln("Optimal Values:");
      for(var i in N){
        for(var j in N){
          writeln("x["+i+"]["+j+"]="+x[i][j]);
        }
      }
    }
    


    Invoke the model as before($oplrun myProblem.mod).

    More on preprocessing and postprocessing using OPL scripts can be found in the following documentation link:
    http://publib.boulder.ibm.com/infocenter/cosinfoc/v12r3/index.jsp?topic=%2Filog.odms.ide.help%2FContent%2FOptimization%2FDocumentation%2FOptimization_Studio%2F_pubskel%2Fps_opl_Language668.html
    #DecisionOptimization
    #OPLusingCPLEXOptimizer