More examples

This commit is contained in:
elvis
2025-09-02 01:34:01 +02:00
parent 7dcdc3a727
commit aa0f795fae
18 changed files with 109 additions and 18 deletions

View File

@ -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"

View File

@ -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}")}
} }

View File

@ -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 {

View File

@ -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
@ -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)
} }
@ -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,
@ -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)
} }

View 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,

View 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}])

View File

@ -0,0 +1,3 @@
Deserialize ("deserialize.serial")
Stats > Print

View 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

View File

@ -0,0 +1,2 @@
Weights: 10, 5
Sets: {a,b}, {a}

View 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

View 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

View File

@ -0,0 +1,2 @@
Weights: 10, 5
Sets: {a,b}, {a}

View 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

View 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

View 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

View 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

View 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

View 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