Iván Riera
unread,Apr 30, 2012, 6:24:52 PM4/30/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to AMPL Modeling Language
I have problems trying to modeler this CVRP:
###Sets and parameters###
param n :=13;
param k :=4;
set dem_nodes := {2..n};
set nodes ordered := {1..n};
set veh;
set links := {i in nodes, j in nodes: i<>j};
param Q{veh}>0;
param q{nodes}>=0;
param travel_cost{links};
###Variables###
var x{links, veh}, binary;
var y{links}, binary;
#var z{nodes}, integer;
###The objective function###
minimize Total_cost:
sum {(i,j) in links} travel_cost[i,j] * x[i,j,k];
###Constraints###
#Starting from depot (node 1), a vehicle must visit a customer i.
subject to Start{j in dem_nodes}:
sum{i in nodes: i<>j} y[i,j]=1;
#After visiting a customer i,the vehicle must leave for another
customer j.
subject to Continue{i in dem_nodes}:
sum{(i,j) in links: i<>j} y[i,j]=1;
#The nº of vehicles going from node 1 to all nodes j must be equal to
K.
subject to Going:
sum{j in dem_nodes, i in nodes: i<>j} y[1,j]=k;
#The nº of vehicles returning to node 1 from all nodes i must be equal
to K.
subject to Backing:
sum{i in dem_nodes, j in nodes: i<>j} y[i,1]=k;
#Each vehicle must carry less than or equal to its capacity.
subject to Capacity:
sum {i in dem_nodes, j in nodes: i<>j} x[i,j,k]*q[j]<=Q[k];
#There must be a link between xkij and yij variables. Each node,
except
#the depot, can only be served once by only one vehicle.
subject to Served:
sum{i in nodes, j in nodes: i<>j} x[i,j,1] + sum{i in nodes, j in
nodes: i<>j} x[i,j,2] + sum{i in nodes, j in nodes: i<>j} x[i,j,3] +
sum{i in nodes, j in nodes: i<>j} x[i,j,4] =sum{i in nodes, j in
nodes: i<>j} y[i,j];
#The solution must not contain any cycle using the nodes 2,3,..,n. Not
#contain any subtours of these nodes.
Each time I try to use {k in veh}, I get syntex error, and I need a
hand for doing the last constraint...should I define a subtour set or
something similar? how?
Thank you!