00001 import java.util.*;
00002 import java.io.*;
00003
00004 public class GenerateSyntheticActionData {
00005
00006 protected Random rand;
00007
00008 GenerateSyntheticActionData() {
00009 rand = new Random(375957361);
00010 }
00011
00012
00016 public static void main(String[] args) throws IOException {
00017
00018 GenerateSyntheticActionData dataGen = new GenerateSyntheticActionData();
00019
00020 String dataset = "twoPlans_diffActions_noisy0.1";
00021 new File("data/"+dataset).mkdir();
00022
00023 for(int num : new int[]{5, 10, 15, 20, 25, 30, 35, 40, 45, 50}) {
00024
00025 new File("data/"+dataset+"/train_"+num).mkdir();
00026 new File("data/"+dataset+"/test_"+num).mkdir();
00027
00028 dataGen.writeDataToFile(dataGen.generateExample1Tree(), "data/"+dataset+"/train_"+num+"/synth1_", num, 0, 0.1, 5);
00029 dataGen.writeDataToFile(dataGen.generateExample2Tree(), "data/"+dataset+"/train_"+num+"/synth2_", num, num, 0.1, 5);
00030
00031
00032
00033
00034 }
00035 }
00036
00037
00038 private void writeDataToFile(PartialOrderNode tree, String filename, int numSamples, int startNum, double noiseProb, int numNoiseAct) throws IOException {
00039
00040 for(int i=startNum;i<startNum+numSamples;i++) {
00041
00042 ArrayList<PartialOrderNode> data = this.sampleFromTree(tree, noiseProb, numNoiseAct);
00043 Writer output = new BufferedWriter(new FileWriter(new File(filename+(i-startNum)+".dat")));
00044 try {
00045 for(PartialOrderNode p : data)
00046 output.write( p.toString() + "\n" );
00047 }
00048 finally {
00049 output.close();
00050 }
00051 }
00052 }
00053
00054
00055 ArrayList<PartialOrderNode> sampleFromTree(PartialOrderNode root, double noiseProb, int numNoiseAct) {
00056
00057 ArrayList<PartialOrderNode> res = new ArrayList<PartialOrderNode>();
00058 ArrayList<PartialOrderNode> possibleNextNodes = new ArrayList<PartialOrderNode>();
00059
00060
00061 ArrayList<PartialOrderNode> noiseNodes = new ArrayList<PartialOrderNode>();
00062 for(int i=0;i<numNoiseAct;i++) {
00063 noiseNodes.add(new PartialOrderNode("x"+i));
00064 }
00065
00066
00067 possibleNextNodes.add(root);
00068 while(!possibleNextNodes.isEmpty()) {
00069
00070
00071
00072 if(rand.nextDouble()<noiseProb) {
00073 PartialOrderNode drawn = noiseNodes.get(rand.nextInt(noiseNodes.size()));
00074 res.add(0,drawn);
00075 }
00076
00077
00078 PartialOrderNode drawn = possibleNextNodes.get(rand.nextInt(possibleNextNodes.size()));
00079
00080
00081 res.add(0,drawn);
00082
00083
00084 for(PartialOrderNode c : drawn.getPred()) {
00085 possibleNextNodes.add(c);
00086 }
00087 possibleNextNodes.remove(drawn);
00088 }
00089 return res;
00090 }
00091
00092
00093 PartialOrderNode generateExample1Tree() {
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107 PartialOrderNode n1 = new PartialOrderNode("n1");
00108 PartialOrderNode n2 = new PartialOrderNode("n2");
00109 PartialOrderNode n3 = new PartialOrderNode("n3");
00110 PartialOrderNode n4 = new PartialOrderNode("n4");
00111 PartialOrderNode n5 = new PartialOrderNode("n5");
00112 PartialOrderNode n6 = new PartialOrderNode("n6");
00113 PartialOrderNode n7 = new PartialOrderNode("n7");
00114 PartialOrderNode n8 = new PartialOrderNode("n8");
00115
00116 n2.addPred(n1); n4.addPred(n3);
00117
00118 n5.addPred(n2); n5.addPred(n4);
00119
00120 n7.addPred(n5); n7.addPred(n6);
00121
00122 n8.addPred(n7);
00123 return n8;
00124 }
00125
00126
00127 PartialOrderNode generateExample2Tree() {
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141 PartialOrderNode nA = new PartialOrderNode("nA");
00142 PartialOrderNode nB = new PartialOrderNode("nB");
00143 PartialOrderNode nC = new PartialOrderNode("nC");
00144 PartialOrderNode nD = new PartialOrderNode("nD");
00145 PartialOrderNode nE = new PartialOrderNode("nE");
00146 PartialOrderNode nF = new PartialOrderNode("nF");
00147 PartialOrderNode nG = new PartialOrderNode("nG");
00148 PartialOrderNode nH = new PartialOrderNode("nH");
00149
00150 nB.addPred(nA);nE.addPred(nD);
00151 nC.addPred(nB);nF.addPred(nE);
00152 nG.addPred(nC);nG.addPred(nF);
00153 nH.addPred(nG);
00154
00155 return nH;
00156 }
00157
00158
00159 protected class PartialOrderNode {
00160
00161 protected ArrayList<PartialOrderNode> pred;
00162 protected String name;
00163
00164 PartialOrderNode() {
00165 this("");
00166 }
00167
00168 public String toString() {
00169 return this.name;
00170 }
00171
00172 PartialOrderNode(String _name) {
00173 pred = new ArrayList<PartialOrderNode>();
00174 name=_name;
00175 }
00176
00177 void addPred(PartialOrderNode s) {
00178 this.pred.add(s);
00179 }
00180
00181 void delPred(PartialOrderNode s) {
00182 this.pred.remove(s);
00183 }
00184
00185 ArrayList<PartialOrderNode> getPred() {
00186 return this.pred;
00187 }
00188
00189 boolean isPred(PartialOrderNode s) {
00190 return this.pred.contains(s);
00191 }
00192
00193 }
00194
00195 }