01: //
02: // Copyright (C) 2005 United States Government as represented by the
03: // Administrator of the National Aeronautics and Space Administration
04: // (NASA). All Rights Reserved.
05: //
06: // This software is distributed under the NASA Open Source Agreement
07: // (NOSA), version 1.3. The NOSA has been approved by the Open Source
08: // Initiative. See the file NOSA-1.3-JPF at the top of the distribution
09: // directory tree for the complete NOSA document.
10: //
11: // THE SUBJECT SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY OF ANY
12: // KIND, EITHER EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT
13: // LIMITED TO, ANY WARRANTY THAT THE SUBJECT SOFTWARE WILL CONFORM TO
14: // SPECIFICATIONS, ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR
15: // A PARTICULAR PURPOSE, OR FREEDOM FROM INFRINGEMENT, ANY WARRANTY THAT
16: // THE SUBJECT SOFTWARE WILL BE ERROR FREE, OR ANY WARRANTY THAT
17: // DOCUMENTATION, IF PROVIDED, WILL CONFORM TO THE SUBJECT SOFTWARE.
18: //
19: package gov.nasa.ltl.graph;
20:
21: import java.io.IOException;
22:
23: /**
24: * DOCUMENT ME!
25: */
26: public class Label {
27: public static Graph label(Graph g) {
28: String type = g.getStringAttribute("type");
29: String ac = g.getStringAttribute("ac");
30:
31: if (type.equals("gba")) {
32: if (ac.equals("nodes")) {
33: final int nsets = g.getIntAttribute("nsets");
34:
35: g.forAllNodes(new EmptyVisitor() {
36: public void visitNode(Node n) {
37: n.forAllEdges(new EmptyVisitor() {
38: public void visitEdge(Edge e) {
39: Node n1 = e.getSource();
40:
41: for (int i = 0; i < nsets; i++) {
42: if (n1.getBooleanAttribute("acc"
43: + i)) {
44: e.setBooleanAttribute(
45: "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: }
|