Main Page   Packages   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

Generate.java

00001 package gov.nasa.arc.ase.util.graph;
00002 
00003 public class Generate {
00004 
00005 /*
00006   public static Graph generate1(int nsets) {
00007     Graph g = new Graph();
00008     int nnodes = 1 << nsets;
00009     Node[] nodes = new Node[nnodes];
00010 
00011     g.setIntAttribute("nsets", nsets);
00012     g.setStringAttribute("type", "ba");
00013     g.setStringAttribute("ac", "nodes");
00014     
00015     for(int i = 0; i < nnodes; i++) {
00016       nodes[i] = new Node(g);
00017       StringBuffer label = new StringBuffer();
00018       for(int k = 0; k < nsets; k++)
00019     if((i & (1 << k)) != 0)
00020       label.append("acc"+k+"+");
00021       nodes[i].setStringAttribute("label", label.toString());
00022     }
00023 
00024     for(int i = 0; i < nnodes; i++)
00025       for(int j = 0; j < nnodes; j++) {
00026     int d = (i == nnodes - 1 ? 0 : i) | j;
00027     Edge e = new Edge(nodes[i], nodes[d], "-", "-", null);
00028     for(int k = 0; k < nsets; k++)
00029       if((j & (1 << k)) != 0)
00030         e.setBooleanAttribute("acc"+k, true);
00031       }
00032 
00033     Node n = nodes[nnodes - 1];
00034     n.setBooleanAttribute("accepting", true);
00035     g.setInit(n);
00036 
00037     return g;
00038   }
00039 */
00040   
00041   public static Graph generate(int nsets) {
00042   
00043     // nsets is number of accepting conditions
00044     // nnodes is number of nodes in automaton generated - numbered from 0
00045     
00046     int nnodes = nsets + 1;
00047 
00048     Node[] nodes = new Node[nnodes];
00049     Graph g = new Graph();
00050 
00051     g.setIntAttribute("nsets", nsets);
00052     g.setStringAttribute("type", "ba");
00053     g.setStringAttribute("ac", "nodes");
00054 
00055     for(int i = 0; i < nnodes; i++) {
00056       nodes[i] = new Node(g);
00057       StringBuffer label = new StringBuffer();
00058 
00059       for(int k = 0; k < i; k++)
00060         label.append("acc"+k+"+");
00061 
00062       nodes[i].setStringAttribute("label", label.toString());
00063     }
00064     
00065     Node n;
00066 
00067     for(int i = 0; i < nsets; i++) {
00068       n = nodes[i];
00069       n.setIntAttribute("lower_bound", i);  
00070       Edge e = new Edge(nodes[i], nodes[i], "-", "-", null);
00071       e.setBooleanAttribute("else", true);
00072 
00073       for(int j = i+1; j < nnodes; j++) {
00074         e = new Edge(nodes[i], nodes[j], "-", "-", null);
00075 
00076         for(int k = i; k < j; k++)
00077             e.setBooleanAttribute("acc"+k, true);
00078       }
00079     }
00080 
00081     n = nodes[nnodes - 1];
00082     n.setIntAttribute("lower_bound", 0);
00083     n.setBooleanAttribute("accepting", true);
00084     Edge e = new Edge(n, n, "-", "-", null);
00085     for(int k = 0; k < nsets; k++)
00086       e.setBooleanAttribute("acc"+k, true);
00087       
00088     for(int i = 0; i < nsets; i++) {
00089       e = new Edge(n, nodes[i], "-", "-", null);
00090       if(i == 0)
00091         e.setBooleanAttribute("else", true);
00092       else
00093         for(int k = 0; k < i; k++)
00094             e.setBooleanAttribute("acc"+k, true);
00095     }
00096 
00097     g.setInit(n);
00098 //  g.setInit(nodes[0]);
00099 
00100     return g;
00101   }  
00102   public static void main(String[] args) {
00103     Graph g = generate(Integer.parseInt(args[0]));
00104     
00105     g.save();
00106   }  
00107 }

Generated at Thu Feb 7 06:45:55 2002 for Bandera by doxygen1.2.10 written by Dimitri van Heesch, © 1997-2001