Mathematical Modeling with LPL : Explain and run a Model
Problem Statement
Modeling Description
||
Back to MatMod
model cvrp "Vehicle Routing Problem"; set i,j,k "Nodes set"; s; S{s,i} "Subsets for subtours"; parameter c{i}; D{i,j}; K; C; binary variable x{i,j|i
1}: sum{j} (x[i,j]+x[j,i]) = 2; SU{s}: sum{i,j|S[s,i] and S[s,j]} x <= sum{i|S}1-1; minimize obj: sum{i,j} D*x; model data; //schoolbus data parameter d{i,j}; X{i}; Y{i};; //coordinates K:=2 "number of busses"; C:=35 "bus capacity"; Read{i}('schoolbus.txt,%1:Table', i,c,X,Y); Read{i,j}('%2', i,j,d); Read{s}('%3', {i} S); --define the 3 subsets -- The Floyd-Warshall algorithm D{i,j} := if(i=j,0,d or d[j,i],Max(d,d[j,i]),999); for {k} do D{i,j} := Min(D[i,j],D[i,k]+D[k,j]); end end model output friend data; set h:=1..K; parameter C{i}; E{i,j|i<>'0' and j<>'0'}:=x; nC:=Graph.Components(E,C); CC{i,h}:=C=h+1 or i='0'; L{h}:=sum{i,j|x and CC[i,h] and CC[j,h]} D; Write{h}('Length of Tour %s: %d , children: %d\n', h,L,sum{i|CC}c); Write{h}('Nodes of Tour %s : %3s\n', h, {i|CC} i); Draw.Scale(1,1); --Draw.Picture('schoolbus0.jpg',-40,0,1040,780); Draw.DefFont('Verdana',12); {i,j|x} Draw.Line(X[i],Y[i],X[j],Y[j],3,5); --{i,j|x} Draw.Line(X[i],Y[i],X[j],Y[j],if(d,3,4),5); {i,j|d} Draw.Line(X[i],Y[i],X[j],Y[j],2,2); {i} Draw.Circle(i&'',X,Y,10,1,0); end end
Problem Statement
Modeling Description
Back to model
The solution is as follows:
The LOG-File output of LPL is as follows: