Skip to content

Commit

Permalink
wip: improve statos
Browse files Browse the repository at this point in the history
  • Loading branch information
Yirmandias committed Dec 11, 2023
1 parent 8434232 commit 13b9537
Show file tree
Hide file tree
Showing 9 changed files with 199 additions and 83 deletions.
14 changes: 0 additions & 14 deletions domains/gripper/om.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,6 @@
(release res_g)
)))

(def-method pick_and_drop_debug
(:task place)
(:params (?o carriable) (?r room) (?g gripper) (?p room))
(:pre-conditions (!= ?p ?r) (= (pos ?o) ?p))
(:body
(do
(define rh (acquire 'robby))
(go2 ?a)
(pick ?o ?p ?g)
(go2 ?r)
(drop ?o ?r ?g)
)))


(def-method move_and_drop
(:task place)
(:params (?o carriable) (?r room) (?g gripper))
Expand Down
34 changes: 24 additions & 10 deletions stat/src/bin/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use ompas_stat::config::StatosConfig;
use ompas_stat::stat::system::{SystemRunData, SystemStatFormatter};
use ompas_stat::statis_config::StatosConfig;
use std::fs;
use std::fs::OpenOptions;
use std::io::Write;
Expand Down Expand Up @@ -27,7 +27,7 @@ pub fn main() {
println!("config: {:?}", config);

for config in config.configs {
let system_run = SystemRunData::new(&config.input_dir);
let system_run = SystemRunData::new(&config.input_dir, config.clone());

let time = SystemTime::now();
let stat = system_run.compute_stat();
Expand All @@ -40,14 +40,28 @@ pub fn main() {

println!("{}", formatter);

let csv = formatter.to_csv();
if let Some(csv_output) = config.csv_output {
let csv = formatter.to_csv();

let mut file = OpenOptions::new()
.create(true)
.write(true)
.truncate(true)
.open(&config.output_file)
.unwrap();
file.write_all(csv.as_bytes()).unwrap();
let mut file = OpenOptions::new()
.create(true)
.write(true)
.truncate(true)
.open(&csv_output)
.unwrap();
file.write_all(csv.as_bytes()).unwrap();
}

if let Some(latex_output) = config.latex_output {
let csv = formatter.to_latex();

let mut file = OpenOptions::new()
.create(true)
.write(true)
.truncate(true)
.open(&latex_output)
.unwrap();
file.write_all(csv.as_bytes()).unwrap();
}
}
}
13 changes: 0 additions & 13 deletions stat/src/config.rs

This file was deleted.

2 changes: 1 addition & 1 deletion stat/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pub mod config;
pub mod stat;
pub mod statis_config;
150 changes: 116 additions & 34 deletions stat/src/stat/config.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use crate::stat::instance::ContinuousPlanningStat;
use crate::stat::system::Cell;
use crate::stat::DurationStat;
use crate::statis_config::Field;
use ompas_core::ompas::interface::stat::OMPASRunData;
use std::fmt::{Display, Formatter};

Expand Down Expand Up @@ -38,11 +40,11 @@ impl ConfigRunData {
execution_time: self.get_execution_time_stat(),
score: self.get_score(),
deliberation_ratio: self.get_deliberation_ratio(),
planning_ratio: self.get_planning_ratio(),
best_config_ratio: 0.0,
distance_to_best: 0.0,
success_rate: self.get_success_rate(),
number_failures: self.get_n_failures(),
continuous_planning_stat: None,
}
}

Expand Down Expand Up @@ -107,63 +109,143 @@ pub struct ConfigInstanceStat {
pub execution_time: DurationStat,
pub score: f64,
pub deliberation_ratio: f64,
pub planning_ratio: Option<f64>,
pub best_config_ratio: f64,
pub distance_to_best: f64,
pub success_rate: f64,
pub number_failures: f64,
pub continuous_planning_stat: Option<ContinuousPlanningStat>,
}

pub const EXECUTION_TIME: &str = "T_{exec}";
pub const DELIBERATION_TIME_RATIO: &str = "R_{delib}";
pub const SCORE: &str = "score";
pub const PLANNING_TIME_RATIO: &str = "R_{plan}";
pub const VIRTUAL_BEST_RATIO: &str = "R_{VBest}";
pub const DISTANCE_TO_BEST: &str = "D_{VBest}";
pub const SUCCESS_RATE: &str = "P_{Success}";
pub const N_FAILURES: &str = "N_{Fail}";
pub const EXECUTION_TIME: &str = "$T(exec)$";
pub const DISTANCE_TO_BEST_EXECUTION_TIME: &str = "$D(Best(T(exec)))$";
pub const DELIBERATION_TIME: &str = "$T(delib)$";
pub const DELIBERATION_TIME_RATIO: &str = "$R(delib)$";
pub const COVERAGE: &str = "Cov";
pub const SCORE: &str = "Score";
pub const NUMBER_RETRIES: &str = "$N(retries)$";
pub const NUMBER_FAILURES: &str = "$N(failures)$";
pub const DISTANCE_TO_BEST_SCORE: &str = "$D(BScore)$";
pub const PLANNING_TIME: &str = "$T(plan)$";
pub const PLANNING_TIME_RATIO: &str = "$R(plan)$";
pub const NUMBER_PLANNING_INSTANCE: &str = "$N(PI)$";
pub const AVERAGE_PLANNING_TIME: &str = "$E(T(plan))$";
pub const PLANNING_SUCCESS_RATE: &str = "$R(P_{Success})$";
pub const VIRTUAL_BEST_RATIO: &str = "R(VBest)";
pub const DISTANCE_TO_BEST: &str = "$D(VBest)$";
pub const N_FAILURES: &str = "$N(Fail)$";

pub struct ConfigProblemStat {
pub execution_time: f64,
pub score: f64,
pub deliberation_ratio: f64,
pub planning_ratio: Option<f64>,
pub virtual_best_ratio: f64,
pub distance_to_best: f64,
pub success_rate: f64,
pub coverage: f64,
pub number_failures: f64,
pub continuous_planning_state: Option<ContinuousPlanningStat>,
}

impl ConfigProblemStat {
pub fn header() -> Vec<Cell> {
vec![
//Cell::start(EXECUTION_TIME.to_string()),
//Cell::start(DELIBERATION_TIME_RATIO.to_string()),
//Cell::start(PLANNING_TIME_RATIO.to_string()),
Cell::start(SCORE.to_string()),
Cell::start(VIRTUAL_BEST_RATIO.to_string()),
Cell::start(DISTANCE_TO_BEST.to_string()),
// Cell::start(SUCCESS_RATE.to_string()),
Cell::double(SUCCESS_RATE.to_string()),
//Cell::double(N_FAILURES.to_string()),
]
pub fn header(fields: &[Field]) -> Vec<Cell> {
let mut cells = vec![];
let last = fields.len() - 1;
for (i, field) in fields.iter().enumerate() {
let info = match field {
Field::ExecutionTime => EXECUTION_TIME,
Field::DistanceToBestExecutionTime => DISTANCE_TO_BEST_EXECUTION_TIME,
Field::DeliberationTime => DELIBERATION_TIME,
Field::DeliberationTimeRatio => DELIBERATION_TIME_RATIO,
Field::Coverage => COVERAGE,
Field::Score => SCORE,
Field::DistanceToBestScore => DISTANCE_TO_BEST_SCORE,
Field::NumberRetries => NUMBER_RETRIES,
Field::NumberFailures => NUMBER_FAILURES,
Field::PlanningTime => PLANNING_TIME,
Field::PlanningTimeRatio => PLANNING_TIME_RATIO,
Field::NumberPlanningInstance => NUMBER_PLANNING_INSTANCE,
Field::AveragePlanningTime => AVERAGE_PLANNING_TIME,
Field::PlanningSuccessRate => PLANNING_SUCCESS_RATE,
}
.to_string();
if i == last {
cells.push(Cell::double(info))
} else {
cells.push(Cell::start(info))
}
}

cells
}

pub fn to_formatted(&self) -> Vec<Cell> {
vec![
pub fn to_formatted(&self, fields: &[Field]) -> Vec<Cell> {
let mut cells = vec![];
let last = fields.len() - 1;
for (i, field) in fields.iter().enumerate() {
let info = match field {
Field::ExecutionTime => {
format!("{:.1}", self.execution_time)
}
Field::DistanceToBestExecutionTime => {
todo!()
}
Field::DeliberationTime => {
todo!()
}
Field::DeliberationTimeRatio => {
format!("{:.1}", self.deliberation_ratio)
}
Field::Coverage => {
format!("{:.1}", self.coverage)
}
Field::Score => {
format!("{:.1}", self.score)
}
Field::DistanceToBestScore => {
todo!()
}
Field::NumberRetries => {
todo!()
}
Field::NumberFailures => {
todo!()
}
Field::PlanningTime => {
todo!()
}
Field::PlanningTimeRatio => {
todo!()
}
Field::NumberPlanningInstance => {
todo!()
}
Field::AveragePlanningTime => {
todo!()
}
Field::PlanningSuccessRate => {
todo!()
}
};

if i == last {
cells.push(Cell::double(info))
} else {
cells.push(Cell::start(info))
}
}
cells
/*vec![
//Cell::start(format!("{:.1}", self.execution_time)),
//Cell::start(format!("{:.1}", self.deliberation_ratio * 100.0)),
// Cell::start(match self.planning_ratio {
// Some(p) => format!("{:.1}", p * 100.0),
// None => "None".to_string(),
// }),
Cell::start(format!("{:.1}", self.score)),
Cell::start(format!("{:.1}", self.virtual_best_ratio * 100.0)),
Cell::start(format!("{:.1}", self.distance_to_best)),
//Cell::start(format!("{:.1}", self.success_rate * 100.0)),
Cell::double(format!("{:.1}", self.success_rate * 100.0)),
//Cell::double(format!("{:.1}", self.number_failures)),
]
Cell::start(format!("{:.1}", self.virtual_best_ratio),
Cell::start(format!("{:.1}", self.distance_to_best)),
//Cell::start(format!("{:.1}", self.success_rate * 100.0)),
//Cell::double(format!("{:.1}", self.number_failures)),
]*/
}
}

Expand All @@ -183,11 +265,11 @@ impl From<&[ConfigInstanceStat]> for ConfigProblemStat {
.map(|stat| stat.deliberation_ratio)
.sum::<f64>()
/ n,
planning_ratio: None,
virtual_best_ratio: stats.iter().map(|stat| stat.best_config_ratio).sum::<f64>() / n,
distance_to_best: stats.iter().map(|stat| stat.distance_to_best).sum::<f64>() / n,
success_rate: stats.iter().map(|stat| stat.success_rate).sum::<f64>() / n,
coverage: stats.iter().map(|stat| stat.success_rate).sum::<f64>() / n,
number_failures: stats.iter().map(|stat| stat.number_failures).sum::<f64>() / n,
continuous_planning_state: None,
}
}
}
6 changes: 6 additions & 0 deletions stat/src/stat/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ pub struct InstanceRunStat {
pub inner: HashMap<ConfigName, ConfigInstanceStat>,
}

pub struct ContinuousPlanningStat {
pub planning_time: f64,
pub planning_time_ratio: f64,
pub success_rate: f64,
}

#[derive(Default)]
pub struct InstanceRunData {
pub inner: HashMap<ConfigName, ConfigRunData>,
Expand Down
Loading

0 comments on commit 13b9537

Please sign in to comment.