Skip to content

Commit

Permalink
major update and refactoring to processes interface (among others add…
Browse files Browse the repository at this point in the history
…ed abstract loggers and implemented an additional trace generation logger for the exploration process), added support for multi-events in input multi-traces and the printing of multi-traces to htf files etc.
  • Loading branch information
erwanM974 committed Aug 29, 2022
1 parent 211dfb5 commit 22155bf
Show file tree
Hide file tree
Showing 104 changed files with 3,705 additions and 2,894 deletions.
14 changes: 12 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "hibou_label"
version = "0.7.4"
version = "0.7.6"
authors = ["Erwan Mahe"]
edition = "2018"

Expand All @@ -18,4 +18,5 @@ rusttype = "0.9.2" # for fonts and scale for text i
pest = "2.1.3" # for pest parser
pest_derive = "2.1.0" # ...
clap = {version="3.0.6",features=["yaml"]} # for the command line interface
maplit = "1.0.2" # for !hashset macro etc
maplit = "1.0.2" # for !hashset macro etc
itertools = "0.10.2" # for .sorted() etc
45 changes: 43 additions & 2 deletions src/core/general_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ use crate::core::error::HibouCoreError;
pub struct GeneralContext {
lf_names : Vec<String>,
ms_names : Vec<String>,
gt_names : Vec<String>
gt_names : Vec<String>,
pub co_localizations : Vec<HashSet<usize>>
}


Expand All @@ -36,14 +37,54 @@ impl GeneralContext {
return GeneralContext {
lf_names: Vec::new(),
ms_names: Vec::new(),
gt_names: Vec::new()
gt_names: Vec::new(),
co_localizations : Vec::new()
}
}

// ********** ********** ********** ********** ********** ********** **********
// ********** ********** ********** ********** ********** ********** **********
// ********** ********** ********** ********** ********** ********** **********

pub fn get_lf_coloc_id(&self, lf_id : usize) -> Option<usize> {
for (coloc_id,coloc) in self.co_localizations.iter().enumerate() {
if coloc.contains(&lf_id) {
return Some(coloc_id);
}
}
return None;
}

pub fn are_colocalizations_singletons(&self) -> bool {
for coloc in &self.co_localizations {
if coloc.len() > 1 {
return false;
}
}
return true;
}

pub fn set_partition(&mut self, co_localizations : Vec<HashSet<usize>>) {
self.co_localizations = co_localizations;
}

pub fn get_trivial_partition(&self) -> Vec<HashSet<usize>> {
let mut all_lfs : HashSet<usize> = HashSet::from_iter((0..self.get_lf_num()).collect::<Vec<usize>>().iter().cloned());
return vec![all_lfs];
}

pub fn get_discrete_partition(&self) -> Vec<HashSet<usize>> {
let mut colocs = vec![];
for lf_id in 0..self.get_lf_num() {
colocs.push( hashset!{lf_id} )
}
return colocs;
}

// ********** ********** ********** ********** ********** ********** **********
// ********** ********** ********** ********** ********** ********** **********
// ********** ********** ********** ********** ********** ********** **********

