Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  OPL Script, update decision variables

    Posted 11/07/11 07:37 PM

    Originally posted by: FQYA_Majid_Khoshghalb


    Hi All

    1- how I can update a dvar pos][] after execute, I mean, I want to do some computations in postprocessing and then update pos[][.
    how we can update a decision variable after execution?

    2- how we can export computations we did in post processing in a .dat file or .txt file?

    3- how we can make a matrix in EXECUTE block, because I can make Array, but no information about Matrices.
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: OPL Script, update decision variables

    Posted 11/09/11 08:47 PM

    Originally posted by: SystemAdmin


    I am not sure if I completely understand your question, but here's some code to get you started. It creates a trivial model, uses the optimal values of the decision variable in the post-processsing (POST_SOLVE) execute block, and then writes some of the values to a txt file in disk. I have also included some code to create a 2-D Array object, but using the same concept you can extend it to more dimensions as your need may be:

    
    range r = 1..5; 
    
    int y[i in r] = i;   dvar int+ x[r]; minimize sum(i in r) x[i]; subject to 
    { forall(i in r) x[i] >= 2*y[i]; 
    } execute POST_SOLVE
    { var f = 
    
    new IloOplOutputFile(
    "Output.txt"); var modifiedValue=0; f.writeln(
    "Testing OUTPUT"); writeln(
    "Objective Value = "+cplex.getObjValue()); f.writeln(
    "Objective Value = "+cplex.getObjValue()); 
    
    for(var index in r)
    { modifiedValue=2*x[index]; writeln(
    "x["+index+
    "]="+x[index]+
    "; modifiedValue="+modifiedValue); f.writeln(
    "x["+index+
    "]="+x[index]+
    "; modifiedValue="+modifiedValue); 
    } 
    //extending the Array object in two dimensions to make it a matrix var a2 = 
    
    new Array(); 
    
    for (var i=0; i<3; i++) 
    { a2[i] = 
    
    new Array(); 
    
    for(var j=0; j<3; j++) 
    { a2[i][j] = 10; 
    } 
    } 
    
    for (var ii=0; ii<3; ii++) 
    { 
    
    for(var jj=0; jj<3; jj++) 
    { writeln(
    "a2["+ii+
    "]["+jj+
    "]="+a2[ii][jj]); f.writeln(
    "a2["+ii+
    "]["+jj+
    "]="+a2[ii][jj]); 
    } 
    } f.close(); 
    }
    

    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: OPL Script, update decision variables

    Posted 11/17/11 08:08 PM

    Originally posted by: FQYA_Majid_Khoshghalb


    Thanks a lot.
    Do you know how we can generate all feasible sequences on every machine in a scheduling problem?
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 4.  Re: OPL Script, update decision variables

    Posted 11/18/11 01:58 PM

    Originally posted by: SystemAdmin


    > Do you know how we can generate all feasible sequences on every machine
    > in a scheduling problem?

    You could do so by setting a few CPLEX parameters and then calling the cplex.populate()
    method instead of the cplex.solve() method. One such trivial model could look like the
    following which prints out the objective value and variable values of each feasible
    solution into a file called 'feasibleSolutions.txt':

    
    range r = 1..5; 
    
    int y[i in r] = i; dvar int+ x[r]; minimize sum(i in r) x[i]; subject to 
    { forall(i in r)
    { x[i] >= 2*y[i]; x[i] <= 3*y[i]; 
    } 
    } main
    { thisOplModel.generate(); 
    //set cplex parameters to enumerate all possible feasible solutions cplex.populatelim = 2100000000;
    //increase the limit of solutions in the solution pool cplex.solnpoolintensity = 4;
    //search for all possible solutions cplex.solnpoolagap=1e+75;
    //allow any feasible solution to be part of the solution pool cplex.populate();
    //call populate instead of solve var nSols = cplex.solnPoolNsolns; var xRange = thisOplModel.r; var fOut = 
    
    new IloOplOutputFile(
    "feasibleSolutions.txt"); 
    
    for(var solIndex=0;solIndex<nSols;solIndex++)
    { thisOplModel.setPoolSolution(solIndex); fOut.writeln(
    "Solution#"+(solIndex+1)+
    " : Objective="+cplex.getObjValue()); 
    
    for(var xIndex in xRange )
    { fOut.writeln(
    "x["+xIndex+
    "]="+thisOplModel.x[xIndex]); 
    } 
    } fOut.close(); 
    }
    

    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 5.  Re: OPL Script, update decision variables

    Posted 11/18/11 09:08 PM

    Originally posted by: FQYA_Majid_Khoshghalb


    Thanks a lot, but my code is using CP;
    what can I do for that?
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 6.  Re: OPL Script, update decision variables

    Posted 11/18/11 10:16 PM

    Originally posted by: FQYA_Majid_Khoshghalb


    In fact, I want to do the same you sent for scheduling problem to have all possible sequence
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 7.  Re: OPL Script, update decision variables

    Posted 11/29/11 04:28 PM

    Originally posted by: SystemAdmin


    Am sorry about the delay in my response- was on vacation. If your's is a satisfiability problem using CP, you could use the following scheme:

    using CP;
    range r = 1..5;
    int y[i in r] = i;
     
    dvar int+ x[r];
    subject to {
      forall(i in r){
         x[i] >= 2*y[i];
         x[i] <= 3*y[i];
      }     
    } 
    main{
        thisOplModel.generate();
        cp.startNewSearch();
        var fOut = new IloOplOutputFile("feasibleSolutions.txt");
        var solIndex=0;
        var xRange = thisOplModel.r;
        while (cp.next()) {
         solIndex++;
         fOut.writeln("Solution#"+solIndex);
         for(var xIndex in xRange ){
            fOut.writeln("x["+xIndex+"]="+thisOplModel.x[xIndex]);
         }                          
        }
        fOut.close();
    }
    

    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 8.  Re: OPL Script, update decision variables

    Posted 11/29/11 05:02 PM

    Originally posted by: FQYA_Majid_Khoshghalb


    Thanks.

    Wish the Best.
    Majid.
    #DecisionOptimization
    #OPLusingCPLEXOptimizer