stamina-core 0.5.0
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.
- data/CHANGELOG.md +78 -0
- data/LICENCE.md +22 -0
- data/lib/stamina-core/stamina-core.rb +1 -0
- data/lib/stamina-core/stamina/adl.rb +298 -0
- data/lib/stamina-core/stamina/automaton.rb +1300 -0
- data/lib/stamina-core/stamina/automaton/complement.rb +26 -0
- data/lib/stamina-core/stamina/automaton/complete.rb +36 -0
- data/lib/stamina-core/stamina/automaton/compose.rb +111 -0
- data/lib/stamina-core/stamina/automaton/determinize.rb +104 -0
- data/lib/stamina-core/stamina/automaton/equivalence.rb +57 -0
- data/lib/stamina-core/stamina/automaton/hide.rb +41 -0
- data/lib/stamina-core/stamina/automaton/metrics.rb +77 -0
- data/lib/stamina-core/stamina/automaton/minimize.rb +23 -0
- data/lib/stamina-core/stamina/automaton/minimize/hopcroft.rb +118 -0
- data/lib/stamina-core/stamina/automaton/minimize/pitchies.rb +130 -0
- data/lib/stamina-core/stamina/automaton/strip.rb +16 -0
- data/lib/stamina-core/stamina/automaton/walking.rb +361 -0
- data/lib/stamina-core/stamina/command.rb +38 -0
- data/lib/stamina-core/stamina/command/adl2dot.rb +82 -0
- data/lib/stamina-core/stamina/command/help.rb +23 -0
- data/lib/stamina-core/stamina/command/robustness.rb +21 -0
- data/lib/stamina-core/stamina/command/run.rb +84 -0
- data/lib/stamina-core/stamina/core.rb +11 -0
- data/lib/stamina-core/stamina/dsl.rb +6 -0
- data/lib/stamina-core/stamina/dsl/automata.rb +23 -0
- data/lib/stamina-core/stamina/dsl/core.rb +14 -0
- data/lib/stamina-core/stamina/engine.rb +32 -0
- data/lib/stamina-core/stamina/engine/context.rb +35 -0
- data/lib/stamina-core/stamina/errors.rb +26 -0
- data/lib/stamina-core/stamina/ext/math.rb +19 -0
- data/lib/stamina-core/stamina/loader.rb +3 -0
- data/lib/stamina-core/stamina/markable.rb +42 -0
- data/lib/stamina-core/stamina/utils.rb +1 -0
- data/lib/stamina-core/stamina/utils/decorate.rb +81 -0
- data/lib/stamina-core/stamina/version.rb +14 -0
- metadata +93 -0
@@ -0,0 +1 @@
|
|
1
|
+
require_relative 'utils/decorate'
|
@@ -0,0 +1,81 @@
|
|
1
|
+
module Stamina
|
2
|
+
module Utils
|
3
|
+
#
|
4
|
+
# Decorates states of an automaton by applying a propagation rule
|
5
|
+
# until a fix point is reached.
|
6
|
+
#
|
7
|
+
class Decorate
|
8
|
+
|
9
|
+
# The key to use to maintain the decoration on states (:invariant
|
10
|
+
# is used by default)
|
11
|
+
attr_writer :decoration_key
|
12
|
+
|
13
|
+
# Creates a decoration algorithm instance
|
14
|
+
def initialize(decoration_key = :invariant)
|
15
|
+
@decoration_key = decoration_key
|
16
|
+
@suppremum = nil
|
17
|
+
@propagate = nil
|
18
|
+
end
|
19
|
+
|
20
|
+
# Installs a suppremum function through a block.
|
21
|
+
def set_suppremum(&block)
|
22
|
+
raise ArgumentError, 'Suppremum expected through a block' if block.nil?
|
23
|
+
raise ArgumentError, 'Block of arity 2 expected' unless block.arity==2
|
24
|
+
@suppremum = block
|
25
|
+
end
|
26
|
+
|
27
|
+
# Installs a propagate function through a block.
|
28
|
+
def set_propagate(&block)
|
29
|
+
raise ArgumentError, 'Propagate expected through a block' if block.nil?
|
30
|
+
raise ArgumentError, 'Block of arity 2 expected' unless block.arity==2
|
31
|
+
@propagate = block
|
32
|
+
end
|
33
|
+
|
34
|
+
# Computes the suppremum between two decorations. By default, this method
|
35
|
+
# looks for a suppremum function installed with set_suppremum. If not found,
|
36
|
+
# it tries calling a suppremum method on d0. If not found it raises an error.
|
37
|
+
# This method may be overriden.
|
38
|
+
def suppremum(d0, d1)
|
39
|
+
return @suppremum.call(d0, d1) if @suppremum
|
40
|
+
return d0.suppremum(d1) if d0.respond_to?(:suppremum)
|
41
|
+
raise "No suppremum function installed or implemented by decorations"
|
42
|
+
end
|
43
|
+
|
44
|
+
# Computes the propagation rule. By default, this method looks for a propagate
|
45
|
+
# function installed with set_propagate. If not found, it tries calling a +
|
46
|
+
# method on deco. If not found it raises an error.
|
47
|
+
# This method may be overriden.
|
48
|
+
def propagate(deco, edge)
|
49
|
+
return @propagate.call(deco, edge) if @propagate
|
50
|
+
return deco.+(edge) if deco.respond_to?(:+)
|
51
|
+
raise "No propagate function installed or implemented by decorations"
|
52
|
+
end
|
53
|
+
|
54
|
+
# Executes the propagation algorithm on a given automaton.
|
55
|
+
def execute(fa, bottom, d0)
|
56
|
+
# install initial decoration
|
57
|
+
fa.states.each do |s|
|
58
|
+
s[@decoration_key] = (s.initial? ? d0 : bottom)
|
59
|
+
end
|
60
|
+
|
61
|
+
# fix-point loop starting with initial states
|
62
|
+
to_explore = fa.initial_states
|
63
|
+
until to_explore.empty?
|
64
|
+
source = to_explore.pop
|
65
|
+
source.out_edges.each do |edge|
|
66
|
+
target = edge.target
|
67
|
+
p_decor = propagate(source[@decoration_key], edge)
|
68
|
+
p_decor = suppremum(target[@decoration_key], p_decor)
|
69
|
+
unless p_decor == target[@decoration_key]
|
70
|
+
target[@decoration_key] = p_decor
|
71
|
+
to_explore << target unless to_explore.include?(target)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
fa
|
77
|
+
end
|
78
|
+
|
79
|
+
end # class Decorate
|
80
|
+
end # module Utils
|
81
|
+
end # module Stamina
|
metadata
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: stamina-core
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Bernard Lambeau
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-02-24 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: quickl
|
16
|
+
requirement: &70173945608140 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.4.3
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70173945608140
|
25
|
+
description: ! "Stamina is an automaton and regular inference toolkit initially developped
|
26
|
+
for the \nbaseline of the Stamina Competition (stamina.chefbe.net)."
|
27
|
+
email:
|
28
|
+
- blambeau@gmail.com
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- LICENCE.md
|
34
|
+
- CHANGELOG.md
|
35
|
+
- lib/stamina-core/stamina/adl.rb
|
36
|
+
- lib/stamina-core/stamina/automaton/complement.rb
|
37
|
+
- lib/stamina-core/stamina/automaton/complete.rb
|
38
|
+
- lib/stamina-core/stamina/automaton/compose.rb
|
39
|
+
- lib/stamina-core/stamina/automaton/determinize.rb
|
40
|
+
- lib/stamina-core/stamina/automaton/equivalence.rb
|
41
|
+
- lib/stamina-core/stamina/automaton/hide.rb
|
42
|
+
- lib/stamina-core/stamina/automaton/metrics.rb
|
43
|
+
- lib/stamina-core/stamina/automaton/minimize/hopcroft.rb
|
44
|
+
- lib/stamina-core/stamina/automaton/minimize/pitchies.rb
|
45
|
+
- lib/stamina-core/stamina/automaton/minimize.rb
|
46
|
+
- lib/stamina-core/stamina/automaton/strip.rb
|
47
|
+
- lib/stamina-core/stamina/automaton/walking.rb
|
48
|
+
- lib/stamina-core/stamina/automaton.rb
|
49
|
+
- lib/stamina-core/stamina/command/adl2dot.rb
|
50
|
+
- lib/stamina-core/stamina/command/help.rb
|
51
|
+
- lib/stamina-core/stamina/command/robustness.rb
|
52
|
+
- lib/stamina-core/stamina/command/run.rb
|
53
|
+
- lib/stamina-core/stamina/command.rb
|
54
|
+
- lib/stamina-core/stamina/core.rb
|
55
|
+
- lib/stamina-core/stamina/dsl/automata.rb
|
56
|
+
- lib/stamina-core/stamina/dsl/core.rb
|
57
|
+
- lib/stamina-core/stamina/dsl.rb
|
58
|
+
- lib/stamina-core/stamina/engine/context.rb
|
59
|
+
- lib/stamina-core/stamina/engine.rb
|
60
|
+
- lib/stamina-core/stamina/errors.rb
|
61
|
+
- lib/stamina-core/stamina/ext/math.rb
|
62
|
+
- lib/stamina-core/stamina/loader.rb
|
63
|
+
- lib/stamina-core/stamina/markable.rb
|
64
|
+
- lib/stamina-core/stamina/utils/decorate.rb
|
65
|
+
- lib/stamina-core/stamina/utils.rb
|
66
|
+
- lib/stamina-core/stamina/version.rb
|
67
|
+
- lib/stamina-core/stamina-core.rb
|
68
|
+
homepage: https://github.com/blambeau/stamina
|
69
|
+
licenses: []
|
70
|
+
post_install_message:
|
71
|
+
rdoc_options: []
|
72
|
+
require_paths:
|
73
|
+
- lib/stamina-core
|
74
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
75
|
+
none: false
|
76
|
+
requirements:
|
77
|
+
- - ! '>='
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
requirements: []
|
87
|
+
rubyforge_project:
|
88
|
+
rubygems_version: 1.8.10
|
89
|
+
signing_key:
|
90
|
+
specification_version: 3
|
91
|
+
summary: Automaton and Regular Inference Toolkit
|
92
|
+
test_files: []
|
93
|
+
has_rdoc:
|