More examples
This commit is contained in:
@ -2,6 +2,7 @@
|
|||||||
name = "reactionsystems"
|
name = "reactionsystems"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
exclude = ["*.system", "*.experiment", "/testing/", "*.serial"]
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
lalrpop = "0.22"
|
lalrpop = "0.22"
|
||||||
|
|||||||
@ -1,8 +1,13 @@
|
|||||||
fn main() {
|
fn main() {
|
||||||
|
use reactionsystems::rsprocess::presets;
|
||||||
|
|
||||||
|
let mut input = String::new();
|
||||||
|
std::io::stdin().read_line(&mut input).unwrap();
|
||||||
|
input = input.trim().into();
|
||||||
|
|
||||||
let now = std::time::Instant::now();
|
let now = std::time::Instant::now();
|
||||||
|
|
||||||
use reactionsystems::rsprocess::presets;
|
match presets::run(input) {
|
||||||
match presets::run("testing/medical.system".into()) {
|
|
||||||
Ok(()) => {},
|
Ok(()) => {},
|
||||||
Err(e) => {println!("{e}")}
|
Err(e) => {println!("{e}")}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -845,7 +845,6 @@ Instruction: presets::Instruction = {
|
|||||||
presets::Instruction::FastFrequency { experiment: p, so },
|
presets::Instruction::FastFrequency { experiment: p, so },
|
||||||
"Digraph" ">" <gso: Separated_Or<GraphSaveOptions, "|">> =>
|
"Digraph" ">" <gso: Separated_Or<GraphSaveOptions, "|">> =>
|
||||||
presets::Instruction::Digraph { gso },
|
presets::Instruction::Digraph { gso },
|
||||||
// <edge_relabeler: Assert>
|
|
||||||
"Bisimilarity" "(" <p: Path> ")" "relabel" <edge_relabeler: Assert>
|
"Bisimilarity" "(" <p: Path> ")" "relabel" <edge_relabeler: Assert>
|
||||||
">" <so: SaveOptions> =>
|
">" <so: SaveOptions> =>
|
||||||
presets::Instruction::Bisimilarity {
|
presets::Instruction::Bisimilarity {
|
||||||
|
|||||||
@ -162,20 +162,20 @@ where
|
|||||||
// relative path
|
// relative path
|
||||||
let mut path = match env::current_dir() {
|
let mut path = match env::current_dir() {
|
||||||
Ok(p) => p,
|
Ok(p) => p,
|
||||||
Err(_) => return Err("Error getting current directory.".into()),
|
Err(e) => return Err(format!("Error getting current directory: {e}")),
|
||||||
};
|
};
|
||||||
path = path.join(path_string);
|
path = path.join(path_string);
|
||||||
|
|
||||||
// we read the file with a buffer
|
// we read the file with a buffer
|
||||||
let f = match fs::File::open(path) {
|
let f = match fs::File::open(path) {
|
||||||
Ok(f) => f,
|
Ok(f) => f,
|
||||||
Err(_) => return Err("Error opening file.".into()),
|
Err(e) => return Err(format!("Error opening file: {e}.")),
|
||||||
};
|
};
|
||||||
let mut buf_reader = io::BufReader::new(f);
|
let mut buf_reader = io::BufReader::new(f);
|
||||||
let mut contents = String::new();
|
let mut contents = String::new();
|
||||||
match buf_reader.read_to_string(&mut contents) {
|
match buf_reader.read_to_string(&mut contents) {
|
||||||
Ok(_) => {}
|
Ok(_) => {}
|
||||||
Err(_) => return Err("Error reading file.".into()),
|
Err(e) => return Err(format!("Error reading file: {e}")),
|
||||||
}
|
}
|
||||||
|
|
||||||
// parse
|
// parse
|
||||||
@ -215,7 +215,7 @@ where
|
|||||||
|
|
||||||
let mut err = format!(
|
let mut err = format!(
|
||||||
"Unrecognized token {}{}{} \
|
"Unrecognized token {}{}{} \
|
||||||
between positions {l} and {r}. ",
|
between positions {l} and {r}.",
|
||||||
"\"".red(),
|
"\"".red(),
|
||||||
t.to_string().red(),
|
t.to_string().red(),
|
||||||
"\"".red(),
|
"\"".red(),
|
||||||
@ -252,7 +252,7 @@ where
|
|||||||
let line_pos_r = r - left_new_line;
|
let line_pos_r = r - left_new_line;
|
||||||
|
|
||||||
err.push_str(
|
err.push_str(
|
||||||
&format!(".\nLine {} position {} to {}:\n{}{}{}{}",
|
&format!("\nLine {} position {} to {}:\n{}{}{}{}",
|
||||||
line_number,
|
line_number,
|
||||||
line_pos_l,
|
line_pos_l,
|
||||||
line_pos_r,
|
line_pos_r,
|
||||||
@ -334,7 +334,7 @@ pub fn stats(system: &EvaluatedSystem) -> Result<String, String> {
|
|||||||
Ok(sys.statistics(translator)),
|
Ok(sys.statistics(translator)),
|
||||||
EvaluatedSystem::Graph { graph, translator } => {
|
EvaluatedSystem::Graph { graph, translator } => {
|
||||||
let Some(sys) = graph.node_weights().next() else {
|
let Some(sys) = graph.node_weights().next() else {
|
||||||
return Err("No node found in graph".into());
|
return Err("No node found in graph.".into());
|
||||||
};
|
};
|
||||||
Ok(sys.statistics(translator))
|
Ok(sys.statistics(translator))
|
||||||
}
|
}
|
||||||
@ -350,7 +350,7 @@ pub fn target(system: &EvaluatedSystem) -> Result<String, String> {
|
|||||||
(sys.target()?, translator),
|
(sys.target()?, translator),
|
||||||
EvaluatedSystem::Graph { graph, translator } => {
|
EvaluatedSystem::Graph { graph, translator } => {
|
||||||
let Some(sys) = graph.node_weights().next() else {
|
let Some(sys) = graph.node_weights().next() else {
|
||||||
return Err("No node found in graph".into());
|
return Err("No node found in graph.".into());
|
||||||
};
|
};
|
||||||
(sys.target()?, translator)
|
(sys.target()?, translator)
|
||||||
}
|
}
|
||||||
@ -373,7 +373,7 @@ pub fn traversed(system: &EvaluatedSystem) -> Result<String, String> {
|
|||||||
}
|
}
|
||||||
EvaluatedSystem::Graph { graph, translator } => {
|
EvaluatedSystem::Graph { graph, translator } => {
|
||||||
let Some(sys) = graph.node_weights().next() else {
|
let Some(sys) = graph.node_weights().next() else {
|
||||||
return Err("No node found in graph".into());
|
return Err("No node found in graph.".into());
|
||||||
};
|
};
|
||||||
(sys.run_separated()?, translator)
|
(sys.run_separated()?, translator)
|
||||||
}
|
}
|
||||||
@ -381,7 +381,7 @@ pub fn traversed(system: &EvaluatedSystem) -> Result<String, String> {
|
|||||||
|
|
||||||
let mut output = String::new();
|
let mut output = String::new();
|
||||||
|
|
||||||
output.push_str("The trace is composed by the set of entities:");
|
output.push_str("The trace is composed by the set of entities: ");
|
||||||
for (e, _c, _t) in res {
|
for (e, _c, _t) in res {
|
||||||
output.push_str(&format!(
|
output.push_str(&format!(
|
||||||
"{}",
|
"{}",
|
||||||
@ -394,7 +394,7 @@ pub fn traversed(system: &EvaluatedSystem) -> Result<String, String> {
|
|||||||
/// Finds the looping list of states in a reaction system with a perpetual
|
/// Finds the looping list of states in a reaction system with a perpetual
|
||||||
/// context. IMPORTANT: for loops, we assume Delta defines the process constant
|
/// context. IMPORTANT: for loops, we assume Delta defines the process constant
|
||||||
/// x = Q.x and the context process is x .
|
/// x = Q.x and the context process is x .
|
||||||
/// equivalent to main_do(loop,Es)
|
/// equivalent to main_do(loop,Es)
|
||||||
pub fn hoop(
|
pub fn hoop(
|
||||||
system: &EvaluatedSystem,
|
system: &EvaluatedSystem,
|
||||||
symbol: String
|
symbol: String
|
||||||
@ -403,14 +403,14 @@ pub fn hoop(
|
|||||||
EvaluatedSystem::System { sys, translator } => (sys, translator),
|
EvaluatedSystem::System { sys, translator } => (sys, translator),
|
||||||
EvaluatedSystem::Graph { graph, translator } => {
|
EvaluatedSystem::Graph { graph, translator } => {
|
||||||
let Some(sys) = graph.node_weights().next() else {
|
let Some(sys) = graph.node_weights().next() else {
|
||||||
return Err("No node found in graph".into());
|
return Err("No node found in graph.".into());
|
||||||
};
|
};
|
||||||
(sys, translator)
|
(sys, translator)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
// we retrieve the id for "x" and use it to find the corresponding loop
|
// we retrieve the id for "x" and use it to find the corresponding loop
|
||||||
let Some(id) = translator.encode_not_mut(&symbol) else {
|
let Some(id) = translator.encode_not_mut(&symbol) else {
|
||||||
return Err(format!("Symbol {symbol} not found"));
|
return Err(format!("Symbol {symbol} not found."));
|
||||||
};
|
};
|
||||||
let res = match res.lollipops_only_loop_named(id) {
|
let res = match res.lollipops_only_loop_named(id) {
|
||||||
Some(o) => o,
|
Some(o) => o,
|
||||||
@ -421,7 +421,7 @@ pub fn hoop(
|
|||||||
|
|
||||||
let mut output = String::new();
|
let mut output = String::new();
|
||||||
|
|
||||||
output.push_str("The loop is composed by the sets:");
|
output.push_str("The loop is composed by the sets: ");
|
||||||
for e in res {
|
for e in res {
|
||||||
output.push_str(&format!(
|
output.push_str(&format!(
|
||||||
"{}",
|
"{}",
|
||||||
@ -440,7 +440,7 @@ pub fn freq(system: &EvaluatedSystem) -> Result<String, String> {
|
|||||||
EvaluatedSystem::System { sys, translator } => (sys, translator),
|
EvaluatedSystem::System { sys, translator } => (sys, translator),
|
||||||
EvaluatedSystem::Graph { graph, translator } => {
|
EvaluatedSystem::Graph { graph, translator } => {
|
||||||
let Some(sys) = graph.node_weights().next() else {
|
let Some(sys) = graph.node_weights().next() else {
|
||||||
return Err("No node found in graph".into());
|
return Err("No node found in graph.".into());
|
||||||
};
|
};
|
||||||
(sys, translator)
|
(sys, translator)
|
||||||
}
|
}
|
||||||
@ -465,7 +465,7 @@ pub fn limit_freq(
|
|||||||
EvaluatedSystem::System { sys, translator } => (sys, translator),
|
EvaluatedSystem::System { sys, translator } => (sys, translator),
|
||||||
EvaluatedSystem::Graph { graph, translator } => {
|
EvaluatedSystem::Graph { graph, translator } => {
|
||||||
let Some(sys) = graph.node_weights().next() else {
|
let Some(sys) = graph.node_weights().next() else {
|
||||||
return Err("No node found in graph".into());
|
return Err("No node found in graph.".into());
|
||||||
};
|
};
|
||||||
(sys, translator)
|
(sys, translator)
|
||||||
}
|
}
|
||||||
|
|||||||
8
testing/examples/bisimilarity.system
Normal file
8
testing/examples/bisimilarity.system
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
Environment: [x = {a}.y, y =({a}.x + {b}.y)]
|
||||||
|
Initial Entities: {a, b}
|
||||||
|
Context: [({a,b}.{a}.{a,c}.x + {a,b}.{a}.{a}.nill)]
|
||||||
|
Reactions: ([{a,b}, {c}, {b}])
|
||||||
|
|
||||||
|
Bisimilarity ("bisimilarity2.system")
|
||||||
|
relabel label { return true }
|
||||||
|
> Print,
|
||||||
4
testing/examples/bisimilarity2.system
Normal file
4
testing/examples/bisimilarity2.system
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
Environment: [x = {a}.y, y =({a}.x + {b}.y)]
|
||||||
|
Initial Entities: {a}
|
||||||
|
Context: [{a,b}.{a}.{a,c}.nill]
|
||||||
|
Reactions: ([r: {a,b}, i: {c}, p: {b}])
|
||||||
3
testing/examples/deserialize.system
Normal file
3
testing/examples/deserialize.system
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
Deserialize ("deserialize.serial")
|
||||||
|
|
||||||
|
Stats > Print
|
||||||
16
testing/examples/digraph.system
Normal file
16
testing/examples/digraph.system
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
Environment: [x = {a}.y, y =({a}.x + {b}.y) ]
|
||||||
|
Initial Entities: {a, b}
|
||||||
|
Context: [({a,b}.{a}.{a,c}.x + {a,b}.{a}.{a}.nill)]
|
||||||
|
Reactions: ([{a,b}, {c}, {b}])
|
||||||
|
|
||||||
|
Digraph > Dot
|
||||||
|
| Entities " - " Context " - entities masked: " MaskEntities {a}
|
||||||
|
| Entities
|
||||||
|
| Entities < {a} ? "blue" ! "white"
|
||||||
|
| ! "black"
|
||||||
|
> Print,
|
||||||
|
|
||||||
|
Digraph > GraphML
|
||||||
|
| Entities
|
||||||
|
| Entities
|
||||||
|
> Print
|
||||||
2
testing/examples/fastfrequency.experiment
Normal file
2
testing/examples/fastfrequency.experiment
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
Weights: 10, 5
|
||||||
|
Sets: {a,b}, {a}
|
||||||
6
testing/examples/fastfrequency.system
Normal file
6
testing/examples/fastfrequency.system
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
Environment: [ x = {b}.{c}.x ]
|
||||||
|
Initial Entities: {a, b}
|
||||||
|
Context: [({a,b}.{a}.{a,c}.x + {a,b}.{a}.{a}.nill)]
|
||||||
|
Reactions: ([{a}, {b}, {b}]; [{b}, {a}, {a}]; [{c}, {b}, {c}])
|
||||||
|
|
||||||
|
FastFrequency("fastfrequency.experiment") > Print
|
||||||
6
testing/examples/frequency.system
Normal file
6
testing/examples/frequency.system
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
Environment: [x = {a}.y, y =({a}.{a, b}.nill + {b}.nill) ]
|
||||||
|
Initial Entities: {a, b}
|
||||||
|
Context: [({a,b}.{a}.{a,c}.x + {a,b}.{a}.{a}.nill)]
|
||||||
|
Reactions: ([{a,b}, {c}, {b}])
|
||||||
|
|
||||||
|
Frequency > Print
|
||||||
2
testing/examples/limitfrequency.experiment
Normal file
2
testing/examples/limitfrequency.experiment
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
Weights: 10, 5
|
||||||
|
Sets: {a,b}, {a}
|
||||||
6
testing/examples/limitfrequency.system
Normal file
6
testing/examples/limitfrequency.system
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
Environment: [ x = {b}.{c}.x ]
|
||||||
|
Initial Entities: {a, b}
|
||||||
|
Context: [({a,b}.{a}.{a,c}.x + {a,b}.{a}.{a}.nill)]
|
||||||
|
Reactions: ([{a}, {b}, {b}]; [{b}, {a}, {a}]; [{c}, {b}, {c}])
|
||||||
|
|
||||||
|
LimitFrequency("limitfrequency.experiment") > Print
|
||||||
7
testing/examples/loop.system
Normal file
7
testing/examples/loop.system
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
Environment: [ x = {b}.x, y = {a, c}.y ]
|
||||||
|
Initial Entities: {a, b}
|
||||||
|
Context: [({a,b}.{a}.{a,c}.x + {a,b}.{a}.{a}.y)]
|
||||||
|
Reactions: ([{a}, {b}, {b}]; [{b}, {a}, {a}]; [{c}, {}, {d}])
|
||||||
|
|
||||||
|
Loop (x) > Print,
|
||||||
|
Loop (y) > Print
|
||||||
6
testing/examples/run.system
Normal file
6
testing/examples/run.system
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
Environment: [x = {a}.y, y =({a}.{a, b}.nill + {b}.nill) ]
|
||||||
|
Initial Entities: {a, b}
|
||||||
|
Context: [({a,b}.{a}.{a,c}.x + {a,b}.{a}.{a}.nill)]
|
||||||
|
Reactions: ([{a,b}, {c}, {b}])
|
||||||
|
|
||||||
|
Run > Print
|
||||||
8
testing/examples/serialize.system
Normal file
8
testing/examples/serialize.system
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
Environment: [x = {a}.y, y =({a}.x + {b}.y)]
|
||||||
|
Initial Entities: {a, b}
|
||||||
|
Context: [({a,b}.{a}.{a,c}.x + {a,b}.{a}.{a}.nill)]
|
||||||
|
Reactions: ([{a,b}, {c}, {b}])
|
||||||
|
|
||||||
|
Digraph > Serialize ("deserialize.serial"),
|
||||||
|
|
||||||
|
Stats > Print
|
||||||
6
testing/examples/stats.system
Normal file
6
testing/examples/stats.system
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
Environment: [x = {a}.y, y =({a}.x + {b}.y) ]
|
||||||
|
Initial Entities: {a, b}
|
||||||
|
Context: [({a,b}.{a}.{a,c}.x + {a,b}.{a}.{a}.nill)]
|
||||||
|
Reactions: ([{a,b}, {c}, {b}])
|
||||||
|
|
||||||
|
Stats > Print
|
||||||
6
testing/examples/target.system
Normal file
6
testing/examples/target.system
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
Environment: [x = {a}.y, y =({a}.{a, b}.nill + {b}.nill) ]
|
||||||
|
Initial Entities: {a, b}
|
||||||
|
Context: [({a,b}.{a}.{a,c}.x + {a,b}.{a}.{a}.nill)]
|
||||||
|
Reactions: ([{a,b}, {c}, {b}])
|
||||||
|
|
||||||
|
Target > Print
|
||||||
Reference in New Issue
Block a user