Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  How to define a vector or array variable in main block?

    Posted 07/16/14 08:06 PM

    Originally posted by: TracyLLL


    Hi There

    I am working on the main block for flow control to do the following:

    1. In each iteration, use a vector with only one element =1 and other elements =0, i.e. UDC[i in 1..3], in iteration 1: UDC=[1 0 0],  iteration 2: UDC=[0 1 0]...to run the optimization model to get some results.

    2. After all iterations, only some of iterations yeild good results. I want to store UDC of each of the good iterations in a new vector, which could be the sum of these good UDC. e.g. if UDC=[0 1 0] and UDC[0 0 1] are good, UDCnew[i in 1..3]=[0 1 1]

    3. Use UDCnew to run one last time the model to get a final result. 

    Note that the whole process involves the same .mod and .dat files, i.e., thisOplModel. I tried defining UDC and UDCnew by accessing the same opl model. But found that the two variables always contains the same elements, no matter what (I guess when UDC and UDCnew are pointing to the same model object, every time I change any one of them, the object has been changed, so does the other variable). 

    I know I can achieve what I want through defining UDCnew by pointing it to a second OPL model. But since the second model would be exactly the same as the master model, this way doesn't look concise. I was wondering if there is a better alternative.

    I also tried to define a vector or array in the main block, but couldn't find a proper way. Does OPL allow defining a vector or array variable in script blocks? How?

    Thanks!


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: How to define a vector or array variable in main block?



  • 3.  Re: How to define a vector or array variable in main block?

    Posted 07/19/14 05:27 PM

    Originally posted by: TracyLLL


    Thanks a lot Alex! It works! 


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 4.  Re: How to define a vector or array variable in main block?

    Posted 07/19/14 06:58 PM

    Originally posted by: TracyLLL


    Hi Alex,

    I have new question regarding the var array definition. I tried to print the defined array to an output txt file to show its values.

    var UDCnew= new Array(3);
    ofile.writeln("Initial UDCnew = "); 
    for(var i in 1..3){
        UDCnew[i]=0;
        ofile.writeln(UDCnew[i]);}  // option 1
    ofile.writeln("Initial UDCnew = ",UDCnew); // option 2

    option 1 gives 

    Initial UDCnew = 
    0
    0
    0

    option 2 gives

    Initial UDCnew = [object Object]

    option 2 works well when I tried print out the array variable defined through pointing to a .mod object. How come this? 

    Thanks!


    #DecisionOptimization
    #OPLusingCPLEXOptimizer