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: */package org.griphyn.cPlanner.partitioner.graph;
15:
16: import org.griphyn.cPlanner.classes.ADag;
17: import org.griphyn.cPlanner.classes.SubInfo;
18: import org.griphyn.cPlanner.classes.PCRelation;
19: import org.griphyn.cPlanner.classes.PlannerOptions;
20:
21: import org.griphyn.cPlanner.common.PegasusProperties;
22:
23: import java.util.Iterator;
24: import java.util.Map;
25: import java.util.HashMap;
26: import java.util.Vector;
27: import java.util.List;
28:
29: /**
30: * A Adapter class that converts the <code>ADag</code> to <code>Graph</code> and
31: * vice a versa.
32: *
33: *
34: * @author Karan Vahi
35: * @version $Revision: 50 $
36: */
37:
38: public class Adapter {
39:
40: /**
41: * Converts the <code>ADag</code> to <code>Graph</code> instance.
42: *
43: * @param adag the <code>ADag</code> object.
44: *
45: * @return it's representation as a <code>Graph</code> instance.
46: */
47: public static Graph convert(ADag dag) {
48: Graph graph = new MapGraph();
49:
50: //iterate through the list of jobs and populate the nodes in the graph
51: for (Iterator it = dag.vJobSubInfos.iterator(); it.hasNext();) {
52: //pass the jobs to the callback
53: //populate the job as a node in the graph
54: SubInfo job = (SubInfo) it.next();
55: GraphNode node = new GraphNode(job.getID(), job);
56: graph.addNode(node);
57: }
58:
59: //add the edges between the nodes in the graph
60: for (Iterator it = dag.dagInfo.relations.iterator(); it
61: .hasNext();) {
62: PCRelation rel = (PCRelation) it.next();
63: graph.addEdge(rel.getParent(), rel.getChild());
64: }
65:
66: return graph;
67:
68: }
69:
70: }
|