Decision Optimization

 View Only
  • 1.  unknown error / code issue

    Posted Mon May 17, 2021 04:14 PM
    Hey everyone,

    I am just starting to learn CPLEX for my internship.
    However, I still have some issues debugging the code.

    My CPLEX code gives me this message. Can someone help me finding the problem? I cannot find anything wrong.

    /*********************************************
    * OPL 12.6.0.0 Model
    * Author: Puno
    * Creation Date: 01.02.2018 at 11:41:34
    *********************************************/

    // problem size
    int n = 50; // no of demand nodes
    int f = 4; // no of acility locations
    int p = 4; // no of facilities

    // indices
    range I = 1..n; // demand node index
    range J = 1..f; // facility location index x axis
    range K = 1..f; // facility location index y axis
    // parameters
    int d[I][J][K] = [[25,93,36,98,100,22,63,3,96,62,16,49,66,79,44,37,94,89,4,93,81,27,48,48,73,30,7,8,90,96,91,53,15,26,65,63,54,44,46,69,70,84,87,2,15,67,81,32,25,37
    ], // distances between facility locations and demand nodes
    [9,0,13,19,17,26], // in this example, each demand node is a potential location
    [12,13,0,8,7,15],
    [10,19,8,0,13,7],
    [19,17,7,13,0,9],
    [17,26,15,7,9,0]];

    // decision variable
    dvar boolean y[I][J][K]; // binary indicator, if node i is assigned to facility j
    dvar boolean x[J]; // binary indicator, if facility j is selected
    dvar int z;

    // objective function
    minimize z;

    // constraints
    subject to{
    // each demand node must be assigned to a facility
    forall(i in I)
    sum(j in J) y[i][j] == 1;

    // demand nodes can only be assigned to selected facilities
    forall(j in J, i in I)
    y[i][j] - x[j] <= 0;

    // p facilities must be selected
    sum(j in J) x[j] == p;

    // calculation of maximum distance from a facility to a node
    forall(i in I)
    sum(j in J) d[i][j][k] * y[i][j][k] <= z;
    }


    ------------------------------
    Raphael Simon
    ------------------------------

    #DecisionOptimization


  • 2.  RE: unknown error / code issue

    Posted Tue May 18, 2021 02:40 AM
    Hi,

    several issues in your model :

    After

    d[I][J][K]=​

    you should have a 3 D array and not a 2D array


    forall(i in I)
    sum(j in J) y[i][j] == 1;


    cannot work since y is a 3D array

    Plus in

    forall(i in I)
    sum(j in J) d[i][j][k] * y[i][j][k] <= z;


    k is not declared anywhere

    regards



    ------------------------------
    [Alex] [Fleischer]
    [EMEA CPLEX Optimization Technical Sales]
    [IBM]
    ------------------------------