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: /**
022: * DOCUMENT ME!
023: */
024: public class Generate {
025: public static Graph generate(int nsets) {
026: // nsets is number of accepting conditions
027: // nnodes is number of nodes in automaton generated - numbered from 0
028: int nnodes = nsets + 1;
029:
030: Node[] nodes = new Node[nnodes];
031: Graph g = new Graph();
032:
033: g.setIntAttribute("nsets", nsets);
034: g.setStringAttribute("type", "ba");
035: g.setStringAttribute("ac", "nodes");
036:
037: for (int i = 0; i < nnodes; i++) {
038: nodes[i] = new Node(g);
039:
040: StringBuffer label = new StringBuffer();
041:
042: for (int k = 0; k < i; k++) {
043: label.append("acc" + k + "+");
044: }
045:
046: nodes[i].setStringAttribute("label", label.toString());
047: }
048:
049: Node n;
050:
051: // careful- generating edges acc/ding to which is to be explored first
052: // corrected by Dimitra
053: for (int i = 0; i < nsets; i++) {
054: n = nodes[i];
055:
056: for (int j = nsets; j > i; j--) {
057: Edge e = new Edge(nodes[i], nodes[j], "-", "-", null);
058:
059: for (int k = i; k < j; k++) {
060: e.setBooleanAttribute("acc" + k, true);
061: }
062: }
063:
064: Edge e = new Edge(nodes[i], nodes[i], "-", "-", null);
065: e.setBooleanAttribute("else", true);
066: }
067:
068: // now the last node
069: n = nodes[nnodes - 1];
070: n.setBooleanAttribute("accepting", true);
071:
072: Edge e = new Edge(n, n, "-", "-", null);
073:
074: for (int k = 0; k < nsets; k++) {
075: e.setBooleanAttribute("acc" + k, true);
076: }
077:
078: for (int i = nsets - 1; i >= 0; i--) {
079: e = new Edge(n, nodes[i], "-", "-", null);
080:
081: if (i == 0) {
082: e.setBooleanAttribute("else", true);
083: } else {
084: for (int k = 0; k < i; k++) {
085: e.setBooleanAttribute("acc" + k, true);
086: }
087: }
088: }
089:
090: g.setInit(n);
091:
092: // g.setInit(nodes[0]);
093: return g;
094: }
095:
096: public static void main(String[] args) {
097: Graph g = generate(5);
098:
099: g.save(Graph.FSP_FORMAT);
100: }
101:
102: /*
103: public static void main(String[] args) {
104: Graph g = generate(Integer.parseInt(args[0]));
105:
106: g.save();
107: }
108: */
109: }
|