Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  how to write appropriate cplex code for mip model

    Posted 12/04/11 12:42 PM

    Originally posted by: kutikz


    im a newbie on cplex code. i have a model about production-inventory-distribution-routing problem. i already wrote the cplex code for the model and using some random datas to implement it, but i found too many errors on my code, and mostly dealing with the bounds of the period.

    i attached the model and the code that ive been wrote, hopefully u cud give me help and fix the errors.

    many thanks
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: how to write appropriate cplex code for mip model

    Posted 12/04/11 12:43 PM

    Originally posted by: kutikz


    and this is the code that i wrote
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: how to write appropriate cplex code for mip model

    Posted 12/04/11 04:45 PM
    Hi,

    indeed you face many out of bounds since you do "forall" that are out of the range of the arrays you use.

    I fixed some to give you some idea but you should review your code line by line and check that when you do forall(t in period) then all data and decision variables are defined for all t in period:

    
    subject to 
    { 
    //non negativity constraints c1=forall(t in period2) inventP[t]>=0; c2=forall(t in period2) inventP[t]<=inventPmax; c3=forall(i in customer, t in period2) inventC[i][t]>=0; c4=forall(i in customer, t in period2) inventC[i][t]<=inventCmax[i]; c5=forall(t in period) inventP[T]==0; c6=forall(i in customer, t in period) inventC[i][T]==0; c7=forall(i in demands, j in demands, t in period) x[i][j][t]>=0; c8=forall(i in demands, j in demands, t in period) x[i][j][t]<=1; c9=forall(t in period) zp[t]>=0; c10=forall(t in period) zp[t]<=1; c11=forall(i in demands,t in period) y[i][t]>=0; c12=forall(i in demands, t in period) y[i][t] <=Q; c13=forall(t in period) P[t]>=0; c14=forall(i in demands, t in period) w[i][t]>=0; c15=forall(t in period) inventP[t]==inventP[t-1]+P[t]-sum(i in customer, t in period0)w[i][t]; c16=forall(i in customer, t in period) inventC[i][t]==inventC[i][t-1]+w[i][t]-dem[i][t]; c17=forall(t in period) sum(i in customer) w[i][t]<=inventP[t-1]; c18=forall(t in period1) P[t]<=(C*zp[t]); c19=forall(t in period0) P[0]>=sum(i in customer) (dem[i][1]-inventC[i][0]); c20=forall(i in customer, t in period) sum(j in demands) x[i][j][t]<=1; c21=forall(j in customer, t in period) sum(i in demands) x[i][j][t]==sum(i in demands) x[j][i][t]; c22=forall(t in period) sum(j in customer) x[0][j][t]<=K; c23=forall(t in period, i in customer) DCsum[i][t]==sum(t in period) dem[i][t]; c24=forall(i in customer, t in period) DCmax[i][t]==minl(Q,DCsum[i][t]); c25=forall(t in period,i in customer) Dsum[i][t]== sum(i in customer, t in period) dem[i][t]; c26=forall(t in period,i in customer) Dmax[t]== minl(Q, Dsum[i][t]); c27=forall(i in customer, j in demands, t in period) y[j][t]<=y[i][t]-w[i][t]+((Dmax[t])*(1-x[i][j][t])); c28=forall(i in customer, t in period) w[i][t]<=DCmax[i][t]*sum(j in demands) x[i][j][t] ; 
    }
    

    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 4.  Re: how to write appropriate cplex code for mip model

    Posted 12/04/11 07:11 PM

    Originally posted by: kutikz


    i alredy tried the new code but it still has many errors, this is the model of the code that i wanna write.

    i also wanna ask about constraint c23 and c25, where the period in the model is defined by l, which is a subset of the period t, but its we only count the period l from the current day until the end of the period.
    can u help me how to write the constraint properly?

    thank in advance
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 5.  Re: how to write appropriate cplex code for mip model

    Posted 12/05/11 02:53 AM
    Hi

    For ct23, if you want do use a subset of period that starts today and if today is an int then you could write

    
    c23=forall(t in period, i in customer:t>=today) DCsum[i][t]==sum(t in period:t>=today) dem[i][t];
    


    the following code works fine (I replaced ... by random data)
    
    
    
    int N=2; 
    //number of customers 
    
    int T=10; 
    //number of periods 
    
    int K=2; 
    //number of vehicle 
    
    int C=2; 
    //production capacity 
    
    int Q=2; 
    //capacity of each vehicle 
    
    int f=2; 
    //setup cost at production facility 
    
    int V=2; 
    //variable mileage cost 
    
    int hP=2; 
    //holding cost at the production facility 
    
    int inventPmax=2; 
    //maximum inventory at production facility 
    
    int inv0=2; 
    //initial inventory=0   
    //indices range demands=0..N; 
    //including 0 for depot range customer=0..N; 
    //customers only range period=1..T; range period0=0..T; range period1=0..T-1; range period2=1..T-1; 
    //variable with indices 
    
    int dem[c in customer][p in period0]=c+p; 
    //demand of customer i on day t 
    
    int inventCmax[c in customer]=c; 
    //maximum inventory of customer i 
    
    float dist[d in demands][d2 in demands]=d*d2; 
    //distance ij 
    
    int hC[c in customer]=c; 
    //unit holding cost at customer i 
    
    int Dmax[period0]; 
    
    int DCmax[customer][period0]; 
    
    int DCsum[customer][period0]; 
    
    int Dsum[customer][period0]; 
    //variables for writing program 
    
    int  k1; 
    //demand at day 0 
    
    int kk; 
    
    int kz; 
    
    float Z1; 
    
    float Z2; 
    
    float Z3; 
    
    float inventC0; 
    
    float inventP0; 
    
    float inventcost; 
    
    float f0; 
    
    float Z; 
    //decision variables dvar 
    
    int x[customer][customer][period0]; 
    // {0,1} dvar 
    
    int y[customer][period0]; 
    //load on a vehicle immediately before making a delivery to customer i on day t dvar 
    
    int P[period0]; 
    //production quantity on day t dvar 
    
    int zp[period0]; 
    // {0,1} for production dvar 
    
    int inventP[period0]; 
    //inventory at the production facility at the end of day t dvar 
    
    int inventC[customer][period0]; 
    //inventory at customer i at the end of day t dvar 
    
    int w[customer][period0]; 
    //amount delivered to customer i on day t constraint c1; constraint c2; constraint c3; constraint c4; constraint c5; constraint c6; constraint c7; constraint c8; constraint c9; constraint c10; constraint c11; constraint c12; constraint c13; constraint c14; constraint c15; constraint c16; constraint c17; constraint c18; constraint c19; constraint c20; constraint c21; constraint c22; constraint c23; constraint c24; constraint c25; constraint c26; constraint c27; constraint c28; 
    //objective function minimize sum(t in period, i in demands, j in demands) (dist[i][j]*x[i][j][t]) + sum(t in period) (f*zp[t]) + sum(t in period1) (hP*inventP[t]) + sum(i in customer, t in period2) (hC[i]*inventC[i][t]) ; 
    //constraints subject to 
    { 
    //non negativity constraints c1=forall(t in period2) inventP[t]>=0; c2=forall(t in period2) inventP[t]<=inventPmax; c3=forall(i in customer, t in period2) inventC[i][t]>=0; c4=forall(i in customer, t in period2) inventC[i][t]<=inventCmax[i]; c5=forall(t in period) inventP[T]==0; c6=forall(i in customer, t in period) inventC[i][T]==0; c7=forall(i in demands, j in demands, t in period) x[i][j][t]>=0; c8=forall(i in demands, j in demands, t in period) x[i][j][t]<=1; c9=forall(t in period) zp[t]>=0; c10=forall(t in period) zp[t]<=1; c11=forall(i in demands,t in period) y[i][t]>=0; c12=forall(i in demands, t in period) y[i][t] <=Q; c13=forall(t in period) P[t]>=0; c14=forall(i in demands, t in period) w[i][t]>=0; c15=forall(t in period) inventP[t]==inventP[t-1]+P[t]-sum(i in customer, t in period0)w[i][t]; c16=forall(i in customer, t in period) inventC[i][t]==inventC[i][t-1]+w[i][t]-dem[i][t]; c17=forall(t in period) sum(i in customer) w[i][t]<=inventP[t-1]; c18=forall(t in period1) P[t]<=(C*zp[t]); c19=forall(t in period0) P[0]>=sum(i in customer) (dem[i][1]-inventC[i][0]); c20=forall(i in customer, t in period) sum(j in demands) x[i][j][t]<=1; c21=forall(j in customer, t in period) sum(i in demands) x[i][j][t]==sum(i in demands) x[j][i][t]; c22=forall(t in period) sum(j in customer) x[0][j][t]<=K; c23=forall(t in period, i in customer) DCsum[i][t]==sum(t in period) dem[i][t]; c24=forall(i in customer, t in period) DCmax[i][t]==minl(Q,DCsum[i][t]); c25=forall(t in period,i in customer) Dsum[i][t]== sum(i in customer, t in period) dem[i][t]; c26=forall(t in period,i in customer) Dmax[t]== minl(Q, Dsum[i][t]); c27=forall(i in customer, j in demands, t in period) y[j][t]<=y[i][t]-w[i][t]+((Dmax[t])*(1-x[i][j][t])); c28=forall(i in customer, t in period) w[i][t]<=DCmax[i][t]*sum(j in demands) x[i][j][t] ; 
    } 
    //end of constraints
    


    Besides are you sure that you want DCsum and DCmax to be data and not decision variables?

    You could still improve your model.

    Regards
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 6.  Re: how to write appropriate cplex code for mip model

    Posted 12/11/11 09:14 PM

    Originally posted by: kutikz


    how could i define the "today" variable , because of "today" will be started at day 0 until day 10, (based on the period of the planning horizon), should i write it in a range form?

    DCsum and DCmax supposed to be a data, but based on the constraint i need to count them first (in the model) because they will be related to the next constraint. or maybe i should change them into decision variables?

    best regards
    #DecisionOptimization
    #OPLusingCPLEXOptimizer