pub fn discover_behavior_constraints(
locel: &SlimLinkedOCEL,
options: OCDeclareDiscoveryOptions,
) -> Vec<OCDeclareArc>Expand description
Discover behavioral OC-DECLARE constraints from the given OCEL
Examples found in repository?
examples/oc_declare.rs (lines 16-21)
11pub fn main() {
12 let path_opt = args().nth(1);
13 if let Some(path) = path_opt.map(PathBuf::from) {
14 let ocel = OCEL::import_from_path(&path).expect("Failed to import OCEL.");
15 let locel = SlimLinkedOCEL::from_ocel(ocel);
16 let discovered_constraints = discover_behavior_constraints(
17 &locel,
18 OCDeclareDiscoveryOptions {
19 ..Default::default()
20 },
21 );
22 println!(
23 "Discovered {} OC-DECLARE constraints",
24 discovered_constraints.len()
25 );
26 }
27}More examples
examples/oc_declare_evaluation.rs (line 89)
19fn main() {
20 let base_path: Option<String> = env::args().nth(1);
21 match base_path {
22 None => panic!("Please provide a base path for the OCEL 2.0 files as the first argument!"),
23 Some(base_path) => {
24 let path: PathBuf = PathBuf::from(base_path);
25 println!("Using base path {:?}", path);
26 let num_runs = 1;
27 let noise_thresh = 0.2;
28 let event_logs = vec![
29 ("Logistics", path.join("ContainerLogistics.json")),
30 ("P2P", path.join("ocel2-p2p.json")),
31 ("O2C", path.join("order-management.json")),
32 (
33 "BPIC2017",
34 path.join("bpic2017-o2o-workflow-qualifier-index-no-ev-attrs.json"),
35 ),
36 ("BPIC2014", path.join("BPIC14.jsonocel-OCEL2.xml")),
37 ("BPIC2019", path.join("BPIC19.jsonocel-OCEL2.xml")),
38 ];
39 for (name, path) in event_logs {
40 println!("Evaluating on {name}.");
41 let ocel = OCEL::import_from_path(path).expect("Failed to import OCEL.");
42 let num_evs = ocel.events.len();
43 let num_obs = ocel.objects.len();
44 let num_et = ocel.event_types.len();
45 let num_ot = ocel.object_types.len();
46
47 let locel = SlimLinkedOCEL::from_ocel(ocel);
48 for o2o_mode in [O2OMode::None] {
49 //, O2OMode::Direct] {
50 println!("{:?}", o2o_mode);
51 for (max_gen_count, max_filter_count) in [
52 ((Some(1), None), (Some(1), None)),
53 ((Some(1), None), (Some(1), Some(20))),
54 ((Some(1), Some(20)), (Some(1), Some(20))),
55 ] {
56 println!(
57 "Gen max: {:?} Filter max: {:?}",
58 max_gen_count.1, max_filter_count.1
59 );
60 let mut eval_res = EvaluationResult {
61 num_events: num_evs,
62 num_objects: num_obs,
63 num_event_types: num_et,
64 num_object_types: num_ot,
65 ..Default::default()
66 };
67 let mut res = Vec::new();
68 let mut reduced = Vec::new();
69 let mut refined = Vec::new();
70 for i in 0..num_runs {
71 let options = OCDeclareDiscoveryOptions {
72 noise_threshold: noise_thresh,
73 o2o_mode,
74 reduction: OCDeclareReductionMode::None,
75 counts_for_generation: max_gen_count,
76 counts_for_filter: max_filter_count,
77 refinement: false,
78 considered_arrow_types: vec![
79 OCDeclareArcType::AS,
80 OCDeclareArcType::EF,
81 OCDeclareArcType::EP,
82 ]
83 .into_iter()
84 .collect(),
85 ..Default::default()
86 };
87 let total_start = Instant::now();
88 let now = Instant::now();
89 res = black_box(discover_behavior_constraints(&locel, options.clone()));
90 let discovery_duration = now.elapsed();
91 eval_res
92 .discovery_durations_seconds
93 .push(discovery_duration.as_secs_f64());
94 if i == 0 {
95 eval_res.number_of_discovered_results = res.len();
96 } else {
97 assert_eq!(eval_res.number_of_discovered_results, res.len());
98 }
99 let now = Instant::now();
100 reduced = black_box(reduce_oc_arcs(res.clone(), true));
101 let duration = now.elapsed();
102 eval_res.number_of_results_after_reduction = reduced.len();
103 eval_res
104 .reduction_duration_seconds
105 .push(duration.as_secs_f64());
106 if i == 0 {
107 eval_res.number_of_results_after_reduction = reduced.len();
108 } else {
109 assert_eq!(
110 eval_res.number_of_results_after_reduction,
111 reduced.len()
112 );
113 }
114 // Refinement
115 let act_ob_inv: HashMap<
116 String,
117 HashMap<String, ObjectInvolvementCounts>,
118 > = get_activity_object_involvements(&locel);
119 let ob_ob_inv: HashMap<
120 String,
121 HashMap<String, ObjectInvolvementCounts>,
122 > = get_object_to_object_involvements(&locel);
123
124 let ob_ob_rev_inv = get_rev_object_to_object_involvements(&locel);
125 let now = Instant::now();
126 refined = black_box(refine_oc_arcs(
127 &reduced,
128 &act_ob_inv,
129 &ob_ob_inv,
130 &ob_ob_rev_inv,
131 &options,
132 &locel,
133 ));
134 let duration = now.elapsed();
135 eval_res.number_of_results_after_refinement = refined.len();
136 eval_res
137 .refinement_duration_seconds
138 .push(duration.as_secs_f64());
139 if i == 0 {
140 eval_res.number_of_results_after_refinement = refined.len();
141 } else {
142 assert_eq!(
143 eval_res.number_of_results_after_refinement,
144 refined.len()
145 );
146 }
147 println!(
148 "Got {} (reduced to {}, refined to {}) results in {:?} / total {:?}",
149 res.len(),
150 reduced.len(),
151 refined.len(),
152 discovery_duration,
153 total_start.elapsed()
154 );
155 }
156 eval_res.mean_discovery_duration =
157 eval_res.discovery_durations_seconds.iter().sum::<f64>()
158 / eval_res.discovery_durations_seconds.len() as f64;
159
160 eval_res.mean_reduction_duration =
161 eval_res.reduction_duration_seconds.iter().sum::<f64>()
162 / eval_res.reduction_duration_seconds.len() as f64;
163
164 eval_res.mean_refinement_duration =
165 eval_res.refinement_duration_seconds.iter().sum::<f64>()
166 / eval_res.refinement_duration_seconds.len() as f64;
167
168 eval_res.mean_lossy_reduction_duration = eval_res
169 .lossy_reduction_duration_seconds
170 .iter()
171 .sum::<f64>()
172 / eval_res.lossy_reduction_duration_seconds.len() as f64;
173
174 let summary_file = File::create(format!(
175 "{}-{:?}-GEN{:?}-FILTER{:?}-summary.json",
176 name, o2o_mode, max_gen_count.1, max_filter_count.1
177 ))
178 .unwrap();
179 serde_json::to_writer_pretty(summary_file, &eval_res).unwrap();
180
181 let results_file = File::create(format!(
182 "{}-{:?}-GEN{:?}-FILTER{:?}-discovered.json",
183 name, o2o_mode, max_gen_count.1, max_filter_count.1
184 ))
185 .unwrap();
186 serde_json::to_writer_pretty(results_file, &res).unwrap();
187 let reduced_file = File::create(format!(
188 "{}-{:?}-GEN{:?}-FILTER{:?}-reduced-lossless.json",
189 name, o2o_mode, max_gen_count.1, max_filter_count.1
190 ))
191 .unwrap();
192 serde_json::to_writer_pretty(reduced_file, &reduced).unwrap();
193 let refined_file = File::create(format!(
194 "{}-{:?}-GEN{:?}-FILTER{:?}-refined.json",
195 name, o2o_mode, max_gen_count.1, max_filter_count.1
196 ))
197 .unwrap();
198 serde_json::to_writer_pretty(refined_file, &refined).unwrap();
199 }
200 }
201 }
202 }
203 }
204}