Deterministic discrete Petri net modeling and reachability analysis for MoonBit
Dependencies
moon add okMambaOut/moonpetri@0.1.3git clone https://github.com/okMambaOut/moonpetri.git
cd moonpetri
moon update
moon check --target wasm-gc --deny-warn
moon test --target wasm-gc
moon run examples/api-demolet net = @petri.PetriNet::new()
let free = net.add_place("free", 2).unwrap()
let buffer = net.add_place("buffer", 0).unwrap()
let produce = net.add_transition("produce").unwrap()
let consume = net.add_transition("consume").unwrap()
ignore(net.add_input(free, produce, 1).unwrap())
ignore(net.add_output(produce, buffer, 1).unwrap())
ignore(net.add_input(buffer, consume, 1).unwrap())
ignore(net.add_output(consume, free, 1).unwrap())
let result = @petri.reachable(net, net.initial_marking(), 100).unwrap()
let report = @petri.analysis_report(net, result)moon run cmd/moonpetri -- validate examples/producer-consumer.pnml
moon run cmd/moonpetri -- explore examples/traffic-light.pnml
moon run cmd/moonpetri -- report examples/deadlock.pnmlpython scripts/readiness.py --skip-native-runtimepub struct AnalysisReport {
states : Int
edges : Int
deadlocks : Int
truncated : Bool
max_tokens : Int
}pub(all) enum PetriError {
EmptyName
InvalidName
NegativeTokens
InvalidWeight
InvalidPlace
InvalidTransition
InvalidMarking
NotEnabled
InvalidMaxStates
DuplicateName(String)
TokenOverflow
SequenceFailed(Int, Int, PetriError)
ParseError(String)
} derive(Eq, Debug)pub struct PetriNet {
// private fields
}pub struct ReachabilityResult {
edges : Int
truncated : Bool
max_tokens : Int
// private fields
}fn run_command(command : String, input : String, args : Array[String]) -> Result[String, Array[PetriError]]Install
Download zipDeterministic discrete Petri net modeling and reachability analysis for MoonBit
Dependencies