00001 package gov.nasa.arc.ase.util.graph; 00002 00003 import java.io.IOException; 00004 00005 public class Label { 00006 public static Graph label(Graph g) { 00007 String type = g.getStringAttribute("type"); 00008 String ac = g.getStringAttribute("ac"); 00009 00010 if(type.equals("gba")) { 00011 if(ac.equals("nodes")) { 00012 final int nsets = g.getIntAttribute("nsets"); 00013 00014 g.forAllNodes(new EmptyVisitor() { 00015 public void visitNode(Node n) { 00016 n.forAllEdges(new EmptyVisitor() { 00017 public void visitEdge(Edge e) { 00018 Node n1 = e.getSource(); 00019 for(int i = 0; i < nsets; i++) 00020 if(n1.getBooleanAttribute("acc"+i)) 00021 e.setBooleanAttribute("acc"+i, true); 00022 } 00023 }); 00024 for(int i = 0; i < nsets; i++) 00025 n.setBooleanAttribute("acc"+i, false); 00026 } 00027 }); 00028 } 00029 g.setStringAttribute("ac", "edges"); 00030 } else { 00031 throw new RuntimeException("invalid graph type: " + type); 00032 } 00033 00034 return g; 00035 } 00036 public static void main(String[] args) { 00037 try { 00038 Graph g = Graph.load(args[0]); 00039 label(g); 00040 g.save(); 00041 } catch(IOException e) { 00042 System.err.println("Can't load file: " + args[0]); 00043 System.exit(1); 00044 } 00045 } 00046 }