Problem
Define the undirected graph in Figure 1 and draw it with the drawing tool of LPL.
Figure 1: A Graph with 5 nodes and 8 edges
Solution
Listing 1: The Complete Model implemented in LPL [2]
model aGraph "Draw a Graph I";
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 :=[ a b c d e ];
X{i} := [0 0 2 2 3];
Y{i} := [0 2 0 2 1];
e{i,j}:=[ (a,*) b c d,
(b,*) a c d,
(c,*) a b d e,
(d,*) a b c e,
(e,*) c d ];
drawgraph;
--------------------
model drawgraph;
Draw.Scale(60,60);
Draw.DefFont('Verdana',16);
{e[i,j]|i<j} Draw.Line(X[i],Y[i],X[j],Y[j]);
{i}Draw.Circle(i&'', X,Y,.2,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.