Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Treating 2D arrays as variables in CPLEX

    Posted 10/10/16 12:30 AM

    Originally posted by: mutinifni


    Hello,

    I have only recently begun using CPLEX, and I want to solve the LP mentioned in section 5 of this paper:

    http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.86.1151&rep=rep1&type=pdf

     

    I am using the command-line CPLEX optimizer and modeling the problem in a plain .lp file. Hence, I have:

    \ Constants

    int N;
    int M;
    float u[N][M];

    range tasks = 1..N;
    range processors = 1..M;

    \ Problem model

    minimize
    obj: U

    subject to

    sum(j in processors) x[i][j] = 1                  for i in tasks \ (N equations)
    sum(i in tasks) [ u[i][j] * x[i][j] ] - U <= 0     for j in processors \ (M inequalities)

    bounds
    0 <= x[i][j]        for i in tasks, for j in processors

    0 <= U

    end

     

    I understand it is possible to model this problem by using individual variables such as x11, x12, x21, etc. However using a 2D array would be easier. 

    However, CPLEX does not allow me to use x[i][j] variables if represented as above. Is it possible to do so? Also, can "for i in tasks, for j in processors" notation be used?

    Thank you.


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Treating 2D arrays as variables in CPLEX

    Posted 10/10/16 01:51 AM

    LP does not allow any of the statements you used above. It looks like you tried to write an OPL file instead. See here for more details about OPL, how to write files, how to solve problems described in OPL files, etc. If you experience trouble with that you may want to turn to the OPL Forum.

    The LP file format neither supports arrays, nor does it support 'forall' constructs or any sort of loops.


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Treating 2D arrays as variables in CPLEX

    Posted 10/10/16 09:15 AM

    Hi,

    you could start with

    int N;
    int M=5;


    range tasks = 1..N;
    range processors = 1..M;

    float u[i in tasks][j in processors]=i*j;

    dvar float+ x[tasks][processors]; //0 <= x[i][j]       // for i in tasks, for j in processors
    dvar float U;
    minimize U;

    subject to
    {
    forall(i in tasks) sum(j in processors) x[i][j] == 1  ;     //           for i in tasks \ (N equations)

    forall(j in processors)sum(i in tasks)  u[i][j] * x[i][j]  - U <= 0  ;  // for j in processors \ (M inequalities)

    }

    that you could run either with the IDE or with oplrun (command line)

    regards


    #CPLEXOptimizers
    #DecisionOptimization