Problem
Define the picture in Figure 1 and draw it with the drawing tool of LPL.
Figure 1: A Grid
Solution
We define a parameter Pi,j which is 1 for a black circle, 0 for a white circle, and 2 for no circle. It is define as follows:
In LPL the function if(a,b,c,d,e) is like a case statement: “if a is true return b, elseif c is true return d, else return e”.
Note that the 5-th parameter for Draw.Circle() is the color: 0=black, 1=white (see color assignments in LPL: xDrawColors).
Listing 1: The Complete Model implemented in LPL [2]
model aGraph2 "Draw a Graph IV";
set i,j :=1..6 "A set of nodes";
parameter P{i,j}:=if(i=j,1,i=7-j,0,2);
Draw.Scale(20,20);
{i|i<#i} Draw.Line(0,i,#j,i,2);
{j|j<#j} Draw.Line(j,0,j,#i,2);
{i,j|P<>2} Draw.Circle(j-.5,i-.5,.4,1-P,0);
end
References
[1] MatMod. Homepage for Learning Mathematical Modeling : https://matmod.ch.
[2] Hürlimann T. Reference Manual for the LPL Modeling Language, most recent version. https://matmod.ch/lpl/doc/manual.pdf.