Skip to content

Commit

Permalink
[ALL TESTS PASS] Reduce scanning at the end of the computations if th…
Browse files Browse the repository at this point in the history
…e new heuristic passes.
  • Loading branch information
SamuelAppleby committed Aug 14, 2023
1 parent a76c43a commit ec329a2
Showing 1 changed file with 32 additions and 9 deletions.
41 changes: 32 additions & 9 deletions src/knobab/mining/bolt2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ Bolt2Branching(const KnowledgeBase &kb, bool only_precise_temporal_patterns,
size_t expected_support = only_precise_temporal_patterns ? ntraces :minimum_support_threshold;
size_t alles_not_precedence = 0, alles_not_response = 0, alles_not_succession_ab = TRACE_SET_SIZE(data.r_lb_violations), alles_not_succession_ba = TRACE_SET_SIZE(data.p_lb_violations);
bool alles_response = true, alles_precedence = true, alles_succession_ab = ((kb.nTraces() - alles_not_succession_ab) >= expected_support), alles_succession_ba = ((kb.nTraces() - alles_not_succession_ba) >= expected_support);
u_int32_t count_b_total = 0;

/* Only if the heuristic was activated (for next-based conditions to happen I need to have As and Bs in the same
* number. Otherwise, this is unlikely to happen, and I do not ever start performing the search. */
Expand Down Expand Up @@ -324,6 +325,7 @@ Bolt2Branching(const KnowledgeBase &kb, bool only_precise_temporal_patterns,
/* We have B's on their own */
else if (a_trace_id > b_trace_id) {
SoloBCompute(branch, data, b_trace_id);
count_b_total += (count_table.resolve_length(B, b_trace_id));

/* Moving B until I find something related to A. A is kept fixed and not incremented */
while ((b_beginend.first != b_beginend.second) && (b_beginend.first->entry.id.parts.trace_id < a_trace_id)) {
Expand All @@ -333,8 +335,8 @@ Bolt2Branching(const KnowledgeBase &kb, bool only_precise_temporal_patterns,
not_a_activated_and_not_b_activated += diff;

b_trace_id = b_beginend.first->entry.id.parts.trace_id;

SoloBCompute(branch, data, b_trace_id);
count_b_total += (count_table.resolve_length(B, b_trace_id));
}

b_beginend.first++;
Expand All @@ -352,6 +354,7 @@ Bolt2Branching(const KnowledgeBase &kb, bool only_precise_temporal_patterns,
/* Problem 2). If B happens before the event A, this cannot be referred to the precedence, and therefore this
* should be decreased. Still, this consideration should be performed only up until the first event is visited */
a_activation_count++;
count_b_total += (count_table.resolve_length(B, a_trace_id));

if (branch == branch_type::LEFT) {
TRACE_SET_ADD(data.r_activation_traces.first, a_trace_id);
Expand Down Expand Up @@ -436,15 +439,35 @@ Bolt2Branching(const KnowledgeBase &kb, bool only_precise_temporal_patterns,
if ((a_beginend.first == a_beginend.second) && (b_beginend.first != b_beginend.second)) {
b_trace_id = b_beginend.first->entry.id.parts.trace_id;
SoloBCompute(branch, data, b_trace_id);

for (uint32_t current = (b_trace_id + 1); current++ < ntraces; current++) {
if (count_table.resolve_length(B, b_trace_id) == 0) {
not_b_activated++;
not_a_activated_and_not_b_activated++;
}
else {
count_b_total += (count_table.resolve_length(B, b_trace_id));

/* Optimization: We would prefer to scan the remaining Bs if it is likely there are fewer remaining than the
* number of remaining traces, otherwise perform a log scan */
if (((double)count_b_total / (b_trace_id + 1)) < 1.0) {
fast_forward_equals(b_trace_id, b_beginend.first, b_beginend.second);
while (b_beginend.first != b_beginend.second) {
const uint32_t diff = (b_beginend.first->entry.id.parts.trace_id - b_trace_id - 1);
not_b_activated += diff;
not_a_activated_and_not_b_activated += diff;

b_trace_id = b_beginend.first->entry.id.parts.trace_id;
SoloBCompute(branch, data, b_trace_id);
b_trace_id = current;
fast_forward_equals(b_trace_id, b_beginend.first, b_beginend.second);
}

not_b_activated += (ntraces - b_trace_id - 1);
not_a_activated_and_not_b_activated += (ntraces - b_trace_id - 1);
}
else {
for (uint32_t current = (b_trace_id + 1); current++ < ntraces; current++) {
if (count_table.resolve_length(B, current) == 0) {
not_b_activated++;
not_a_activated_and_not_b_activated++;
}
else {
b_trace_id = current;
SoloBCompute(branch, data, b_trace_id);
}
}
}
}
Expand Down

0 comments on commit ec329a2

Please sign in to comment.