petri_net 0.7.9.1 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/petri_net/graph/edge.rb +2 -1
- data/lib/petri_net/graph/graph.rb +14 -1
- data/lib/petri_net/graph/node.rb +15 -1
- data/lib/petri_net/net.rb +16 -11
- data/lib/petri_net/reachability_graph/edge.rb +2 -2
- data/lib/petri_net/reachability_graph/node.rb +4 -4
- data/lib/petri_net/version.rb +1 -1
- data/test/reachability_graph/tc_node.rb +10 -9
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6280711333c42af2d42f9f72dc8d7e9addf491d0
|
4
|
+
data.tar.gz: 0f5c88804ad2453ac2ac5f58ed48b402e6a46332
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d11cb20273590228cc3324d6e5483eb6f6d79fb2cf8e3217200fb86e4464d511126eb2c9a2843c11ec8f69a54ff061d63f3c4037fd9b7c637dabe749eda05d4c
|
7
|
+
data.tar.gz: 4bf91f1daf2975b146139be896386cc1704d393f33d3d4936afc4e7e607b97ad214d09c674dd6c189c3b51b5a25a323308a78a8201bcc7e3ba5ad249c530f0b1
|
data/lib/petri_net/graph/edge.rb
CHANGED
@@ -15,7 +15,8 @@ class PetriNet::Graph::Edge < PetriNet::Base
|
|
15
15
|
attr_reader :transition
|
16
16
|
|
17
17
|
# Creates an edge for PetriNet::Graph
|
18
|
-
def initialize(options = {}, &block)
|
18
|
+
def initialize(graph, options = {}, &block)
|
19
|
+
@graph = graph
|
19
20
|
@id = next_object_id
|
20
21
|
@name = (options[:name] or "Edge#{@id}")
|
21
22
|
@description = (options[:description] or "Edge #{@id}")
|
@@ -4,7 +4,12 @@ class PetriNet::InfiniteReachabilityGraphError < RuntimeError
|
|
4
4
|
end
|
5
5
|
|
6
6
|
class PetriNet::Graph < PetriNet::Base
|
7
|
+
|
8
|
+
# The PetriNet this graph belongs to
|
9
|
+
attr_reader :net
|
10
|
+
|
7
11
|
def initialize(net, options = Hash.new)
|
12
|
+
@net = net
|
8
13
|
@objects = Array.new
|
9
14
|
@nodes = Hash.new
|
10
15
|
@edges = Hash.new
|
@@ -55,7 +60,15 @@ class PetriNet::Graph < PetriNet::Base
|
|
55
60
|
alias_method :add_object, :<<
|
56
61
|
|
57
62
|
def get_node(id)
|
58
|
-
|
63
|
+
@objects[id]
|
64
|
+
end
|
65
|
+
|
66
|
+
def get_nodes
|
67
|
+
res = Array.new
|
68
|
+
@nodes.each_value do |n|
|
69
|
+
res << @objects[n]
|
70
|
+
end
|
71
|
+
res
|
59
72
|
end
|
60
73
|
|
61
74
|
def to_gv(output = 'png', filename = '')
|
data/lib/petri_net/graph/node.rb
CHANGED
@@ -20,7 +20,8 @@ class PetriNet::Graph::Node < PetriNet::Base
|
|
20
20
|
# True if this is the start-marking
|
21
21
|
attr_reader :start
|
22
22
|
|
23
|
-
def initialize(options = {}, &block)
|
23
|
+
def initialize(graph, options = {}, &block)
|
24
|
+
@graph = graph
|
24
25
|
@id = next_object_id
|
25
26
|
@name = (options[:name] or "Node#{@id}")
|
26
27
|
@description = (options[:description] or "Node #{@id}")
|
@@ -72,6 +73,19 @@ class PetriNet::Graph::Node < PetriNet::Base
|
|
72
73
|
ret
|
73
74
|
end
|
74
75
|
|
76
|
+
def include_place(place)
|
77
|
+
places = @graph.net.get_place_list
|
78
|
+
included_places = Array.new
|
79
|
+
i = 0
|
80
|
+
@markings.each do |m|
|
81
|
+
if m > 0
|
82
|
+
included_places << places[i]
|
83
|
+
end
|
84
|
+
i += 1
|
85
|
+
end
|
86
|
+
included_places.include? place
|
87
|
+
end
|
88
|
+
|
75
89
|
def validate
|
76
90
|
true
|
77
91
|
end
|
data/lib/petri_net/net.rb
CHANGED
@@ -247,7 +247,7 @@ Arcs
|
|
247
247
|
def generate_coverability_graph()
|
248
248
|
startmarkings = get_markings
|
249
249
|
@graph = PetriNet::CoverabilityGraph.new(self)
|
250
|
-
@graph.add_node current_node = PetriNet::CoverabilityGraph::Node.new(markings: get_markings, start: true)
|
250
|
+
@graph.add_node current_node = PetriNet::CoverabilityGraph::Node.new(@graph, markings: get_markings, start: true)
|
251
251
|
|
252
252
|
coverability_helper startmarkings, current_node
|
253
253
|
|
@@ -258,7 +258,7 @@ Arcs
|
|
258
258
|
def generate_reachability_graph()
|
259
259
|
startmarkings = get_markings
|
260
260
|
@graph = PetriNet::ReachabilityGraph.new(self)
|
261
|
-
@graph.add_node current_node = PetriNet::ReachabilityGraph::Node.new(markings: get_markings, start: true)
|
261
|
+
@graph.add_node current_node = PetriNet::ReachabilityGraph::Node.new(@graph, markings: get_markings, start: true)
|
262
262
|
|
263
263
|
reachability_helper startmarkings, current_node
|
264
264
|
|
@@ -309,6 +309,11 @@ Arcs
|
|
309
309
|
changed_state
|
310
310
|
end
|
311
311
|
|
312
|
+
def get_place_list
|
313
|
+
@places.map{|key,pid| @objects[pid]}
|
314
|
+
end
|
315
|
+
|
316
|
+
|
312
317
|
def objects_size
|
313
318
|
@objects.count{|o| !o.nil?}
|
314
319
|
end
|
@@ -357,19 +362,19 @@ Arcs
|
|
357
362
|
raise PetriNet::ReachabilityGraph::InfinityGraphError if @objects[tid].inputs.empty? && !@objects[tid].outputs.empty?
|
358
363
|
next if @objects[tid].inputs.empty?
|
359
364
|
if @objects[tid].fire
|
360
|
-
current_node = PetriNet::ReachabilityGraph::Node.new(markings: get_markings)
|
365
|
+
current_node = PetriNet::ReachabilityGraph::Node.new(@graph, markings: get_markings)
|
361
366
|
begin
|
362
367
|
node_id = @graph.add_node current_node
|
363
368
|
rescue
|
364
369
|
@graph.add_node! current_node
|
365
|
-
@graph.add_edge PetriNet::ReachabilityGraph::Edge.new(source: source, destination: current_node)
|
366
|
-
infinity_node = PetriNet::ReachabilityGraph::InfinityNode.new
|
370
|
+
@graph.add_edge PetriNet::ReachabilityGraph::Edge.new(@graph, source: source, destination: current_node)
|
371
|
+
infinity_node = PetriNet::ReachabilityGraph::InfinityNode.new(@graph)
|
367
372
|
@graph.add_node infinity_node
|
368
|
-
@graph.add_edge PetriNet::ReachabilityGraph::Edge.new(source: current_node, destination: infinity_node)
|
373
|
+
@graph.add_edge PetriNet::ReachabilityGraph::Edge.new(@graph, source: current_node, destination: infinity_node)
|
369
374
|
next
|
370
375
|
end
|
371
|
-
@graph.add_edge PetriNet::ReachabilityGraph::Edge.new(source: source, destination: current_node)
|
372
|
-
reachability_helper get_markings, current_node
|
376
|
+
@graph.add_edge PetriNet::ReachabilityGraph::Edge.new(@graph, source: source, destination: current_node)# if node_id
|
377
|
+
reachability_helper get_markings, current_node if node_id
|
373
378
|
end
|
374
379
|
set_markings markings
|
375
380
|
end
|
@@ -378,9 +383,9 @@ Arcs
|
|
378
383
|
def coverability_helper(markings, source, added_omega = false)
|
379
384
|
@transitions.each_value do |tid|
|
380
385
|
if @objects[tid].fire
|
381
|
-
current_node = PetriNet::ReachabilityGraph::Node.new(markings: get_markings)
|
386
|
+
current_node = PetriNet::ReachabilityGraph::Node.new(@graph, markings: get_markings)
|
382
387
|
current_node_id = @graph.add_node current_node
|
383
|
-
@graph.add_edge PetriNet::ReachabilityGraph::Edge.new(source: source, destination: current_node, probability: @objects[tid].probability, transition: @objects[tid].name) if (!(current_node_id < 0))
|
388
|
+
@graph.add_edge PetriNet::ReachabilityGraph::Edge.new(@graph, source: source, destination: current_node, probability: @objects[tid].probability, transition: @objects[tid].name) if (!(current_node_id < 0))
|
384
389
|
omega = false
|
385
390
|
if current_node_id != -Float::INFINITY && current_node_id < 0 && @graph.get_node(current_node_id * -1) != current_node
|
386
391
|
omega = true
|
@@ -389,7 +394,7 @@ Arcs
|
|
389
394
|
if added_omega_old == added_omega
|
390
395
|
break
|
391
396
|
end
|
392
|
-
@graph.add_edge PetriNet::ReachabilityGraph::Edge.new(source: source, destination: @graph.get_node(current_node_id * -1), probability: @objects[tid].probability, transition: @objects[tid].name)
|
397
|
+
@graph.add_edge PetriNet::ReachabilityGraph::Edge.new(@graph, source: source, destination: @graph.get_node(current_node_id * -1), probability: @objects[tid].probability, transition: @objects[tid].name)
|
393
398
|
end
|
394
399
|
coverability_helper get_markings, @graph.get_node(current_node_id.abs), added_omega if ((!(current_node_id < 0) || !omega) && current_node_id != -Float::INFINITY )
|
395
400
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
class PetriNet::ReachabilityGraph::Edge < PetriNet::Graph::Edge
|
2
2
|
# Creates an edge for PetriNet::ReachabilityGraph
|
3
|
-
def initialize(options = {}, &block)
|
4
|
-
super(options)
|
3
|
+
def initialize(graph, options = {}, &block)
|
4
|
+
super(graph, options)
|
5
5
|
yield self unless block.nil?
|
6
6
|
end
|
7
7
|
|
@@ -1,13 +1,13 @@
|
|
1
1
|
class PetriNet::ReachabilityGraph::Node < PetriNet::Graph::Node
|
2
|
-
def initialize(options = {}, &block)
|
3
|
-
super(options)
|
2
|
+
def initialize(graph, options = {}, &block)
|
3
|
+
super(graph, options)
|
4
4
|
yield self unless block.nil?
|
5
5
|
end
|
6
6
|
|
7
7
|
end
|
8
8
|
|
9
9
|
class PetriNet::ReachabilityGraph::InfinityNode < PetriNet::ReachabilityGraph::Node
|
10
|
-
def initialize()
|
11
|
-
super(markings: [Float::INFINITY])
|
10
|
+
def initialize(graph)
|
11
|
+
super(graph, markings: [Float::INFINITY])
|
12
12
|
end
|
13
13
|
end
|
data/lib/petri_net/version.rb
CHANGED
@@ -6,7 +6,8 @@ require "#{File.dirname(__FILE__)}/../../lib/petri_net"
|
|
6
6
|
class TestReachabilityGraphNode < Test::Unit::TestCase
|
7
7
|
def setup
|
8
8
|
@net = PetriNet::Net.new(:name => 'Water', :description => 'Creation of water from base elements.')
|
9
|
-
@
|
9
|
+
@graph = PetriNet::ReachabilityGraph.new(@net)
|
10
|
+
@node = PetriNet::ReachabilityGraph::Node.new(@graph, markings: [1,3,5,4,0])
|
10
11
|
end
|
11
12
|
|
12
13
|
def teardown
|
@@ -14,7 +15,7 @@ class TestReachabilityGraphNode < Test::Unit::TestCase
|
|
14
15
|
end
|
15
16
|
|
16
17
|
def test_create_node
|
17
|
-
node = PetriNet::ReachabilityGraph::Node.new(markings: [1,3,5,4,0])
|
18
|
+
node = PetriNet::ReachabilityGraph::Node.new(@graph, markings: [1,3,5,4,0])
|
18
19
|
assert_not_nil node
|
19
20
|
assert_equal "Node2", node.name
|
20
21
|
assert_equal [], node.inputs
|
@@ -25,7 +26,7 @@ class TestReachabilityGraphNode < Test::Unit::TestCase
|
|
25
26
|
end
|
26
27
|
|
27
28
|
def test_omega_marking
|
28
|
-
node = PetriNet::ReachabilityGraph::Node.new(markings: [1,3,5,Float::INFINITY,0])
|
29
|
+
node = PetriNet::ReachabilityGraph::Node.new(@graph, markings: [1,3,5,Float::INFINITY,0])
|
29
30
|
assert node.omega_marked, "should be omega_marked as there is an omega marking"
|
30
31
|
end
|
31
32
|
|
@@ -37,12 +38,12 @@ class TestReachabilityGraphNode < Test::Unit::TestCase
|
|
37
38
|
end
|
38
39
|
|
39
40
|
def test_compare
|
40
|
-
node1 = PetriNet::ReachabilityGraph::Node.new(markings: [0,1,0,0,1])
|
41
|
-
node2 = PetriNet::ReachabilityGraph::Node.new(markings: [0,1,0,0,1])
|
42
|
-
node3 = PetriNet::ReachabilityGraph::Node.new(markings: [0,0,1,0,1])
|
43
|
-
node4 = PetriNet::ReachabilityGraph::Node.new(markings: [0,2,0,0,1])
|
44
|
-
node5 = PetriNet::ReachabilityGraph::Node.new(markings: [1,1,0,0,1])
|
45
|
-
node6 = PetriNet::ReachabilityGraph::Node.new(markings: [1,1,0,0,0])
|
41
|
+
node1 = PetriNet::ReachabilityGraph::Node.new(@graph, markings: [0,1,0,0,1])
|
42
|
+
node2 = PetriNet::ReachabilityGraph::Node.new(@graph, markings: [0,1,0,0,1])
|
43
|
+
node3 = PetriNet::ReachabilityGraph::Node.new(@graph, markings: [0,0,1,0,1])
|
44
|
+
node4 = PetriNet::ReachabilityGraph::Node.new(@graph, markings: [0,2,0,0,1])
|
45
|
+
node5 = PetriNet::ReachabilityGraph::Node.new(@graph, markings: [1,1,0,0,1])
|
46
|
+
node6 = PetriNet::ReachabilityGraph::Node.new(@graph, markings: [1,1,0,0,0])
|
46
47
|
|
47
48
|
assert node1 == node1
|
48
49
|
assert node2 == node2
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: petri_net
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- cclausen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-03-
|
11
|
+
date: 2014-03-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruby-graphviz
|