use cpnets::error::Error; use cpnets::prelude::*; use cpnets::state_graph::StateGraph; use criterion::{criterion_group, criterion_main, Criterion}; fn build_traffic_light() -> Result { let mut net = Net::new("traffic_light"); net.add_place(Place::new("green").with_capacity(1))?; net.add_place(Place::new("yellow").with_capacity(1))?; net.add_place(Place::new("red").with_capacity(1))?; net.add_transition(Transition::new("T0"))?; net.add_transition(Transition::new("T1"))?; net.add_transition(Transition::new("T2"))?; net.add_transition(Transition::new("T3"))?; net.add_arcs(arcs! { "green" => "T0"; "x", "T0" => "yellow"; expression!("x", &["x"]), "yellow" => "T1"; "x", "T1" => "red"; expression!("x", &["x"]), "red" => "T2"; "x", "T2" => "yellow"; expression!("x", &["x"]), "T2" => "red"; expression!("x", &["x"]), "yellow" => "T3"; "x", "red" => "T3"; "y", "T3" => "green"; expression!("x", &["x"]), })?; Ok(net) } fn traffic_light() { let net = build_traffic_light().unwrap(); let marking = net.empty_marking().with("red", [token!("\"on\"")]).unwrap(); StateGraph::init(net).compute(marking).unwrap(); } fn benchmark(c: &mut Criterion) { c.bench_function("traffic light", |b| b.iter(traffic_light)); } criterion_group!(benches, benchmark); criterion_main!(benches);