petri_net 0.2.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3862dd137aeee506ef93dc6c0247d5f872bb5dba
4
- data.tar.gz: 1159a8fa6abde650583c95cd80a9d54a749b57e3
3
+ metadata.gz: 05aa522c5e70ab46c5873a40cffe845f288ab674
4
+ data.tar.gz: aef6cc24ebb8ceeb44788a3cbf962f967bddd3d1
5
5
  SHA512:
6
- metadata.gz: ad0e40f4bfb501824223f2f36fc0dc32aa42391e8903fd2a21f5805f88ec946b91f7cf238124d6f7fb06da055d65c50301f44f3ca2b9fd9279469a683e0b2885
7
- data.tar.gz: c43775deaab72b0f5a8c56a7040665d2762d7ac4ecbd07230bb4382cab51998fc9fd81fd4c653f32153dded901baab56d5761b8f69a1a12d3f7bf785075b01aa
6
+ metadata.gz: 0df2e5b3ca5598fc01e5835c6c79c3959df93d34b8620dd3734349842f4751718558ca10d0c8f00d106a646950b1a75ac65826f63a70cc3601d0564e321c435e
7
+ data.tar.gz: a64f758521a8a0a25b2343c41410330949d788b64e307de8725408865a8ac6f6bff5bd545eff7b226e96d7bc8d1209ee74509538e0eb353d7771e7112786f78e
data/.travis.yml ADDED
@@ -0,0 +1,11 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - jruby-19mode # JRuby in 1.9 mode
5
+ - 2.0.0
6
+
7
+ before_install:
8
+ gem install net-sftp
9
+
10
+ script:
11
+ rake test
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in petri.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,18 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ petri_net (0.6.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ net-sftp (2.1.2)
10
+ net-ssh (>= 2.6.5)
11
+ net-ssh (2.7.0)
12
+
13
+ PLATFORMS
14
+ ruby
15
+
16
+ DEPENDENCIES
17
+ net-sftp
18
+ petri_net!
data/README.rdoc CHANGED
@@ -1,8 +1,12 @@
1
+ {<img src="https://travis-ci.org/cclausen/petri.png" />}[https://travis-ci.org/cclausen/petri]
2
+
3
+ {<img src="https://codeclimate.com/github/cclausen/petri.png" />}[https://codeclimate.com/github/cclausen/petri]
4
+
1
5
  = PTNet: Petri-net Simulation in Ruby
2
6
  ===== based on the code by Brian D Nelson <bdnelson@wildcoder.com>
3
7
  ===== Christian Clausen cclausen@tzi.de
4
8
 
5
- == Version 0.5
9
+ == Version 0.6
6
10
  I implemented most of the basics you need for playing with PetriNets but there are a lot things to add.
7
11
  Next big step will be a stochastic analysis of the PetriNet.
8
12
 
data/Rakefile CHANGED
@@ -1,6 +1,6 @@
1
1
  require 'rubygems'
2
2
  require 'rake/testtask'
3
- require 'hanna/rdoctask'
3
+ #require 'hanna/rdoctask'
4
4
  require 'net/sftp'
5
5
  require 'fileutils'
6
6
 
@@ -13,12 +13,12 @@ Rake::TestTask.new(:test) do |t|
13
13
  t.ruby_opts = ['-rubygems'] if defined? Gem
14
14
  end
15
15
 
16
- Rake::RDocTask.new(:rdoc) do |rdoc|
17
- rdoc.rdoc_files.include('LICENSE', 'CHANGELOG', 'README', 'lib/')
18
- rdoc.title = "PetriNet Documentation"
19
- rdoc.options << '--webcvs=http://svn.wildcoder.com/svn/petri/trunk/'
20
- rdoc.rdoc_dir = 'doc' # rdoc output folder
21
- end
16
+ #Rake::RDocTask.new(:rdoc) do |rdoc|
17
+ # rdoc.rdoc_files.include('LICENSE', 'CHANGELOG', 'README', 'lib/')
18
+ # rdoc.title = "PetriNet Documentation"
19
+ # rdoc.options << '--webcvs=http://svn.wildcoder.com/svn/petri/trunk/'
20
+ # rdoc.rdoc_dir = 'doc' # rdoc output folder
21
+ #end
22
22
 
23
23
  desc 'Clean up unused files.'
24
24
  task :clean => :clobber_rdoc do
@@ -5,6 +5,8 @@ class PetriNet::ReachabilityGraph::Edge < PetriNet::Base
5
5
  attr_reader :id
6
6
  # Graph this edge belongs to
7
7
  attr_accessor :graph
8
+ # Probability of the relating transition
9
+ attr_accessor :probability
8
10
 
9
11
  # Creates an edge for PetriNet::ReachabilityGraph
10
12
  def initialize(options = {}, &block)
@@ -14,6 +16,7 @@ class PetriNet::ReachabilityGraph::Edge < PetriNet::Base
14
16
  @source = options[:source]
15
17
  @destination = options[:destination]
16
18
  @label = (options[:label] or @name)
19
+ @probability = options[:probability]
17
20
 
18
21
  yield self unless block.nil?
19
22
  end
@@ -24,7 +27,7 @@ class PetriNet::ReachabilityGraph::Edge < PetriNet::Base
24
27
  end
25
28
 
26
29
  def to_gv
27
- "\t#{@source.gv_id} -> #{@destination.gv_id};\n"
30
+ "\t#{@source.gv_id} -> #{@destination.gv_id}#{probability_to_gv};\n"
28
31
  end
29
32
 
30
33
  def ==(object)
@@ -35,4 +38,13 @@ class PetriNet::ReachabilityGraph::Edge < PetriNet::Base
35
38
  "#{@id}: #{@name} #{@source.id} -> #{@destination} )"
36
39
  end
37
40
 
41
+ private
42
+ def probability_to_gv
43
+ if @probability
44
+ " [ label = \"#{@probability.to_s}\" ] "
45
+ else
46
+ ''
47
+ end
48
+ end
49
+
38
50
  end
data/lib/petri_net/net.rb CHANGED
@@ -305,7 +305,7 @@ class PetriNet::Net < PetriNet::Base
305
305
  if @objects[tid].fire
306
306
  current_node = PetriNet::ReachabilityGraph::Node.new(markings: get_markings)
307
307
  current_node_id = @graph.add_node current_node
308
- @graph.add_edge PetriNet::ReachabilityGraph::Edge.new(source: source, destination: current_node) unless current_node_id < 0
308
+ @graph.add_edge PetriNet::ReachabilityGraph::Edge.new(source: source, destination: current_node, probability: @objects[tid].probability) unless current_node_id < 0
309
309
  reachability_helper get_markings, current_node unless (current_node_id < 0)
310
310
  end
311
311
  set_markings markings
@@ -1,6 +1,8 @@
1
1
  class PetriNet::Place < PetriNet::Base
2
2
  # Unique ID
3
3
  attr_reader :id
4
+ # Needed to sanitize a Petrinet after merging
5
+ attr_writer :id
4
6
  # Human readable name
5
7
  attr_accessor :name
6
8
  # description
@@ -7,6 +7,8 @@ module PetriNet
7
7
  attr_accessor :name
8
8
  # Description
9
9
  attr_accessor :description
10
+ # Probability of firing (this moment)
11
+ attr_accessor :probability
10
12
  # List of input-arcs
11
13
  attr_reader :inputs
12
14
  # List of output-arcs
@@ -21,6 +23,7 @@ module PetriNet
21
23
  @description = (options[:description] or "Transition #{@id}")
22
24
  @inputs = Array.new
23
25
  @outputs = Array.new
26
+ @probability = options[:probability]
24
27
 
25
28
  yield self unless block == nil
26
29
  end
@@ -54,7 +57,7 @@ module PetriNet
54
57
 
55
58
  # GraphViz definition
56
59
  def to_gv
57
- "\t#{self.gv_id} [ label = \"#{@name}\" ];\n"
60
+ "\t#{self.gv_id} [ label = \"#{@name}#{@probability ? ' ' + @probability.to_s : ''}\" ];\n"
58
61
  end
59
62
 
60
63
  def ==(object)
@@ -0,0 +1,5 @@
1
+ module PetriNet
2
+ VERSION = "0.6.0"
3
+ DEBUG = false
4
+ end
5
+
data/petri_net.gemspec ADDED
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/petri_net/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["cclausen"]
6
+ gem.email = ["\"cclausen@tzi.de\""]
7
+ gem.description = %q{A Petri net modeling gem}
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/petri"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "petri_net"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = PetriNet::VERSION
17
+
18
+ gem.license = 'MIT'
19
+ #gem.add_dependency "ruby-graphviz"
20
+ gem.add_development_dependency "net-sftp"
21
+ end
data/test/tc_petri_net.rb CHANGED
@@ -3,9 +3,9 @@
3
3
  require 'rubygems'
4
4
  require 'logger'
5
5
  require 'test/unit'
6
- require "#{`pwd`.strip}/../lib/petri_net"
6
+ require "#{File.dirname(__FILE__)}/../lib/petri_net"
7
7
 
8
- require 'pry'
8
+ #require 'pry'
9
9
 
10
10
  class TestPetriNet < Test::Unit::TestCase
11
11
  def setup
@@ -1,4 +1,4 @@
1
- require "../lib/petri_net/transition"
1
+ require "#{File.dirname(__FILE__)}/../lib/petri_net.rb"
2
2
  require "test/unit"
3
3
 
4
4
  class TestTransition < Test::Unit::TestCase
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: petri_net
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - cclausen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-26 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2014-01-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: net-sftp
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  description: A Petri net modeling gem
14
28
  email:
15
29
  - '"cclausen@tzi.de"'
@@ -18,7 +32,10 @@ extensions: []
18
32
  extra_rdoc_files: []
19
33
  files:
20
34
  - .ruby-version
35
+ - .travis.yml
21
36
  - CHANGELOG
37
+ - Gemfile
38
+ - Gemfile.lock
22
39
  - LICENSE
23
40
  - README.rdoc
24
41
  - Rakefile
@@ -32,6 +49,8 @@ files:
32
49
  - lib/petri_net/place.rb
33
50
  - lib/petri_net/reachability_graph.rb
34
51
  - lib/petri_net/transition.rb
52
+ - lib/petri_net/version.rb
53
+ - petri_net.gemspec
35
54
  - test/create.rb
36
55
  - test/tc_arc.rb
37
56
  - test/tc_edge.rb
@@ -61,7 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
61
80
  version: '0'
62
81
  requirements: []
63
82
  rubyforge_project:
64
- rubygems_version: 2.0.3
83
+ rubygems_version: 2.1.11
65
84
  signing_key:
66
85
  specification_version: 4
67
86
  summary: You can create Petri Nets and do some calculations with them like generating