petri_net 0.7.2 → 0.7.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/petri_net/arc.rb +8 -2
- data/lib/petri_net/coverability_graph/edge.rb +13 -0
- data/lib/petri_net/coverability_graph/graph.rb +54 -0
- data/lib/petri_net/coverability_graph/node.rb +127 -0
- data/lib/petri_net/coverability_graph.rb +6 -0
- data/lib/petri_net/graph/edge.rb +57 -0
- data/lib/petri_net/graph/graph.rb +108 -0
- data/lib/petri_net/graph/node.rb +129 -0
- data/lib/petri_net/graph.rb +5 -0
- data/lib/petri_net/net.rb +84 -11
- data/lib/petri_net/place.rb +15 -2
- data/lib/petri_net/reachability_graph/edge.rb +3 -40
- data/lib/petri_net/reachability_graph/graph.rb +11 -105
- data/lib/petri_net/reachability_graph/node.rb +6 -112
- data/lib/petri_net/reachability_graph.rb +3 -94
- data/lib/petri_net/transition.rb +16 -2
- data/lib/petri_net/version.rb +2 -2
- data/lib/petri_net.rb +9 -8
- data/petri_net.gemspec +3 -2
- data/test/reachability_graph/tc_graph.rb +124 -0
- data/test/tc_petri_net.rb +4 -1
- metadata +39 -3
data/lib/petri_net/place.rb
CHANGED
@@ -33,12 +33,12 @@ class PetriNet::Place < PetriNet::Base
|
|
33
33
|
|
34
34
|
# Add an input arc
|
35
35
|
def add_input(arc)
|
36
|
-
@inputs << arc.id unless arc.nil?
|
36
|
+
@inputs << arc.id unless (arc.nil? or !validate_input arc)
|
37
37
|
end
|
38
38
|
|
39
39
|
# Add an output arc
|
40
40
|
def add_output(arc)
|
41
|
-
@outputs << arc.id unless arc.nil?
|
41
|
+
@outputs << arc.id unless (arc.nil? or !validate_input arc)
|
42
42
|
end
|
43
43
|
|
44
44
|
def add_marking(count = 1)
|
@@ -107,4 +107,17 @@ class PetriNet::Place < PetriNet::Base
|
|
107
107
|
return true if name == object.name && description = object.description
|
108
108
|
end
|
109
109
|
|
110
|
+
private
|
111
|
+
def validate_input(arc)
|
112
|
+
self.inputs.each do |a|
|
113
|
+
return false if ((@net.get_objects[a] <=> arc) == 0)
|
114
|
+
end
|
115
|
+
true
|
116
|
+
end
|
117
|
+
def validate_output(arc)
|
118
|
+
self.outputs.each do |a|
|
119
|
+
return false if ((@net.get_objects[a] <=> arc) == 0)
|
120
|
+
end
|
121
|
+
true
|
122
|
+
end
|
110
123
|
end
|
@@ -1,50 +1,13 @@
|
|
1
|
-
class PetriNet::ReachabilityGraph::Edge < PetriNet::
|
2
|
-
# Human readable name
|
3
|
-
attr_reader :name
|
4
|
-
# Unique ID
|
5
|
-
attr_reader :id
|
6
|
-
# Graph this edge belongs to
|
7
|
-
attr_accessor :graph
|
8
|
-
# Probability of the relating transition
|
9
|
-
attr_accessor :probability
|
10
|
-
|
1
|
+
class PetriNet::ReachabilityGraph::Edge < PetriNet::Graph::Edge
|
11
2
|
# Creates an edge for PetriNet::ReachabilityGraph
|
12
3
|
def initialize(options = {}, &block)
|
13
|
-
|
14
|
-
@name = (options[:name] or "Edge#{@id}")
|
15
|
-
@description = (options[:description] or "Edge #{@id}")
|
16
|
-
@source = options[:source]
|
17
|
-
@destination = options[:destination]
|
18
|
-
@label = (options[:label] or @name)
|
19
|
-
@probability = options[:probability]
|
20
|
-
|
4
|
+
super(options)
|
21
5
|
yield self unless block.nil?
|
22
6
|
end
|
23
7
|
|
24
8
|
# Validates the data holded by this edge, this will be used while adding the edge to the graph
|
25
9
|
def validate
|
26
|
-
|
27
|
-
end
|
28
|
-
|
29
|
-
def to_gv
|
30
|
-
"\t#{@source.gv_id} -> #{@destination.gv_id}#{probability_to_gv};\n"
|
31
|
-
end
|
32
|
-
|
33
|
-
def ==(object)
|
34
|
-
return false unless object.class.to_s == "PetriNet::ReachabilityGraph::Edge"
|
35
|
-
(@source == object.yource && @destination == oject.destination)
|
36
|
-
end
|
37
|
-
def to_s
|
38
|
-
"#{@id}: #{@name} #{@source.id} -> #{@destination} )"
|
39
|
-
end
|
40
|
-
|
41
|
-
private
|
42
|
-
def probability_to_gv
|
43
|
-
if @probability
|
44
|
-
" [ label = \"#{@probability.to_s}\" ] "
|
45
|
-
else
|
46
|
-
''
|
47
|
-
end
|
10
|
+
super
|
48
11
|
end
|
49
12
|
|
50
13
|
end
|
@@ -1,122 +1,28 @@
|
|
1
|
-
|
2
|
-
end
|
1
|
+
require 'graphviz'
|
3
2
|
|
4
|
-
class PetriNet::ReachabilityGraph < PetriNet::
|
3
|
+
class PetriNet::ReachabilityGraph < PetriNet::Graph
|
5
4
|
def initialize(net, options = Hash.new)
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
@name = net.name
|
10
|
-
if options['unlimited'].nil?
|
11
|
-
@unlimited = true
|
12
|
-
else
|
13
|
-
@unlimited = options['unlimited']
|
14
|
-
end
|
5
|
+
options[:type] = "Reachability"
|
6
|
+
super(net, options)
|
7
|
+
self
|
15
8
|
end
|
16
9
|
|
17
10
|
def add_node(node)
|
18
|
-
double = false
|
19
11
|
@nodes.each_value do |n|
|
20
12
|
begin
|
21
|
-
if
|
22
|
-
|
23
|
-
double = n
|
24
|
-
break
|
25
|
-
#return @objects[n].id *-1
|
26
|
-
else
|
27
|
-
raise PetriNet::ReachabilityGraph::InfiniteReachabilityGraphError
|
28
|
-
end
|
13
|
+
if @objects[n] < node
|
14
|
+
raise PetriNet::InfiniteReachabilityGraphError
|
29
15
|
end
|
30
16
|
rescue ArgumentError
|
31
|
-
#
|
17
|
+
#Just an InfiniteNode
|
32
18
|
end
|
33
|
-
end
|
34
|
-
return (@objects[double].id * -1) if double
|
35
|
-
node_index = @objects.index node
|
36
|
-
if (!node_index.nil?)
|
37
|
-
return @objects[node_index].id * -1
|
38
|
-
end
|
39
|
-
|
40
|
-
if (node.validate && (!@nodes.include? node.name))
|
41
|
-
@objects[node.id] = node
|
42
|
-
@nodes[node.name] = node.id
|
43
|
-
node.graph = self
|
44
|
-
return node.id
|
45
|
-
end
|
46
|
-
return false
|
47
|
-
end
|
48
|
-
|
49
|
-
def add_edge(edge)
|
50
|
-
if (edge.validate && (!@edges.include? edge.name))
|
51
|
-
@objects[edge.id] = edge
|
52
|
-
@edges[edge.name] = edge.id
|
53
|
-
edge.graph = self
|
54
|
-
return edge.id
|
55
|
-
end
|
56
|
-
return false
|
57
|
-
end
|
58
19
|
|
59
|
-
# Add an object to the Petri Net.
|
60
|
-
def <<(object)
|
61
|
-
case object.class.to_s
|
62
|
-
when "Array"
|
63
|
-
object.each {|o| self << o}
|
64
|
-
when "PetriNet::ReachabilityGraph::Edge"
|
65
|
-
add_edge(object)
|
66
|
-
when "PetriNet::ReachabilityGraph::Node"
|
67
|
-
add_node(object)
|
68
|
-
else
|
69
|
-
raise "(PetriNet::ReachabilityGraph) Unknown object #{object.class}."
|
70
20
|
end
|
71
|
-
|
21
|
+
super node
|
72
22
|
end
|
73
|
-
alias_method :add_object, :<<
|
74
|
-
|
75
|
-
def get_node(id)
|
76
|
-
return @objects[id]
|
77
|
-
end
|
78
|
-
|
79
|
-
def to_gv
|
80
|
-
# General graph options
|
81
|
-
str = "digraph #{@name} {\n"
|
82
|
-
str += "\t// General graph options\n"
|
83
|
-
str += "\trankdir = LR;\n"
|
84
|
-
str += "\tsize = \"10.5,7.5\";\n"
|
85
|
-
str += "\tnode [ style = filled, fillcolor = white, fontsize = 8.0 ]\n"
|
86
|
-
str += "\tedge [ arrowhead = vee, arrowsize = 0.5, fontsize = 8.0 ]\n"
|
87
|
-
str += "\n"
|
88
|
-
|
89
|
-
str += "\t// Nodes\n"
|
90
|
-
str += "\tnode [ shape = circle ];\n"
|
91
|
-
@nodes.each_value {|id| str += @objects[id].to_gv }
|
92
|
-
str += "\n"
|
93
|
-
|
94
|
-
str += "\t// Edges\n"
|
95
|
-
@edges.each_value {|id| str += @objects[id].to_gv }
|
96
|
-
str += "}\n" # Graph closure
|
97
|
-
|
98
|
-
return str
|
99
|
-
|
100
|
-
end
|
101
|
-
|
102
|
-
def to_s
|
103
|
-
str = "Reachability Graph [#{@name}]\n"
|
104
|
-
str += "----------------------------\n"
|
105
|
-
str += "Description: #{@description}\n"
|
106
|
-
str += "Filename: #{@filename}\n"
|
107
|
-
str += "\n"
|
108
|
-
|
109
|
-
str += "Nodes\n"
|
110
|
-
str += "----------------------------\n"
|
111
|
-
@nodes.each_value {|p| str += @objects[p].to_s + "\n" }
|
112
|
-
str += "\n"
|
113
|
-
|
114
|
-
str += "Edges\n"
|
115
|
-
str += "----------------------------\n"
|
116
|
-
@edges.each_value {|t| str += @objects[t].to_s + "\n" }
|
117
|
-
str += "\n"
|
118
23
|
|
119
|
-
|
24
|
+
def add_node!(node)
|
25
|
+
super node
|
120
26
|
end
|
121
27
|
|
122
28
|
end
|
@@ -1,119 +1,13 @@
|
|
1
|
-
class PetriNet::ReachabilityGraph::Node < PetriNet::
|
2
|
-
include Comparable
|
3
|
-
|
4
|
-
# human readable name
|
5
|
-
attr_reader :name
|
6
|
-
# unique ID
|
7
|
-
attr_reader :id
|
8
|
-
# Makking this node represents
|
9
|
-
attr_reader :markings
|
10
|
-
# The graph this node belongs to
|
11
|
-
attr_accessor :graph
|
12
|
-
# Omega-marked node (unlimited Petrinet -> coverabilitygraph)
|
13
|
-
attr_reader :omega_marked
|
14
|
-
# Incoming edges
|
15
|
-
attr_reader :inputs
|
16
|
-
# Outgoing edges
|
17
|
-
attr_reader :outputs
|
18
|
-
# Label of the node
|
19
|
-
attr_reader :label
|
20
|
-
|
1
|
+
class PetriNet::ReachabilityGraph::Node < PetriNet::Graph::Node
|
21
2
|
def initialize(options = {}, &block)
|
22
|
-
|
23
|
-
@name = (options[:name] or "Node#{@id}")
|
24
|
-
@description = (options[:description] or "Node #{@id}")
|
25
|
-
@inputs = Array.new
|
26
|
-
@outputs = Array.new
|
27
|
-
@label = (options[:label] or @name)
|
28
|
-
@markings = options[:markings]
|
29
|
-
if @markings.nil?
|
30
|
-
raise ArgumentError.new "Every Node needs markings"
|
31
|
-
end
|
32
|
-
if @markings.include? Float::INFINITY
|
33
|
-
@omega_marked = true
|
34
|
-
else
|
35
|
-
@omega_marked = false
|
36
|
-
end
|
37
|
-
|
3
|
+
super(options)
|
38
4
|
yield self unless block.nil?
|
39
5
|
end
|
40
6
|
|
41
|
-
|
42
|
-
def add_omega object
|
43
|
-
if object.class.to_s == "PetriNet::ReachabilityGraph::Node"
|
44
|
-
if self < object
|
45
|
-
counter = 0
|
46
|
-
object.markings.each do |marking|
|
47
|
-
if @markings[counter] < marking
|
48
|
-
@markings[counter] = Float::INFINITY
|
49
|
-
end
|
50
|
-
counter += 1
|
51
|
-
end
|
52
|
-
else
|
53
|
-
return false
|
54
|
-
end
|
55
|
-
elsif object.class.to_s == "Array"
|
56
|
-
object.each do |place|
|
57
|
-
markings[place] = Float::INFINITY
|
58
|
-
end
|
59
|
-
elsif object.class.to_s == "Fixnum"
|
60
|
-
markings[object] = Float::INFINITY
|
61
|
-
end
|
62
|
-
@omega_marked = true
|
63
|
-
end
|
64
|
-
|
65
|
-
def validate
|
66
|
-
true
|
67
|
-
end
|
68
|
-
|
69
|
-
def gv_id
|
70
|
-
"N#{@id}"
|
71
|
-
end
|
72
|
-
|
73
|
-
def to_gv
|
74
|
-
"\t#{self.gv_id} [ label = \"#{@markings}\" ];\n"
|
75
|
-
end
|
76
|
-
|
77
|
-
# Compare-operator, other Operators are available through comparable-mixin
|
78
|
-
def <=>(object)
|
79
|
-
return nil unless object.class.to_s == "PetriNet::ReachabilityGraph::Node"
|
80
|
-
if @markings == object.markings
|
81
|
-
return 0
|
82
|
-
end
|
83
|
-
|
84
|
-
counter = 0
|
85
|
-
less = true
|
86
|
-
self.markings.each do |marking|
|
87
|
-
if marking <= object.markings[counter] && less
|
88
|
-
less = true
|
89
|
-
else
|
90
|
-
less = false
|
91
|
-
break
|
92
|
-
end
|
93
|
-
counter += 1
|
94
|
-
end
|
95
|
-
if less
|
96
|
-
return -1
|
97
|
-
end
|
98
|
-
counter = 0
|
99
|
-
more = true
|
100
|
-
self.markings.each do |marking|
|
101
|
-
if marking >= object.markings[counter] && more
|
102
|
-
more = true
|
103
|
-
else
|
104
|
-
more = false
|
105
|
-
break
|
106
|
-
end
|
107
|
-
counter += 1
|
108
|
-
end
|
109
|
-
if more
|
110
|
-
return 1
|
111
|
-
end
|
112
|
-
return nil
|
113
|
-
end
|
7
|
+
end
|
114
8
|
|
115
|
-
|
116
|
-
|
9
|
+
class PetriNet::ReachabilityGraph::InfinityNode < PetriNet::ReachabilityGraph::Node
|
10
|
+
def initialize()
|
11
|
+
super(markings: [Float::INFINITY])
|
117
12
|
end
|
118
|
-
|
119
13
|
end
|
@@ -1,97 +1,6 @@
|
|
1
|
+
require_relative 'graph'
|
1
2
|
require_relative 'reachability_graph/graph'
|
2
3
|
require_relative 'reachability_graph/node'
|
3
4
|
require_relative 'reachability_graph/edge'
|
4
|
-
class PetriNet::ReachabilityGraph < PetriNet::Base
|
5
|
-
|
6
|
-
def initialize(net)
|
7
|
-
@objects = Array.new
|
8
|
-
@nodes = Hash.new
|
9
|
-
@edges = Hash.new
|
10
|
-
@name = net.name
|
11
|
-
end
|
12
|
-
|
13
|
-
def add_node(node)
|
14
|
-
node_index = @objects.index node
|
15
|
-
if (!node_index.nil?)
|
16
|
-
return @objects[node_index].id * -1
|
17
|
-
end
|
18
|
-
|
19
|
-
if (node.validate && (!@nodes.include? node.name))
|
20
|
-
@objects[node.id] = node
|
21
|
-
@nodes[node.name] = node.id
|
22
|
-
node.graph = self
|
23
|
-
return node.id
|
24
|
-
end
|
25
|
-
return false
|
26
|
-
end
|
27
|
-
|
28
|
-
def add_edge(edge)
|
29
|
-
if (edge.validate && (!@edges.include? edge.name))
|
30
|
-
@objects[edge.id] = edge
|
31
|
-
@edges[edge.name] = edge.id
|
32
|
-
edge.graph = self
|
33
|
-
return edge.id
|
34
|
-
end
|
35
|
-
return false
|
36
|
-
end
|
37
|
-
|
38
|
-
# Add an object to the Petri Net.
|
39
|
-
def <<(object)
|
40
|
-
case object.class.to_s
|
41
|
-
when "Array"
|
42
|
-
object.each {|o| self << o}
|
43
|
-
when "PetriNet::ReachabilityGraph::Edge"
|
44
|
-
add_edge(object)
|
45
|
-
when "PetriNet::ReachabilityGraph::Node"
|
46
|
-
add_node(object)
|
47
|
-
else
|
48
|
-
raise "(PetriNet::ReachabilityGraph) Unknown object #{object.class}."
|
49
|
-
end
|
50
|
-
self
|
51
|
-
end
|
52
|
-
alias_method :add_object, :<<
|
53
|
-
|
54
|
-
def to_gv
|
55
|
-
# General graph options
|
56
|
-
str = "digraph #{@name} {\n"
|
57
|
-
str += "\t// General graph options\n"
|
58
|
-
str += "\trankdir = LR;\n"
|
59
|
-
str += "\tsize = \"10.5,7.5\";\n"
|
60
|
-
str += "\tnode [ style = filled, fillcolor = white, fontsize = 8.0 ]\n"
|
61
|
-
str += "\tedge [ arrowhead = vee, arrowsize = 0.5, fontsize = 8.0 ]\n"
|
62
|
-
str += "\n"
|
63
|
-
|
64
|
-
str += "\t// Nodes\n"
|
65
|
-
str += "\tnode [ shape = circle ];\n"
|
66
|
-
@nodes.each_value {|id| str += @objects[id].to_gv }
|
67
|
-
str += "\n"
|
68
|
-
|
69
|
-
str += "\t// Edges\n"
|
70
|
-
@edges.each_value {|id| str += @objects[id].to_gv }
|
71
|
-
str += "}\n" # Graph closure
|
72
|
-
|
73
|
-
return str
|
74
|
-
|
75
|
-
end
|
76
|
-
|
77
|
-
def to_s
|
78
|
-
str = "Reachability Graph [#{@name}]\n"
|
79
|
-
str += "----------------------------\n"
|
80
|
-
str += "Description: #{@description}\n"
|
81
|
-
str += "Filename: #{@filename}\n"
|
82
|
-
str += "\n"
|
83
|
-
|
84
|
-
str += "Nodes\n"
|
85
|
-
str += "----------------------------\n"
|
86
|
-
@nodes.each_value {|p| str += @objects[p].to_s + "\n" }
|
87
|
-
str += "\n"
|
88
|
-
|
89
|
-
str += "Edges\n"
|
90
|
-
str += "----------------------------\n"
|
91
|
-
@edges.each_value {|t| str += @objects[t].to_s + "\n" }
|
92
|
-
str += "\n"
|
93
|
-
|
94
|
-
return str
|
95
|
-
end
|
96
|
-
=end
|
97
|
-
end
|
5
|
+
#class PetriNet::ReachabilityGraph < PetriNet::Base
|
6
|
+
#end
|
data/lib/petri_net/transition.rb
CHANGED
@@ -30,12 +30,12 @@ module PetriNet
|
|
30
30
|
|
31
31
|
# Add an input arc
|
32
32
|
def add_input(arc)
|
33
|
-
@inputs << arc.id unless arc.nil?
|
33
|
+
@inputs << arc.id unless (arc.nil? or !validate_input arc)
|
34
34
|
end
|
35
35
|
|
36
36
|
# Add an output arc
|
37
37
|
def add_output(arc)
|
38
|
-
@outputs << arc.id unless arc.nil?
|
38
|
+
@outputs << arc.id unless (arc.nil? or !validate_output arc)
|
39
39
|
end
|
40
40
|
|
41
41
|
# GraphViz ID
|
@@ -108,5 +108,19 @@ module PetriNet
|
|
108
108
|
end
|
109
109
|
true
|
110
110
|
end
|
111
|
+
|
112
|
+
private
|
113
|
+
def validate_input(arc)
|
114
|
+
self.inputs.each do |a|
|
115
|
+
return false if ((@net.get_objects[a] <=> arc) == 0)
|
116
|
+
end
|
117
|
+
true
|
118
|
+
end
|
119
|
+
def validate_output(arc)
|
120
|
+
self.outputs.each do |a|
|
121
|
+
return false if ((@net.get_objects[a] <=> arc) == 0)
|
122
|
+
end
|
123
|
+
true
|
124
|
+
end
|
111
125
|
end
|
112
126
|
end
|
data/lib/petri_net/version.rb
CHANGED
data/lib/petri_net.rb
CHANGED
@@ -23,11 +23,12 @@
|
|
23
23
|
# This library provides a way to represent petri nets in ruby and do some algorithms on them as generating the Reachability Graph.
|
24
24
|
|
25
25
|
# Holds the path of the base-file petri_net.rb
|
26
|
-
|
27
|
-
require "#{
|
28
|
-
require "#{
|
29
|
-
require "#{
|
30
|
-
require "#{
|
31
|
-
require "#{
|
32
|
-
require "#{
|
33
|
-
require "#{
|
26
|
+
PETRI_NET_LIB_FILE_PATH = File.dirname(__FILE__)
|
27
|
+
require "#{PETRI_NET_LIB_FILE_PATH}/petri_net/base"
|
28
|
+
require "#{PETRI_NET_LIB_FILE_PATH}/petri_net/net"
|
29
|
+
require "#{PETRI_NET_LIB_FILE_PATH}/petri_net/place"
|
30
|
+
require "#{PETRI_NET_LIB_FILE_PATH}/petri_net/transition"
|
31
|
+
require "#{PETRI_NET_LIB_FILE_PATH}/petri_net/arc"
|
32
|
+
require "#{PETRI_NET_LIB_FILE_PATH}/petri_net/marking"
|
33
|
+
require "#{PETRI_NET_LIB_FILE_PATH}/petri_net/reachability_graph"
|
34
|
+
require "#{PETRI_NET_LIB_FILE_PATH}/petri_net/coverability_graph"
|
data/petri_net.gemspec
CHANGED
@@ -6,7 +6,7 @@ Gem::Specification.new do |gem|
|
|
6
6
|
gem.email = ["\"cclausen@tzi.de\""]
|
7
7
|
gem.description = %q{A Petri net modeling gem}
|
8
8
|
gem.summary = %q{You can create Petri Nets and do some calculations with them like generating the Reachability Graph}
|
9
|
-
gem.homepage = "https://github.com/cclausen/
|
9
|
+
gem.homepage = "https://github.com/cclausen/petri_net"
|
10
10
|
|
11
11
|
gem.files = `git ls-files`.split($\)
|
12
12
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
@@ -16,6 +16,7 @@ Gem::Specification.new do |gem|
|
|
16
16
|
gem.version = PetriNet::VERSION
|
17
17
|
|
18
18
|
gem.license = 'MIT'
|
19
|
-
|
19
|
+
gem.add_dependency "ruby-graphviz"
|
20
|
+
gem.add_dependency "graphviz"
|
20
21
|
gem.add_development_dependency "net-sftp"
|
21
22
|
end
|
@@ -57,5 +57,129 @@ Edges
|
|
57
57
|
", @net.generate_reachability_graph().to_s, "Reachability Graph of sample net"
|
58
58
|
end
|
59
59
|
|
60
|
+
def test_to_gv
|
61
|
+
fill_net
|
62
|
+
# @net.generate_reachability_graph().to_gv_new
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_simple_net_1
|
66
|
+
@net = PetriNet::Net.new(:name => 'SimpleNet1', :description => 'PTP')
|
67
|
+
@net << PetriNet::Place.new(name: 'A')
|
68
|
+
@net << PetriNet::Place.new(name: 'B')
|
69
|
+
@net << PetriNet::Transition.new(name:'T')
|
70
|
+
@net << PetriNet::Arc.new(source:@net.get_place('A'), destination:@net.get_transition('T'))
|
71
|
+
@net << PetriNet::Arc.new(source:@net.get_transition('T'), destination:@net.get_place('B'))
|
72
|
+
@net.get_place('A').add_marking
|
73
|
+
rn = @net.generate_reachability_graph
|
74
|
+
assert_equal "Reachability Graph [SimpleNet1]\n----------------------------\nDescription: \nFilename: \n\nNodes\n----------------------------\n6: Node6 ([1, 0])\n7: Node7 ([0, 1])\n\nEdges\n----------------------------\n8: Edge8 6 -> 7: Node7 ([0, 1]) )\n\n", rn.to_s
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_simple_net_2
|
79
|
+
@net = PetriNet::Net.new(:name => 'SimpleNet2', :description => 'PTTPP')
|
80
|
+
@net << PetriNet::Place.new(name: 'A')
|
81
|
+
@net << PetriNet::Place.new(name: 'B')
|
82
|
+
@net << PetriNet::Place.new(name: 'C')
|
83
|
+
@net << PetriNet::Transition.new(name:'T1')
|
84
|
+
@net << PetriNet::Transition.new(name:'T2')
|
85
|
+
@net << PetriNet::Arc.new(source:@net.get_place('A'), destination:@net.get_transition('T1'))
|
86
|
+
@net << PetriNet::Arc.new(source:@net.get_transition('T1'), destination:@net.get_place('B'))
|
87
|
+
@net << PetriNet::Arc.new(source:@net.get_place('A'), destination:@net.get_transition('T2'))
|
88
|
+
@net << PetriNet::Arc.new(source:@net.get_transition('T2'), destination:@net.get_place('C'))
|
89
|
+
@net.get_place('A').add_marking
|
90
|
+
rn = @net.generate_reachability_graph
|
91
|
+
assert_equal "Reachability Graph [SimpleNet2]\n----------------------------\nDescription: \nFilename: \n\nNodes\n----------------------------\n10: Node10 ([1, 0, 0])\n11: Node11 ([0, 1, 0])\n13: Node13 ([0, 0, 1])\n\nEdges\n----------------------------\n12: Edge12 10 -> 11: Node11 ([0, 1, 0]) )\n14: Edge14 10 -> 13: Node13 ([0, 0, 1]) )\n\n", rn.to_s
|
92
|
+
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_simple_net_3
|
96
|
+
@net = PetriNet::Net.new(:name => 'SimpleNet3', :description => 'PTPPinf')
|
97
|
+
@net << PetriNet::Place.new(name: 'A')
|
98
|
+
@net << PetriNet::Place.new(name: 'B')
|
99
|
+
@net << PetriNet::Transition.new(name:'T')
|
100
|
+
@net << PetriNet::Arc.new(source:@net.get_place('A'), destination:@net.get_transition('T'))
|
101
|
+
@net << PetriNet::Arc.new(source:@net.get_transition('T'), destination:@net.get_place('B'))
|
102
|
+
@net << PetriNet::Arc.new(source:@net.get_transition('T'), destination:@net.get_place('A'))
|
103
|
+
@net.get_place('A').add_marking
|
104
|
+
rn = @net.generate_reachability_graph
|
105
|
+
assert_equal "Reachability Graph [SimpleNet3]\n----------------------------\nDescription: \nFilename: \n\nNodes\n----------------------------\n7: Node7 ([1, 0])\n8: Node8 ([1, 1])\n10: Node10 ([Infinity])\n\nEdges\n----------------------------\n9: Edge9 7 -> 8: Node8 ([1, 1]) )\n11: Edge11 8 -> 10: Node10 ([Infinity]) )\n\n", rn.to_s
|
106
|
+
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_simple_net_4
|
110
|
+
@net = PetriNet::Net.new(:name => 'SimpleNet4', :description => 'PTPPinf')
|
111
|
+
@net << PetriNet::Place.new(name: 'A')
|
112
|
+
@net << PetriNet::Place.new(name: 'B')
|
113
|
+
@net << PetriNet::Transition.new(name:'T1')
|
114
|
+
@net << PetriNet::Transition.new(name:'T2')
|
115
|
+
@net << PetriNet::Arc.new(source:@net.get_place('A'), destination:@net.get_transition('T1'))
|
116
|
+
@net << PetriNet::Arc.new(source:@net.get_transition('T1'), destination:@net.get_place('B'))
|
117
|
+
@net << PetriNet::Arc.new(source:@net.get_transition('T1'), destination:@net.get_place('A'))
|
118
|
+
@net << PetriNet::Arc.new(source:@net.get_place('B'), destination:@net.get_transition('T2'))
|
119
|
+
@net << PetriNet::Arc.new(source:@net.get_transition('T2'), destination:@net.get_place('A'))
|
120
|
+
@net.get_place('A').add_marking
|
121
|
+
rn = @net.generate_reachability_graph
|
122
|
+
assert_equal "Reachability Graph [SimpleNet4]\n----------------------------\nDescription: \nFilename: \n\nNodes\n----------------------------\n10: Node10 ([1, 0])\n11: Node11 ([1, 1])\n13: Node13 ([Infinity])\n15: Node15 ([2, 0])\n17: Node17 ([Infinity])\n\nEdges\n----------------------------\n12: Edge12 10 -> 11: Node11 ([1, 1]) )\n14: Edge14 11 -> 13: Node13 ([Infinity]) )\n16: Edge16 10 -> 15: Node15 ([2, 0]) )\n18: Edge18 15 -> 17: Node17 ([Infinity]) )\n\n", rn.to_s
|
60
123
|
|
124
|
+
end
|
125
|
+
|
126
|
+
def test_simple_net_5
|
127
|
+
@net = PetriNet::Net.new(:name => 'SimpleNet5', :description => 'PTPTP')
|
128
|
+
@net << PetriNet::Place.new(name: 'A')
|
129
|
+
@net << PetriNet::Place.new(name: 'B')
|
130
|
+
@net << PetriNet::Transition.new(name:'T1')
|
131
|
+
@net << PetriNet::Transition.new(name:'T2')
|
132
|
+
@net << PetriNet::Arc.new(source:@net.get_place('A'), destination:@net.get_transition('T1'))
|
133
|
+
@net << PetriNet::Arc.new(source:@net.get_transition('T1'), destination:@net.get_place('B'))
|
134
|
+
@net << PetriNet::Arc.new(source:@net.get_place('B'), destination:@net.get_transition('T2'))
|
135
|
+
@net << PetriNet::Arc.new(source:@net.get_transition('T2'), destination:@net.get_place('A'))
|
136
|
+
@net.get_place('A').add_marking
|
137
|
+
@net.to_gv_new
|
138
|
+
rn = @net.generate_reachability_graph
|
139
|
+
assert_equal "Reachability Graph [SimpleNet5]\n----------------------------\nDescription: \nFilename: \n\nNodes\n----------------------------\n9: Node9 ([1, 0])\n10: Node10 ([0, 1])\n\nEdges\n----------------------------\n11: Edge11 9 -> 10: Node10 ([0, 1]) )\n\n", rn.to_s
|
140
|
+
|
141
|
+
rn.to_gv
|
142
|
+
end
|
143
|
+
|
144
|
+
def test_real_net_1
|
145
|
+
@net = PetriNet::Net.new(:name => 'RealNet1', :description => 'Failed in real situation')
|
146
|
+
@net << PetriNet::Place.new(name: 'A')
|
147
|
+
@net << PetriNet::Place.new(name: 'B')
|
148
|
+
@net << PetriNet::Place.new(name: 'C')
|
149
|
+
@net << PetriNet::Place.new(name: 'D')
|
150
|
+
@net << PetriNet::Transition.new(name:'T1')
|
151
|
+
@net << PetriNet::Transition.new(name:'T2')
|
152
|
+
@net << PetriNet::Transition.new(name:'T3')
|
153
|
+
@net << PetriNet::Arc.new(source:@net.get_place('A'), destination:@net.get_transition('T1'))
|
154
|
+
@net << PetriNet::Arc.new(source:@net.get_transition('T1'), destination:@net.get_place('B'))
|
155
|
+
@net << PetriNet::Arc.new(source:@net.get_transition('T1'), destination:@net.get_place('D'))
|
156
|
+
@net << PetriNet::Arc.new(source:@net.get_place('B'), destination:@net.get_transition('T2'))
|
157
|
+
@net << PetriNet::Arc.new(source:@net.get_transition('T2'), destination:@net.get_place('C'))
|
158
|
+
@net << PetriNet::Arc.new(source:@net.get_transition('T2'), destination:@net.get_place('D'))
|
159
|
+
@net << PetriNet::Arc.new(source:@net.get_place('D'), destination:@net.get_transition('T3'))
|
160
|
+
@net << PetriNet::Arc.new(source:@net.get_transition('T3'), destination:@net.get_place('A'))
|
161
|
+
@net.get_place('A').add_marking
|
162
|
+
@net.to_gv_new
|
163
|
+
rg = @net.generate_reachability_graph
|
164
|
+
|
165
|
+
rg.to_gv
|
166
|
+
#TODO assert_equal "", rg.to_s
|
167
|
+
|
168
|
+
end
|
169
|
+
|
170
|
+
def test_empty_net1
|
171
|
+
@net = PetriNet::Net.new(:name => 'EmptyNet1', :description => 'Should be boring')
|
172
|
+
@net.generate_reachability_graph # Don't know what to test here, bit this crashed with an Error before...
|
173
|
+
end
|
174
|
+
def test_empty_net2
|
175
|
+
@net = PetriNet::Net.new(:name => 'EmptyNet2', :description => 'Should be boring')
|
176
|
+
@net << PetriNet::Place.new(name: 'A')
|
177
|
+
@net.generate_reachability_graph # Don't know what to test here, bit this crashed with an Error before...
|
178
|
+
end
|
179
|
+
def test_empty_net3
|
180
|
+
@net = PetriNet::Net.new(:name => 'EmptyNet3', :description => 'Should be boring')
|
181
|
+
@net << PetriNet::Place.new(name: 'A')
|
182
|
+
@net << PetriNet::Transition.new(name:'T1')
|
183
|
+
@net.generate_reachability_graph # Don't know what to test here, bit this crashed with an Error before...
|
184
|
+
end
|
61
185
|
end
|