Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing test #15

Merged
merged 2 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions scripts/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ directories=$(find "$script_dir/../res/" -mindepth 1 -type d -printf "%P\n")
for dir in $directories; do
dir="../res/${dir}/"
echo "Running Lazy eval with subsampling using ${dir}"
../target/release/tbt-segmentation -l -c -u -s ../specification/shiplanding_formula_combined.tbt -f $dir> "${dir}/subsamplingAndLazy_result.txt"
../target/release/tbt-segmentation -l -c -u -s ../specification/shiplanding_formula_combined.tbt --toml "${dir}/subsamplingAndLazy_result.toml" -f $dir> "${dir}/subsamplingAndLazy_result.txt"
python3 infer_parameters_visualization.py "${dir}/subsamplingAndLazy_result.txt"
echo "Running eval with subsampling using ${dir}"
../target/release/tbt-segmentation -c -u -s ../specification/shiplanding_formula_combined.tbt -f $dir> "${dir}/subsampling_result.txt"
../target/release/tbt-segmentation -c -u -s ../specification/shiplanding_formula_combined.tbt --toml "${dir}/subsampling_result.toml" -f $dir> "${dir}/subsampling_result.txt"
python3 infer_parameters_visualization.py "${dir}/subsampling_result.txt"
done

Expand Down
8 changes: 7 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,14 @@ pub fn get_alternative_segmentation(

pub fn generate_toml_output_file(
location: String,
number_skipped_entries: usize,
best_segmentation: ClonedSegmentation,
alternative_segmentation: Option<Vec<ClonedSegmentation>>,
) -> std::io::Result<()> {
generate_toml(location, best_segmentation, alternative_segmentation)
generate_toml(
location,
number_skipped_entries,
best_segmentation,
alternative_segmentation,
)
}
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ fn main() {
println!("Generating toml file: {}", toml_output_location);
match generate_toml_output_file(
toml_output_location,
number_skipped_entries,
best_segmentation,
alternative_segmentations,
) {
Expand Down
16 changes: 14 additions & 2 deletions src/toml_out.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ struct NamedSegmentation(String, TomlSegmentation);

#[derive(Serialize)]
struct TomlSegmentation {
delta: usize,
robustness: f32,
segments: Vec<Segment>,
}
Expand All @@ -37,16 +38,25 @@ struct Segmentations {

pub fn generate_toml(
location: String,
delta: usize,
best_segmentation: ClonedSegmentation,
alternative_segmentation: Option<Vec<ClonedSegmentation>>,
) -> std::io::Result<()> {
let mut segmentations = Vec::<NamedSegmentation>::new();
// Adding best segmentation
segmentations.push(read_segmentation(best_segmentation, "best".to_string()));
segmentations.push(read_segmentation(
best_segmentation,
delta,
"best".to_string(),
));
// Adding the alternative segmentations
if let Some(alternatives) = alternative_segmentation {
alternatives.into_iter().enumerate().for_each(|(i, seg)| {
segmentations.push(read_segmentation(seg, format!("alternative_{}", i + 1)))
segmentations.push(read_segmentation(
seg,
delta,
format!("alternative_{}", i + 1),
))
})
}
let all_segmentations = Segmentations { segmentations };
Expand All @@ -59,6 +69,7 @@ pub fn generate_toml(

fn read_segmentation(
segmentation: (f32, Vec<(crate::behaviortree::TbtNode, usize, usize, f32)>),
delta: usize,
name: String,
) -> NamedSegmentation {
let mut segments = Vec::<Segment>::new();
Expand All @@ -78,6 +89,7 @@ fn read_segmentation(
NamedSegmentation(
name,
TomlSegmentation {
delta,
robustness: segmentation.0,
segments,
},
Expand Down
23 changes: 13 additions & 10 deletions tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ fn run_test(
) -> Result<(), String> {
for (trace, expected) in traces_with_expected_value {
let trace: Trace = (trace.len(), HashMap::from([(signal_name.clone(), trace)]));
let robustness = evaluate(
let ((robustness, _), _) = evaluate(
tbt.clone(),
trace,
SystemTime::now(),
Expand All @@ -54,10 +54,10 @@ fn run_test(
None,
false,
);
if robustness.0 == expected {
if robustness == expected {
continue;
} else {
return Err(format!("Expected {expected} but was {}.", robustness.0));
return Err(format!("Expected {expected} but was {}.", robustness));
}
}
Ok(())
Expand Down Expand Up @@ -87,7 +87,7 @@ fn test_hardcoded_maneuver(specification: &str, logfile: &str) {
let setting_2 = setting.clone();
let start = SystemTime::now();
println!("Run using parsed tbt!");
let first_run = evaluate(
let (first_run, first_run_alt) = evaluate(
new_tbt,
trace,
start,
Expand All @@ -99,7 +99,7 @@ fn test_hardcoded_maneuver(specification: &str, logfile: &str) {
false,
);
println!("Run using hand-coded tbt!");
let second_run = evaluate(
let (second_run, second_run_alt) = evaluate(
old_tbt,
trace_2,
start,
Expand Down Expand Up @@ -140,12 +140,15 @@ fn test_hardcoded_maneuver(specification: &str, logfile: &str) {
v2.3
);
}
let alternatives_new = first_run.2.unwrap();
let alternatives_old = second_run.2.unwrap();
let alternatives_new = first_run_alt.unwrap();
let alternatives_old = second_run_alt.unwrap();
for j in 0..alternatives_new.len() {
for i in 0..first_run.1.len() {
let v1 = &alternatives_new[j][i];
let v2 = &alternatives_old[j][i];
let alt_new = &alternatives_new[j];
let alt_old = &alternatives_old[j];
assert_eq!(alt_new.0, alt_old.0);
for i in 0..alt_old.1.len() {
let v1 = &alt_new.1[i];
let v2 = &alt_old.1[i];
assert!(
v1.1 == v2.1,
"Entry of alternatives i={i} j={j} is expected to have same lower but wasnt {} != {}",
Expand Down
Loading