Skip to content

Commit

Permalink
Clean up the dining philosophers example
Browse files Browse the repository at this point in the history
nxsaken committed Jan 7, 2024
1 parent 00c6fb3 commit 496e7b9
Showing 7 changed files with 170 additions and 187 deletions.
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
7 changes: 7 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## 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.

4 changes: 1 addition & 3 deletions src/net.rs
Original file line number Diff line number Diff line change
@@ -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 {}
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.
5 changes: 3 additions & 2 deletions src/net/trans.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
//! 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 bevy_utils::StableHashMap;
use educe::Educe;

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

6 changes: 1 addition & 5 deletions src/token.rs
Original file line number Diff line number Diff line change
@@ -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 {}

0 comments on commit 496e7b9

Please sign in to comment.