Skip to content

Commit

Permalink
Merge pull request #11 from DLR-FT/line-ending
Browse files Browse the repository at this point in the history
added rebuttal feedback
  • Loading branch information
sebastianHi authored Mar 13, 2024
2 parents 43ee5be + 024f82b commit 2cbae37
Show file tree
Hide file tree
Showing 7 changed files with 202 additions and 114 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ Requires Rust to compile source code and Python for visualization.

For instance:

``cargo run --release -- -s -f .\res\logs_wind_front_Lateral\`` runs segmentation using subsampling on a provided logfile.
``cargo run --release -- -s -f ./res/logs_wind_front_Lateral/`` runs segmentation using subsampling on a provided logfile.
For this example, ``get_trace`` and ``get_tree`` is already provided.

Using the [visualization script](scripts/visualize_ship_landing.py), we can easily plot a segmentation by, e.g., ``python visualize_ship_landing.py plot -b Lateral -s 5000 10000 20000 -e 0 -l ../res/logs_wind_front_Lateral/`` where ``5000, 10000, 20000`` represent beginning of segments (omitting 0), ``-b`` states the expected behavior and is used to plot the dotted lines, and ``-e`` represents the number of skipped entries due to subsampling.
Using the [visualization script](scripts/visualize_ship_landing.py), we can easily plot a segmentation by, e.g., ``python visualize_ship_landing.py plot -b Lateral -s 5000 10000 20000 -e 0 -l ../res/logs_wind_front_Lateral/`` where ``5000, 10000, 20000`` represent beginning of segments (omitting 0), ``-b`` states the expected behavior and is used to plot the dotted lines, and ``-e`` represents the number of skipped entries due to subsampling. There is also the option to save a plot to inspect it in a docker environment using ``-p``.
We can also replay the flight by, e.g., ``python visualize_ship_landing.py live -l ../res/logs_wind_front_Lateral/ -b Lateral -f 0.005 0.1 2.0``.

