From f4895008771a4bd3a340dea1bbca454a06913cf7 Mon Sep 17 00:00:00 2001
From: ehuang32 <ericchristopherwong@gmail.com>
Date: Fri, 23 Oct 2020 12:45:48 +1100
Subject: [PATCH] MAX_STACK=2 but with added prob for zero and one cases

---
 fuzzer/Fuzzer.java      |  2 +-
 fuzzer/Instruction.java | 20 ++++++++++++++++++--
 2 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/fuzzer/Fuzzer.java b/fuzzer/Fuzzer.java
index a91f0bb..abb7b03 100644
--- a/fuzzer/Fuzzer.java
+++ b/fuzzer/Fuzzer.java
@@ -52,7 +52,7 @@ public class Fuzzer {
     // Current stack of instructions
     private static ArrayList<Instruction> instructionStack = new ArrayList<Instruction>();
     // Max stack of instructions before resetting stack
-    private static final int MAX_STACK = 3;
+    private static final int MAX_STACK = 2;
 
     public static void main(String[] args) throws IOException {
         System.out.println(Instruction.getBNF());
diff --git a/fuzzer/Instruction.java b/fuzzer/Instruction.java
index fffc4f0..b7a7229 100644
--- a/fuzzer/Instruction.java
+++ b/fuzzer/Instruction.java
@@ -142,14 +142,30 @@ public enum Instruction {
 
             cumProb = 0;
             for (Instruction instruction : MAX_ZERO_INSTRUCTIONS) {
-                cumProb += instruction.probability;
+                // Temporary stack where we add this loop's instruction
+                List<Instruction> tempStack = new ArrayList<Instruction>(instructionStack);
+                tempStack.add(instruction);
+                // If the probability has increased, find it and add to base prob, otherwise 0
+                int probToAdd = 0;
+                if (pathwayProb.containsKey(tempStack)) {
+                    probToAdd = pathwayProb.get(tempStack);
+                }
+                cumProb += instruction.probability + probToAdd;
                 ZERO_CUML_PROB.add(cumProb);
             }
             ZERO_MAX_CUML_PROB = cumProb;
 
             cumProb = 0;
             for (Instruction instruction : MAX_ONE_INSTRUCTIONS) {
-                cumProb += instruction.probability;
+                // Temporary stack where we add this loop's instruction
+                List<Instruction> tempStack = new ArrayList<Instruction>(instructionStack);
+                tempStack.add(instruction);
+                // If the probability has increased, find it and add to base prob, otherwise 0
+                int probToAdd = 0;
+                if (pathwayProb.containsKey(tempStack)) {
+                    probToAdd = pathwayProb.get(tempStack);
+                }
+                cumProb += instruction.probability + probToAdd;
                 ONE_CUML_PROB.add(cumProb);
             }
             ONE_MAX_CUML_PROB = cumProb;
-- 
GitLab