-
Notifications
You must be signed in to change notification settings - Fork 0
/
petri_net.jl
945 lines (653 loc) · 26.6 KB
/
petri_net.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
# =============================================================================
# Creation of type Place for Petri nets
# =============================================================================
struct Place
name::String
type::Symbol
end
"""
place(name::String)
place(name::String, type::Symbol)
Creates an object of type Place for the Petri net object.
Note: acceptable place types are:
:string, :control, :control_init, :counter
Also, note that an input or output place cannot be of type :control.
# Examples
```julia-repl
julia> place("new_place", :string)
Place "new_place" created.
julia> place("in_place", :control)
Place "in_place" with control token created.
```
See also [`transition`](@ref), [`arc`](@ref), [`port`](@ref), [`Workflow_PetriNet`](@ref), [`connect`](@ref), [`remove`](@ref).
"""
function place(name::String, token_type::Symbol=:string)
possible_tokens = [:string, :control, :counter, :control_init]
if !(token_type in possible_tokens)
error("Token type \":$(token_type)\" invalid. Please provide either :string, :control, :control_init, or :counter as a token type.")
end
Place(name, token_type)
end
function Base.show(io::IO, P::Place)
if P.type in [:control, :control_init]
return println(io,"Place \"$(P.name)\" with control token created.")
elseif P.type == :counter
return println(io,"Place \"$(P.name)\" with counter created.")
else
return println(io,"Place \"$(P.name)\" created.")
end
end
# =============================================================================
# Creation of type Transition for Petri nets
# =============================================================================
struct Transition
name::String
condition::String
type::Symbol
exp::Vector
end
"""
transition(name::String)
transition(name::String, condition::String)
Creates an object of type Transition for the Petri net object. If a condition string is given, the the transition is a condiational transition.
Note: the condition and/or expression follows Fortran style expression. The following are possible expressions that can be wrapped in a string:
Comparison expressions: :lt: :le: :gt: :ge: :ne: :eq:
Boolean expressions: :or: :and: :not:
Operations: +, -, *, /, :=
See the example on how to use.
# Examples
```julia-repl
julia> transition("transition1")
Transition "transition1" created.
julia> transition("do_stuff", "counter :eq: 0UL")
A conditional transition "do_stuff" created.
```
See also [`place`](@ref), [`arc`](@ref), [`Workflow_PetriNet`](@ref), [`connect`](@ref), [`remove`](@ref).
"""
function transition(name::String, condition::String="")
Transition(name, condition, :mod, [])
end
"""
transition(name::String, exp::Vector{String})
transition(name::String, exp::Vector{String}, condition::String)
Creates an object of type Transition for the Petri net object containing an expression. If a condition string is given, the the transition is a condiational transition.
Note: the condition and/or expression follows Fortran style expression. The following are possible expressions that can be wrapped in a string:
Comparison expressions: :lt: :le: :gt: :ge: :ne: :eq:
Boolean expressions: :or: :and: :not:
Operations: +, -, *, /, :=
See the example on how to use.
# Examples
```julia-repl
julia> transition("transition1")
Transition "transition1" created.
julia> transition("do_stuff", "counter :eq: 0UL")
A conditional transition "do_stuff" created.
```
See also [`place`](@ref), [`arc`](@ref), [`Workflow_PetriNet`](@ref), [`connect`](@ref), [`remove`](@ref).
"""
function transition(name::String, type::Symbol, exp_str::Vector=[], condition::String="")
if type != :exp
error("Wrong function signature for a module transition. Please use one of the other function signature(s) to create a module transition.")
else
Transition(name, condition, :exp, exp_str)
end
end
# ToDo: Add special transitions with counter, parallel-reduce, and weighted transitions
# """
# parallel_reduce_transition(name::String, condition::String)
# Creates an object of type Transition for the Petri net.
# # Examples
# ```julia-repl
# julia> transition("transition1")
# Transition "transition1" created.
# ```
# See also [`place`](@ref), [`arc`](@ref), [`Workflow_PetriNet`](@ref), [`connect`](@ref), [`remove`](@ref), [`transition`](@ref).
# """
# function parallel_reduce_transition(name::String, condition::String="")
# type = :reduce
# end
# """
# counter_transition(name::String, count::Symbol, n::Int, condition::String)
# Creates an object of type Transition for the Petri net.
# # Examples
# ```julia-repl
# julia> transition("transition1")
# Transition "transition1" created.
# ```
# See also [`place`](@ref), [`arc`](@ref), [`Workflow_PetriNet`](@ref), [`connect`](@ref), [`remove`](@ref), [`reduce_transition`](@ref), [`transition`](@ref).
# """
# function counter_transition(name::String, count::Symbol, n::Int, condition::String="")
# type = :counter
# # count == :up, :down
# end
# """
# weighted_transition(name::String, weight::Int, condition::String)
# Creates an object of type Transition for the Petri net.
# # Examples
# ```julia-repl
# julia> transition("transition1")
# Transition "transition1" created.
# ```
# See also [`place`](@ref), [`arc`](@ref), [`Workflow_PetriNet`](@ref), [`connect`](@ref), [`remove`](@ref), [`reduce_transition`](@ref), [`transition`](@ref).
# """
# function weighted_transition(name::String, weight::Int, condition::String="")
# return Transition(name, condition, Symbol(weight))
# end
"""
conditional_transition(name::String, condition::String)
conditional_transition(name::String, exp::Vector, condition::String)
Creates an object of type Transition for the Petri net.
# Examples
```julia-repl
julia> transition("transition1")
Transition "transition1" created.
```
See also [`place`](@ref), [`arc`](@ref), [`Workflow_PetriNet`](@ref), [`connect`](@ref), [`remove`](@ref), [`transition`](@ref).
"""
# function conditional_transition(name::String, condition::String="")
# t1 = Transition(name, condition, :mod, [])
# neg_cond = string(":not: ", condition)
# t2 = Transition(name, ne_cond, :mod, [])
# return t1, t2
# end
# function conditional_transition(name::String, exp::Vector=[], condition::String="")
# t1 = Transition(name, condition, :exp, exp)
# neg_cond = string(":not: ", condition)
# t2 = Transition(name, ne_cond, :exp, exp)
# return t1, t2
# end
function Base.show(io::IO, T::Transition)
if isempty(T.condition) && T.type == :mod
return println(io,"Transition \"$(T.name)\" created.")
elseif isempty(T.condition) && T.type == :exp
return println(io,"An expression transition \"$(T.name)\" created.")
elseif T.type == :mod
return println(io,"A conditional transition \"$(T.name)\" created.")
else
return println(io,"An expression conditional transition \"$(T.name)\" created.")
end
end
# =============================================================================
# Creation of type Arc for Petri nets
# =============================================================================
struct Arc
place::Place
transition::Transition
type::Symbol
end
"""
arc(place::Place, transition::Transition, type::Symbol)
Creates an object of type Arc that joins a place to a transition in a Petri net.
Note: acceptable arcs are one of the following:
:in, :read, :inout, :out, :out_many
# Examples
```julia-repl
julia> p1 = place("place1", "input_place")
Place "place1" created.
julia> t1 = transition("transition1")
Transition "transition1" created.
julia> arc(p1, t1, :in)
An arc of type "in", connecting the place: place1 to the transition: transition1.
```
See also [`place`](@ref), [`transition`](@ref), [`Workflow_PetriNet`](@ref), [`connect`](@ref), [`remove`](@ref).
"""
function arc(place::Place, transition::Transition, arc_type::Symbol)
possible_arcs = [:in, :read, :inout, :out, :out_many]
if !(arc_type in possible_arcs)
error("Arc type doesn't match any of the types acceptable by the Petri net.\n Please replace the arc type \"$(arc_type)\" with one of the following possible arcs: \n $(possible_arcs).")
end
Arc(place, transition, arc_type)
end
function Base.show(io::IO, A::Arc)
return println(io,"An arc of type \"$(A.type)\", connecting the place: $(A.place.name) to the transition: $(A.transition.name).")
end
# =============================================================================
# Creating ports for Petri nets
# =============================================================================
struct Port
name::String
type::Symbol
place::Place
end
"""
port(type::Symbol, place::Place)
Creates a port connecting to the given place with respect to the arc type.
Note: the allowed port types are one of the following:
:in, :out, :inout
# Examples
```julia-repl
julia> p1 = place("input1", :string)
Place "input1" created.
julia> port(:in, p1)
A port of type "in" connected to place "input1".
```
See also [`place`](@ref), [`Workflow_PetriNet`](@ref), [`connect`](@ref), [`remove`](@ref).
"""
function port(type::Symbol, place::Place)
possible_ports = [:in, :out, :inout]
if !(type in possible_ports)
error("The port type should match one of the following types:\n :in, :out, or :inout.")
end
if !(place.type == :string)
error("Invalid place type. Place needs to be of type :string.")
end
Port(place.name, type, place)
end
function Base.show(io::IO, x::Port)
return println(io,"A port of type \"$(x.type)\" connected to place \"$(x.place.name)\".")
end
# =============================================================================
# Creating Petri nets
# =============================================================================
"""
Workflow_PetriNet(workflow_name::String)
A struct creating an empty Petri net named: "workflow_name". Throws an error, if workflow name is not provided.
Use the `connect()` function to populate the Petri net, and `remove()` function to remove Petri net components.
# Examples
```julia-repl
julia> pn = Workflow_PetriNet("hello_julia")
A Petri net with name "hello_julia", having 0 ports, 0 places, and 0 transitions.
julia> p1 = place("input1", :string)
Place "input1" created.
julia> p2 = place("input2",:string)
Place "input2" created.
julia> p3 = place("output",:string)
Place "output" created.
julia> t = transition("trans")
Transition trans created.
julia> connect(pn, p1, t, :in)
A Petri net with name "hello_julia", having 0 ports, 1 places, and 1 transitions.
julia> connect(pn, p2, t, :read)
A Petri net with name "hello_julia", having 0 ports, 2 places, and 1 transitions.
julia> connect(pn, p3, t, :out_many)
A Petri net with name "hello_julia", having 0 ports, 3 places, and 1 transitions.
julia> connect(pn, p1, :in)
A Petri net with name "hello_julia", having 1 ports, 3 places, and 1 transitions.
julia> connect(pn, :in, p2)
A Petri net with name "hello_julia", having 2 ports, 3 places, and 1 transitions.
julia> connect(pn, :out, p3)
A Petri net with name "hello_julia", having 3 ports, 3 places, and 1 transitions.
```
See also [`place`](@ref), [`transition`](@ref), [`arc`](@ref), [`port`](@ref), [`connect`](@ref), [`remove`](@ref), [`generate_workflow`](@ref), [`compile_workflow`](@ref).
"""
struct Workflow_PetriNet
name::String
places::Vector{Place}
transitions::Vector{Transition}
arcs::Vector{Arc}
ports::Vector{Port}
function Workflow_PetriNet(name::String)
if isempty(name)
error("An empty string as Petri net name is not allowed. Please provide a name for the Petri net.")
end
new(name, [], [], [], [])
end
end
function Base.show(io::IO, Pnet::Workflow_PetriNet)
k = length(Pnet.ports)
n = length(Pnet.places)
m = length(Pnet.transitions)
return println(io,"A Petri net with name \"$(Pnet.name)\", having $k ports, $n places, and $m transitions.")
end
"""
connect(pnet::Workflow_PetriNet, place::Place, transition::Transition, arc_type::Symbol)
connect(pnet::Workflow_PetriNet, transition::Transition, place::Place, arc_type::Symbol)
Given a Petri net connects the place to the transition with the given arc type.
# Examples
```julia-repl
# initiating an empty Petri net.
julia> pn = Workflow_PetriNet("hello_julia")
A Petri net with name "hello_julia", having 0 ports, 0 places, and 0 transitions.
julia> p1 = place("input1", :string)
Place "input1" created.
julia> p2 = place("input2",:string)
Place "input2" created.
julia> p3 = place("output",:string)
Place "output" created.
julia> t = transition("transition1")
Transition "transition1" created.
julia> connect(pn, p1,t, :in)
A Petri net with name "hello_julia", having 0 ports, 1 places, and 1 transitions.
julia> connect(pn, p2,t, :read)
A Petri net with name "hello_julia", having 0 ports, 2 places, and 1 transitions.
julia> connect(pn, p3,t, :out_many)
A Petri net with name "hello_julia", having 0 ports, 3 places, and 1 transitions.
julia> connect(pn, p1, :in)
A Petri net with name "hello_julia", having 1 ports, 3 places, and 1 transitions.
julia> connect(pn, :in, p2)
A Petri net with name "hello_julia", having 2 ports, 3 places, and 1 transitions.
julia> connect(pn, :out, p3)
A Petri net with name "hello_julia", having 3 ports, 3 places, and 1 transitions.
```
See also [`place`](@ref), [`transition`](@ref), [`arc`](@ref), [`port`](@ref), [`Workflow_PetriNet`](@ref), [`remove`](@ref).
"""
function connect(pnet::Workflow_PetriNet, place::Place, transition::Transition, arc_type::Symbol)
connect_arc = arc(place, transition, arc_type)
if !(connect_arc in pnet.arcs)
push!(pnet.arcs, connect_arc)
if !(place in pnet.places)
push!(pnet.places, place)
end
if !(transition in pnet.transitions)
push!(pnet.transitions, transition)
end
end
return pnet
end
connect(pnet::Workflow_PetriNet, transition::Transition, place::Place, arc_type::Symbol) = connect(pnet, place, transition, arc_type)
"""
connect(pnet::Workflow_PetriNet, places_arcs::Vector{Tuple{Place, Symbol}}, transition::Transition)
connect(pnet::Workflow_PetriNet, transition::Transition, places_arcs::Vector{Tuple{Place, Symbol}})
Given a Petri net, connects the vector of tuples (places, arc_types) to the given transition.
# Examples
```julia-repl
julia> pn = Workflow_PetriNet("hello_julia")
A Petri net with name "hello_julia", having 0 ports, 0 places, and 0 transitions.
julia> p1 = place("input1", :string)
Place "input1" created.
julia> p2 = place("input2", :string)
Place "input2" created.
julia> p3 = place("output_result", :string)
Place "output_result" created.
julia> t = transition("initial_transition")
Transition "initial_transition" created.
julia> connect(pn,[(p1, :in),(p2, :read),(p3, :out_many)], t)
A Petri net with name "hello_julia", having 0 ports, 3 places, and 1 transitions.
```
See also [`place`](@ref), [`transition`](@ref), [`arc`](@ref), [`port`](@ref), [`Workflow_PetriNet`](@ref), [`remove`](@ref).
"""
function connect(pnet::Workflow_PetriNet, places_arcs::Vector{Tuple{Place, Symbol}}, transition::Transition)
connect_list = Vector{Arc}()
for (p, a) in places_arcs
connect(pnet, p, transition, a)
end
return pnet
end
connect(pnet::Workflow_PetriNet, transition::Transition, places_arcs::Vector{Tuple{Place, Symbol}}) = connect(pnet, places_arcs, transition)
"""
connect(pnet::Workflow_PetriNet, place::Place, port::Port)
connect(pnet::Workflow_PetriNet, port::Port, place::Place)
Given a Petri net, connects the given place to the given port.
# Examples
```julia-repl
julia> pn = Workflow_PetriNet("hello_julia")
A Petri net with name "hello_julia", having 0 ports, 0 places, and 0 transitions.
julia> p1 = place("input1", :string)
Place "input1" created.
julia> p2 = place("input2", :string)
Place "input2" created.
julia> p3 = place("output_result", :string)
Place "output_result" created.
julia> t = transition("initial_transition")
Transition "initial_transition" created.
julia> connect(pn,[(p1, :in),(p2, :read),(p3, :out_many)], t)
A Petri net with name "hello_julia", having 0 ports, 3 places, and 1 transitions.
julia> connect(pn, p1, :in)
A Petri net with name "hello_julia", having 1 ports, 3 places, and 1 transitions.
julia> connect(pn, p2, :in)
A Petri net with name "hello_julia", having 2 ports, 3 places, and 1 transitions.
julia> connect(pn, p3, :out)
A Petri net with name "hello_julia", having 3 ports, 3 places, and 1 transitions.
```
See also [`place`](@ref), [`transition`](@ref), [`arc`](@ref), [`port`](@ref), [`Workflow_PetriNet`](@ref), [`remove`](@ref).
"""
function connect(pnet::Workflow_PetriNet, place::Place, port::Port)
if !(place in pnet.places)
push!(pnet.places, place)
end
if !(port in pnet.ports)
push!(pnet.ports, port)
end
return pnet
end
connect(pnet::Workflow_PetriNet, port::Port, place::Place) = connect(pnet, place, port)
"""
connect(pnet::Workflow_PetriNet, port_type::Symbol, place::Place)
connect(pnet::Workflow_PetriNet, place::Place, port_type::Symbol)
Given a Petri net, connects the given place to a port of name port_name and type port_type.
# Examples
```julia-repl
julia> pn = Workflow_PetriNet("hello_julia")
A Petri net with name "hello_julia", having 0 ports, 0 places, and 0 transitions.
julia> p1 = place("input1", :string)
Place "input1" created.
julia> p2 = place("input2", :string)
Place "input2" created.
julia> p3 = place("output_result", :string)
Place "output_result" created.
julia> t = transition("initial_transition")
Transition "initial_transition" created.
julia> connect(pn,[(p1, :in),(p2, :read),(p3, :out_many)], t)
A Petri net with name "hello_julia", having 0 ports, 3 places, and 1 transitions.
julia> prt = port(:in, p1)
A port of type "in", connected to place "input1".
julia> connect(pn, p1, prt)
A Petri net with name "hello_julia", having 1 ports, 3 places, and 1 transitions.
```
See also [`place`](@ref), [`transition`](@ref), [`arc`](@ref), [`port`](@ref), [`Workflow_PetriNet`](@ref), [`remove`](@ref).
"""
function connect(pnet::Workflow_PetriNet, port_type::Symbol, place::Place)
pt = port(port_type, place)
return connect(pnet, place, pt)
end
connect(pnet::Workflow_PetriNet, place::Place, port_type::Symbol) = connect(pnet, port_type, place)
"""
connect(pnet::Workflow_PetriNet, place_port::Vector{Tuple{Place, Symbol}})
connect(pnet::Workflow_PetriNet, port_place::Vector{Tuple{Symbol, Place}})
Given a Petri net, connects the given places to a port of name port_name and type port_type.
See also [`place`](@ref), [`transition`](@ref), [`arc`](@ref), [`port`](@ref), [`Workflow_PetriNet`](@ref), [`remove`](@ref).
"""
function connect(pnet::Workflow_PetriNet, place_port::Vector{Tuple{Place, Symbol}})
for (p, s) in place_port
connect(pnet, p, s)
end
return pnet
end
function connect(pnet::Workflow_PetriNet, port_place::Vector{Tuple{Symbol, Place}})
for (s, p) in place_port
connect(pnet, p, s)
end
return pnet
end
"""
remove(pnet::Workflow_PetriNet, place::Place)
Remove the place from the given Petri net.
# Examples
```julia-repl
julia> pn = Workflow_PetriNet("hello_julia")
A Petri net with name "hello_julia", having 0 ports, 0 places, and 0 transitions.
julia> p1 = place("input1", :string)
Place "input1" created.
julia> p2 = place("input2", :string)
Place "input2" created.
julia> p3 = place("output_result", :string)
Place "output_result" created.
julia> t = transition("initial_transition")
Transition "initial_transition" created.
julia> connect(pn,[(p1, :in),(p2, :read),(p3, :out_many)], t)
A Petri net with name "hello_julia", having 0 ports, 3 places, and 1 transitions.
julia> connect(pn, p1, :in)
A Petri net with name "hello_julia", having 1 ports, 3 places, and 1 transitions.
julia> connect(pn, p2, :in)
A Petri net with name "hello_julia", having 2 ports, 3 places, and 1 transitions.
julia> connect(pn, p3, :out)
A Petri net with name "hello_julia", having 3 ports, 3 places, and 1 transitions.
julia> pn.places
3-element Vector{DistributedWorkflows.Place}:
Place "input1" created.
Place "input2" created.
Place "output_result" created.
julia> remove(pn, p1)
A Petri net with name "hello_julia", having 2 ports, 2 places, and 1 transitions.
julia> pn.places
2-element Vector{DistributedWorkflows.Place}:
Place "input2" created.
Place "output_result" created.
```
See also [`place`](@ref), [`transition`](@ref), [`arc`](@ref), [`port`](@ref), [`Workflow_PetriNet`](@ref), [`connect`](@ref).
"""
function remove(pnet::Workflow_PetriNet, place::Place)
if place in pnet.places
deleteat!(pnet.places, findall(x->x==place, pnet.places))
end
arc_list = []
for i in 1:length(pnet.arcs)
arc = pnet.arcs[i]
if place == arc.place
push!(arc_list, arc)
end
end
for a in arc_list
deleteat!(pnet.arcs, findall(x->x==a, pnet.arcs))
end
port_list = []
for i in 1:length(pnet.ports)
prt = pnet.ports[i]
if place == pnet.ports[i].place
push!(port_list, prt)
end
end
for pt in port_list
deleteat!(pnet.ports, findall(x->x==pt, pnet.ports))
end
return pnet
end
"""
remove(pnet::Workflow_PetriNet, transition::Transition)
Remove the transition from the given Petri net.
# Examples
```julia-repl
julia> pn = Workflow_PetriNet("hello_julia")
A Petri net with name "hello_julia", having 0 ports, 0 places, and 0 transitions.
julia> p1 = place("input1", :string)
Place "input1" created.
julia> p2 = place("input2", :string)
Place "input2" created.
julia> p3 = place("output_result", :string)
Place "output_result" created.
julia> t = transition("initial_transition")
Transition "initial_transition" created.
julia> connect(pn,[(p1, :in),(p2, :read),(p3, :out_many)], t)
A Petri net with name "hello_julia", having 0 ports, 3 places, and 1 transitions.
julia> connect(pn, p1, :in)
A Petri net with name "hello_julia", having 1 ports, 3 places, and 1 transitions.
julia> connect(pn, p2, :in)
A Petri net with name "hello_julia", having 2 ports, 3 places, and 1 transitions.
julia> connect(pn, p3, :out)
A Petri net with name "hello_julia", having 3 ports, 3 places, and 1 transitions.
julia> pn.transitions
1-element Vector{DistributedWorkflows.Transition}:
Transition "initial_transition" created.
julia> remove(pn, t)
A Petri net with name "hello_julia", having 2 ports, 2 places, and 0 transitions.
julia> pn.transitions
DistributedWorkflows.Transition[]
```
See also [`place`](@ref), [`transition`](@ref), [`arc`](@ref), [`port`](@ref), [`Workflow_PetriNet`](@ref), [`connect`](@ref).
"""
function remove(pnet::Workflow_PetriNet, transition::Transition)
if transition in pnet.transitions
deleteat!(pnet.transitions, findall(x->x==transition, pnet.transitions))
end
arc_list = []
for i in 1:length(pnet.arcs)
arc = pnet.arcs[i]
if transition == arc.transition
push!(arc_list, arc)
end
end
for a in arc_list
deleteat!(pnet.arcs, findall(x->x==a, pnet.arcs))
end
return pnet
end
"""
remove(pnet::Workflow_PetriNet, arc::Arc)
Remove the arc from the given Petri net.
# Examples
```julia-repl
julia> pn = Workflow_PetriNet("hello_julia")
A Petri net with name "hello_julia", having 0 ports, 0 places, and 0 transitions.
julia> p1 = place("input1", :string)
Place "input1" created.
julia> p2 = place("input2", :string)
Place "input2" created.
julia> p3 = place("output_result", :string)
Place "output_result" created.
julia> t = transition("initial_transition")
Transition "initial_transition" created.
julia> connect(pn,[(p1, :in),(p2, :read),(p3, :out_many)], t)
A Petri net with name "hello_julia", having 0 ports, 3 places, and 1 transitions.
julia> connect(pn, p1, :in)
A Petri net with name "hello_julia", having 1 ports, 3 places, and 1 transitions.
julia> connect(pn, p2, :in)
A Petri net with name "hello_julia", having 2 ports, 3 places, and 1 transitions.
julia> connect(pn, p3, :out)
A Petri net with name "hello_julia", having 3 ports, 3 places, and 1 transitions.
julia> a1 = arc(p1,t,:in)
An arc of type "in", connecting the place: input1 to the transition: initial_transition.
julia> pn.arcs
3-element Vector{DistributedWorkflows.Arc}:
An arc of type "in", connecting the place: input1 to the transition: initial_transition.
An arc of type "read", connecting the place: input2 to the transition: initial_transition.
An arc of type "out_many", connecting the place: output_result to the transition: initial_transition.
julia> remove(pn, a1)
A Petri net with name "hello_julia", having 3 ports, 3 places, and 1 transitions.
julia> pn.arcs
2-element Vector{DistributedWorkflows.Arc}:
An arc of type "read", connecting the place: input2 to the transition: initial_transition.
An arc of type "out_many", connecting the place: output_result to the transition: initial_transition.
```
See also [`place`](@ref), [`transition`](@ref), [`arc`](@ref), [`port`](@ref), [`Workflow_PetriNet`](@ref), [`connect`](@ref).
"""
function remove(pnet::Workflow_PetriNet, arc::Arc)
if arc in pnet.arcs
deleteat!(pnet.arcs, findall(x->x==arc, pnet.arcs))
end
return pnet
end
"""
remove(pnet::Workflow_PetriNet, port::Port)
Remove the port from the given Petri net.
# Examples
```julia-repl
julia> pn = Workflow_PetriNet("hello_julia")
A Petri net with name "hello_julia", having 0 ports, 0 places, and 0 transitions.
julia> p1 = place("input1", :string)
Place "input1" created.
julia> p2 = place("input2", :string)
Place "input2" created.
julia> p3 = place("output_result", :string)
Place "output_result" created.
julia> t = transition("initial_transition")
Transition "initial_transition" created.
julia> connect(pn,[(p1, :in),(p2, :read),(p3, :out_many)], t)
A Petri net with name "hello_julia", having 0 ports, 3 places, and 1 transitions.
julia> connect(pn, p1, :in)
A Petri net with name "hello_julia", having 1 ports, 3 places, and 1 transitions.
julia> connect(pn, p2, :in)
A Petri net with name "hello_julia", having 2 ports, 3 places, and 1 transitions.
julia> connect(pn, p3, :out)
A Petri net with name "hello_julia", having 3 ports, 3 places, and 1 transitions.
julia> pn.ports
3-element Vector{DistributedWorkflows.Port}:
A port of type "in" connected to place "input1".
A port of type "in" connected to place "input2".
A port of type "out" connected to place "output_result".
julia> prt = port(:in, p1)
A port of type "in" connected to place "input1".
julia> remove(pn, prt)
A Petri net with name "hello_julia", having 2 ports, 3 places, and 1 transitions.
julia> pn.ports
2-element Vector{DistributedWorkflows.Port}:
A port of type "in" connected to place "input2".
A port of type "out" connected to place "output_result".
```
See also [`place`](@ref), [`transition`](@ref), [`arc`](@ref), [`port`](@ref), [`Workflow_PetriNet`](@ref), [`connect`](@ref).
"""
function remove(pnet::Workflow_PetriNet, port::Port)
if port in pnet.ports
deleteat!(pnet.ports, findall(x->x==port, pnet.ports))
end
return pnet
end