KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gov > nasa > ltl > graph > Degeneralize


1
2 //
3
// Copyright (C) 2005 United States Government as represented by the
4
// Administrator of the National Aeronautics and Space Administration
5
// (NASA). All Rights Reserved.
6
//
7
// This software is distributed under the NASA Open Source Agreement
8
// (NOSA), version 1.3. The NOSA has been approved by the Open Source
9
// Initiative. See the file NOSA-1.3-JPF at the top of the distribution
10
// directory tree for the complete NOSA document.
11
//
12
// THE SUBJECT SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY OF ANY
13
// KIND, EITHER EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT
14
// LIMITED TO, ANY WARRANTY THAT THE SUBJECT SOFTWARE WILL CONFORM TO
15
// SPECIFICATIONS, ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR
16
// A PARTICULAR PURPOSE, OR FREEDOM FROM INFRINGEMENT, ANY WARRANTY THAT
17
// THE SUBJECT SOFTWARE WILL BE ERROR FREE, OR ANY WARRANTY THAT
18
// DOCUMENTATION, IF PROVIDED, WILL CONFORM TO THE SUBJECT SOFTWARE.
19
//
20
package gov.nasa.ltl.graph;
21
22 import java.io.IOException JavaDoc;
23
24
25 /**
26  * DOCUMENT ME!
27  */

28 public class Degeneralize {
29   public static Graph degeneralize (Graph g) {
30     int nsets = g.getIntAttribute("nsets");
31     String JavaDoc type = g.getStringAttribute("type");
32
33     if (type.equals("gba")) {
34       String JavaDoc ac = g.getStringAttribute("ac");
35
36       if (ac.equals("nodes")) {
37         if (nsets == 1) {
38           accept(g);
39         } else {
40           Label.label(g);
41
42           Graph d = Generate.generate(nsets);
43
44
45           // d.save(Graph.FSP_FORMAT);
46
g = SynchronousProduct.product(g, d);
47         }
48       } else if (ac.equals("edges")) {
49         Graph d = Generate.generate(nsets);
50         g = SynchronousProduct.product(g, d);
51       }
52     } else if (!type.equals("ba")) {
53       throw new RuntimeException JavaDoc("invalid graph type: " + type);
54     }
55
56     return g;
57   }
58
59   public static void help () {
60     System.err.println("usage:");
61     System.err.println("\tDegenalize [outfile]");
62     System.exit(1);
63   }
64
65   public static void main (String JavaDoc[] args) {
66     if (args.length > 1) {
67       System.out.println("usage:");
68       System.out.println("\tjava gov.nasa.ltl.graph.Degeneralize [<filename>]");
69
70       return;
71     }
72
73     Graph g = null;
74
75     try {
76       if (args.length == 0) {
77         g = Graph.load();
78       } else {
79         g = Graph.load(args[0]);
80       }
81     } catch (IOException JavaDoc e) {
82       System.out.println("Can't load the graph.");
83
84       return;
85     }
86
87     g = degeneralize(g);
88
89     g.save();
90   }
91
92   private static void accept (Graph g) {
93     g.setBooleanAttribute("nsets", false);
94
95     g.forAllNodes(new EmptyVisitor() {
96       public void visitNode (Node n) {
97         if (n.getBooleanAttribute("acc0")) {
98           n.setBooleanAttribute("accepting", true);
99           n.setBooleanAttribute("acc0", false);
100         }
101       }
102     });
103   }
104 }
Popular Tags