Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions src/main/java/ee/ut/cs/dsg/confcheck/ConformanceChecker.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
package ee.ut.cs.dsg.confcheck;

import ee.ut.cs.dsg.confcheck.alignment.Alignment;
import ee.ut.cs.dsg.confcheck.alignment.Move;
import ee.ut.cs.dsg.confcheck.cost.CostFunction;
import ee.ut.cs.dsg.confcheck.trie.Trie;
import ee.ut.cs.dsg.confcheck.trie.TrieNode;
import ee.ut.cs.dsg.spine.Spine;

import java.util.*;

public abstract class ConformanceChecker {
protected final Trie modelTrie;
protected final int logMoveCost ;
protected final int modelMoveCost ;
protected PriorityQueue<State> nextChecks;
protected Spine<State> nextChecks;

protected int cntr=1;
protected int maxStatesInQueue;
Expand Down Expand Up @@ -56,7 +54,7 @@ public ConformanceChecker(Trie modelTrie, int logCost, int modelCost, int maxSta

states = new ArrayList<>();
this.maxStatesInQueue = maxStatesInQueue;
nextChecks = new PriorityQueue<>(maxStatesInQueue);
nextChecks = new Spine<>(maxStatesInQueue);
// this.seenBefore = new HashSet<>();
}

Expand Down Expand Up @@ -265,7 +263,7 @@ protected void addStateToTheQueue(State state, State candidateState) {
if ((state.getAlignment().getTotalCost() + Math.min(Math.abs(state.getTracePostfix().size() - state.getNode().getMinPathLengthToEnd()),Math.abs(state.getTracePostfix().size() - state.getNode().getMaxPathLengthToEnd())))< candidateState.getAlignment().getTotalCost())// && state.getNode().getLevel() > candidateState.getNode().getLevel())
{

nextChecks.add(state);
nextChecks.push(state);
// states.add(state);
}
else {
Expand All @@ -276,7 +274,7 @@ protected void addStateToTheQueue(State state, State candidateState) {
}
else //if (state.getCostSoFar()< (nextChecks.size() == 0? Integer.MAX_VALUE: nextChecks.peek().getCostSoFar()))
{
nextChecks.add(state);
nextChecks.push(state);
// states.add(state);
}
if (cntr % cleanseFrequency == 0)
Expand All @@ -290,7 +288,7 @@ private void cleanState(State candidateState)
int coundDown=cleanseFrequency;
State current;
while (nextChecks.size() > cleanseFrequency & coundDown > 0) {
current = nextChecks.poll();
current = nextChecks.pollFirst();
if (candidateState != null)
{
if ((current.getAlignment().getTotalCost() + Math.abs(current.getTracePostfix().size() - current.getNode().getMinPathLengthToEnd())) >= candidateState.getAlignment().getTotalCost())// && state.getNode().getLevel() > candidateState.getNode().getLevel())
Expand All @@ -302,7 +300,7 @@ private void cleanState(State candidateState)
}
}
else {
nextChecks.add(new State(current.getAlignment(), current.getTracePostfix(), current.getNode(), (int) (current.getCostSoFar() + (1 + 10))));
nextChecks.push(new State(current.getAlignment(), current.getTracePostfix(), current.getNode(), (int) (current.getCostSoFar() + (1 + 10))));
coundDown--;
}

Expand Down
55 changes: 21 additions & 34 deletions src/main/java/ee/ut/cs/dsg/confcheck/RandomConformanceChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
import java.util.*;

public class RandomConformanceChecker extends ConformanceChecker{



protected int exploitVersusExploreFrequency = 113;
protected int numEpochs;
protected boolean onMatchFollowPrefixOnly = false;
Expand Down Expand Up @@ -55,29 +52,22 @@ protected State pickRandom()
State s;
if (cntr % exploitVersusExploreFrequency== 0) {

// long start = System.currentTimeMillis();
State[] elements = new State[nextChecks.size()];
nextChecks.toArray(elements);





// long start = System.currentTimeMillis()

int upperBound = nextChecks.size();
int lowerBound = Math.max(upperBound- (nextChecks.size()/2)-1,1);
index = rnd.nextInt( lowerBound);

s = elements[(lowerBound*whichDirection)+index >= upperBound? 0:(lowerBound*whichDirection)+index];
s = nextChecks.get((lowerBound*whichDirection)+index >= upperBound? 0:(lowerBound*whichDirection)+index);
// s = states.remove((lowerBound*whichDirection)+index >= upperBound? 0:(lowerBound*whichDirection)+index);
whichDirection = whichDirection == 0 ? 1:0;

nextChecks.remove(s);
nextChecks.delete(s);

cntr = 0;
}
else {
s = nextChecks.poll();
s = nextChecks.pollFirst();
states.remove(s);
}

Expand All @@ -88,17 +78,17 @@ protected void successiveHalving()
{
// if (nextChecks.size() < 100000)
// return ;
List<State> result = new ArrayList<>(nextChecks.size()/2);
State[] elements = new State[nextChecks.size()];
nextChecks.toArray(elements);

Arrays.sort(elements);
int quantile = nextChecks.size()/4;
nextChecks.clear();
for(int i = 0; i < quantile*4; i+=2)
{
nextChecks.add(elements[i]);
}
// List<State> result = new ArrayList<>(nextChecks.size()/2);
// State[] elements = new State[nextChecks.size()];
// nextChecks.toArray(elements);
//
// Arrays.sort(elements);
// int quantile = nextChecks.size()/4;
// nextChecks.clear();
// for(int i = 0; i < quantile*4; i+=2)
// {
// nextChecks.add(elements[i]);
// }
// for (int i = quantile*2; i < quantile*3; i++)
// {
// nextChecks.add(elements[i]);
Expand Down Expand Up @@ -127,7 +117,7 @@ public Alignment check(List<String> trace)

List<String> traceSuffix;
State state = new State(alg,trace, modelTrie.getRoot(),0);
nextChecks.add(state);
nextChecks.push(state);

State candidateState = null;
String event;
Expand Down Expand Up @@ -275,7 +265,6 @@ else if (alg.getTotalCost() < candidateState.getAlignment().getTotalCost())
//
if(!onMatchFollowPrefixOnly)
{

List<String> trSuffix = new LinkedList<>();
trSuffix.addAll(traceSuffix);
State nonSyncState = new State(alg, trSuffix, node.getParent(),0);
Expand Down Expand Up @@ -312,8 +301,6 @@ else if (alg.getTotalCost() < candidateState.getAlignment().getTotalCost())
syncState = new State(alg,traceSuffix,prev,cost);
addStateToTheQueue(syncState, candidateState);



}
// On 27th of May 2021. we need to give the option to a log move as well as a model move
else // there is no match, we have to make the model move and the log move
Expand Down Expand Up @@ -355,13 +342,13 @@ protected void addStateToTheQueue(State state, State candidateState) {
{
// if (verbose)
// System.out.println("Max queue size reached. New state is not added!");
if (state.getCostSoFar() < nextChecks.peek().getCostSoFar())
if (state.getCostSoFar() < nextChecks.peekFirst().getCostSoFar())
// if (state.getAlignment().getTotalCost() < nextChecks.peek().getAlignment().getTotalCost())
{
// System.out.println(String.format("Adding a good candidate whose cost is %d which is less that the least cost so far %d", state.getAlignment().getTotalCost(), nextChecks.peek().getAlignment().getTotalCost()));
// System.out.println(String.format("Replacement state suffix length %d, number of model moves %d", state.getTracePostfix().size(), state.getNode().getLevel()));
nextChecks.poll();
nextChecks.add(state);
nextChecks.pollFirst();
nextChecks.push(state);
// states.add(state);
}
return;
Expand All @@ -370,7 +357,7 @@ protected void addStateToTheQueue(State state, State candidateState) {
if ((state.getAlignment().getTotalCost()+Math.min(Math.abs(state.getTracePostfix().size() - state.getNode().getMinPathLengthToEnd()),Math.abs(state.getTracePostfix().size() - state.getNode().getMaxPathLengthToEnd()))) < candidateState.getAlignment().getTotalCost())// && state.getNode().getLevel() > candidateState.getNode().getLevel())
{

nextChecks.add(state);
nextChecks.push(state);
// states.add(state);
}
else if (verbose) {
Expand All @@ -382,7 +369,7 @@ else if (verbose) {
}
else //if (state.getCostSoFar()< (nextChecks.size() == 0? Integer.MAX_VALUE: nextChecks.peek().getCostSoFar()))
// {
nextChecks.add(state);
nextChecks.push(state);
// states.add(state);
// }

Expand Down
77 changes: 37 additions & 40 deletions src/main/java/ee/ut/cs/dsg/confcheck/Runner.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,52 +62,49 @@ public static void main(String... args)

// testBed3();
// System.exit(0);
String randomProxyLog = "C:\\Work\\DSG\\Data\\Logs\\BPI2015\\randomLog.xml";
String clusteredLog = "C:\\Work\\DSG\\Data\\Logs\\BPI2015\\sampledClusteredLog.xml";
String simulatedLog = "C:\\Work\\DSG\\Data\\Logs\\BPI2015\\simulatedLog.xml";
String reducedActivityLog = "C:\\Work\\DSG\\Data\\Logs\\BPI2015\\reducedLogActivity.xml";
String frequencyActivityLog = "C:\\Work\\DSG\\Data\\Logs\\BPI2015\\frequencyLog.xml";
String sampleLog = "C:\\Work\\DSG\\Data\\Logs\\BPI2015\\sampledLog.xml";
String singular = "C:\\Work\\DSG\\Data\\Logs\\BPI2015\\Singular.xes";

String randomSepsisProxyLog = "C:\\Work\\DSG\\Data\\Logs\\Sepsis\\randomLog.xml";
String clusteredSepsisLog = "C:\\Work\\DSG\\Data\\Logs\\Sepsis\\sampledClusteredLog.xml";
String simulatedSepsisLog = "C:\\Work\\DSG\\Data\\Logs\\Sepsis\\simulatedLog.xml";
String frequencySepsisLog = "C:\\Work\\DSG\\Data\\Logs\\Sepsis\\frequencyLog.xml";
String reducedSepsisActivityLog = "C:\\Work\\DSG\\Data\\Logs\\Sepsis\\reducedLogActivity.xml";
String sampleSepsisLog = "C:\\Work\\DSG\\Data\\Logs\\Sepsis\\sampledLog.xml";
String randomProxyLog = "./BPI2015/randomLog.xml";
String clusteredLog = "./BPI2015/sampledClusteredLog.xml";
String simulatedLog = "./BPI2015/simulatedLog.xml";
String reducedActivityLog = "./BPI2015/reducedLogActivity.xml";
String frequencyActivityLog = "./BPI2015/frequencyLog.xml";
String sampleLog = "./BPI2015/sampledLog.xml";
String singular = "./BPI2015/Singular.xes";

String randomSepsisProxyLog = "./Sepsis/randomLog.xml";
String clusteredSepsisLog = "./Sepsis/sampledClusteredLog.xml";
String simulatedSepsisLog = "./Sepsis/simulatedLog.xml";
String frequencySepsisLog = "./Sepsis/frequencyLog.xml";
String reducedSepsisActivityLog = "./Sepsis/reducedLogActivity.xml";
String sampleSepsisLog = "./Sepsis/sampledLog.xml";

// BPI 2019
String originalLog2019 = "C:\\Work\\DSG\\Data\\Logs\\BPI2019\\BPI_Challenge_2019.xml";
String random2019ProxyLog = "C:\\Work\\DSG\\Data\\Logs\\BPI2019\\randomLog.xml";
String clustered2019Log = "C:\\Work\\DSG\\Data\\Logs\\BPI2019\\sampledClusteredLog.xml";
String simulated2019Log = "C:\\Work\\DSG\\Data\\Logs\\BPI2019\\simulatedLog.xml";
String reduced2019ActivityLog = "C:\\Work\\DSG\\Data\\Logs\\BPI2019\\reducedLogActivity.xml";
String sample2019Log = "C:\\Work\\DSG\\Data\\Logs\\BPI2019\\sampledLog.xml";
String frequency2019Log = "C:\\Work\\DSG\\Data\\Logs\\BPI2019\\frequencyLog.xml";
String originalLog2019 = "./BPI2019/BPI_Challenge_2019.xml";
String random2019ProxyLog = "./BPI2019/randomLog.xml";
String clustered2019Log = "./BPI2019/sampledClusteredLog.xml";
String simulated2019Log = "./BPI2019/simulatedLog.xml";
String reduced2019ActivityLog = "./BPI2019/reducedLogActivity.xml";
String sample2019Log = "./BPI2019/sampledLog.xml";
String frequency2019Log = "./BPI2019/frequencyLog.xml";

// BPI 2012
String originalLog2012 = "C:\\Work\\DSG\\Data\\Logs\\BPI2012\\BPIC2012.xes";
String random2012ProxyLog = "C:\\Work\\DSG\\Data\\Logs\\BPI2012\\randomLog.xml";
String clustered2012Log = "C:\\Work\\DSG\\Data\\Logs\\BPI2012\\sampledClusteredLog.xml";
String simulated2012Log = "C:\\Work\\DSG\\Data\\Logs\\BPI2012\\simulatedLog.xml";
String reduced2012ActivityLog = "C:\\Work\\DSG\\Data\\Logs\\BPI2012\\reducedLogActivity.xml";
String sample2012Log = "C:\\Work\\DSG\\Data\\Logs\\BPI2012\\sampledLog.xml";
String frequency2012Log = "C:\\Work\\DSG\\Data\\Logs\\BPI2012\\frequencyLog.xml";
String originalLog2012 = "./BPI2012/BPIC2012.xes";
String random2012ProxyLog = "./BPI2012/randomLog.xml";
String clustered2012Log = "./BPI2012/sampledClusteredLog.xml";
String simulated2012Log = "./BPI2012/simulatedLog.xml";
String reduced2012ActivityLog = "./BPI2012/reducedLogActivity.xml";
String sample2012Log = "./BPI2012/sampledLog.xml";
String frequency2012Log = "./BPI2012/frequencyLog.xml";

// BPI 2017
String originalLog2017 = "C:\\Work\\DSG\\Data\\Logs\\BPI2017\\BPIC2017.xes.xes";
String random2017ProxyLog = "C:\\Work\\DSG\\Data\\Logs\\BPI2017\\rand_randomLog.xml";
String clustered2017Log = "C:\\Work\\DSG\\Data\\Logs\\BPI2017\\sampledClusteredLog.xml";
String simulated2017Log = "C:\\Work\\DSG\\Data\\Logs\\BPI2017\\simulatedLog.xml";
String reduced2017ActivityLog = "C:\\Work\\DSG\\Data\\Logs\\BPI2017\\reducedLogActivity.xml";
String sample2017Log = "C:\\Work\\DSG\\Data\\Logs\\BPI2017\\sampledLog.xml";
String frequency2017Log = "C:\\Work\\DSG\\Data\\Logs\\BPI2017\\freq_frequencyLog.xml";




testOnConformanceApproximationResults(frequencyActivityLog, sampleLog, ConformanceCheckerType.TRIE_RANDOM_STATEFUL, LogSortType.TRACE_LENGTH_ASC );
String originalLog2017 = "./BPI2017/BPIC2017.xes.xes";
String random2017ProxyLog = "./BPI2017/rand_randomLog.xml";
String clustered2017Log = "./BPI2017/sampledClusteredLog.xml";
String simulated2017Log = "./BPI2017/simulatedLog.xml";
String reduced2017ActivityLog = "./BPI2017/reducedLogActivity.xml";
String sample2017Log = "./BPI2017/sampledLog.xml";
String frequency2017Log = "./BPI2017/freq_frequencyLog.xml";

testOnConformanceApproximationResults(clusteredLog, sampleLog, ConformanceCheckerType.TRIE_RANDOM_STATEFUL, LogSortType.TRACE_LENGTH_ASC );


// // BPI 2015
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import ee.ut.cs.dsg.confcheck.trie.TrieNode;
import ee.ut.cs.dsg.confcheck.util.Configuration;
import ee.ut.cs.dsg.confcheck.util.Utils;
import ee.ut.cs.dsg.spine.Spine;

import java.util.*;

Expand All @@ -25,7 +26,7 @@ public StatefulRandomConformanceChecker(Trie trie, int logCost, int modelCost, i
}

private int trialsPerEvent;
private final Map<State, PriorityQueue<State>> searchSpace;
private final Map<State, Spine<State>> searchSpace;
private final boolean reuseSearchSpace =false;

public void setTrialsPerEvent(int tpe)
Expand All @@ -42,11 +43,14 @@ private State getStateFromTracesTrie(List<String> trace)
List<String> tracePrefix = trace.subList(0,node.getLevel());
// fill the queue based on the state
if (reuseSearchSpace) {
PriorityQueue<State> previousSearchSpace = searchSpace.get(node.getAlignmentState());
Spine<State> previousSearchSpace = searchSpace.get(node.getAlignmentState());
if (previousSearchSpace != null) {
// previousSearchSpace.stream().filter(ps -> isAValidState(ps, trace)).forEach(vs -> nextChecks.add(vs));
previousSearchSpace.stream().filter(ps -> isAValidState(ps, trace)).forEach(vs -> nextChecks.add(
new State(vs.getAlignment(), trace.subList(vs.getNode().getLevel(),trace.size()),vs.getNode(),vs.getCostSoFar())));
for (State state: previousSearchSpace) {
if (isAValidState(state, trace)) {
nextChecks.push(new State(state.getAlignment(), trace.subList(state.getNode().getLevel(),trace.size()),state.getNode(),state.getCostSoFar()));
}
}
if (verbose)
System.out.printf("Loading previous search space to resume from. Kept %d states from original %d states%n", nextChecks.size(), previousSearchSpace.size());
}
Expand Down Expand Up @@ -82,7 +86,7 @@ public Alignment check(List<String> trace)

}

nextChecks.add(state);
nextChecks.push(state);

State candidateState = null;
String event;
Expand Down Expand Up @@ -378,8 +382,6 @@ private void updateTracesTrie(final State candidateState)
{
int stateSize = nextChecks.size();



Stack<State> statesBack = new Stack<State>();
State currentState = candidateState.getParentState();
int alignmentSize = currentState.getAlignment().getMoves().size();
Expand All @@ -388,11 +390,13 @@ private void updateTracesTrie(final State candidateState)
{
if (reuseSearchSpace && stateSize > 0)
{
PriorityQueue<State> currentSearchSpace = new PriorityQueue<>();
currentSearchSpace.addAll(nextChecks);
Spine<State> currentSearchSpace = new Spine<>(1024);
for (State check:nextChecks) {
currentSearchSpace.push(check);
}
// PriorityQueue<State> currentSearchSpace = nextChecks;
// currentSearchSpace.addAll(prevStates);
currentSearchSpace.add(currentState);
currentSearchSpace.push(currentState);
searchSpace.put(currentState,currentSearchSpace);

}
Expand Down
Loading