Skip to main content

pictl_types/
models.rs

1use serde::{Deserialize, Serialize};
2
3/// A node in a Directly-Follows Graph
4#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)]
5pub struct DFGNode {
6    pub activity: String,
7    pub frequency: usize,
8}
9
10impl DFGNode {
11    pub fn new(activity: String, frequency: usize) -> Self {
12        DFGNode {
13            activity,
14            frequency,
15        }
16    }
17}
18
19/// An edge in a Directly-Follows Graph
20#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)]
21pub struct DFGEdge {
22    pub source: String,
23    pub target: String,
24    pub frequency: usize,
25}
26
27impl DFGEdge {
28    pub fn new(source: String, target: String, frequency: usize) -> Self {
29        DFGEdge {
30            source,
31            target,
32            frequency,
33        }
34    }
35}
36
37/// A Directly-Follows Graph model
38#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
39pub struct DFG {
40    pub nodes: Vec<DFGNode>,
41    pub edges: Vec<DFGEdge>,
42    pub start_activities: Vec<String>,
43    pub end_activities: Vec<String>,
44}
45
46impl DFG {
47    pub fn new() -> Self {
48        DFG {
49            nodes: Vec::new(),
50            edges: Vec::new(),
51            start_activities: Vec::new(),
52            end_activities: Vec::new(),
53        }
54    }
55
56    pub fn len(&self) -> usize {
57        self.nodes.len()
58    }
59
60    pub fn is_empty(&self) -> bool {
61        self.nodes.is_empty()
62    }
63}
64
65impl Default for DFG {
66    fn default() -> Self {
67        Self::new()
68    }
69}
70
71/// A place in a Petri net
72#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
73pub struct PetriNetPlace {
74    pub id: String,
75    pub label: String,
76    pub initial_marking: usize,
77}
78
79impl PetriNetPlace {
80    pub fn new(id: String, label: String) -> Self {
81        PetriNetPlace {
82            id,
83            label,
84            initial_marking: 0,
85        }
86    }
87}
88
89/// A transition in a Petri net
90#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
91pub struct PetriNetTransition {
92    pub id: String,
93    pub label: String,
94    pub invisible: bool,
95}
96
97impl PetriNetTransition {
98    pub fn new(id: String, label: String, invisible: bool) -> Self {
99        PetriNetTransition {
100            id,
101            label,
102            invisible,
103        }
104    }
105}
106
107/// An arc in a Petri net
108#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
109pub struct PetriNetArc {
110    pub source: String,
111    pub target: String,
112    pub weight: usize,
113}
114
115impl PetriNetArc {
116    pub fn new(source: String, target: String, weight: usize) -> Self {
117        PetriNetArc {
118            source,
119            target,
120            weight,
121        }
122    }
123}
124
125/// A Petri net model
126#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
127pub struct PetriNet {
128    pub places: Vec<PetriNetPlace>,
129    pub transitions: Vec<PetriNetTransition>,
130    pub arcs: Vec<PetriNetArc>,
131}
132
133impl PetriNet {
134    pub fn new() -> Self {
135        PetriNet {
136            places: Vec::new(),
137            transitions: Vec::new(),
138            arcs: Vec::new(),
139        }
140    }
141
142    pub fn len_places(&self) -> usize {
143        self.places.len()
144    }
145
146    pub fn len_transitions(&self) -> usize {
147        self.transitions.len()
148    }
149
150    pub fn is_empty(&self) -> bool {
151        self.places.is_empty() && self.transitions.is_empty()
152    }
153}
154
155impl Default for PetriNet {
156    fn default() -> Self {
157        Self::new()
158    }
159}
160
161/// A Declare constraint
162#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
163pub struct DeclareConstraint {
164    pub constraint_type: String,
165    pub activities: Vec<String>,
166    pub condition: String,
167}
168
169impl DeclareConstraint {
170    pub fn new(constraint_type: String, activities: Vec<String>, condition: String) -> Self {
171        DeclareConstraint {
172            constraint_type,
173            activities,
174            condition,
175        }
176    }
177}
178
179/// A Declare process model
180#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
181pub struct DeclareModel {
182    pub constraints: Vec<DeclareConstraint>,
183    pub activities: Vec<String>,
184}
185
186impl DeclareModel {
187    pub fn new() -> Self {
188        DeclareModel {
189            constraints: Vec::new(),
190            activities: Vec::new(),
191        }
192    }
193}
194
195impl Default for DeclareModel {
196    fn default() -> Self {
197        Self::new()
198    }
199}
200
201#[cfg(test)]
202mod tests {
203    use super::*;
204
205    #[test]
206    fn test_dfg_creation() {
207        let dfg = DFG::new();
208        assert!(dfg.is_empty());
209    }
210
211    #[test]
212    fn test_petri_net_creation() {
213        let pn = PetriNet::new();
214        assert!(pn.is_empty());
215    }
216}