For more information call ``python visualize_ship_landing.py --help``.
Expand Down Expand Up @@ -132,13 +132,15 @@ For more details, we refer to the paper. TODO: add paper link here
- The script calls the tool as defined [here](#getting-started) for each logfolder that exists in [res](res).
- The results for each run are stored in the respective logfolder.
- Check results of each logfiles that are located in the following subfolder: ``cd ./res/``
- The files in the folders [res/<folder\>](res) are called ``subsampling_result.txt`` and ``subsamplingAndLazy_result.txt``.
- The files in the folders [res/<folder>](res) are called ``subsampling_result.txt`` and ``subsamplingAndLazy_result.txt``.
- Besides the result-files, for each segmentation, the script produces a `.png`-plot. Every `.png`-plot that has a name that ends with `aX`, where `X` is a number, represents an alternative segmentations where the number corresponds to the alternative in the result-file. For instance, Figure 9 of the HSCC paper can then be found [here](res/logs_wind_front_Oblique/subsampling_result_a3.png).
- (Optional) To display plots copy them from the docker container to your host machine; dont use the docker bash.
- ``docker cp <container_id>:<location_png/results> <location_to_be_stored>`` (copy whole folder or individual files), e.g., ``docker cp e7ba94d69e94:/app/res ./docker``
- to get container_id call ``docker ps``

> The Dockerfile uses multiple stages. The first stage builds the executable using rust/cargo and the second stage uses a debian environment to execute it. Therefore, there are no cargo-commands available in the container while running.
> Also, there is a line ending issue, when building the docker image in a Windows environment. We recommend building the image on a Linux machine to avoid this issue (WSL is an option for Windows systems).
## How to Interpret the Output Format
Running e.g. `cargo run --release -- -l -c -s -f /<your-foulder>/TBT-Segmentation/res/logs_wind_front_Lateral/` produces an output that contains the following lines:
Expand Down
149 changes: 96 additions & 53 deletions src/behaviortree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::{collections::HashMap, time::SystemTime};
type SubtreeIdx = usize;
pub type Segmentation<'a> = Vec<(&'a TbtNode, usize, usize, f32)>;
static mut NODECOUNT: SubtreeIdx = 0;
// get formula count
/// Gets formula count
fn gnc() -> SubtreeIdx {
unsafe {
NODECOUNT += 1;
Expand All @@ -23,9 +23,12 @@ pub fn tbt_node_reset_count() {

#[derive(Clone)]
#[allow(dead_code)]
/// # Arguments
/// * `next_nodes` - Maps current nodes to its successor nodes
/// * `tree` - The main tbt tree
pub struct Tbt {
pub next_nodes: HashMap<usize, Vec<usize>>, // Maps current nodes to its successor nodes
pub tree: TbtNode, // The main tbt tree
pub next_nodes: HashMap<usize, Vec<usize>>,
pub tree: TbtNode,
}

#[allow(dead_code)]
Expand All @@ -34,11 +37,10 @@ impl Tbt {
let mut next_nodes = HashMap::new();
let mut stack = Vec::new();
Tbt::init_next_nodes_map(&tree, &mut stack, &mut next_nodes);
// println!("Next nodes map:\n {:?}", next_nodes);
Tbt { next_nodes, tree }
}

// Creates the initial mapping for the TBT.next_nodes ie for each node its successor node
/// Creates the initial mapping for the TBT.next_nodes ie for each node its successor node
fn init_next_nodes_map<'a>(
tbt_node: &'a TbtNode,
stack_sequence: &mut Vec<(&'a TbtNode, usize)>,
Expand Down Expand Up @@ -80,7 +82,7 @@ impl Tbt {
}
}

// Returns the first leafe given a TBT, I.e given Fallback(Sequence(A,B),B,C)) it returns [A, B, C]
/// Returns the first leafe given a TBT, I.e given Fallback(Sequence(A,B),B,C)) it returns [A, B, C]
fn get_first_leaf(tbt_node: &TbtNode) -> Vec<usize> {
match tbt_node {
TbtNode::Leaf(index, _, _) => vec![*index],
Expand Down Expand Up @@ -117,7 +119,7 @@ pub enum TbtNode {

#[allow(dead_code)]
impl TbtNode {
// Returns the index of a TBT node
/// Returns the index of a TBT node
fn get_index(&self) -> SubtreeIdx {
match self {
TbtNode::Leaf(index, _, _)
Expand All @@ -129,7 +131,7 @@ impl TbtNode {
}
}

// Recursive call until first leaf node it found
/// Recursive call until first leaf node it found
fn get_leaf(&self, leaf_index: usize) -> Option<&TbtNode> {
match self {
TbtNode::Leaf(index, _, _) => {
Expand Down Expand Up @@ -224,7 +226,7 @@ impl TbtNode {
/******************
* Helper functions
******************/
// Retursn a string representation given an TBT. If with_children is false, then only leaves are printed. Line_shift is used to format the output.
/// Returns a string representation given an TBT. If with_children is false, then only leaves are printed. Line_shift is used to format the output.
pub fn pretty_print(&self, with_children: bool, line_shift: usize) -> String {
let indent_num = line_shift + 2;
let indent = " ".repeat(line_shift);
Expand Down Expand Up @@ -293,7 +295,7 @@ impl TbtNode {
}
}

// Returns the first STL formula in the TBT tree
/// Returns the first STL formula in the TBT tree
pub fn get_leaf_formula(&self, look_for_index: usize) -> Option<&Stl> {
match self {
TbtNode::Leaf(index, formula, _) => {
Expand Down Expand Up @@ -326,7 +328,7 @@ impl TbtNode {
}
}

// Returns all the STL formulas in a TBT
/// Returns all the STL formulas in a TBT
pub fn get_atomics(&self) -> Vec<&Stl> {
match self {
TbtNode::Leaf(_, formula, _) => formula.get_atomics(),
Expand All @@ -349,19 +351,29 @@ impl TbtNode {
/***********************
* Standard Evaluation
***********************/
// Evaluates a provided trace given TBT semantics
/// Evaluates a provided trace given TBT semantics
/// # Arguments
/// * `depth_manager_tree` - Used for lazy evaluation to return where stopped early
/// * `tree_table` - TBT data structure for dynamic programming
/// * `formula_table` - STL data structure for dynamic programming
/// * `trace` - Provided Trace that is analyzed
/// * `lower` - Segment start
/// * `upper` - Segment end
/// * `system_time` - Used for profiling
/// * `debug` - Enables debugging messages
/// * `lazy_eval` - Enables / disables lazy evaluation
#[allow(clippy::too_many_arguments)]
pub fn evaluate(
&self,
depth_manager_tree: &mut HashMap<usize, (usize, usize, f32)>, // used for lazy evaluation to return where stopped early
tree_table: &mut Table, // TBT data structure for dynamic programming
formula_table: &mut Table, // STL data structure for dynamic programming
trace: &Trace, // Provided Trace that is analyzed
lower: usize, // Segment start
upper: usize, // Segment end
system_time: &SystemTime, // Used for profiling
debug: bool, // Enables debugging messages
lazy_eval: bool, // Enables / disables lazy evaluation
depth_manager_tree: &mut HashMap<usize, (usize, usize, f32)>,
tree_table: &mut Table,
formula_table: &mut Table,
trace: &Trace,
lower: usize,
upper: usize,
system_time: &SystemTime,
debug: bool,
lazy_eval: bool,
) -> f32 {
// Display progress
if debug {
Expand Down Expand Up @@ -565,15 +577,22 @@ impl TbtNode {
/*******************
* Segmentation
*******************/
// Returns a segmentation by reading off the dynamic programming entries
/// Returns a segmentation by reading off the dynamic programming entries
/// # Arguments
/// * `tree_table` - TBT data structure for dynamic programming
/// * `formula_table` - STL data structure for dynamic programming
/// * `trace` - Provided Trace that is analyzed
/// * `lower` - Segment start
/// * `upper` - Segment end
/// * `is_lazy` - Enables / disables lazy evaluation
pub fn get_segmentation(
&self,
tree_table: &mut Table, // TBT data structure for dynamic programming
formula_table: &mut Table, // STL data structure for dynamic programming
trace: &Trace, // Provided Trace that is analyzed
lower: usize, // Segment start
upper: usize, // Segment end
is_lazy: bool, // Enables / disables lazy evaluation
tree_table: &mut Table,
formula_table: &mut Table,
trace: &Trace,
lower: usize,
upper: usize,
is_lazy: bool,
) -> Segmentation {
match self {
TbtNode::Leaf(index, formula, _) => {
Expand Down Expand Up @@ -818,12 +837,16 @@ impl TbtNode {
}
}

// Computes tau difference that is used to filter out alternative segmentations
/// Computes tau difference that is used to filter out alternative segmentations
/// # Arguments
/// * `lower` - Segment start
/// * `upper` - Segment end
/// * `segmentations` - Previously computed segmentations
fn get_tau_dif(
&self,
lower: usize, // Segment start
upper: usize, // Segment end
segmentations: &Vec<Segmentation>, // Previously computed segmentations
lower: usize,
upper: usize,
segmentations: &Vec<Segmentation>,
) -> Option<usize> {
let mut found = None;
for segmentation in segmentations {
Expand Down Expand Up @@ -863,16 +886,25 @@ impl TbtNode {
}

#[allow(clippy::too_many_arguments)]
// Is used to filter alternative segmentations
/// Is used to filter alternative segmentations
/// # Arguments
/// * `tree_table` - TBT data structure for dynamic programming
/// * `formula_table` - STL data structure for dynamic programming
/// * `trace` - Provided Trace that is analyzed
/// * `lower` - Segment start
/// * `upper` - Segment end
/// * `tau_dif` - Used to filter out alternatives based on where segments start and end
/// * `rho_dif` - Used to filter out alternatives based on their difference in robustness
/// * `segmentations` - Previously identified alternative segmentations
fn get_segmentation_under_restriction(
&self,
tree_table: &mut Table, // TBT data structure for dynamic programming
formula_table: &mut Table, // STL data structure for dynamic programming
trace: &Trace, // Provided Trace that is analyzed
lower: usize, // Segment start
upper: usize, // Segment end
tau_dif: usize, // Used to filter out alternatives based on where segments start and end
rho_dif: f32, // Used to filter out alternatives based on their difference in robustness
tree_table: &mut Table,
formula_table: &mut Table,
trace: &Trace,
lower: usize,
upper: usize,
tau_dif: usize,
rho_dif: f32,
segmentations: &Vec<Segmentation>,
) -> (usize, Segmentation) {
match self {
Expand Down Expand Up @@ -1167,19 +1199,30 @@ impl TbtNode {
}

#[allow(clippy::too_many_arguments)]
// Is used to compute alternative segmentations
/// Is used to compute alternative segmentations
/// # Arguments
/// * `tree_table` - TBT data structure for dynamic programming
/// * `formula_table` - STL data structure for dynamic programming
/// * `trace` - Provided Trace that is analyzed
/// * `lower` - Segment start
/// * `upper` - Segment end
/// * `best_segmentation` - Reference/optimal segmentation
/// * `tau_dif` - Used to filter out alternatives based on where segments start and end
/// * `rho_dif` - Used to filter out alternatives based on their difference in robustness
/// * `number` - Number of alternatives that shall be computed
/// * `print_leaf_segments_only` - Defines whether only leaves or also other nodes are printed
pub fn get_alternative_segmentation(
&self,
tree_table: &mut Table, // TBT data structure for dynamic programming
formula_table: &mut Table, // STL data structure for dynamic programming
trace: &Trace, // Provided Trace that is analyzed
lower: usize, // Segment start
upper: usize, // Segment end
best_segmentation: &Segmentation, // Reference/optimal segmentation
tau_dif: usize, // Used to filter out alternatives based on where segments start and end
rho_dif: f32, // Used to filter out alternatives based on their difference in robustness
number: usize, // Number of alternatives that shall be computed
print_leaf_segments_only: bool, // Defines whether only leaves or also other nodes are printed
tree_table: &mut Table,
formula_table: &mut Table,
trace: &Trace,
lower: usize,
upper: usize,
best_segmentation: &Segmentation,
tau_dif: usize,
rho_dif: f32,
number: usize,
print_leaf_segments_only: bool,
) -> Vec<(usize, Segmentation)> {
println!("\n\nAlternatives:");
let mut res_segmentation = Vec::new();
Expand Down Expand Up @@ -1209,7 +1252,7 @@ impl TbtNode {
/*******************************
* Progress and print functions
*******************************/
// Debugging progress bar
/// Debugging progress bar
fn progress(tree_table: &mut Table, formula_table: &mut Table, system_time: &SystemTime) {
let (tree_set_calls, tree_total) = tree_table.progress();
let (formula_set_calls, formula_total) = formula_table.progress();
Expand All @@ -1229,7 +1272,7 @@ fn progress(tree_table: &mut Table, formula_table: &mut Table, system_time: &Sys
}
}

// Given a Segmentation is prints the result
/// Given a Segmentation is prints the result
pub fn print_segmentation(
segmentation: &Segmentation,
only_leaves: bool,
Expand Down
2 changes: 1 addition & 1 deletion src/command_line_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ pub fn parse_command_line() -> CommandLineArguments {
.short("c")
.long("children")
.help("Specifies whether only leaf nodes of a segmentation shall be printed");
// Add to the app to be parsed
// Add arguments to the app to be parsed
let app = app
.arg(logfile)
.arg(lazy_evaluation)
Expand Down
1 change: 0 additions & 1 deletion src/csv_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ pub fn get_best_number_skipped(trace: Trace, tree: TbtNode) -> (usize, (f32, f32
global_streak_neg_dif = neg_number_consecutive_false_dif;
}
}
// println!("Minimal negative streak: {global_streak_neg}, minimal positive streak: {global_streak_pos}");
if global_streak_pos == usize::MAX || global_streak_neg == usize::MAX {
(0, global_streak_pos_dif, global_streak_neg_dif)
} else {
Expand Down
Loading

0 comments on commit 2cbae37

Please sign in to comment.