Mathematical Modeling with LPL : Explain and run a Model
Problem Statement
Modeling Description
||
Back to MatMod
model IntersectingLines "Paths in a Grid"; set i "A set of rows"; j "A set of columns"; k "A set of paths"; parameter a{i,j} "Initial assignment"; binary variable x{k,i,j} "paths points"; constraint I{k,i,j|a[i,j]=k}: x[k,i,j]=1; N{k,i,j|a=k}: x[k,i,j+1]+x[k,i-1,j] +x[k,i,j-1]+x[k,i+1,j]=1; L{k,i,j|a[i,j]<>k}: x[k,i,j] -> (x[k,i,j+1]+x[k,i-1,j]+x[k,i,j-1]+x[k,i+1,j]=2); E{i,j}: sum{k} x <=1; minimize pathL: sum{k,i,j} x[k,i,j]; Write('path length = %2d\n', pathL); Draw.Scale(40,40); {i} Draw.Line(1,i,#j,i,9); {j} Draw.Line(j,1,j,#i,9); {i,j,k|x and x[k,i+1,j]} Draw.Line(j,i,j,i+1,0,4,2); {i,j,k|x and x[k,i,j+1]} Draw.Line(j,i,j+1,i,0,4,2); {i,j|~a} Draw.Circle(j,i,.04); {i,j|a} Draw.Circle(a&'',j,i,.2,1,0); model data "A feasible layout"; i:= [1..8]; j:=[1..8]; k:=[1..5]; a{i,j}:= [(1,1)=1 (4,5)=1 (1,3)=2 (7,5)=2, (2,5)=3 (6,7)=3, (3,3)=4 (3,8)=4, (6,2)=5 (4,8)=5]; end end
Problem Statement
Modeling Description
Back to model
The solution is as follows:
The LOG-File output of LPL is as follows: