Mathematical Modeling with LPL : Explain and run a Model
Problem Statement
Modeling Description
||
Back to MatMod
model intersec "Find No-intersecting Paths"; set i,j := [1..7] "A set of columns and rows"; k,k1,k2 := [1..3] "Three colors (paths)"; parameter a{i,j} "Initial assignment of colors" := [(1,4)=1, (7,4)=1, (4,1)=2, (4,5)=2, (4,3)=3, (4,7)=3]; binary variable x{k,i,j}; constraint I{k,i,j|a=k}: x[k,i,j]=1; N{k,i,j|a=k}: x[k,i,j+1]+x[k,i-1,j+1]+x[k,i-1,j] +x[k,i-1,j-1]+x[k,i,j-1]+x[k,i+1,j-1] +x[k,i+1,j]+x[k,i+1,j+1] = 1; NN{k,i,j|a[i,j]<>k}: x[k,i,j] ->( x[k,i,j+1] +x[k,i-1,j+1]+x[k,i-1,j]+x[k,i-1,j-1]+x[k,i,j-1] +x[k,i+1,j-1]+x[k,i+1,j]+x[k,i+1,j+1] = 2); E{i,j}: atmost(1){k} x[k,i,j]; K{i,j,k1,k2|k1<>k2 and i<#i and j<#j}: x[k1,i,j] and x[k1,i+1,j+1] and x[k2,i+1,j] -> ~x[k2,i,j+1]; minimize pathL: sum{k,i,j} x[k,i,j]; Write('path length = %2d\n %3s \n', pathL, {i}i); Write{i}(' %s %s \n', i, {j} if (x[1,i,j],'x ', x[2,i,j],'* ',x[3,i,j],'+ ',' ')); Draw.Scale(30,30); {i,j,k} Draw.Rect(if(x,k&''),j,i,1,1,if(x,k+6,-1)); end
Problem Statement
Modeling Description
Back to model
The solution is as follows:
The LOG-File output of LPL is as follows: