From 6b0a825210109710d22ec78aa113f631f602ebcd Mon Sep 17 00:00:00 2001 From: elvis Date: Tue, 8 Jul 2025 01:03:50 +0200 Subject: [PATCH] advdigraph --- src/examples.rs | 46 ++++++++++++++++++++++++++++++++++++++ src/main.rs | 2 ++ testing/adversarial.system | 4 ++++ 3 files changed, 52 insertions(+) create mode 100644 testing/adversarial.system diff --git a/src/examples.rs b/src/examples.rs index 7b46c0d..5066385 100644 --- a/src/examples.rs +++ b/src/examples.rs @@ -276,3 +276,49 @@ pub fn digraph() -> std::io::Result<()> { 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(()) +} diff --git a/src/main.rs b/src/main.rs index e7317c9..6df2cf9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -27,5 +27,7 @@ fn main() -> std::io::Result<()> { examples::digraph()?; + examples::adversarial()?; + Ok(()) } diff --git a/testing/adversarial.system b/testing/adversarial.system new file mode 100644 index 0000000..b3ddd79 --- /dev/null +++ b/testing/adversarial.system @@ -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}])