Source code: org/objectstyle/ashwood/test/TestGenApp.java
1 /* ====================================================================
2 *
3 * Copyright(c) 2003, Andriy Shapochka
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * 1. Redistributions of source code must retain the above
11 * copyright notice, this list of conditions and the following
12 * disclaimer.
13 *
14 * 2. Redistributions in binary form must reproduce the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer in the documentation and/or other materials
17 * provided with the distribution.
18 *
19 * 3. Neither the name of the ASHWOOD nor the
20 * names of its contributors may be used to endorse or
21 * promote products derived from this software without
22 * specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 *
35 * ====================================================================
36 *
37 * This software consists of voluntary contributions made by
38 * individuals on behalf of the ASHWOOD Project and was originally
39 * created by Andriy Shapochka.
40 *
41 */
42
43 package org.objectstyle.ashwood.test;
44
45 import java.util.*;
46 import java.io.*;
47 import org.objectstyle.ashwood.graph.access.*;
48 import org.objectstyle.ashwood.graph.convert.*;
49 import org.objectstyle.ashwood.graph.*;
50
51 public class TestGenApp {
52 public static void main(String[] args) throws Exception {
53 File dir = new File("d:/temp");
54 int graphCount = 100;
55 int order = 15;
56 int size = 45;
57 long seed = 1000;//System.currentTimeMillis();
58 PropertiesConverter converter = new PropertiesConverter();
59 converter.setVertexAccessor(new IntegerAccessor());
60 Digraph digraph;
61 for (int i = 1; i <= graphCount; i++) {
62 digraph = new MapDigraph(MapDigraph.TREEMAP_FACTORY);
63 //GraphUtils.randomize(digraph, order, size, seed++);
64 GraphUtils.randomizeAcyclic(digraph, order, 3, 3, new Random(seed++));
65 boolean acyclic = GraphUtils.isAcyclic(digraph);
66 boolean stronglyConnected = GraphUtils.isStronglyConnected(digraph);
67 StrongConnection contractor = new StrongConnection(digraph, CollectionFactory.TREESET_FACTORY);
68 Digraph contactedDigraph = contractor.contract(new MapDigraph(MapDigraph.HASHMAP_FACTORY));
69 int componentCount = contactedDigraph.order();
70 String graphName = "digraph-" + i;
71 String desc = "seed=" + (seed-1);
72 desc += ", acyclic=" + acyclic;
73 desc += ", strongly_connected=" + stronglyConnected;
74 desc += ", components=" + componentCount;
75 System.out.println(graphName + ": " + desc);
76 converter.convert(digraph);
77 Properties data = converter.getGraphData();
78 converter.reset();
79 File f = new File(dir, graphName + ".txt");
80 FileOutputStream out = new FileOutputStream(f);
81 data.store(out, desc);
82 out.close();
83 }
84 }
85 }