Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  cplex code error

    Posted 08/02/18 04:20 AM

    Originally posted by: Arnautarrago


    Hi everyone,

    I'm having an error when trying to run a cplex code. Basically the error says that the index is out of bound for the array x. 

    Please find attach the code as well as the data. 

    Thanks in advance.

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: cplex code error



  • 3.  Re: cplex code error

    Posted 08/02/18 05:41 AM

    Originally posted by: Arnautarrago


    Hi Alex,

    I don't know but i can't upload the model itself, i only can upload the project file.

    If you can't see the model i copy it here:

    using CP;
     
    // NETWORK+PARAMETERS
     
    int trucks=...; // set of trucks
    range truck= 1..trucks;
     
    int times=...; // set of time windows 
    range time=1..times;
     
    int capacity [truck]=...; // capacity of a truck
     
    int WBs=...; // working bench (WB1,WB2)
    range WB= 1..WBs;
     
    int OCs=...; // ore crusher (OC1,OC2)
    range OC= 1..OCs;
     
    int nodes=...; // (WB1,WB2,OC1,OC2)
    range node= 1..nodes;
     
    int nodecalling [node][time]=...; // 1 if node n calls for truck t at time k
     
    // VARIABLES
     
    dvar boolean x [truck,node,time]; // 1 if truck t is at node n at time k, 0 otherwise
     
    // OBJECTIVE FUNCTION 
     
    dexpr float totalproduction = 
    sum (t in truck, n in OC, k in time) x [t,n,k] * capacity [t];
     
    maximize totalproduction;
     
    //CONSTRAINTS
     
    subject to {
     
    forall(t in truck,n in node,k in time)
      
      ct1: x[1,1,1]==1 || x[1,2,1]==1;
      
      ct2: x[2,1,1]==1 || x[2,2,1]==1;
      
    forall (k in time) ct3:(nodecalling [1,k]==1) => 
     
    x [1,3,k+1] ==1 || x [2,3,k+1] ==1 || x [1,4,k+1] ==1 || x [2,4,k+1] ==1 || x [1,1,k] ==0 || x [2,1,k] ==0;
        
    forall (k in time) ct4:(nodecalling [2,k]==1) => 
     
    x [1,3,k+1] ==1 || x [2,3,k+1] ==1 || x [1,4,k+1] ==1 || x [2,4,k+1] ==1 || x [1,2,k] ==0 || x [2,2,k] ==0;
     
    forall (k in time) ct5:(nodecalling [3,k]==1) => 
     
    x [1,1,k+1] ==1 || x [2,1,k+1] ==1 || x [1,2,k+1] ==1 || x [2,2,k+1] ==1 || x [1,3,k] ==0 || x [2,3,k] ==0;
        
    forall (k in time) ct6:(nodecalling [4,k]==1) => 
     
    x [1,1,k+1] ==1 || x [2,1,k+1] ==1 || x [1,2,k+1] ==1 || x [2,2,k+1] ==1 || x [1,4,k] ==0 || x [2,4,k] ==0;
     
    };

    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 4.  Re: cplex code error

    Posted 08/02/18 06:52 AM

    Hi,

    you have many out of bounds.

    If you write

     

        

         using CP;
     
    // NETWORK+PARAMETERS
     
    int trucks=...; // set of trucks
    range truck= 1..trucks;
     
    int times=...; // set of time windows
    range time=1..times;
     
    int capacity [truck]=...; // capacity of a truck
     
    int WBs=...; // working bench (WB1,WB2)
    range WB= 1..WBs;
     
    int OCs=...; // ore crusher (OC1,OC2)
    range OC= 1..OCs;
     
    int nodes=...; // (WB1,WB2,OC1,OC2)
    range node= 1..nodes;
     
    int nodecalling [node][time]=...; // 1 if node n calls for truck t at time k
     
    // VARIABLES
     
    dvar boolean x [truck,node,time]; // 1 if truck t is at node n at time k, 0 otherwise
     
    // OBJECTIVE FUNCTION
     
    dexpr float totalproduction =
    sum (t in truck, n in OC, k in time) x [t,n,k] * capacity [t];
     
    maximize totalproduction;
     
    //CONSTRAINTS
     
    subject to {
     
    forall(t in truck,n in node,k in time)
     
      ct1: x[1,1,1]==1 || x[1,2,1]==1;
     
      ct2: x[2,1,1]==1 || x[2,2,1]==1;
     
    forall (k in time:(k+1) in time) ct3:(nodecalling [1,k]==1) =>
     
    x [1,3,k+1] ==1 || x [2,3,k+1] ==1 || x [1,4,k+1] ==1 || x [2,4,k+1] ==1 || x [1,1,k] ==0 || x [2,1,k] ==0;
        
    forall (k in time:(k+1) in time) ct4:(nodecalling [2,k]==1) =>
     
    x [1,3,k+1] ==1 || x [2,3,k+1] ==1 || x [1,4,k+1] ==1 || x [2,4,k+1] ==1 || x [1,2,k] ==0 || x [2,2,k] ==0;
     
    forall (k in time:(k+1) in time) ct5:(nodecalling [3,k]==1) =>
     
    x [1,1,k+1] ==1 || x [2,1,k+1] ==1 || x [1,2,k+1] ==1 || x [2,2,k+1] ==1 || x [1,3,k] ==0 || x [2,3,k] ==0;
        
    forall (k in time:(k+1) in time) ct6:(nodecalling [4,k]==1) =>
     
    x [1,1,k+1] ==1 || x [2,1,k+1] ==1 || x [1,2,k+1] ==1 || x [2,2,k+1] ==1 || x [1,4,k] ==0 || x [2,4,k] ==0;
     
    };

     

    it will be much better

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 5.  Re: cplex code error

    Posted 08/05/18 04:15 PM

    Originally posted by: Arnautarrago


    Hi Alex,

     

    Thank you very much for the help.

     

    By the way, I'm writing a new code and i have a problem trying to write these expressions (red colour), which aim to compare the values of two different sums:

     

    Here you can see the code:

     

    using CP;
     
     // NETWORK+PARAMETERS
     
    float shifttime= 8;
     
    int shovels=...; // set of shovels
    range shovel=1..shovels;

    int dumpsites=...; // set of dump sites
    range dumpsite= 1..dumpsites;

    float O [shovel]=...;

    float W [shovel]=...;

    float demand [dumpsite]=...;

    float distance [dumpsite][shovel]=...;

    float loadingspeed= 1.848;

    float dumpingspeed= 3.078;

    float capacity= 154;

    // VARIABLES

    dvar int+ x [dumpsite][shovel];

    dvar int+ y [dumpsite][shovel];

    // OBJECTIVE FUNCTION 

    dexpr float totalcost= 
    sum (i in dumpsite, j in shovel) (1.283 * x[i,j] * distance [i,j] + 1 * y[i,j] * distance [i,j]);

    minimize totalcost;

    //CONSTRAINTS

    subject to {

    forall (i in dumpsite) ct1: demand [i] <= sum (j in shovel) capacity * x[i,j]; // demand constraint (1)

    forall (j in shovel) ct6: sum (i in dumpsite) x[i,j] * (capacity/loadingspeed) <= shifttime; // maximum number of trucks a shovel can serve in a shift (6)

    forall (i in dumpsite) ct7: sum (j in shovel) x[i,j] * (capacity/dumpingspeed) <= shifttime; // maximum number of trucks a dumping site can serve in a shift (7)

    forall (i in dumpsite) ct8: sum (j in shovel) x[i,j] = sum (j in shovel) y [i,j]; // number of trucks at each dumpsite remain unchanged at the end of the shift (8)

    forall (j in shovel) ct9: sum (i in dumpsite) x[i,j] = sum (i in dumpsite) y [i,j]; // number of trucks at each loading area remain unchanged at the end of the shift (9)

    };

     

    Thank you in advance.

    Regards

     

     

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 6.  Re: cplex code error

    Posted 08/06/18 11:55 AM

    Hi

    try == instead of =

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 7.  Re: cplex code error

    Posted 08/06/18 06:15 PM

    Originally posted by: Arnautarrago


    Hi Alex,

    Thank you for the help it worked perfectly! Even though, when I simulated the code, after 1h 30 min running the simulation I aborted it because I didn't find that normal. Do you know why this happens?

    Once again, thank you in advance.

    Regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer