01: /*
02: * This file or a portion of this file is licensed under the terms of
03: * the Globus Toolkit Public License, found in file GTPL, or at
04: * http://www.globus.org/toolkit/download/license.html. This notice must
05: * appear in redistributions of this file, with or without modification.
06: *
07: * Redistributions of this Software, with or without modification, must
08: * reproduce the GTPL in: (1) the Software, or (2) the Documentation or
09: * some other similar material which is provided with the Software (if
10: * any).
11: *
12: * Copyright 1999-2004 University of Chicago and The University of
13: * Southern California. All rights reserved.
14: */
15:
16: package org.griphyn.vdl.planner;
17:
18: import java.util.Iterator;
19: import org.griphyn.vdl.dax.*;
20: import org.griphyn.vdl.planner.Graph;
21:
22: /**
23: * This class converts a given DAX into the internal representation of a
24: * graph.
25: *
26: * @author Jens-S. Vöckler
27: * @author Yong Zhao
28: * @version $Revision: 50 $
29: *
30: * @see Graph
31: */
32: public class DAX2Graph {
33: /**
34: * Converts a DAX into the internal representation of a graph.
35: *
36: * @param adag is the parsed DAX's internal representation.
37: * @return our internal representation of a graph that we can sort on.
38: */
39: public static Graph DAG2Graph(ADAG adag) {
40: Graph result = new Graph();
41:
42: // add all nodes
43: for (Iterator i = adag.iterateJob(); i.hasNext();)
44: result.addVertex(((Job) i.next()).getID());
45:
46: // add all edges
47: for (Iterator i = adag.iterateChild(); i.hasNext();) {
48: Child c = (Child) i.next();
49: String child = c.getChild();
50: for (Iterator j = c.iterateParent(); j.hasNext();) {
51: String parent = (String) j.next();
52: result.addArc(parent, child);
53: }
54: }
55:
56: return result;
57: }
58:
59: /**
60: * Simple test program.
61: */
62: public static void main(String[] args) {
63: // construct a fake diamond DAG as DAX w/o any real transformations.
64: ADAG adag = new ADAG();
65: Job A = new Job();
66: Job B = new Job();
67: Job C = new Job();
68: Job D = new Job();
69: A.setID("A");
70: B.setID("B");
71: C.setID("C");
72: D.setID("D");
73: adag.addJob(A);
74: adag.addJob(B);
75: adag.addJob(C);
76: adag.addJob(D);
77: adag.addChild("C", "A");
78: adag.addChild("C", "B");
79: adag.addChild("D", "C");
80:
81: // convert DAX into graph
82: Graph g = DAG2Graph(adag);
83:
84: // show
85: System.out.println(g.toString());
86: }
87: }
|