next up previous contents
Next: Construct Graph G2: Up: The New Run Time Previous: The New Run Time

Construct Graph G1:

  //construct graph G1
  Graph *G1 = new Graph(ES,NS,
                        T->radius,T->center,     
                        T->foreground,             
                        T->background,         
                        graph_colors,            
                        T->display, 
                        T->drawable,
                        T->pixmap,
                        T->pixmap2,
                        T->gc); 

  NodeStruct node_data[4];
  EdgeStruct edge_data[7];
   
  for(int i = 0;i<4;++i){
    node_data[i].load = i;
    node_data[i].time = float(i)*float(i);
    node_data[i].V.x = i-1;
    node_data[i].V.y = i+1;
    }
   
  for(int i=0;i<7;++i){ 
    edge_data[i].capacity = 10.0;
    edge_data[i].loss = -i;
    edge_data[i].time = float(i)*float(i);
    edge_data[i].V.x =10*i-1;
    edge_data[i].V.y =10*i+1;
    }
        
  Gnode *g1n1 = G1->addNode("Quinn",40.0,200.0,&(node_data[0]));
  Gnode *g1n2 = G1->addNode("Qaitlin",120.0,100.0,&(node_data[1]));
  Gnode *g1n3 = G1->addNode("Pauli",120.0,200.0,&(node_data[2]));
  Gnode *g1n4 = G1->addNode("Clive",120.0,300.0,&(node_data[3]));
      
  G1->addEdge(g1n2,g1n1,4.0,&(edge_data[0]));
  G1->addEdge(g1n1,g1n3,5.0,&(edge_data[1]));
  G1->addEdge(g1n3,g1n2,1.0,&(edge_data[2]));
  G1->addEdge(G1->findNode("Qaitlin"),G1->findNode("Clive"),6.0,&(edge_data[3]));
  G1->addEdge(G1->findNode("Pauli"),G1->findNode("Clive"),3.0,&(edge_data[4]));
  G1->addEdge(G1->findNode("Pauli"),G1->findNode("Qaitlin"),4.5,&(edge_data[5]));
  G1->addEdge(G1->findNode("Quinn"),G1->findNode("Clive"),14.5,&(edge_data[6]));

This constructs a graph of 4 nodes and 7 edges using NodeStruct and EdgeStruct data types. We output this graph using the line

out << "Graph G1 = " << G1 << endl;

and at run-time will see the following output

Graph G1 = Graph: 
Nodes: 
entering node loop 
node 1
  Clive    Load = 3
           Time = 9
           Vertex = (2,4)
node 2
  Pauli    Load = 2
           Time = 4
           Vertex = (1,3)
node 3
  Qaitlin  Load = 1
           Time = 1
           Vertex = (0,2)
node 4
           Quinn Load = 0
           Time = 0
           Vertex = (-1,1)
entering edge loop
Edges:
edge 1
          Quinn-----(14.5)---> Clive Capacity = 10
                                     Loss = -6
                                     time = 36
                                     Vertex = (59,61)
edge 2
          Pauli-----(4.5)---> Qaitlin Capacity = 10
                                      Loss = -5
                                      time = 25
                                      Vertex = (49,51)
edge 3
          Pauli-----(3)---> Clive Capacity = 10
                                  Loss = -4
                                  time = 16
                                  Vertex = (39,41)
edge 4
          Qaitlin-----(6)---> Clive Capacity = 10
                                    Loss = -3
                                    time = 9
                                    Vertex = (29,31)
edge 5
          Pauli-----(1)---> Qaitlin Capacity = 10
                                    Loss = -2
                                    time = 4
                                    Vertex = (19,21)
edge 6
          Quinn-----(5)---> Pauli Capacity = 10
                                  Loss = -1
                                  time = 1
                                  Vertex = (9,11)
edge 7
          Qaitlin-----(4)---> Quinn Capacity = 10
                                    Loss = 0
                                    time = 0
                                    Vertex = (-1,1)
End Graph



Jim Peterson
1999-05-17