Skip to content

Commit 9b1b011

Browse files
committed
Optimizations
1 parent e6feef3 commit 9b1b011

File tree

6 files changed

+51
-30
lines changed

6 files changed

+51
-30
lines changed

backend/shared/src/binding_box/expand_step.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl BindingBox {
4040
}
4141

4242
pub fn expand(&self, parent_binding: Binding, ocel: &IndexLinkedOCEL) -> (Vec<Binding>, bool) {
43-
let order = BindingStep::get_binding_order(self, Some(&parent_binding), Some(ocel));
43+
let order = BindingStep::get_binding_order(self, Some(&parent_binding), ocel);
4444
self.expand_with_steps(parent_binding, ocel, &order)
4545
}
4646

backend/shared/src/binding_box/step_order.rs

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::collections::{HashMap, HashSet};
33
use itertools::Itertools;
44
use process_mining::ocel::linked_ocel::{IndexLinkedOCEL, LinkedOCELAccess};
55

6-
use crate::discovery::advanced::EventOrObjectType;
6+
use crate::discovery::advanced::EventOrObjectTypeRef;
77

88
use super::{
99
structs::{BindingBox, BindingStep, Filter, Qualifier, Variable},
@@ -14,53 +14,58 @@ pub fn get_expected_relation_count(
1414
bound_by: &Variable,
1515
bbox: &BindingBox,
1616
parent_binding_opt: Option<&Binding>,
17-
ocel: Option<&IndexLinkedOCEL>,
18-
) -> Option<f32> {
19-
if ocel.is_none() {
20-
eprintln!("NO OCEL?! for step order");
21-
return None;
22-
}
17+
ocel: &IndexLinkedOCEL,
18+
) -> Option<usize> {
2319
let mut bound_by_types = Vec::new();
2420
// First check if bound_by is already bound by parent
2521
if let Some(bound_by_index) = parent_binding_opt.and_then(|b| b.get_any_index(bound_by)) {
26-
if let Some(ocel) = ocel {
27-
let bound_by_type = match bound_by_index {
28-
process_mining::ocel::linked_ocel::index_linked_ocel::EventOrObjectIndex::Event(event_index) => EventOrObjectType::Event(ocel.get_ev(&event_index).event_type.clone()),
29-
process_mining::ocel::linked_ocel::index_linked_ocel::EventOrObjectIndex::Object(object_index) => EventOrObjectType::Object(ocel.get_ob(&object_index).object_type.clone()),
30-
};
31-
bound_by_types.push(bound_by_type);
32-
}
22+
let bound_by_type = match bound_by_index {
23+
process_mining::ocel::linked_ocel::index_linked_ocel::EventOrObjectIndex::Event(
24+
event_index,
25+
) => EventOrObjectTypeRef::Event(ocel.get_ev(&event_index).event_type.as_str()),
26+
process_mining::ocel::linked_ocel::index_linked_ocel::EventOrObjectIndex::Object(
27+
object_index,
28+
) => EventOrObjectTypeRef::Object(ocel.get_ob(&object_index).object_type.as_str()),
29+
};
30+
bound_by_types.push(bound_by_type);
3331
} else {
3432
bound_by_types = match bound_by {
3533
Variable::Event(var_ev) => bbox
3634
.new_event_vars
3735
.get(var_ev)
3836
.unwrap()
3937
.iter()
40-
.map(|t| EventOrObjectType::Event(t.clone()))
38+
.map(|t| EventOrObjectTypeRef::Event(t.as_str()))
4139
.collect(),
4240
Variable::Object(var_ob) => bbox
4341
.new_object_vars
4442
.get(var_ob)
4543
.unwrap()
4644
.iter()
47-
.map(|t| EventOrObjectType::Object(t.clone()))
45+
.map(|t| EventOrObjectTypeRef::Object(t.as_str()))
4846
.collect(),
4947
}
5048
}
5149
let res = bound_by_types
5250
.into_iter()
5351
.map(|bound_by_type| {
54-
// TODO
55-
0.0
56-
// ocel.unwrap()
57-
// .avg_rels_of_type_per_type
58-
// .get(&bound_by_type)
59-
// .copied()
60-
// .unwrap_or_default()
52+
// Previously this was based on the average relations of an object/event
53+
// Now it's simply the count (how many exist)
54+
match bound_by_type {
55+
EventOrObjectTypeRef::Event(t) => ocel
56+
.events_per_type
57+
.get(t)
58+
.map(|es| es.len())
59+
.unwrap_or_default(),
60+
EventOrObjectTypeRef::Object(t) => ocel
61+
.objects_per_type
62+
.get(t)
63+
.map(|es| es.len())
64+
.unwrap_or_default(),
65+
}
6166
})
6267
.sum();
63-
// println!("{res} for {var:?} {bound_by:?}");
68+
println!("{res} for {bound_by:?}");
6469
Some(res)
6570
}
6671
impl BindingStep {
@@ -75,7 +80,7 @@ impl BindingStep {
7580
pub fn get_binding_order(
7681
bbox: &BindingBox,
7782
parent_binding_opt: Option<&Binding>,
78-
ocel: Option<&IndexLinkedOCEL>,
83+
ocel: &IndexLinkedOCEL,
7984
) -> Vec<Self> {
8085
let mut ret = Vec::new();
8186

@@ -251,8 +256,7 @@ impl BindingStep {
251256
})
252257
.sorted_by_cached_key(|(bound_by_var, (_v, _q, _filter_index, _reversed))| {
253258
get_expected_relation_count(bound_by_var, bbox, parent_binding_opt, ocel)
254-
.unwrap_or(10.0)
255-
.round() as usize
259+
.unwrap_or(10)
256260
})
257261
.next()
258262
{

backend/shared/src/discovery/advanced/mod.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,3 +285,17 @@ impl EventOrObjectType {
285285
}
286286
}
287287
}
288+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
289+
pub enum EventOrObjectTypeRef<'a> {
290+
Event(&'a str),
291+
Object(&'a str),
292+
}
293+
294+
impl<'a> EventOrObjectTypeRef<'a> {
295+
pub fn inner(&'a self) -> &'a str {
296+
match self {
297+
EventOrObjectTypeRef::Event(et) => et,
298+
EventOrObjectTypeRef::Object(ot) => ot,
299+
}
300+
}
301+
}

backend/web-server/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ pub async fn get_qualifers_for_object_types<'a>(
207207
Json<Option<HashMap<String, HashSet<QualifierAndObjectType>>>>,
208208
) {
209209
let qualifier_and_type =
210-
with_ocel_from_state(&State(state), |ocel| get_object_rels_per_type(ocel));
210+
with_ocel_from_state(&State(state), get_object_rels_per_type);
211211
match qualifier_and_type {
212212
Some(x) => (StatusCode::OK, Json(Some(x))),
213213
None => (StatusCode::BAD_REQUEST, Json(None)),

tauri/src-tauri/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ url = "2.5.2"
2525
tauri-plugin-process = "2"
2626
tauri-plugin-log = "2"
2727
log = "0.4.27"
28-
28+
mimalloc = { version = "0.1.47", default-features = false }
2929

3030
[features]
3131
# this feature is used for production builds or when `devPath` points to the filesystem and the built-in dev server is disabled.

tauri/src-tauri/src/main.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
22
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
33

4+
#[global_allocator]
5+
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
6+
47
use std::{
58
collections::{HashMap, HashSet},
69
fs::File,

0 commit comments

Comments
 (0)