Mathematical Modeling with LPL : Explain and run a Model
Problem Statement
Modeling Description
||
Back to MatMod
model cross92 "Hamiltonian Circuit"; set i,j "set of vertices of a graph"; parameter d{i,j} "distance between i and j"; binary variable x{i,j|i<>j}; constraint A{i}: sum{j} x = 1; B{j}: sum{i} x = 1; F{i,j|j>i}: x[i,j] + x[j,i] <= 1; minimize obj: sum{i,j} d*x; Write('minimal tour is: %5.2f\n', obj); draw; model data,D "The star"; i:=1..92; set k:=1..#i/4; parameter x{k}:=[ 0 -1 -1 -2 -3 -4 -4 -4 -2 -1 -1 -1 -2 -4 -5 -5 -5 -6 -7 -7 -8 -9 -10]; y{k}:=[10 10 8 7 7 7 6 5 5 4 3 2 1 1 2 3 4 4 4 2 1 1 1]; X{i}:=(if(i<=23,x[i], i<=46,-y[i-23], i<=69,-x[i-46], y[i-69]) +10)/3*2 +.3; Y{i}:=(if(i<=23,y[i],i<=46, x[i-23], i<=69,-y[i-46], -x[i-69]) +10)/3*2 +.3;; d{i,j}:= Sqrt((X[j]-X[i])^2+(Y[j]-Y[i])^2); d{i,j|d>=3.1}:=99999; end model draw; Draw.Scale(40,40); Draw.DefFont('Verdana',10); {i,j|d<3.1} Draw.Line(D.X[i],D.Y[i],D.X[j],D.Y[j],2); {i,j|x} Draw.Line(D.X[i],D.Y[i],D.X[j],D.Y[j],3,3); {i} Draw.Circle(i&'',D.X,D.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: