Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 package hittingsetalg;
00026
00027 import java.io.*;
00028 import java.util.*;
00029
00030 import theoremprover.*;
00031 import utils.SortedIntList;
00032
00033 public class TestMinHittingSets {
00034
00035
00036 public static void main(String[] args) {
00037
00038 TestMinHittingSets inst = new TestMinHittingSets();
00039 inst.run();
00040 }
00041
00042 void createConflictSets(ArrayList conflictSets, long seed) {
00043 SortedIntList cs = new SortedIntList();
00044 cs.addSorted(1);
00045 cs.addSorted(2);
00046 conflictSets.add(cs);
00047
00048 cs = new SortedIntList();
00049 cs.addSorted(2);
00050 cs.addSorted(3);
00051 conflictSets.add(cs);
00052
00053 cs = new SortedIntList();
00054 cs.addSorted(1);
00055 cs.addSorted(3);
00056 conflictSets.add(cs);
00057
00058 cs = new SortedIntList();
00059 cs.addSorted(2);
00060 cs.addSorted(4);
00061 conflictSets.add(cs);
00062
00063 cs = new SortedIntList();
00064 cs.addSorted(2);
00065 conflictSets.add(cs);
00066 }
00067
00068 void createConflictSets1(ArrayList conflictSets, long seed) {
00069
00070 int numComponents = 20;
00071 int minNumConflictSets = 30;
00072 int maxNumConflictSets = 50;
00073 int minSizeConflictSet = 2;
00074 int maxSizeConflictSet = 6;
00075
00076 Random r = new Random();
00077 if (seed != 0) r.setSeed(seed);
00078
00079 int numCS = r.nextInt(maxNumConflictSets - minNumConflictSets) + minNumConflictSets;
00080 System.out.println("number of CS: " + numCS);
00081 System.out.println();
00082
00083 for (int i = 0; i < numCS; ++i) {
00084 SortedIntList cs = new SortedIntList();
00085 int csSize = r.nextInt(maxSizeConflictSet - minSizeConflictSet) + minSizeConflictSet;
00086
00087 for (int j = 0; j < csSize; ++j) {
00088 int c = r.nextInt(numComponents);
00089 cs.addSorted(c);
00090 }
00091
00092 conflictSets.add(cs);
00093
00094 System.out.println("CS: " + cs);
00095 }
00096
00097
00098 }
00099
00100 void run() {
00101
00102 Random r = new Random();
00103
00104 long seed = 6654432597477221005L;
00105 System.out.println("SEED: " + seed);
00106
00107 try {
00108 ArrayList conflictSets = new ArrayList();
00109 createConflictSets1(conflictSets, seed);
00110
00111 MinHittingSets hittingSets = new MinHittingSets(false, conflictSets);
00112
00113 Date startComputationTime = new Date();
00114
00115 hittingSets.compute(100, 100);
00116
00117 Date endComputationTime = new Date();
00118 long passedTime = endComputationTime.getTime() - startComputationTime.getTime();
00119
00120 Iterator itHS = hittingSets.getMinHSAsIntLists().iterator();
00121 while(itHS.hasNext()) {
00122 System.out.println();
00123
00124 SortedIntList hs = (SortedIntList)itHS.next();
00125
00126 Iterator itInt = hs.iterator();
00127 while(itInt.hasNext()) {
00128 Integer n = (Integer)itInt.next();
00129 System.out.print(n.intValue() + " ");
00130 }
00131 System.out.println();
00132 }
00133
00134 System.out.println();
00135
00136 System.out.println("passed milliseconds: " + passedTime);
00137
00138 boolean minimal = hittingSets.checkMinimalityHS();
00139 if (minimal) System.out.println("MINIMAL!");
00140 else System.out.println("NOT MINIMAL!");
00141
00142 boolean hitsAllCS = hittingSets.hitsAllConflictSets();
00143 if (hitsAllCS) System.out.println("OK, hits all conflict sets");
00144 else System.out.println("ERROR: does not hit all conflict sets!");
00145
00146 } catch (AssertionError e) {
00147 System.out.println("SEED: " + seed);
00148 throw e;
00149 }
00150 }
00151
00152
00153
00154 }