Skip to content

Commit

Permalink
revert for amr id changes (#588)
Browse files Browse the repository at this point in the history
Reverted amr id to previous representation. 

Still need to make check to make sure amr id's from code conform to
specs

Co-authored-by: Justin <[email protected]>
  • Loading branch information
Free-Quarks and Justin authored Oct 18, 2023
1 parent 5496ff2 commit c41b78c
Showing 1 changed file with 28 additions and 82 deletions.
110 changes: 28 additions & 82 deletions skema/skema-rs/mathml/src/acset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use serde::{Deserialize, Serialize};
use std::collections::{BTreeSet, HashMap, HashSet};
use utoipa;
use utoipa::ToSchema;
use nanoid::nanoid;

// We keep our ACSet representation in addition to the new SKEMA model representation since it is
// more compact and easy to work with for development.
Expand Down Expand Up @@ -322,12 +321,6 @@ pub struct AMRmathml {
// -------------------------------------------------------------------------------------------
impl From<Vec<FirstOrderODE>> for PetriNet {
fn from(ode_vec: Vec<FirstOrderODE>) -> PetriNet {

// for nanoid uuids:
let alphabet: [char; 17] = [
'1', '2', '3', '4', '5', '6', '7', '8', '9', '0', 'a', 'b', 'c', 'd', 'e', 'f', 'g'
];

// initialize vecs
let mut states_vec = BTreeSet::<State>::new();
let mut transitions_vec = BTreeSet::<Transition>::new();
Expand All @@ -340,25 +333,25 @@ impl From<Vec<FirstOrderODE>> for PetriNet {
// this first for loop is for the creation state related parameters in the AMR
for ode in ode_vec.iter() {
let states = State {
id: format!("{}_{}", ode.lhs_var.to_string().clone(), nanoid!(8, &alphabet)),
id: ode.lhs_var.to_string().clone(),
name: ode.lhs_var.to_string().clone(),
..Default::default()
};
let initials = Initial {
target: states.id.clone(),
//expression: format!("{}0", ode.lhs_var.to_string().clone()),
target: ode.lhs_var.to_string().clone(),
expression: "".to_string(),
..Default::default()
};
let parameters = Parameter {
/*let parameters = Parameter {
id: initials.expression.clone(),
name: Some(initials.expression.clone()),
/*description: Some(format!(
description: Some(format!(
"The total {} population at timestep 0",
ode.lhs_var.to_string().clone()
)),*/
)),
..Default::default()
};
parameter_vec.push(parameters.clone());
};*/
//parameter_vec.push(parameters.clone());
initial_vec.push(initials.clone());
states_vec.insert(states.clone());
state_string_list.push(ode.lhs_var.to_string().clone()); // used later for transition parsing
Expand Down Expand Up @@ -477,22 +470,11 @@ impl From<Vec<FirstOrderODE>> for PetriNet {
// now we construct transitions of all paired terms
for (i, t) in transition_pair.iter().enumerate() {
if t.0.exp_states.len() == 1 {
let mut input = Vec::<String>::new();
let mut output = Vec::<String>::new();

for state in states_vec.iter() {
if state.name == t.1.dyn_state {
input.push(state.id.clone());
}
else if state.name == t.0.dyn_state {
output.push(state.id.clone());
}
}
// construct transtions for simple transtions
let transitions = Transition {
id: format!("t{}_{}", i.clone(), nanoid!(8, &alphabet)),
input: Some(input.clone()),
output: Some(output.clone()),
id: format!("t{}", i.clone()),
input: Some([t.1.dyn_state.clone()].to_vec()),
output: Some([t.0.dyn_state.clone()].to_vec()),
..Default::default()
};
transitions_vec.insert(transitions.clone());
Expand Down Expand Up @@ -522,33 +504,17 @@ impl From<Vec<FirstOrderODE>> for PetriNet {
} else {
// construct transitions for complicated transitions
// mainly need to construct the output specially,
let mut input = Vec::<String>::new();
let mut output = Vec::<String>::new();
for exp in t.1.exp_states.iter() {
for state in states_vec.iter() {
if state.name == *exp {
input.push(state.id.clone());
}
}
}
for state in states_vec.iter() {
if state.name == t.0.dyn_state {
output.push(state.id.clone());
}
}
for exp in t.0.exp_states.iter() {
if *exp != t.1.dyn_state {
for state in states_vec.iter() {
if state.name == *exp {
output.push(state.id.clone());
}
}
let mut output = [t.0.dyn_state.clone()].to_vec();

for state in t.0.exp_states.iter() {
if *state != t.1.dyn_state {
output.push(state.clone());
}
}

let transitions = Transition {
id: format!("t{}_{}", i.clone(), nanoid!(8, &alphabet)),
input: Some(input.clone()),
id: format!("t{}", i.clone()),
input: Some(t.1.exp_states.clone()),
output: Some(output.clone()),
..Default::default()
};
Expand Down Expand Up @@ -584,23 +550,15 @@ impl From<Vec<FirstOrderODE>> for PetriNet {
for (i, term) in terms.iter().enumerate() {
if term.polarity {
let mut input = Vec::<String>::new();
let mut output = Vec::<String>::new();

for state in states_vec.iter() {
if state.name == term.dyn_state {
output.push(state.id.clone());
}
}
for exp in term.exp_states.iter() {
for state in states_vec.iter() {
if state.name == *exp {
input.push(state.id.clone());
}
}
let output = [term.dyn_state.clone()].to_vec();

for state in term.exp_states.iter() {
input.push(state.clone());
}

let transitions = Transition {
id: format!("s{}_{}", i, nanoid!(8, &alphabet)),
id: format!("s{}", i),
input: Some(input.clone()),
output: Some(output.clone()),
..Default::default()
Expand Down Expand Up @@ -634,23 +592,14 @@ impl From<Vec<FirstOrderODE>> for PetriNet {
};
rate_vec.push(rate.clone());
} else {
let mut input = Vec::<String>::new();
for state in states_vec.iter() {
if state.name == term.dyn_state {
input.push(state.id.clone());
}
}
let mut input = [term.dyn_state.clone()].to_vec();

for exp in term.exp_states.iter() {
for state in states_vec.iter() {
if *exp == state.name {
input.push(state.id.clone());
}
}
for state in term.exp_states.iter() {
input.push(state.clone());
}

let transitions = Transition {
id: format!("s{}_{}", i, nanoid!(8, &alphabet)),
id: format!("s{}", i),
input: Some(input.clone()),
output: None,
..Default::default()
Expand Down Expand Up @@ -691,9 +640,6 @@ impl From<Vec<FirstOrderODE>> for PetriNet {

parameter_vec.sort();
parameter_vec.dedup();
for parameter in parameter_vec.iter_mut() {
parameter.id = format!("{}", nanoid!(8, &alphabet));
}

// construct the PetriNet
let ode = Ode {
Expand All @@ -712,7 +658,7 @@ impl From<Vec<FirstOrderODE>> for PetriNet {
};

let header = Header {
name: "math model".to_string(),
name: "mathml model".to_string(),
schema: "https://github.com/DARPA-ASKEM/Model-Representations/blob/main/petrinet/petrinet_schema.json".to_string(),
schema_name: "PetriNet".to_string(),
description: "This is a model from equations".to_string(),
Expand Down

0 comments on commit c41b78c

Please sign in to comment.