[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] [taler-schemafuzz] 01/03: working on the weight picking pat
From: |
gnunet |
Subject: |
[GNUnet-SVN] [taler-schemafuzz] 01/03: working on the weight picking patern |
Date: |
Thu, 17 May 2018 12:19:32 +0200 |
This is an automated email from the git hooks/post-receive script.
erwan-ulrich pushed a commit to branch master
in repository schemafuzz.
commit 66a1ea560435a61d74b23272aa9edcbbbf3e3360
Author: Feideus <address@hidden>
AuthorDate: Wed May 16 18:56:56 2018 +0200
working on the weight picking patern
---
src/main/java/org/schemaspy/DBFuzzer.java | 20 +++---
src/main/java/org/schemaspy/model/GenericTree.java | 31 ++-------
.../java/org/schemaspy/model/GenericTreeNode.java | 79 +++++++++++++++++++---
3 files changed, 88 insertions(+), 42 deletions(-)
diff --git a/src/main/java/org/schemaspy/DBFuzzer.java
b/src/main/java/org/schemaspy/DBFuzzer.java
index 33f27f0..3ab194f 100644
--- a/src/main/java/org/schemaspy/DBFuzzer.java
+++ b/src/main/java/org/schemaspy/DBFuzzer.java
@@ -49,7 +49,6 @@ public class DBFuzzer
Row randomRow = pickRandomRow();
GenericTreeNode currentMutation = new
GenericTreeNode(randomRow,nextId());
-
currentMutation.initPotential_changes(currentMutation.discoverMutationPossibilities(analyzer.getDb()));
currentMutation.setChosenChange(currentMutation.getPotential_changes().get(0));
mutationTree.setRoot(currentMutation);
@@ -85,9 +84,10 @@ public class DBFuzzer
Process evaluatorProcess = new ProcessBuilder("/bin/bash",
"./evaluator.sh").start();
mark = Integer.parseInt(getEvaluatorResponse(evaluatorProcess));
currentMutation.setInterest_mark(mark);
- currentMutation.initWeight();
- System.out.println("Weight for currentMut
"+currentMutation.getWeight());
+ currentMutation.setWeight(mark);
System.out.println("marking here : "+mark);
+ System.out.println("Weight for currentMut
"+currentMutation.getWeight());
+ mutationTree.printTree(0);
}
catch(Exception e)
{
@@ -256,7 +256,8 @@ public class DBFuzzer
int markingDiff = previousMutation.getInterest_mark();
Random rand = new Random();
- if(mutationTree.getNumberOfNodes() > 1)
+
+ if(mutationTree.getNumberOfNodes() > 2)
{
markingDiff =
previousMutation.getInterest_mark()-mutationTree.find(mutationTree.getLastId()).getInterest_mark();
}
@@ -265,7 +266,6 @@ public class DBFuzzer
{
if(markingDiff > 0)
{
-
previousMutation.initPotential_changes(previousMutation.discoverMutationPossibilities(analyzer.getDb()));
int randNumber =
rand.nextInt(previousMutation.getPotential_changes().size());
nextMut = new
GenericTreeNode(previousMutation.getPost_change_row(),nextId(),mutationTree.getRoot(),previousMutation);
nextMut.initPotential_changes(nextMut.discoverMutationPossibilities(analyzer.getDb()));
@@ -273,11 +273,11 @@ public class DBFuzzer
}
else if(markingDiff == 0 || markingDiff < 0)
{
- GenericTreeNode randMutation =
mutationTree.pickMutationBasedOnWeight(mutationTree.mutationsBasedOnWeight());
- int randChange =
rand.nextInt(randMutation.getPotential_changes().size());
- nextMut = new
GenericTreeNode(mutationTree.findFirstMutationWithout(mutationTree.getRoot(),randMutation.getChosenChange()).getPost_change_row(),nextId(),mutationTree.getRoot(),mutationTree.findFirstMutationWithout(mutationTree.getRoot(),randMutation.getChosenChange()));
-
nextMut.initPotential_changes(nextMut.discoverMutationPossibilities(analyzer.getDb()));
-
nextMut.setChosenChange(randMutation.getPotential_changes().get(randChange));
+ System.err.println("Hey");
+ SingleChange tmp =
mutationTree.getRoot().singleChangeBasedOnWeight();
+ System.out.println("chosen change = "+tmp);
+ nextMut = new
GenericTreeNode(tmp.getattachedToMutation().getPost_change_row(),nextId(),mutationTree.getRoot(),tmp.getattachedToMutation());
+ nextMut.setChosenChange(tmp);
}
else
{
diff --git a/src/main/java/org/schemaspy/model/GenericTree.java
b/src/main/java/org/schemaspy/model/GenericTree.java
index 63674fc..947c35f 100644
--- a/src/main/java/org/schemaspy/model/GenericTree.java
+++ b/src/main/java/org/schemaspy/model/GenericTree.java
@@ -225,35 +225,18 @@ public class GenericTree {
return res; // should never be null unless the algorithm is not
looking for something precise
}
- public ArrayList<GenericTreeNode> mutationsBasedOnWeight()
+ public void printTree(int tabs)
{
- ArrayList<GenericTreeNode> mutationsBasedOnWeight = new
ArrayList<GenericTreeNode>();
- GenericTreeNode currentMutation;
-
- for(int i = 1; i <= getNumberOfNodes();i++)
+ for(int i = 1; i <= getNumberOfNodes(); i++)
{
- currentMutation = find(i);
- for(int j = 0; j < currentMutation.getWeight();j++)
+ for(int j = 0; j < tabs ; j++)
{
- mutationsBasedOnWeight.add(currentMutation);
+ System.out.println(" ");
}
+ System.out.println(find(i));
+ if(find(i).getChildren().size() != 0)
+ printTree(find(i).getDepth());
}
- return mutationsBasedOnWeight;
- }
-
- public GenericTreeNode
pickMutationBasedOnWeight(ArrayList<GenericTreeNode> mutationsBasedOnWeight)
- {
- int randNumber = 0;
- Random rand = new Random();
- if(mutationsBasedOnWeight.size() > 0)
- {
- System.out.println(" size "+mutationsBasedOnWeight.size());
- randNumber = rand.nextInt(mutationsBasedOnWeight.size());
- System.out.println(" size "+mutationsBasedOnWeight.size());
- }
-
- return mutationsBasedOnWeight.get(randNumber);
}
-
}
diff --git a/src/main/java/org/schemaspy/model/GenericTreeNode.java
b/src/main/java/org/schemaspy/model/GenericTreeNode.java
index 49c30b0..da41697 100644
--- a/src/main/java/org/schemaspy/model/GenericTreeNode.java
+++ b/src/main/java/org/schemaspy/model/GenericTreeNode.java
@@ -24,7 +24,11 @@ public class GenericTreeNode {
private GenericTreeNode rootMutation;
private Integer interest_mark;
private Integer weight;
+<<<<<<< 286021abc272ba0295d224f298bac82861a7c4e0
private Integer subtree_weight;
+=======
+ private Integer subTreeWeight;
+>>>>>>> working on the weight picking patern
private final Row initial_state_row;
private Row post_change_row;
private final ArrayList<SingleChange> potential_changes = new
ArrayList<SingleChange>();
@@ -41,6 +45,9 @@ public class GenericTreeNode {
this.id = id;
this.initial_state_row = initial_state_row;
this.cascadingFK = false;
+ this.potential_changes = discoverMutationPossibilities();
+ this.weight = 1;
+ this.subTreeWeight = this.getPotential_changes().size();
}
public GenericTreeNode(Row initial_state_row,int id, GenericTreeNode
rootMutation, GenericTreeNode parentMutation) {
@@ -48,11 +55,11 @@ public class GenericTreeNode {
this.initial_state_row = initial_state_row;
this.cascadingFK = false;
this.rootMutation = rootMutation;
- this.parent = parentMutation;Error
- if(this.getParent() == null)
- this.depth = 0;
- else
- this.depth = this.getParent().getDepth()+1;
+ this.parent = parentMutation;
+ initDepth();
+ this.potential_changes = discoverMutationPossibilities();
+ this.weight = 1;
+ this.subTreeWeight = this.getPotential_changes().size();
}
public Integer getId() {
@@ -64,10 +71,15 @@ public class GenericTreeNode {
return this.weight;
}
+ public void addToSubTreeWeight(int childWeight)
+ {
+ this.subTreeWeight += childWeight;
+ }
+
public void setWeight(Integer weight)
{
this.weight = weight;
- parent.subtree_weight += weight;
+ propagateWeight();
}
private static final Random r = new Random();
@@ -81,7 +93,7 @@ public class GenericTreeNode {
int rnd = r.nextInt(subtree_weight + potential_changes.size());
assert (rnd >= 0);
if (rnd < potential_changes.size())
- return potential_changes.remove (rnd);
+ return potential_changes.remove (rnd);
rnd -= potential_changes.size();
for (GenericTreeNode n : children)
{
@@ -113,6 +125,11 @@ public class GenericTreeNode {
return chosenChange;
}
+ public int getSubTreeWeight()
+ {
+ return this.subTreeWeight;
+ }
+
public Row getInitial_state_row() {
return initial_state_row;
@@ -178,7 +195,7 @@ public class GenericTreeNode {
return children.get(index);
}
- public ArrayList<SingleChange> discoverMutationPossibilities(Database db)
+ public ArrayList<SingleChange> discoverMutationPossibilities()
{
int i;
@@ -535,4 +552,50 @@ public class GenericTreeNode {
return true;
}
+ public SingleChange singleChangeBasedOnWeight()
+ {
+ Random r = new Random();
+ if (this.potential_changes.isEmpty())
+ throw new Error("This should be impossible to reach");
+
+ System.err.println("subtreeweight = "+subTreeWeight);
+
+ int total = 0;
+ for (GenericTreeNode n : children)
+ {
+ total += n.getSubTreeWeight();
+ }
+ if (total != subTreeWeight)
+ System.out.println("keep your objects consistent in the setter
functions");
+
+ int rnd = r.nextInt(subTreeWeight + potential_changes.size());
+ if (rnd < potential_changes.size())
+ {
+ this.subTreeWeight -= 1;
+ return potential_changes.remove (rnd);
+ }
+ System.out.println("ici");
+ rnd -= potential_changes.size();
+ System.err.println("rnd = "+rnd);
+ for (GenericTreeNode n : children)
+ {
+ int w = n.getSubTreeWeight();
+ System.out.println("w = "+w);
+ if (rnd < w)
+ return n.singleChangeBasedOnWeight();
+ rnd -= w;
+ }
+ System.out.println("ici2");
+ throw new Error("This should be impossible to reach");
+ }
+
+ public void propagateWeight()
+ {
+ if(this.getParent() != null)
+ {
+ this.getParent().addToSubTreeWeight(this.getWeight());
+ this.getParent().propagateWeight();
+ }
+ }
+
}
--
To stop receiving notification emails like this one, please contact
address@hidden