pub fn add_lf(&mut self, lf_name : String) -> usize {
match self.get_lf_id(&lf_name) {
None => {
Expand Down
243 changes: 2 additions & 241 deletions src/core/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@ limitations under the License.
use std::collections::{HashMap, HashSet};
use crate::core::syntax::action::*;
use crate::core::syntax::interaction::Interaction;
use crate::process::hibou_process::SimulationStepKind;

#[derive(Clone, PartialEq, Eq, Hash, Debug)]
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
pub enum TraceActionKind {
Reception,
Emission
}

#[derive(Clone, PartialEq, Eq, Hash, Debug)]
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
pub struct TraceAction {
pub lf_id : usize,
pub act_kind : TraceActionKind,
Expand All @@ -41,244 +40,6 @@ impl TraceAction {
return TraceAction{lf_id,act_kind,ms_id};
}

/*pub fn is_match(&self,model_action: &ObservableAction) -> bool {
if model_action.lf_id != self.lf_id {
return false;
}
if model_action.ms_id != self.ms_id {
return false;
}
if self.act_kind != model_action.get_action_kind() {
return false;
}
return true;
}*/
}


#[derive(Clone, PartialEq, Debug)]
pub struct MultiTraceCanal {
pub lifelines : HashSet<usize>,
pub trace : Vec<TraceAction>,
pub flag_hidden : bool,
pub flag_dirty4local : bool,
pub consumed : u32,
pub simulated_before : u32,
pub simulated_after : u32
}

impl MultiTraceCanal {
pub fn new(lifelines : HashSet<usize>,
trace : Vec<TraceAction>,
flag_hidden : bool,
flag_dirty4local : bool,
consumed : u32,
simulated_before : u32,
simulated_after : u32) -> MultiTraceCanal {
return MultiTraceCanal{lifelines,trace,flag_hidden,flag_dirty4local,consumed,simulated_before,simulated_after};
}
}

#[derive(Clone, PartialEq, Debug)]
pub struct AnalysableMultiTrace {
pub canals : Vec<MultiTraceCanal>,
pub remaining_loop_instantiations_in_simulation : u32
}

impl AnalysableMultiTrace {
pub fn new(canals:Vec<MultiTraceCanal>,remaining_loop_instantiations_in_simulation : u32) -> AnalysableMultiTrace {
return AnalysableMultiTrace{canals,remaining_loop_instantiations_in_simulation};
}

pub fn head_actions(&self) -> HashSet<&TraceAction> {
let mut heads : HashSet<&TraceAction> = HashSet::new();
for canal in &self.canals {
if canal.trace.len() > 0 {
heads.insert( canal.trace.get(0).unwrap() );
}
}
return heads;
}

pub fn length(&self) -> usize {
let mut length = 0;
for canal in &self.canals {
length = length + (canal.trace.len());
}
return length;
}

pub fn is_any_component_empty(&self) -> bool {
for canal in &self.canals {
if canal.trace.len() == 0 {
return true;
}
}
return false;
}

pub fn is_any_component_hidden(&self) -> bool {
for canal in &self.canals {
if canal.flag_hidden {
return true;
}
}
return false;
}

pub fn is_simulated(&self) -> WasMultiTraceConsumedWithSimulation {
let mut got_sim_after = false;
for canal in &self.canals {
if canal.simulated_before > 0 {
return WasMultiTraceConsumedWithSimulation::AsSlice;
}
if canal.simulated_after > 0 {
got_sim_after = true;
}
}
if got_sim_after {
return WasMultiTraceConsumedWithSimulation::OnlyAfterEnd;
} else {
return WasMultiTraceConsumedWithSimulation::No;
}
}

pub fn are_colocalizations_singletons(&self) -> bool {
for canal in &self.canals {
if canal.lifelines.len() > 1 {
return false;
}
}
return true;
}

pub fn update_on_execution(&self,
target_lf_ids : &HashSet<usize>,
affected_lfs : &HashSet<usize>,
new_interaction : &Interaction) -> AnalysableMultiTrace {
let remaining_loop_instantiations_in_simulation = new_interaction.max_nested_loop_depth();
let mut new_canals : Vec<MultiTraceCanal> = Vec::new();
for canal in &self.canals {
let canal_lfs = canal.lifelines.clone();
let mut new_trace = canal.trace.clone();
// ***
let new_simu_before = canal.simulated_before;
let new_simu_after = canal.simulated_after;
let new_flag_hidden = canal.flag_hidden;
// ***
let mut new_consumed = canal.consumed;
if !canal_lfs.is_disjoint(&target_lf_ids) {
new_trace.remove(0);
new_consumed = new_consumed + 1;
}
// ***
let new_flag_dirty4local : bool;
if new_trace.len() > 0 {
if canal_lfs.is_disjoint(affected_lfs) {
new_flag_dirty4local = canal.flag_dirty4local;
} else {
new_flag_dirty4local = true;
}
} else {
new_flag_dirty4local = false;
}
// ***
new_canals.push( MultiTraceCanal::new(canal_lfs,
new_trace,
new_flag_hidden,
new_flag_dirty4local,
new_consumed,
new_simu_before,
new_simu_after) );
}
return AnalysableMultiTrace::new(new_canals,remaining_loop_instantiations_in_simulation);
}

pub fn update_on_hide(&self, lfs_to_hide : &HashSet<usize>) -> AnalysableMultiTrace {
let mut new_canals : Vec<MultiTraceCanal> = Vec::new();
for canal in &self.canals {
if canal.lifelines.is_subset( lfs_to_hide ) {
new_canals.push(MultiTraceCanal::new(canal.lifelines.clone(),
canal.trace.clone(),
true,
canal.flag_dirty4local,
canal.consumed,
canal.simulated_before,
canal.simulated_after));
} else {
new_canals.push(MultiTraceCanal::new(canal.lifelines.clone(),
canal.trace.clone(),
canal.flag_hidden,
canal.flag_dirty4local,
canal.consumed,
canal.simulated_before,
canal.simulated_after));
}
}
return AnalysableMultiTrace::new(new_canals,0);
}

pub fn update_on_simulation(&self,
sim_map : &HashMap<usize,SimulationStepKind>,
target_lf_ids : &HashSet<usize>,
affected_lfs : &HashSet<usize>,
rem_sim_depth : u32) -> AnalysableMultiTrace {
let mut new_canals : Vec<MultiTraceCanal> = Vec::new();
let simulated_lfs : HashSet<usize> = sim_map.keys().cloned().collect();
for canal in &self.canals {
let canal_lfs = canal.lifelines.clone();
let mut new_trace = canal.trace.clone();
// ***
let new_flag_dirty4local : bool;
if canal_lfs.is_disjoint(affected_lfs) {
new_flag_dirty4local = canal.flag_dirty4local;
} else {
new_flag_dirty4local = true;
}
// ***
let new_flag_hidden = canal.flag_hidden;
// ***
// ***
let mut new_consumed = canal.consumed;
let mut new_simu_before = canal.simulated_before;
let mut new_simu_after = canal.simulated_after;
if !canal_lfs.is_disjoint(target_lf_ids) {
if canal_lfs.is_disjoint(&simulated_lfs) {
new_trace.remove(0);
new_consumed = new_consumed + 1;
} else {
for lf_id in &canal_lfs {
match sim_map.get(lf_id) {
None => {},
Some( sim_kind ) => {
match sim_kind {
SimulationStepKind::BeforeStart => {
new_simu_before += 1;
},
SimulationStepKind::AfterEnd => {
new_simu_after += 1;
}
}
}
}
}
}
}
// ***
new_canals.push( MultiTraceCanal::new(canal_lfs,
new_trace,
new_flag_hidden,
new_flag_dirty4local,
new_consumed,
new_simu_before,
new_simu_after) );
}
return AnalysableMultiTrace::new(new_canals,rem_sim_depth);
}
}

pub enum WasMultiTraceConsumedWithSimulation {
No,
OnlyAfterEnd,
AsSlice
}
Loading

0 comments on commit 22155bf

Please sign in to comment.