Problem
Define the directed graph in Figure 1 and draw it with the drawing tool of LPL.
Figure 1: A Graph
Solution
Listing 1: The Complete Model implemented in LPL [2]
model aGraph1 "Draw Graph II";
set i,j "A set of nodes";
e{i,j} "A set of edges";
parameter X{i} "X-position of node";
Y{i} "Y-position of node";;
i :=[ AAA AAB ABA ABB BAA BAB BBA BBB ];
X{i} := [0 0 3 9 0 6 9 9];
Y{i} := [3 0 3 0 6 3 6 3];
e{i,j} := [ (AAA,*), AAB, ABA, BAA,
(AAB,*), ABB, BAB,
(BAA,*), BAB, BBA,
(ABA,*), ABB, BBA,
(ABB,*), BBB,
(BAB,*), BBB, (BBA,*), BBB ];
drawgraph;
model drawgraph;
Draw.Scale(60,60);
Draw.DefFont('Verdana',16);
{e[i,j]} Draw.Arrow(X[i],Y[i],X[j],Y[j],.4);
{i} Draw.Circle(i&'', X,Y,.4,1,0);
end
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.