1 2 package gov.nasa.ltl.graph; 21 22 import java.io.IOException ; 23 24 25 28 public class Label { 29 public static Graph label (Graph g) { 30 String type = g.getStringAttribute("type"); 31 String ac = g.getStringAttribute("ac"); 32 33 if (type.equals("gba")) { 34 if (ac.equals("nodes")) { 35 final int nsets = g.getIntAttribute("nsets"); 36 37 g.forAllNodes(new EmptyVisitor() { 38 public void visitNode (Node n) { 39 n.forAllEdges(new EmptyVisitor() { 40 public void visitEdge (Edge e) { 41 Node n1 = e.getSource(); 42 43 for (int i = 0; i < nsets; i++) { 44 if (n1.getBooleanAttribute("acc" + i)) { 45 e.setBooleanAttribute("acc" + i, true); 46 } 47 } 48 } 49 }); 50 51 for (int i = 0; i < nsets; i++) { 52 n.setBooleanAttribute("acc" + i, false); 53 } 54 } 55 }); 56 } 57 58 g.setStringAttribute("ac", "edges"); 59 } else { 60 throw new RuntimeException ("invalid graph type: " + type); 61 } 62 63 return g; 64 } 65 66 public static void main (String [] args) { 67 try { 68 Graph g = Graph.load(args[0]); 69 label(g); 70 g.save(); 71 } catch (IOException e) { 72 System.err.println("Can't load file: " + args[0]); 73 System.exit(1); 74 } 75 } 76 } | Popular Tags |