start of new file
[IRC.git] / Robust / src / Benchmarks / Prefetch / Em3d / dsm / BiGraph.java
1 /** 
2  * A class that represents the irregular bipartite graph used in
3  * EM3D.  The graph contains two linked structures that represent the
4  * E nodes and the N nodes in the application.
5  **/
6 public class BiGraph
7 {
8   public BiGraph() {
9   }
10   /**
11    * Nodes that represent the electrical field.
12    **/
13   Node eNodes;
14   /**
15    * Nodes that representhe the magnetic field.
16    **/
17   Node hNodes;
18
19   /**
20    * Construct the bipartite graph.
21    * @param e the nodes representing the electric fields
22    * @param h the nodes representing the magnetic fields
23    **/ 
24   BiGraph(Node e, Node h)
25   {
26       eNodes = e;
27       hNodes = h;
28   }
29
30   /**
31    * Create the bi graph that contains the linked list of
32    * e and h nodes.
33    * @param numNodes the number of nodes to create
34    * @param numDegree the out-degree of each node
35    * @param verbose should we print out runtime messages
36    * @return the bi graph that we've created.
37    **/
38
39   static BiGraph create(int numNodes, int numDegree, boolean verbose, Random r)
40   {
41
42     // making nodes (we create a table)
43     //if (verbose) System.printString("making nodes (tables in orig. version)");
44     Node [] eTable=Node.fillTable(numNodes, numDegree, r);
45     Node [] hTable=Node.fillTable(numNodes, numDegree, r);
46
47     // making neighbors
48     //if (verbose) System.printString("updating from and coeffs");
49     for(int i = 0; i< numNodes; i++) {
50       Node n = hTable[i];
51       n.makeUniqueNeighbors(eTable, r);
52     }
53
54     for (int i = 0; i < numNodes; i++) {
55       Node n = eTable[i];
56       n.makeUniqueNeighbors(hTable, r);
57     }
58
59     // Create the fromNodes and coeff field
60     //if (verbose) System.printString("filling from fields");
61     for(int i = 0; i< numNodes; i++) {
62       Node n = hTable[i];
63       n.makeFromNodes();
64     }
65
66     for (int i = 0; i < numNodes; i++) {
67       Node n = eTable[i];
68       n.makeFromNodes();
69     }
70
71     // Update the fromNodes
72     for (int i = 0; i < numNodes; i++) {
73       Node n = hTable[i];
74       n.updateFromNodes(r);
75     }
76     for (int i = 0; i < numNodes; i++) {
77       Node n = eTable[i];
78       n.updateFromNodes(r);
79     }
80
81     BiGraph g = global new BiGraph(eTable[0], hTable[0]);
82     return g;
83   }
84
85   /**
86    * Override the toString method to print out the values of the e and h nodes.
87    * @return a string contain the values of the e and h nodes.
88    **/
89   public String toString()
90   {
91       StringBuffer retval = new StringBuffer();
92       Node tmp = eNodes;
93       while(tmp!=null) {
94           Node n = tmp;
95           retval.append("E: " + n + "\n");
96           tmp = tmp.next;
97       }
98       tmp = hNodes;
99       while(tmp!=null) {
100           Node n = tmp;
101           retval.append("H: " + n + "\n");
102           tmp = tmp.next;
103       }
104       return retval.toString();
105   }
106
107 }