Decision Optimization

Decision Optimization

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


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

Matrix as an input

  • 1.  Matrix as an input

    Posted 04/26/18 01:17 AM

    Originally posted by: Srihitha Reddy B


    Hi,

    I would like to know how to give a matrix as an input to the optimization problem.

    Also, how to use the outputs from other mod file into the current mod file? Are there any options like importing? 

    Please help me out.

     

    Thanks,

    Srihitha.


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: Matrix as an input

    Posted 04/26/18 01:59 AM

    Hi,

    about matrix input , have a look at the example in CPLEX_Studio128\opl\examples\opl\foodmanufact

    In the .mod you ll see

    float Cost[Months][Products] = ...;

     

    and in the .dat

    Cost = [[110.0, 120.0, 130.0, 110.0, 115.0],
    [130.0, 130.0, 110.0,  90.0, 115.0],
    [110.0, 140.0, 130.0, 100.0,  95.0],
    [120.0, 110.0, 120.0, 120.0, 125.0],
    [100.0, 120.0, 150.0, 110.0, 105.0],
    [90.0, 100.0, 140.0,  80.0, 135.0]];

     

    For using the result of a first model in a second model, have a look at https://www.ibm.com/developerworks/community/forums/html/topic?id=471cc451-9dc2-44d8-a0e9-5f146fb14765&ps=25

    regards

     

    PS: Many how to at https://www.linkedin.com/pulse/how-opl-alex-fleischer/

     

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: Matrix as an input

    Posted 04/26/18 02:30 AM

    Originally posted by: Srihitha Reddy B


    Hi, Alex!!

    Thanks for the reply.

    We are having a set of constraints in which we are getting syntax errors. Please have a look at it.

     

     

    ERROR:  Cannot use the type int with "in"

     

    Thanks in advance,

    Srihitha.


    #DecisionOptimization


  • 4.  Re: Matrix as an input

    Posted 04/26/18 02:36 AM

    Hi,

    I guess m1 is an int and you should use a range such as 1..m1 instead of m1!

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 5.  Re: Matrix as an input

    Posted 04/26/18 02:41 AM

    Originally posted by: Srihitha Reddy B


    Hi,

    Thank you. We corrected m1 to 1..m1.

    And, in the code q is an array of integers. Can't we use q itself or should we change the syntax?

     

    Regards,

    Srihitha.


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 6.  Re: Matrix as an input

    Posted 04/26/18 02:44 AM

    Hi

    for q you should maybe use the index. Write q[i] for instance.

    Regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 7.  Re: Matrix as an input

    Posted 04/29/18 03:10 PM

    Originally posted by: Srihitha Reddy B


    Thank you, Alex!

    I tried writing the algorithm, but still, I couldn't figure it out.Am getting errors.

    Please help me out.

    Algorithm is:

     

    Please find attached the CPLEX files.

     

    Thanks in advance.

    Please solve this issue.

    Regards,

    Srihitha.


    #DecisionOptimization


  • 8.  Re: Matrix as an input

    Posted 04/30/18 02:59 AM

    Originally posted by: Srihitha Reddy B


    Hi,

    I founded out the error. It occurs at z[i][j][k].

    Actually, z[i][j][k] is the bivalent variable expressing migration of VMk from server i to server j. 

    But, declaring as shown above (z[i][j][k]) is incorrect. Please provide me an answer to proceed with.

    Thanks in advance,

    Srihitha. 


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 9.  Re: Matrix as an input

    Posted 04/30/18 03:18 AM

    Hi,

    if you rewrite cons1 and cons2 into

    cons1:forall(i,j,l in 1..m1, k in 1..q[i],k1 in 1..q[j])         
           //cons1:
              z[i][j][k] + z[j][l][k1] <= 1;
           
       
           cons2:forall(i,j in 1..m1, k in 1..q[i])
              //cons2:
              sum(j in 1..m1) (z[i][j][k]) <= 1;

    your model will work better.

    See

    https://www.ibm.com/support/knowledgecenter/en/SSSA5P_12.6.1/ilog.odms.ide.help/OPL_Studio/opllangref/topics/opl_langref_constraints_labels_limit.html

    for limits with labeling constraints

    regards

     

    PS:

    What you try to do is linked with https://www.linkedin.com/pulse/best-kept-secret-can-help-alex-fleischer/

    ?


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 10.  Re: Matrix as an input

    Posted 04/30/18 03:41 AM

    Originally posted by: Srihitha Reddy B


    Hi, Alex!
    Thanks for the reply. The errors got resolved.

    But, suggest me a way to declare the bivalent variable zijk, which expresses migration of VMfrom server i to server j. It should be a 2-dimensional matrix. But, by declaring z ijk, as z[i][j][k], we are getting a 3-dimensional matrix.

    Please help me with this issue.

    Thanks in advance,

    Srihitha.


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 11.  Re: Matrix as an input

    Posted 04/30/18 04:10 AM

    Hi,

    what would be the indexes for your  2-dimensional matrix ?

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 12.  Re: Matrix as an input

    Posted 04/30/18 04:16 AM

    Originally posted by: Srihitha Reddy B


    Hi,

    In zijk , i and j values are from the number of non-idle servers out of available servers (4) and k values are from number of VMs(5).

     

    Thanks,

    Srihitha.

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 13.  Re: Matrix as an input

    Posted 04/30/18 04:29 AM


  • 14.  Re: Matrix as an input

    Posted 04/30/18 09:10 AM

    Originally posted by: Srihitha Reddy B


    Hi,

    Whatever the values of inputs may be, we are not getting the dvar z matrix values. We are getting all values as zero.

     //parameters
     int n=...; //no. of requested VMs
     int m=...; //no. of servers
     
     range VMs=1..n;
     range servers=1..m;
     
     float maxpower=...;   //max power consumed by server
     float idlepower=...;
     float power[VMs]=...; //power consumption of VMs
     float currentpower[servers]=...; //current power consumption of servers
     int x[VMs][servers]=...;
     int e[servers]=...;
     int y[servers]=...;
     
     //variables
       
     //dvar boolean y[servers];
     dvar boolean z[servers][servers][VMs];

     //int count;
     int m1=0;
     float p;
     int q[servers];
     float pk=...;
      
     execute
    {
      for(var j=1;j<=m;j++)
      {
         //if(e[j]==1) y[j]==0;
         //else y[j]==1;
         p=0;  
         q[j]=0;
         for (var i=1;i<=n;i++)
         {
           if(x[i][j]==1) 
           {
             p=p+power[i];
             q[j]=q[j]+1;      
           }    
           writeln(q[j]);
         }  
         if(p<maxpower && p>0)
         {
           m1=m1+1;     
         }
      }
      writeln("#non-idle servers=",m1);
      //writeln("#VMs hosted on server i=",q[j]);
    }

     //expression
     maximize sum(i in 1..m1) (idlepower*y[i]) - sum(i in 1..m1)sum(j in 1..m1)sum(k in 1..q[i]) (pk*z[i][j][k]);  //Objective: Min used no. of servers
      
     //constraints
     subject to{
            cons1:
              forall(i,j,l in 1..m1) forall(k,k1 in 1..q[i]) 
              z[i][j][k] + z[j][l][k1] <= 1;
           
           cons2:
              forall(i in 1..m1) forall(k in 1..q[i]) 
              sum(j in 1..m1) (z[i][j][k]) <= 1;
           
           cons3:
              forall(j in servers )
              sum(i in 1..m1)sum(k in 1..q[i]) (pk*z[i][j][k]) <= (maxpower - currentpower[j])*(1-y[j]);  
              
           cons4:
              forall(i in 1..m1)
              sum(j in 1..m1) sum(k in 1..q[i]) (z[i][j][k]) == q[i]*y[i];
                       
           cons5:
           sum(i in 1..m1) y[i] <= m1 - ceil ((sum(j in 1..m1) currentpower[j])/maxpower);   
            }

     

    output: 

    z = [[[0
                     0 0 0 0]
                     [0 0 0 0 0]
                     [0 0 0 0 0]
                     [0 0 0 0 0]]
                 [[0 0 0 0 0]
                     [0 0 0 0 0]
                     [0 0 0 0 0]
                     [0 0 0 0 0]]
                 [[0 0 0 0 0]
                     [0 0 0 0 0]
                     [0 0 0 0 0]
                     [0 0 0 0 0]]
                 [[0 0 0 0 0]
                     [0 0 0 0 0]
                     [0 0 0 0 0]
                     [0 0 0 0 0]]];

     

    Also, we are getting 57 warnings as:

    Decision variable "z[1][1][3]" has never been used by the engine.

    Decision variable "z[1][1][4]" has never been used by the engine.

    Decision variable "z[1][1][5]" has never been used by the engine.

    ....

    Thanks in advance,

    Srihitha.


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 15.  Re: Matrix as an input

    Posted 04/30/18 09:48 AM

    Hi,

    can you attach .dat ?

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 16.  Re: Matrix as an input

    Posted 04/30/18 09:50 AM

    Originally posted by: Srihitha Reddy B


    Hi,

    PFA the files.

     

    Thanks,

    Srihitha


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 17.  Re: Matrix as an input

    Posted 04/30/18 10:03 AM

    Hi

    have a look at

    cons4:
              forall(i in 1..m1)
              sum(j in 1..m1) sum(k in 1..q[i]) (z[i][j][k]) == q[i]*y[i];

    If you realize that y is [ 0 0 0 1] and q is [2 2 1 0]

    you ll understand that for all i in 1..m1

    sum(j in 1..m1) sum(k in 1..q[i]) (z[i][j][k])

    needs to be 0 which explains why all z are 0

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 18.  Re: Matrix as an input

    Posted 04/30/18 10:18 AM

    Originally posted by: Srihitha Reddy B


    Hi,

     

    Please have a look at eq-25 which is cons4 in our code. Neglecting eq-27, the rest (22-26) are our 5 constraints.

    Also, what do those warnings mean?

    And, how should we include i !=j (i not equal to j) in some of the constraints?

     

    Thanks,

    Srihitha.


    #DecisionOptimization


  • 19.  Re: Matrix as an input

    Posted 04/30/18 10:35 AM

    Hi,

    let me  comment the first one:

    Instead of

    cons1:
              forall(i,j,l in 1..m1) forall(k,k1 in 1..q[i])
              z[i][j][k] + z[j][l][k1] <= 1;

    you could try

    cons1:
              forall(i,j,l in 1..m1:i!=j && l!=j) forall(k,k1 in 1..q[i]:k!=k1)
              z[i][j][k] + z[j][l][k1] <= 1;

    The warning meant that the decision variable was not used in any constraint.

    Are you a student ?

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 20.  Re: Matrix as an input

    Posted 04/30/18 10:38 AM

    Originally posted by: Srihitha Reddy B


    Yes, Alex.

    I am a student.

    I will replace the cons1 and I will try that.

     

    Thanks,

    Srihitha.


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 21.  Re: Matrix as an input

    Posted 05/01/18 01:39 PM

    Originally posted by: Srihitha Reddy B


     Hi,

    For this algorithm, the inputs are x ij  matrix and ematrix.  

    Decision variables are z ijk and yj , in which, the 'y' values depend on 'e' values like if e[j] = 0(server j is not being used i.e idle server), then y[j]=1(idle server)  and vice-versa.

    But, in this algorithm, if we are declaring y as a decision variable and giving this condition on "e[j]", then we are not getting the values of 'y' exactly as opposite as 'e.' We are getting some random stuff for 'y' by which q*y may not become zero.

    Unless, if we directly feed in the exact opposite values of 'e' as the matrix 'y', then obviously q*y values become zero and we are getting z values as zeroes.

    So could you suggest us something that works..

     

    Thanks in advance,

    Srihitha.

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 22.  Re: Matrix as an input

    Posted 04/30/18 10:31 AM

    Originally posted by: Srihitha Reddy B


    Hi,

     

    This is the explanation for cons4.

    y=0,if server is non-idle

    y=1, if idle

     

    Thanks,

    Srihitha.


    #DecisionOptimization


  • 23.  Re: Matrix as an input

    Posted 05/01/18 01:01 PM

    Originally posted by: Srihitha Reddy B


    Hi,

    We would like to know how to include the lifetime of VMs in the migration algorithm discussed above.

    For eg. : We have a set of incoming VMs, with a uniform incoming rate(say 1 second) and uniform lifetime (say 10 secs). Suppose, 5th VM take 5 secs to enter the pipeline, similarly 10th  VM take 10 sec to enter. By the time 11th VM enters, which takes 11 secs, the 1st VM should complete its job and that memory should be released such that re-arrangement (migration)  takes place. 

    Could you suggest a way to implement this kind of algorithm?

     

    Thanks in advance,

    Srihitha.


    #DecisionOptimization
    #OPLusingCPLEXOptimizer