Mathematical Modeling with LPL : Explain and run a Model
Problem Statement
Modeling Description
||
Back to MatMod
model snake1 "Snakes Problem"; set i,j "set of notches"; e{i,j} "i and j are neighours"; h "set of snakes (colors)"; k "Length of snakes (ordered set of position)"; parameter J{h} "Starting positions (heads of snake)"; binary variable z{h,i,k}; constraint A{h}: z[h,J,1] = 1; B{i}: sum{h,k} z = 1; C{h,k}: sum{i} z = 1; D{h,i,k|1
= sum{j,k1 in k|e[i,j]} z[h,j,k1]; solve; model data; parameter n:=[50] "number of pellets"; m:=[5] "number of colors"; p:=[10] "Height of the game board";; i:=1..n; h:=1..m; J{h}:=[44 23 28 13 15]; --J{h}:=[44 23 28 15 16] "other solution"; --J{h}:=[1 11 21 31 41 "trivial solution"; k:=1..n/m; parameter x{i}:=Trunc((i-1)/p) "x-coordinate"; y{i}:=Trunc((i-1)%p) "y-coordinate";; e{i,j|i<>j}:= i=j-p or if((i-1)%p,i=j+1); e{i,j}:=e[i,j] or e[j,i]; end model output friend data; Draw.Scale(30,30); Draw.DefFont('Verdana',8); parameter Z{h,k}:=argmax{i} z; {h,k|k<#k} Draw.Line(x[Z[h,k]],y[Z[h,k]],x[Z[h,k+1]],y[Z[h,k+1]],0,5,1); {h,i,k|z} Draw.Circle(i&'',x,y,.3,h+2,0); {h} Draw.Circle(J&'',x[J],y[J],.5,h+2,0); end end
Problem Statement
Modeling Description
Back to model
The solution is as follows:
The LOG-File output of LPL is as follows: