Mathematical Modeling with LPL : Explain and run a Model
Problem Statement
Modeling Description
||
Back to MatMod
model cvrp1 "The Two-index Subtour Formulation"; set i,j,k "nodes set"; parameter c{i}; D{i,j}; K; C; binary variable x{i,j|i<>j}; constraint A{i}: sum{j} x[i,j] = if(i=1,K,1); B{i}: sum{j} x[j,i] = if(i=1,K,1); S2{i,j|i
= 2*bS; set s:=[1..2000]; parameter cNr; cNr1:=2; cNr2; passed; CO{i}; size{i}; Count{i}; maxS; OBJ; S{s,i}; bS{s}; while (cNr1>1 or cNr2) and passed<=200 do minimize obj: sum{i,j} D*x; OBJ:=obj; passed:=passed+1; cNr1:=Graph.Components(x,CO); {i|CO<>CO[1]} (S[CO+cNr,i]:=1, bS[CO+cNr]:=1); cNr:=cNr+cNr1; {i} (x[1,i]:=0, x[i,1]:=0); cNr2:=Graph.Components(x,CO); size{i}:=0; cNr2:=0; {i} (size[CO]:=size[CO]+c); {i|size>C} (cNr:=cNr+1, cNr2:=cNr2+1, {j|CO[j]=i} (S[cNr,j]:=1), bS[cNr]:=Ceil(size/C) ); end; minimize obj1: sum{i,j} D*x; //optimize a last time model data; string File:=['P-n19-k2.vrp']; //opt=212 (problem 1) (K=2) --string File:=['E-n22-k4.vrp'];//opt=375 (problem 2) (K=4) --string File:=['A-n32-k5.vrp'];//opt=784 (problem 3) (K=5) parameter X{i}; Y{i}; dum;; Read(File&',%1;-1:CAPACITY',dum,dum,C); Read{i}('%1:NODE_COORD_SECTION:DEMAND_SECTION',i,X,Y); Read{i}('%1:DEMAND_SECTION:DEPOT_SECTION',i,c); K:=Ceil(sum{i} c/C); D{i,j} := Trunc(Sqrt((X[i]-X[j])^2+(Y[i]-Y[j])^2)+0.5); parameter min0:=min{i,j|D} D; max0:=max{i,j|D} D; set e{i,j}:=D<2*min0; set e1{i,j}:=D>=max0/1.5; set e2{i,j}:=D<=3.5*min0; end model output friend data; parameter cc{s}:=sum{i|S} c; Write('List all subtour sets that have been added\n'); Write(' nr CAP nodes\n'); Write{s|sum{i}S}('%3d\t%3d\t%3d \n', s,cc,{i|S} i); set h:=1..K; parameter C{i}; E{i,j|i>1 and j>1}:=x; nC:=Graph.Components(E,C); CC{i,h}:=C=h+1 or i=1; L{h}:=sum{i,j|x and CC[i,h] and CC[j,h]} D; --Write('The total distance:%d , Capacity: %d , Children: %d\n', obj, Schoolbus.C,sum{i}c); 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(5,5); Draw.DefFont('Verdana',12); {i,j|x} Draw.Line(X[i],Y[i],X[j],Y[j],3); {i} Draw.Circle(i&'',X,Y,2,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: