001: //
002: // Copyright (C) 2005 United States Government as represented by the
003: // Administrator of the National Aeronautics and Space Administration
004: // (NASA). All Rights Reserved.
005: //
006: // This software is distributed under the NASA Open Source Agreement
007: // (NOSA), version 1.3. The NOSA has been approved by the Open Source
008: // Initiative. See the file NOSA-1.3-JPF at the top of the distribution
009: // directory tree for the complete NOSA document.
010: //
011: // THE SUBJECT SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY OF ANY
012: // KIND, EITHER EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT
013: // LIMITED TO, ANY WARRANTY THAT THE SUBJECT SOFTWARE WILL CONFORM TO
014: // SPECIFICATIONS, ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR
015: // A PARTICULAR PURPOSE, OR FREEDOM FROM INFRINGEMENT, ANY WARRANTY THAT
016: // THE SUBJECT SOFTWARE WILL BE ERROR FREE, OR ANY WARRANTY THAT
017: // DOCUMENTATION, IF PROVIDED, WILL CONFORM TO THE SUBJECT SOFTWARE.
018: //
019: package gov.nasa.ltl.graph;
020:
021: import java.io.IOException;
022:
023: /**
024: * DOCUMENT ME!
025: */
026: public class Degeneralize {
027: public static Graph degeneralize(Graph g) {
028: int nsets = g.getIntAttribute("nsets");
029: String type = g.getStringAttribute("type");
030:
031: if (type.equals("gba")) {
032: String ac = g.getStringAttribute("ac");
033:
034: if (ac.equals("nodes")) {
035: if (nsets == 1) {
036: accept(g);
037: } else {
038: Label.label(g);
039:
040: Graph d = Generate.generate(nsets);
041:
042: // d.save(Graph.FSP_FORMAT);
043: g = SynchronousProduct.product(g, d);
044: }
045: } else if (ac.equals("edges")) {
046: Graph d = Generate.generate(nsets);
047: g = SynchronousProduct.product(g, d);
048: }
049: } else if (!type.equals("ba")) {
050: throw new RuntimeException("invalid graph type: " + type);
051: }
052:
053: return g;
054: }
055:
056: public static void help() {
057: System.err.println("usage:");
058: System.err.println("\tDegenalize [outfile]");
059: System.exit(1);
060: }
061:
062: public static void main(String[] args) {
063: if (args.length > 1) {
064: System.out.println("usage:");
065: System.out
066: .println("\tjava gov.nasa.ltl.graph.Degeneralize [<filename>]");
067:
068: return;
069: }
070:
071: Graph g = null;
072:
073: try {
074: if (args.length == 0) {
075: g = Graph.load();
076: } else {
077: g = Graph.load(args[0]);
078: }
079: } catch (IOException e) {
080: System.out.println("Can't load the graph.");
081:
082: return;
083: }
084:
085: g = degeneralize(g);
086:
087: g.save();
088: }
089:
090: private static void accept(Graph g) {
091: g.setBooleanAttribute("nsets", false);
092:
093: g.forAllNodes(new EmptyVisitor() {
094: public void visitNode(Node n) {
095: if (n.getBooleanAttribute("acc0")) {
096: n.setBooleanAttribute("accepting", true);
097: n.setBooleanAttribute("acc0", false);
098: }
099: }
100: });
101: }
102: }
|