Repeat model x time with decreased scalar

Problems with modeling
Post Reply
Bollerwagen
User
User
Posts: 1
Joined: 1 year ago

Repeat model x time with decreased scalar

Post by Bollerwagen »

Hi,
I successfully build a lp model. Now i want to repeat the model several times and decrease one scalar ('CAP') in decrements of five till it reaches 30. I tried to implement a loop and an if statement but it doesnt work. Below I put the running model with the start scalar CAP of 60.

Code: Select all

*Task
******

sets
I      Set of customers incl. the depot        /0*20/
;

alias(v,i,j);

parameter
d(i)     Demand of customer i    /0 0, 1 20, 2 10, 3 15, 4 10, 5 20, 6 15, 7 20, 8 10, 9 15, 10 10,
                                11 10, 12 15, 13 20, 14 10, 15 20, 16 10, 17 20, 18 15, 19 20, 20 10/
                                
a(i)                            /0 0, 1 360, 2 360, 3 360, 4 360, 5 360, 6 480, 7 480, 8 480, 9 480, 10 480,
                                11 360, 12 360, 13 360, 14 360, 15 360, 16 480, 17 480, 18 480, 19 480, 20 480/
                                
b(i)                            /0 0, 1 600, 2 600, 3 600, 4 600, 5 600, 6 720, 7 720, 8 720, 9 720, 10 720,
                                11 600, 12 600, 13 600, 14 600, 15 600, 16 720, 17 720, 18 720, 19 720, 20 720/
                                
s(i)                            /0 0, 1 10, 2 5, 3 15, 4 20, 5 5, 6 10, 7 5, 8 15, 9 20, 10 5,
                                11 10, 12 5, 13 15, 14 20, 15 5, 16 10, 17 20, 18 15, 19 10, 20 20/
;

scalar
CAP       Capacity of the trucks       /60/
K         Truck fleet size             /10/
M         large number                /10000/
;

table
c(i,j) Costs between customer (node) i and customer (node) j
$ONDELIM 
$INCLUDE Data_c.csv
$OFFDELIM

table
t(i,j)
$ONDELIM 
$INCLUDE Data_t.csv
$OFFDELIM
;

binary variables
x(i,j) is 1 - if node j is served after node i (0 otherwise)
;

positive variable
u(i)   Loading of a truck when leaving node i
w(i)
;

variable
F        Objective function value (Total costs)
;


equations
of               Objective function (minimises the total costs)
pred(j)          every customer has only one predecessor node
succ(i)          every customer has only one successor node
start            every tour starts at the central warehouse
end              every tour ends at the central warehouse
load(i,j)        calculates the loading when leaving a node
loadres1(i)      loading is at least as large as the demand at node i
loadres2(i)      loading is at most as large as the capacity of the vehicle
loadres3(i)
loadres4(i)
load2(i,j)
;


of..                             F =E= sum((i,j), c(i,j) * x(i,j));

pred(j)$(ord(j)>1)..             sum(i, x(i,j)) =E= 1;      

succ(i)$(ord(i)>1)..             sum(j, x(i,j)) =E= 1;

start..                          sum(j, x("0",j)) =E= K ;

end..                            sum(i, x(i,"0")) =E= K ;

load(i,j)$(ord(i)>1 and ord(j)>1 and ord(i) <> ord(j)).. u(i) + d(j) - CAP * (1 - x(i,j)) =L= u(j) ;

loadres1(i)$(ord(i)>1)..         d(i) =L= u(i) ;

loadres2(i)$(ord(i)>1)..         u(i) =L= CAP ;
loadres3(i)$(ord(i)>1)..         a(i) =L= w(i) ;
loadres4(i)$(ord(i)>1)..         w(i) =L= b(i) ;

load2(i,j)$(ord(i)>1 and ord(j)>1 and ord(i) <> ord(j)).. w(i) + s(i) + t(i,j) - M * (1 - x(i,j)) =L= w(j) ;




model CVRP /all/ ;

option optcr = 0.0;

solve CVRP minimizing F using mip ;

display F.L, x.L, u.L, w.L ;
Thank you very much in advance for any help :)
User avatar
bussieck
Moderator
Moderator
Posts: 1033
Joined: 7 years ago

Re: Repeat model x time with decreased scalar

Post by bussieck »

Why don't you share your attempts with the loop and provide the missing include files so one can run the model and comment on your approach.

-Michael
Post Reply