MatMod logo

Draw a Graph III (exer-graph2)

Run LPL Code  ,  PDF Document

Problem

Define the simplex in Figure 1 and draw it with the drawing tool of LPL.


PIC

Figure 1: A Graph


Solution

Listing 1: The Complete Model implemented in LPL [2]

model aGraph2 "Draw a Graph III"; 
  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:=1..8; 
  X{i} := [0 2 0 2 0.6 2.6 0.6 2.6]; 
  Y{i} := [0 0 2 2 0.6 0.6 2.6 2.6]; 
  e{i,j} := if(j-i=4 or (j-i=2 and (i-1)%4<2) or ((j-i)=1 and i%2=1) ,1); 
  drawgraph; 
  model drawgraph; 
    Draw.Scale(60,60); 
    Draw.DefFont('Verdana',10); 
    for{e[i,j]} do Draw.Line(X[i],Y[i],X[j],Y[j],.2); end 
    for{i} do Draw.Circle(i&'', X,Y,.2,1,0); end 
  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.