Skip to content

Commit

Permalink
fix bug with conversion: declare parameters in define table to avoid …
Browse files Browse the repository at this point in the history
…race condition when converting in parallel two methods with same parameters label
  • Loading branch information
Yirmandias committed Jan 22, 2024
1 parent 8835225 commit 552c8ac
Show file tree
Hide file tree
Showing 18 changed files with 159 additions and 112 deletions.
44 changes: 30 additions & 14 deletions acting/core/src/model/sym_table/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,31 +226,38 @@ impl SymTable {

// New functions
impl SymTable {
pub fn new_variable(&mut self, sym: impl Display, domain: impl Into<Domain>) -> VarId {
pub fn new_variable(
&mut self,
symbol: impl Display,
label: impl Display,
domain: impl Into<Domain>,
) -> VarId {
let domain_id = self.domains.new_node(VarDomain::new(domain));
let id = self.variables.new_node(Variable::new(sym, domain_id));
let id = self
.variables
.new_node(Variable::new(symbol, label, domain_id));
self.add_var_to_domain(domain_id, id);
id
}

pub fn new_bool(&mut self, b: bool) -> VarId {
self.new_variable(b, b)
self.new_variable(b, b, b)
}

pub fn new_nil(&mut self) -> VarId {
self.new_variable(NIL, BasicType::Nil)
self.new_variable(NIL, NIL, BasicType::Nil)
}

pub fn new_err(&mut self) -> VarId {
self.new_variable(ERR, BasicType::Err)
self.new_variable(ERR, ERR, BasicType::Err)
}

pub fn new_int(&mut self, i: i64) -> VarId {
self.new_variable(i, i)
self.new_variable(i, i, i)
}

pub fn new_float(&mut self, f: f64) -> VarId {
self.new_variable(f, f)
self.new_variable(f, f, f)
}

pub fn new_number(&mut self, n: &LNumber) -> VarId {
Expand Down Expand Up @@ -278,15 +285,15 @@ impl SymTable {
pub fn new_result(&mut self) -> VarId {
let index = self.meta_data.new_result_index();
let sym = format!("{RESULT_PREFIX}{index}");
let id = self.new_variable(&sym, Domain::any());
let id = self.new_variable(&sym, &sym, Domain::any());
self.ids.insert(&sym, &id);
id
}

pub fn new_timepoint(&mut self) -> VarId {
let index = self.meta_data.new_timepoint_index();
let sym = format!("{TIMEPOINT_PREFIX}{index}");
let id = self.new_variable(&sym, self.get_type_as_domain(TYPE_TIMEPOINT).unwrap());
let id = self.new_variable(&sym, &sym, self.get_type_as_domain(TYPE_TIMEPOINT).unwrap());
self.ids.insert(&sym, &id);
id
}
Expand Down Expand Up @@ -333,6 +340,7 @@ impl SymTable {

let sym_if = &format!("{IF_PREFIX}{index}");
let id_if = self.new_variable(
sym_if,
sym_if,
Domain::Cst(
Box::new(self.get_type_as_domain(TYPE_TASK).unwrap()),
Expand All @@ -343,6 +351,7 @@ impl SymTable {

let sym_m_true = &format!("m_{}_true", sym_if);
let id_m_true = self.new_variable(
sym_m_true,
sym_m_true,
Domain::Cst(
Box::new(self.get_type_as_domain(TYPE_METHOD).unwrap()),
Expand All @@ -353,6 +362,7 @@ impl SymTable {

let sym_m_false = &format!("m_{}_false", sym_if);
let id_m_false = self.new_variable(
sym_m_false,
sym_m_false,
Domain::Cst(
Box::new(self.get_type_as_domain(TYPE_METHOD).unwrap()),
Expand All @@ -367,7 +377,7 @@ impl SymTable {
pub fn new_handle(&mut self) -> VarId {
let index = self.meta_data.new_handle_index();
let sym = &format!("{HANDLE_PREFIX}{index}");
let id = self.new_variable(sym, Domain::composed(Handle as usize, vec![Any]));
let id = self.new_variable(sym, sym, Domain::composed(Handle as usize, vec![Any]));
self.ids.insert(sym, &id);
id
}
Expand All @@ -392,7 +402,7 @@ impl SymTable {
pub fn new_arbitrary(&mut self) -> VarId {
let index = self.meta_data.new_arbitrary_index();
let sym = &format!("{ARBITRARY_PREFIX}{index}");
let id = self.new_variable(sym, Domain::any());
let id = self.new_variable(sym, sym, Domain::any());
self.ids.insert(sym, &id);
id
}
Expand All @@ -403,7 +413,7 @@ impl SymTable {
self.get_sym_id(sym).unwrap()
} else {
let sym: &String = &sym.to_string();
let id = self.new_variable(sym, sym.as_str());
let id = self.new_variable(sym, sym, sym.as_str());
self.ids.insert(sym, &id);
id
}
Expand All @@ -416,6 +426,7 @@ impl SymTable {
} else {
let sym: &String = &sym.to_string();
let id = self.new_variable(
sym,
sym,
Domain::Cst(Box::new(domain.into()), Cst::Symbol(sym.to_string())),
);
Expand All @@ -432,11 +443,11 @@ impl SymTable {
) -> VarId {
let symbol = symbol.to_string();
let version = self.ids.version(&symbol);
let sym = format!("{symbol}_{version}");
let label = format!("{symbol}_{version}");
let domain_id = self.domains.new_node(VarDomain::new(domain));
let id = self
.variables
.new_node(Variable::new_parameter(sym, domain_id));
.new_node(Variable::new_parameter(&symbol, label, domain_id));
self.add_var_to_domain(domain_id, id);
self.ids.insert(&symbol, &id);
self.set_declaration(id, declaration);
Expand Down Expand Up @@ -465,6 +476,7 @@ impl SymTable {
domain: domain_id,
parameter: variable.parameter,
label: sym,
symbol: symbol.clone(),
declaration: None,
drop: None,
};
Expand Down Expand Up @@ -518,6 +530,10 @@ impl SymTable {
self.variables[id].label.as_str()
}

pub fn get_symbol(&self, id: VarId) -> String {
self.variables[id].symbol.to_string()
}

pub fn get_domain_of_var(&mut self, v: VarId) -> &Domain {
let domain_id = self.get_domain_id(v);
self.get_domain(domain_id)
Expand Down
10 changes: 7 additions & 3 deletions acting/core/src/model/sym_table/ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ impl RefSymTable {
self.0.write().unwrap().get_label(id, parent).to_string()
}

pub fn get_symbol(&self, id: VarId) -> String {
self.0.read().unwrap().get_symbol(id)
}

pub fn get_var_parent(&self, v: VarId) -> VarId {
self.0.write().unwrap().get_var_parent(v)
}
Expand Down Expand Up @@ -225,7 +229,7 @@ impl RefSymTable {
self.0.read().unwrap().union(d1, d2)
}

pub fn substract(&self, d1: &Domain, d2: &Domain) -> Domain {
pub fn subtract(&self, d1: &Domain, d2: &Domain) -> Domain {
self.0.read().unwrap().substract(d1, d2)
}

Expand All @@ -237,15 +241,15 @@ impl RefSymTable {
self.0.write().unwrap().union_domains(id_d1, id_d2)
}

pub fn substract_domains(&self, id_d1: DomainId, id_d2: DomainId) -> Domain {
pub fn subtract_domains(&self, id_d1: DomainId, id_d2: DomainId) -> Domain {
self.0.write().unwrap().substract_domains(id_d1, id_d2)
}

pub fn meet_to_domain(&self, id_d1: DomainId, domain: impl Into<Domain>) -> EmptyDomains {
self.0.write().unwrap().meet_to_domain(id_d1, domain)
}

pub fn substract_to_domain(&self, id_d1: DomainId, domain: impl Into<Domain>) -> EmptyDomains {
pub fn subtract_to_domain(&self, id_d1: DomainId, domain: impl Into<Domain>) -> EmptyDomains {
self.0.write().unwrap().subtract_to_domain(id_d1, domain)
}

Expand Down
7 changes: 5 additions & 2 deletions acting/core/src/model/sym_table/variable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,29 @@ pub struct Variable {
pub domain: DomainId,
pub parameter: bool,
pub label: String,
pub symbol: String,
pub declaration: Option<VarId>,
pub drop: Option<VarId>,
}

impl Variable {
pub fn new(label: impl Display, domain: DomainId) -> Self {
pub fn new(symbol: impl Display, label: impl Display, domain: DomainId) -> Self {
Self {
domain,
parameter: false,
label: label.to_string(),
symbol: symbol.to_string(),
declaration: None,
drop: None,
}
}

pub fn new_parameter(label: impl Display, domain: DomainId) -> Self {
pub fn new_parameter(symbol: impl Display, label: impl Display, domain: DomainId) -> Self {
Self {
domain,
parameter: true,
label: label.to_string(),
symbol: symbol.to_string(),
declaration: None,
drop: None,
}
Expand Down
19 changes: 11 additions & 8 deletions acting/core/src/ompas/interface/stat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@ use crate::ompas::manager::acting::inner::ActingProcessKind;
use crate::ompas::manager::acting::interval::Duration;
use crate::ompas::manager::acting::process::process_stat::ActingProcessStat;
use crate::ompas::manager::planning::planner_stat::{PlannerStat, PlanningStatus};
use crate::ompas::scheme::monitor::debug_continuous_planning::plan;
use serde::{Deserialize, Serialize};
use std::f64::NAN;

#[derive(Default, Debug, Serialize, Deserialize)]
pub struct OMPASRunData {
inner: Vec<OMPASStat>,
pub inner: Vec<OMPASStat>,
}

impl OMPASRunData {
Expand Down Expand Up @@ -113,8 +111,9 @@ impl OMPASRunData {
let mut i = 0;
for stat in &self.inner {
if let OMPASStat::Process(p) = stat {
deliberation_time +=
p.deliberation_time.mean.as_secs() * p.deliberation_time.instance as f64;
deliberation_time += p.deliberation_time.mean.as_secs()
* p.deliberation_time.instance as f64
/ p.duration.as_secs();
i += 1;
}
}
Expand All @@ -129,7 +128,6 @@ impl OMPASRunData {
if pwt.is_nan() {
pwt = 0.0;
}
println!("twp {}", pwt);
let instance = p.planning_waiting_time.instance as f64;
planning_waiting_time += pwt * instance;
}
Expand All @@ -143,8 +141,13 @@ impl OMPASRunData {
let mut i = 0;
for stat in &self.inner {
if let OMPASStat::Process(p) = stat {
planning_waiting_time += p.planning_waiting_time.mean.as_secs()
* p.planning_waiting_time.instance as f64;
let mut pwt = p.planning_waiting_time.mean.as_secs();
if pwt.is_nan() {
pwt = 0.0;
}
let instance = p.planning_waiting_time.instance as f64;
planning_waiting_time += pwt * instance
/ (p.deliberation_time.mean.as_secs() * (p.deliberation_time.instance as f64));
i += 1;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub fn propagate(
let id = st.get_var_parent(id);
let domain_id = st.get_domain_id(id);
//println!("Subtract({id}, {})", graph.sym_table.format_domain(&d));
let emptys = st.substract_to_domain(domain_id, d);
let emptys = st.subtract_to_domain(domain_id, d);
if let EmptyDomains::Some(emptys) = emptys {
//println!("[Subtract] Domains of {:?} are empty.", emptys);
for e in &emptys {
Expand Down
14 changes: 13 additions & 1 deletion acting/core/src/planning/conversion/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use crate::planning::conversion::flow_graph::algo::p_eval::p_eval;
use crate::planning::conversion::flow_graph::algo::p_eval::r#struct::PLEnv;
use crate::planning::conversion::flow_graph::algo::post_processing::flow_graph_post_processing;
use crate::planning::conversion::flow_graph::algo::pre_processing::pre_processing;
use crate::planning::conversion::flow_graph::define_table::DefineTable;
use crate::planning::conversion::flow_graph::graph::FlowGraph;
use crate::planning::planner::problem::PlanningDomain;
use crate::{ChronicleDebug, OMPAS_CHRONICLE_DEBUG};
Expand Down Expand Up @@ -119,6 +120,16 @@ pub fn _convert(
) -> Result<Chronicle, LRuntimeError> {
let time = SystemTime::now();
let n_conversion = N_CONVERSION.fetch_add(1, Ordering::Relaxed);
let mut define_table: DefineTable = Default::default();
if let Some(ch) = &ch {
for param in &ch.get_name()[1..] {
let sym = st.get_symbol(*param);
//if sym == "?r" {
println!("{sym}");
//}
define_table.insert(sym, *param);
}
}
let mut graph = FlowGraph::new(st);

if OMPAS_CHRONICLE_DEBUG.get() >= ChronicleDebug::Full {
Expand All @@ -128,7 +139,8 @@ pub fn _convert(
lv.format(0)
);
}
let flow = convert_lv(lv, &mut graph, &mut Default::default())?;

let flow = convert_lv(lv, &mut graph, &mut define_table)?;
graph.flow = flow;

#[cfg(feature = "conversion_data")]
Expand Down
4 changes: 0 additions & 4 deletions domains/gripper_door/base.scm
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@
(:params (?r1 room) (?d door) (?r2 room))
(:result boolean))

(def-function min-distance
(:params (?r1 room) (?r2 room))
(:result int))

; New commands
(def-command move (:params (?from room) (?to room) (?d door)))
(def-command-pddl-model move
Expand Down
4 changes: 4 additions & 0 deletions domains/gripper_door/om.scm
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
(load "../gripper/om.scm")
(remove-method m_move)

(def-function min-distance
(:params (?r1 room) (?r2 room))
(:result int))

(def-method m_move
(:task go2)
(:params (?r room) (?a room) (?n room) (?d door))
Expand Down
4 changes: 2 additions & 2 deletions domains/gripper_multi/base.scm
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@

; Additional state functions
(remove-state-function at-robby)
(def-state-function at-rob (:params (?r robot)) (:result room))
(def-state-function carry (:params (?r robot) (?g gripper)) (:result carriable))
(def-state-function at-rob (:params (?ro robot)) (:result room))
(def-state-function carry (:params (?ro robot) (?g gripper)) (:result carriable))

; New commands
(def-command move (:params (?r robot) (?from room) (?to room) (?d door)))
Expand Down
13 changes: 9 additions & 4 deletions domains/gripper_multi/om.scm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(begin
(def-function gripper_of (:params (?r robot) (?g gripper)) (:result object))
(def-function gripper_of (:params (?ro robot) (?g gripper)) (:result object))

(def-task go2 (:params (?ro robot) (?r room)))
(def-method go2_noop
Expand Down Expand Up @@ -60,8 +60,6 @@
(go2 ?ro ?r)
(drop ?ro ?o ?r ?g))))



(def-task t_open (:params (?ro robot) (?d door) (?r room)))
(def-method open_noop
(:task t_open)
Expand All @@ -71,7 +69,7 @@

(def-method open_direct
(:task t_open)
(:params (?ro robot) (?d door) (?r room) (?g gripper))
(:params (?ro robot) (?d door) (?r room) (?g gripper))
(:pre-conditions
(! (opened ?d))
(= (carry ?ro ?g) empty)
Expand All @@ -81,6 +79,13 @@
(go2 ?ro ?r)
(open ?ro ?d ?r ?g))))

; (def-task test (?ro robot) (?r room))
; (def-method m_test
; (:params (?ro robot) (?r room))
; (:pre-conditions )
; (:body nil))


(def-method drop_and_open
(:task t_open)
(:params (?ro robot) (?d door) (?r room))
Expand Down
Loading

0 comments on commit 552c8ac

Please sign in to comment.