petri_net 0.7.1 → 0.7.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/lib/petri_net/net.rb +5 -1
- data/lib/petri_net/place.rb +1 -1
- data/lib/petri_net/reachability_graph/graph.rb +5 -1
- data/lib/petri_net/reachability_graph/node.rb +2 -2
- data/lib/petri_net/version.rb +1 -1
- data/test/reachability_graph/tc_node.rb +0 -4
- data/test/tc_petri_net.rb +64 -21
- metadata +2 -2
- data/Gemfile.lock +0 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fce9fbf19b7836a63649d8b2e2ff923d6b130952
|
4
|
+
data.tar.gz: 0f5a0486c67ede47a093743fe16a1da43b6a5900
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3355739df8da5232040bc7b46b156f4d72ceaff55baba294c55d103c0410a1614920a5ca5afd5b141b1798c8bd1840d4d4b0bc36b40900019c87a9d43ed1bd17
|
7
|
+
data.tar.gz: 5a0a766e885d3dde361311d982a1624284441558ff9d617a62aa026042fa630ac1a95b7c4c5d260f6ceb93d1c67e75f99c75b5b39b08e216019f7c9c8202834e
|
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Gemfile.lock
|
data/lib/petri_net/net.rb
CHANGED
@@ -294,6 +294,10 @@ Arcs
|
|
294
294
|
@net = YAML.load(File.read(filename))
|
295
295
|
end
|
296
296
|
|
297
|
+
def fire transition
|
298
|
+
get_transition(transition).fire
|
299
|
+
end
|
300
|
+
|
297
301
|
private
|
298
302
|
|
299
303
|
def changed_structure
|
@@ -312,7 +316,7 @@ Arcs
|
|
312
316
|
current_node_id = @graph.add_node current_node
|
313
317
|
@graph.add_edge PetriNet::ReachabilityGraph::Edge.new(source: source, destination: current_node, probability: @objects[tid].probability) unless current_node_id < 0
|
314
318
|
if current_node_id < 0 && @graph.get_node(current_node_id * -1) < current_node
|
315
|
-
@graph.
|
319
|
+
@graph.get_node(current_node_id * -1).add_omega current_node
|
316
320
|
end
|
317
321
|
reachability_helper get_markings, current_node unless (current_node_id < 0)
|
318
322
|
end
|
data/lib/petri_net/place.rb
CHANGED
@@ -15,11 +15,14 @@ class PetriNet::ReachabilityGraph < PetriNet::Base
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def add_node(node)
|
18
|
+
double = false
|
18
19
|
@nodes.each_value do |n|
|
19
20
|
begin
|
20
21
|
if node > @objects[n]
|
21
22
|
if @unlimited
|
22
|
-
|
23
|
+
double = n
|
24
|
+
break
|
25
|
+
#return @objects[n].id *-1
|
23
26
|
else
|
24
27
|
raise PetriNet::ReachabilityGraph::InfiniteReachabilityGraphError
|
25
28
|
end
|
@@ -28,6 +31,7 @@ class PetriNet::ReachabilityGraph < PetriNet::Base
|
|
28
31
|
#just two different markings, completly ok
|
29
32
|
end
|
30
33
|
end
|
34
|
+
return (@objects[double].id * -1) if double
|
31
35
|
node_index = @objects.index node
|
32
36
|
if (!node_index.nil?)
|
33
37
|
return @objects[node_index].id * -1
|
@@ -41,11 +41,11 @@ class PetriNet::ReachabilityGraph::Node < PetriNet::Base
|
|
41
41
|
# Add an omega-marking to a specified place
|
42
42
|
def add_omega object
|
43
43
|
if object.class.to_s == "PetriNet::ReachabilityGraph::Node"
|
44
|
-
if self
|
44
|
+
if self < object
|
45
45
|
counter = 0
|
46
46
|
object.markings.each do |marking|
|
47
47
|
if @markings[counter] < marking
|
48
|
-
@markings[counter] =
|
48
|
+
@markings[counter] = Float::INFINITY
|
49
49
|
end
|
50
50
|
counter += 1
|
51
51
|
end
|
data/lib/petri_net/version.rb
CHANGED
@@ -1,12 +1,8 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
1
|
require 'rubygems'
|
4
2
|
require 'logger'
|
5
3
|
require 'test/unit'
|
6
4
|
require "#{File.dirname(__FILE__)}/../../lib/petri_net"
|
7
5
|
|
8
|
-
#require 'pry'
|
9
|
-
|
10
6
|
class TestReachabilityGraphNode < Test::Unit::TestCase
|
11
7
|
def setup
|
12
8
|
@net = PetriNet::Net.new(:name => 'Water', :description => 'Creation of water from base elements.')
|
data/test/tc_petri_net.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
1
|
require 'rubygems'
|
4
2
|
require 'logger'
|
5
3
|
require 'test/unit'
|
@@ -24,6 +22,62 @@ class TestPetriNet < Test::Unit::TestCase
|
|
24
22
|
@net << arc
|
25
23
|
end
|
26
24
|
|
25
|
+
def complex_net
|
26
|
+
@net << PetriNet::Place.new(:name => "P1")
|
27
|
+
@net << PetriNet::Place.new(:name => "P2")
|
28
|
+
@net << PetriNet::Place.new(:name => "C1")
|
29
|
+
@net << PetriNet::Place.new(:name => "C2")
|
30
|
+
@net << PetriNet::Place.new(:name => "buffer")
|
31
|
+
@net << PetriNet::Transition.new(:name => "produce")
|
32
|
+
@net << PetriNet::Transition.new(:name => "consume")
|
33
|
+
@net << PetriNet::Transition.new(:name => "put")
|
34
|
+
@net << PetriNet::Transition.new(:name => "take")
|
35
|
+
@net << PetriNet::Arc.new do |a|
|
36
|
+
a.add_source(@net.get_place 'P1')
|
37
|
+
a.add_destination(@net.get_transition 'produce')
|
38
|
+
end
|
39
|
+
@net << PetriNet::Arc.new do |a|
|
40
|
+
a.add_source(@net.get_transition 'produce')
|
41
|
+
a.add_destination(@net.get_place 'P2')
|
42
|
+
end
|
43
|
+
@net << PetriNet::Arc.new do |a|
|
44
|
+
a.add_source(@net.get_place 'P2')
|
45
|
+
a.add_destination(@net.get_transition 'put')
|
46
|
+
end
|
47
|
+
@net << PetriNet::Arc.new do |a|
|
48
|
+
a.add_source(@net.get_transition 'put')
|
49
|
+
a.add_destination(@net.get_place 'P1')
|
50
|
+
end
|
51
|
+
@net << PetriNet::Arc.new do |a|
|
52
|
+
a.add_source(@net.get_transition 'put')
|
53
|
+
a.add_destination(@net.get_place 'buffer')
|
54
|
+
end
|
55
|
+
@net << PetriNet::Arc.new do |a|
|
56
|
+
a.add_source(@net.get_place 'buffer')
|
57
|
+
a.add_destination(@net.get_transition 'take')
|
58
|
+
end
|
59
|
+
@net << PetriNet::Arc.new do |a|
|
60
|
+
a.add_source(@net.get_transition 'take')
|
61
|
+
a.add_destination(@net.get_place 'C1')
|
62
|
+
end
|
63
|
+
@net << PetriNet::Arc.new do |a|
|
64
|
+
a.add_source(@net.get_place 'C1')
|
65
|
+
a.add_destination(@net.get_transition 'consume')
|
66
|
+
end
|
67
|
+
@net << PetriNet::Arc.new do |a|
|
68
|
+
a.add_source(@net.get_transition 'consume')
|
69
|
+
a.add_destination(@net.get_place 'C2')
|
70
|
+
end
|
71
|
+
@net << PetriNet::Arc.new do |a|
|
72
|
+
a.add_source(@net.get_place 'C2')
|
73
|
+
a.add_destination(@net.get_transition 'take')
|
74
|
+
end
|
75
|
+
|
76
|
+
@net.get_place('P1').add_marking
|
77
|
+
@net.get_place('buffer').add_marking
|
78
|
+
@net.get_place('C2').add_marking
|
79
|
+
end
|
80
|
+
|
27
81
|
def teardown
|
28
82
|
@net.reset
|
29
83
|
end
|
@@ -43,6 +97,13 @@ class TestPetriNet < Test::Unit::TestCase
|
|
43
97
|
assert_empty net.get_markings, "No Places should mean no markings..."
|
44
98
|
end
|
45
99
|
|
100
|
+
def test_complex_net
|
101
|
+
complex_net
|
102
|
+
assert_equal "Petri Net [Water]\n----------------------------\nDescription: Creation of water from base elements.\nFilename: Water\n\nPlaces\n----------------------------\n1: P1 (0) *\n2: P2 (0) \n3: C1 (0) \n4: C2 (0) *\n5: buffer (0) *\n\nTransitions\n----------------------------\n6: produce\n7: consume\n8: put\n9: take\n\nArcs\n----------------------------\n10: Arc10 (1) 1 -> 6\n11: Arc11 (1) 6 -> 2\n12: Arc12 (1) 2 -> 8\n13: Arc13 (1) 8 -> 1\n14: Arc14 (1) 8 -> 5\n15: Arc15 (1) 5 -> 9\n16: Arc16 (1) 9 -> 3\n17: Arc17 (1) 3 -> 7\n18: Arc18 (1) 7 -> 4\n19: Arc19 (1) 4 -> 9\n\n", @net.to_s
|
103
|
+
assert_equal "digraph Water {\n\t// General graph options\n\trankdir = LR;\n\tsize = \"10.5,7.5\";\n\tnode [ style = filled, fillcolor = white, fontsize = 8.0 ]\n\tedge [ arrowhead = vee, arrowsize = 0.5, fontsize = 8.0 ]\n\n\t// Places\n\tnode [ shape = circle ];\n\tP1 [ label = \"P1 1 \" ];\n\tP2 [ label = \"P2 0 \" ];\n\tP3 [ label = \"C1 0 \" ];\n\tP4 [ label = \"C2 1 \" ];\n\tP5 [ label = \"buffer 1 \" ];\n\n\t// Transitions\n\tnode [ shape = box, fillcolor = grey90 ];\n\tT6 [ label = \"produce\" ];\n\tT7 [ label = \"consume\" ];\n\tT8 [ label = \"put\" ];\n\tT9 [ label = \"take\" ];\n\n\t// Arcs\n\tP1 -> T6 [ label = \"Arc10\", headlabel = \"1\" ];\n\tT6 -> P2 [ label = \"Arc11\", headlabel = \"1\" ];\n\tP2 -> T8 [ label = \"Arc12\", headlabel = \"1\" ];\n\tT8 -> P1 [ label = \"Arc13\", headlabel = \"1\" ];\n\tT8 -> P5 [ label = \"Arc14\", headlabel = \"1\" ];\n\tP5 -> T9 [ label = \"Arc15\", headlabel = \"1\" ];\n\tT9 -> P3 [ label = \"Arc16\", headlabel = \"1\" ];\n\tP3 -> T7 [ label = \"Arc17\", headlabel = \"1\" ];\n\tT7 -> P4 [ label = \"Arc18\", headlabel = \"1\" ];\n\tP4 -> T9 [ label = \"Arc19\", headlabel = \"1\" ];\n}\n", @net.to_gv
|
104
|
+
assert_equal "digraph Water {\n\t// General graph options\n\trankdir = LR;\n\tsize = \"10.5,7.5\";\n\tnode [ style = filled, fillcolor = white, fontsize = 8.0 ]\n\tedge [ arrowhead = vee, arrowsize = 0.5, fontsize = 8.0 ]\n\n\t// Nodes\n\tnode [ shape = circle ];\n\tN20 [ label = \"[1, 0, 0, 1, Infinity]\" ];\n\tN21 [ label = \"[0, 1, 0, 1, 1]\" ];\n\tN24 [ label = \"[0, 1, 1, 0, 0]\" ];\n\tN26 [ label = \"[0, 1, 0, 1, Infinity]\" ];\n\tN28 [ label = \"[1, 0, 0, 1, 1]\" ];\n\tN31 [ label = \"[1, 0, 1, 0, Infinity]\" ];\n\tN34 [ label = \"[1, 0, 0, 1, Infinity]\" ];\n\tN36 [ label = \"[0, 1, 0, 1, 0]\" ];\n\tN40 [ label = \"[1, 0, 1, 0, 0]\" ];\n\tN43 [ label = \"[1, 0, 0, 1, 0]\" ];\n\n\t// Edges\n\tN20 -> N21;\n\tN21 -> N24;\n\tN24 -> N26;\n\tN26 -> N28;\n\tN28 -> N31;\n\tN31 -> N34;\n\tN34 -> N36;\n\tN20 -> N40;\n\tN40 -> N43;\n}\n", @net.generate_reachability_graph.to_gv
|
105
|
+
end
|
106
|
+
|
46
107
|
def test_add_place
|
47
108
|
# Create the place
|
48
109
|
place = PetriNet::Place.new(:name => 'Hydrogen')
|
@@ -176,25 +237,7 @@ class TestPetriNet < Test::Unit::TestCase
|
|
176
237
|
a.add_destination(net2.get_transition 'testtrans')
|
177
238
|
end
|
178
239
|
net2 << arc
|
179
|
-
assert_equal "Petri Net [Water]
|
180
|
-
----------------------------
|
181
|
-
Description: Creation of water from base elements.
|
182
|
-
Filename: Water
|
183
|
-
|
184
|
-
Places
|
185
|
-
----------------------------
|
186
|
-
1: testplace (0)
|
187
|
-
4: testplace2 (0)
|
188
|
-
|
189
|
-
Transitions
|
190
|
-
----------------------------
|
191
|
-
2: testtrans
|
192
|
-
|
193
|
-
Arcs
|
194
|
-
----------------------------
|
195
|
-
3: testarc (2) 1 -> 2
|
196
|
-
|
197
|
-
", @net.merge(net2).to_s, "Merge failed, this is only a basic test"
|
240
|
+
assert_equal "Petri Net [Water]\n----------------------------\nDescription: Creation of water from base elements.\nFilename: Water\n\nPlaces\n----------------------------\n1: testplace (0) \n4: testplace2 (0) \n\nTransitions\n----------------------------\n2: testtrans\n\nArcs\n----------------------------\n3: testarc (2) 1 -> 2\n\n", @net.merge(net2).to_s, "Merge failed, this is only a basic test"
|
198
241
|
end
|
199
242
|
|
200
243
|
def test_generate_reachability_graph
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: petri_net
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- cclausen
|
@@ -31,11 +31,11 @@ executables: []
|
|
31
31
|
extensions: []
|
32
32
|
extra_rdoc_files: []
|
33
33
|
files:
|
34
|
+
- .gitignore
|
34
35
|
- .ruby-version
|
35
36
|
- .travis.yml
|
36
37
|
- CHANGELOG
|
37
38
|
- Gemfile
|
38
|
-
- Gemfile.lock
|
39
39
|
- LICENSE
|
40
40
|
- README.rdoc
|
41
41
|
- Rakefile
|
data/Gemfile.lock
DELETED