Skip to content

Commit

Permalink
Clean up the dining philosophers example
Browse files Browse the repository at this point in the history
  • Loading branch information
nxsaken committed Jan 7, 2024
1 parent 00c6fb3 commit 13796a8
Show file tree
Hide file tree
Showing 8 changed files with 175 additions and 190 deletions.
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,4 @@ how I can improve it with time and usage.

## Examples

Check out [this example](examples/simple.rs) demonstrating a simple Petri net in action, as well as [the tests here](src/net.rs) for more Petri net instances.

### More examples:
- [Dining philosophers](examples/dining_philosophers.rs) (demonstrates competing for shared resources, and a deadlock situation)
Examples can be found in the [`examples`](examples) directory.
9 changes: 9 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## Examples

---

Check out [this example](simple.rs) demonstrating a simple Petri net in action, as well as [the tests here](../src/net.rs) for more Petri net instances.

### [Dining philosophers](dining_philosophers.rs)

An interactive demo illustrating competing for shared resources, and a deadlock situation.
325 changes: 154 additions & 171 deletions examples/dining_philosophers.rs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
#![warn(clippy::pedantic)]
#![allow(clippy::module_name_repetitions)]

pub use crate::net::{NetId, Nn, PetriNet};
pub use crate::net::place::{Place, PlaceId, PlaceMetadata, Pn};
pub use crate::net::trans::{Arcs, Tn, Trans, TransId, TransMetadata, W};
pub use crate::net::{NetId, Nn, PetriNet};
pub use crate::plugin::PetriNetPlugin;
pub use crate::token::Token;

Expand Down
6 changes: 2 additions & 4 deletions src/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use educe::Educe;

use crate::net::place::{Place, Places};
use crate::net::trans::{Arcs, Flows, Inflow, Outflow, Trans, TransId, Transitions};
use crate::token::Token;
use crate::PlaceId;
use crate::token::Token;

pub mod place;
pub mod trans;
Expand Down Expand Up @@ -181,9 +181,7 @@ impl<Net: NetId> PetriNet<Net> {

#[cfg(test)]
mod tests {
use super::place::Place;
use super::trans::{Trans, W};
use super::{NetId, PetriNet};
use crate::{NetId, PetriNet, Place, Trans, W};

enum Minimal {}
enum ProdCons {}
Expand Down
5 changes: 3 additions & 2 deletions src/net/place.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
//! Petri net places.
use bevy_utils::StableHashMap;
use educe::Educe;
use std::any::{type_name, TypeId};
use std::borrow::Cow;
use std::marker::PhantomData;

use bevy_utils::StableHashMap;
use educe::Educe;

use crate::net::NetId;

/// Place belonging to a Petri net.
Expand Down
7 changes: 4 additions & 3 deletions src/net/trans.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
//! Petri net transitions.
use bevy_utils::StableHashMap;
use educe::Educe;
use std::any::{type_name, TypeId};
use std::borrow::Cow;
use std::marker::PhantomData;

use crate::net::place::{Place, PlaceId, PlaceMetadata};
use bevy_utils::StableHashMap;
use educe::Educe;

use crate::net::NetId;
use crate::net::place::{Place, PlaceId, PlaceMetadata};

/// Transition belonging to a Petri net.
pub trait Trans<Net: NetId>: Send + Sync + 'static {}
Expand Down
6 changes: 1 addition & 5 deletions src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,7 @@ impl<Net: NetId> Token<Net> {

#[cfg(test)]
mod tests {
use crate::net::trans::{Trans, W};
use crate::net::PetriNet;
use crate::Place;

use super::*;
use crate::{NetId, PetriNet, Place, Trans, W};

enum N0 {}
enum P0 {}
Expand Down

0 comments on commit 13796a8

Please sign in to comment.