advdigraph

This commit is contained in:
elvis
2025-07-08 01:03:50 +02:00
parent 8baa1bafc1
commit 6b0a825210
3 changed files with 52 additions and 0 deletions

View File

@ -276,3 +276,49 @@ pub fn digraph() -> std::io::Result<()> {
Ok(()) Ok(())
} }
// equivalent to main_do(advdigraph, Arcs)
pub fn adversarial() -> std::io::Result<()> {
let mut translator = Translator::new();
let mut path = env::current_dir()?;
// file to read is inside testing/
path = path.join("testing/adversarial.system");
let system = read_file(&mut translator, path, parser_system)?;
// the system needs to terminate to return
let res = match graph::digraph(system) {
Ok(o) => o,
Err(e) => {
println!("Error computing target: {e}");
return Ok(());
}
};
let rc_translator = Rc::new(translator);
let old_res = Rc::new(res.clone());
// map each value to the corresponding value we want to display
let res = res.map(
|id, node|
graph::GraphMapNodesTy::from(graph::GraphMapNodes::Entities,
Rc::clone(&rc_translator)).get()(id, node)
+ "; " +
&graph::GraphMapNodesTy::from(graph::GraphMapNodes::Context,
Rc::clone(&rc_translator)).get()(id, node),
graph::GraphMapEdgesTy::from(graph::GraphMapEdges::EntitiesAdded,
Rc::clone(&rc_translator)).get()
);
println!("Generated graph in dot notation:\n{}",
rsdot::RSDot::with_attr_getters(
&res,
&[],
&graph::default_edge_formatter(Rc::clone(&old_res)),
&graph::default_node_formatter(Rc::clone(&old_res)),
)
);
Ok(())
}

View File

@ -27,5 +27,7 @@ fn main() -> std::io::Result<()> {
examples::digraph()?; examples::digraph()?;
examples::adversarial()?;
Ok(()) Ok(())
} }

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