cudd-rb 0.0.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.
Files changed (68) hide show
  1. data/CHANGELOG.md +5 -0
  2. data/Gemfile +12 -0
  3. data/Gemfile.lock +26 -0
  4. data/LICENCE.md +22 -0
  5. data/Manifest.txt +15 -0
  6. data/README.md +7 -0
  7. data/Rakefile +11 -0
  8. data/cudd-rb.gemspec +188 -0
  9. data/cudd-rb.noespec +30 -0
  10. data/lib/cudd-rb/bdd.rb +68 -0
  11. data/lib/cudd-rb/cube.rb +94 -0
  12. data/lib/cudd-rb/errors.rb +4 -0
  13. data/lib/cudd-rb/interfaces/bdd.rb +334 -0
  14. data/lib/cudd-rb/interfaces/root.rb +35 -0
  15. data/lib/cudd-rb/loader.rb +1 -0
  16. data/lib/cudd-rb/manager.rb +78 -0
  17. data/lib/cudd-rb/version.rb +14 -0
  18. data/lib/cudd-rb/wrapper.rb +58 -0
  19. data/lib/cudd-rb.rb +46 -0
  20. data/spec/cube/test_equality.rb +22 -0
  21. data/spec/cube/test_hash.rb +34 -0
  22. data/spec/cube/test_new.rb +49 -0
  23. data/spec/cube/test_to_a012.rb +34 -0
  24. data/spec/cube/test_to_bdd.rb +42 -0
  25. data/spec/cube/test_to_cube.rb +18 -0
  26. data/spec/cube/test_to_dnf.rb +55 -0
  27. data/spec/cube/test_to_hash.rb +34 -0
  28. data/spec/cube/test_to_truths.rb +34 -0
  29. data/spec/cudd/test_manager.rb +35 -0
  30. data/spec/interfaces/bdd/test_and.rb +14 -0
  31. data/spec/interfaces/bdd/test_bdd2cube.rb +32 -0
  32. data/spec/interfaces/bdd/test_bdd2dnf.rb +39 -0
  33. data/spec/interfaces/bdd/test_cofactor.rb +44 -0
  34. data/spec/interfaces/bdd/test_cube.rb +61 -0
  35. data/spec/interfaces/bdd/test_cube2bdd.rb +22 -0
  36. data/spec/interfaces/bdd/test_each_cube.rb +79 -0
  37. data/spec/interfaces/bdd/test_eval.rb +76 -0
  38. data/spec/interfaces/bdd/test_exist.rb +24 -0
  39. data/spec/interfaces/bdd/test_forall.rb +24 -0
  40. data/spec/interfaces/bdd/test_is_complement.rb +26 -0
  41. data/spec/interfaces/bdd/test_ite.rb +18 -0
  42. data/spec/interfaces/bdd/test_ith_var.rb +34 -0
  43. data/spec/interfaces/bdd/test_ith_vars.rb +40 -0
  44. data/spec/interfaces/bdd/test_new_var.rb +36 -0
  45. data/spec/interfaces/bdd/test_new_vars.rb +45 -0
  46. data/spec/interfaces/bdd/test_not.rb +18 -0
  47. data/spec/interfaces/bdd/test_one.rb +26 -0
  48. data/spec/interfaces/bdd/test_one_cube.rb +35 -0
  49. data/spec/interfaces/bdd/test_or.rb +14 -0
  50. data/spec/interfaces/bdd/test_restrict.rb +26 -0
  51. data/spec/interfaces/bdd/test_satisfiable.rb +33 -0
  52. data/spec/interfaces/bdd/test_satisfied.rb +40 -0
  53. data/spec/interfaces/bdd/test_size.rb +33 -0
  54. data/spec/interfaces/bdd/test_support.rb +66 -0
  55. data/spec/interfaces/bdd/test_var_index.rb +26 -0
  56. data/spec/interfaces/bdd/test_var_name.rb +32 -0
  57. data/spec/interfaces/bdd/test_var_names.rb +25 -0
  58. data/spec/interfaces/bdd/test_zero.rb +26 -0
  59. data/spec/manager/test_interface.rb +49 -0
  60. data/spec/shared/a_bdd.rb +15 -0
  61. data/spec/spec_helper.rb +45 -0
  62. data/spec/test_cudd-rb.rb +8 -0
  63. data/spec/wrapper/test_assumptions.rb +28 -0
  64. data/tasks/gem.rake +73 -0
  65. data/tasks/spec_test.rake +71 -0
  66. data/tasks/unit_test.rake +76 -0
  67. data/tasks/yard.rake +51 -0
  68. metadata +218 -0
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ # 0.0.1 / FIX ME
2
+
3
+ * Enhancements
4
+
5
+ * Birthday!
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source 'http://rubygems.org'
2
+
3
+ group :runtime do
4
+ gem "ffi", "~> 1.1"
5
+ end
6
+
7
+ group :development do
8
+ gem "rake", "~> 0.9.2"
9
+ gem "rspec", "~> 2.11"
10
+ gem "yard", "~> 0.7.2"
11
+ gem "bluecloth", "~> 2.2"
12
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,26 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ bluecloth (2.2.0)
5
+ diff-lcs (1.1.3)
6
+ ffi (1.1.5)
7
+ rake (0.9.2.2)
8
+ rspec (2.11.0)
9
+ rspec-core (~> 2.11.0)
10
+ rspec-expectations (~> 2.11.0)
11
+ rspec-mocks (~> 2.11.0)
12
+ rspec-core (2.11.1)
13
+ rspec-expectations (2.11.3)
14
+ diff-lcs (~> 1.1.3)
15
+ rspec-mocks (2.11.2)
16
+ yard (0.7.5)
17
+
18
+ PLATFORMS
19
+ ruby
20
+
21
+ DEPENDENCIES
22
+ bluecloth (~> 2.2)
23
+ ffi (~> 1.1)
24
+ rake (~> 0.9.2)
25
+ rspec (~> 2.11)
26
+ yard (~> 0.7.2)
data/LICENCE.md ADDED
@@ -0,0 +1,22 @@
1
+ # The MIT Licence
2
+
3
+ Copyright (c) 2012 - Bernard Lambeau
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Manifest.txt ADDED
@@ -0,0 +1,15 @@
1
+ cudd-rb.gemspec
2
+ cudd-rb.noespec
3
+ .gemtest
4
+ CHANGELOG.md
5
+ Gemfile
6
+ Gemfile.lock
7
+ bin/**/*
8
+ lib/**/*
9
+ LICENCE.md
10
+ Manifest.txt
11
+ Rakefile
12
+ README.md
13
+ spec/**/*
14
+ tasks/**/*
15
+ test/**/*
data/README.md ADDED
@@ -0,0 +1,7 @@
1
+ # Cudd
2
+
3
+ A ruby bridge to the CU Decision Diagram package (CUDD).
4
+
5
+ ## Links
6
+
7
+ https://github.com/blambeau/cudd-rb
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ # We run tests by default
2
+ task :default => :test
3
+
4
+ #
5
+ # Install all tasks found in tasks folder
6
+ #
7
+ # See .rake files there for complete documentation.
8
+ #
9
+ Dir["tasks/*.rake"].each do |taskfile|
10
+ load taskfile
11
+ end
data/cudd-rb.gemspec ADDED
@@ -0,0 +1,188 @@
1
+ # We require your library, mainly to have access to the VERSION number.
2
+ # Feel free to set $version manually.
3
+ $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
4
+ require "cudd-rb/version"
5
+ $version = Cudd::Version.to_s
6
+
7
+ #
8
+ # This is your Gem specification. Default values are provided so that your library
9
+ # should be correctly packaged given what you have described in the .noespec file.
10
+ #
11
+ Gem::Specification.new do |s|
12
+
13
+ ################################################################### ABOUT YOUR GEM
14
+
15
+ # Gem name (required)
16
+ s.name = "cudd-rb"
17
+
18
+ # Gem version (required)
19
+ s.version = $version
20
+
21
+ # A short summary of this gem
22
+ #
23
+ # This is displayed in `gem list -d`.
24
+ s.summary = "A ruby bridge to the CU Decision Diagram package (CUDD)."
25
+
26
+ # A long description of this gem (required)
27
+ #
28
+ # The description should be more detailed than the summary. For example,
29
+ # you might wish to copy the entire README into the description.
30
+ s.description = "cudd-rb is a ruby bridge to the CU Decision Diagram (CUDD), an implementation of \nBinary Decision Diagrams."
31
+
32
+ # The URL of this gem home page (optional)
33
+ s.homepage = "https://github.com/blambeau/cudd-rb"
34
+
35
+ # Gem publication date (required but auto)
36
+ #
37
+ # Today is automatically used by default, uncomment only if
38
+ # you know what you do!
39
+ #
40
+ # s.date = Time.now.strftime('%Y-%m-%d')
41
+
42
+ # The license(s) for the library. Each license must be a short name, no
43
+ # more than 64 characters.
44
+ #
45
+ # s.licences = %w{}
46
+
47
+ # The rubyforge project this gem lives under (optional)
48
+ #
49
+ # s.rubyforge_project = nil
50
+
51
+ ################################################################### ABOUT THE AUTHORS
52
+
53
+ # The list of author names who wrote this gem.
54
+ #
55
+ # If you are providing multiple authors and multiple emails they should be
56
+ # in the same order.
57
+ #
58
+ s.authors = ["Bernard Lambeau"]
59
+
60
+ # Contact emails for this gem
61
+ #
62
+ # If you are providing multiple authors and multiple emails they should be
63
+ # in the same order.
64
+ #
65
+ # NOTE: Somewhat strangly this attribute is always singular!
66
+ # Don't replace by s.emails = ...
67
+ s.email = ["blambeau@gmail.com"]
68
+
69
+ ################################################################### PATHS, FILES, BINARIES
70
+
71
+ # Paths in the gem to add to $LOAD_PATH when this gem is
72
+ # activated (required).
73
+ #
74
+ # The default 'lib' is typically sufficient.
75
+ s.require_paths = ["lib"]
76
+
77
+ # Files included in this gem.
78
+ #
79
+ # By default, we take all files included in the Manifest.txt file on root
80
+ # of the project. Entries of the manifest are interpreted as Dir[...]
81
+ # patterns so that lazy people may use wilcards like lib/**/*
82
+ #
83
+ here = File.expand_path(File.dirname(__FILE__))
84
+ s.files = File.readlines(File.join(here, 'Manifest.txt')).
85
+ inject([]){|files, pattern| files + Dir[File.join(here, pattern.strip)]}.
86
+ collect{|x| x[(1+here.size)..-1]}
87
+
88
+ # Test files included in this gem.
89
+ #
90
+ s.test_files = Dir["test/**/*"] + Dir["spec/**/*"]
91
+
92
+ # The path in the gem for executable scripts (optional)
93
+ #
94
+ s.bindir = "bin"
95
+
96
+ # Executables included in the gem.
97
+ #
98
+ s.executables = (Dir["bin/*"]).collect{|f| File.basename(f)}
99
+
100
+ ################################################################### REQUIREMENTS & INSTALL
101
+ # Remember the gem version requirements operators and schemes:
102
+ # = Equals version
103
+ # != Not equal to version
104
+ # > Greater than version
105
+ # < Less than version
106
+ # >= Greater than or equal to
107
+ # <= Less than or equal to
108
+ # ~> Approximately greater than
109
+ #
110
+ # Don't forget to have a look at http://lmgtfy.com/?q=Ruby+Versioning+Policies
111
+ # for setting your gem version.
112
+ #
113
+ # For your requirements to other gems, remember that
114
+ # ">= 2.2.0" (optimistic: specify minimal version)
115
+ # ">= 2.2.0", "< 3.0" (pessimistic: not greater than the next major)
116
+ # "~> 2.2" (shortcut for ">= 2.2.0", "< 3.0")
117
+ # "~> 2.2.0" (shortcut for ">= 2.2.0", "< 2.3.0")
118
+ #
119
+
120
+ #
121
+ # One call to add_dependency('gem_name', 'gem version requirement') for each
122
+ # runtime dependency. These gems will be installed with your gem.
123
+ # One call to add_development_dependency('gem_name', 'gem version requirement')
124
+ # for each development dependency. These gems are required for developers
125
+ #
126
+ s.add_development_dependency("rake", "~> 0.9.2")
127
+ s.add_development_dependency("rspec", "~> 2.11")
128
+ s.add_development_dependency("yard", "~> 0.7.2")
129
+ s.add_development_dependency("bluecloth", "~> 2.2")
130
+ s.add_dependency("ffi", "~> 1.0")
131
+
132
+ # The version of ruby required by this gem
133
+ #
134
+ # Uncomment and set this if your gem requires specific ruby versions.
135
+ #
136
+ # s.required_ruby_version = ">= 0"
137
+
138
+ # The RubyGems version required by this gem
139
+ #
140
+ # s.required_rubygems_version = ">= 0"
141
+
142
+ # The platform this gem runs on. See Gem::Platform for details.
143
+ #
144
+ # s.platform = nil
145
+
146
+ # Extensions to build when installing the gem.
147
+ #
148
+ # Valid types of extensions are extconf.rb files, configure scripts
149
+ # and rakefiles or mkrf_conf files.
150
+ #
151
+ s.extensions = []
152
+
153
+ # External (to RubyGems) requirements that must be met for this gem to work.
154
+ # It’s simply information for the user.
155
+ #
156
+ s.requirements = nil
157
+
158
+ # A message that gets displayed after the gem is installed
159
+ #
160
+ # Uncomment and set this if you want to say something to the user
161
+ # after gem installation
162
+ #
163
+ s.post_install_message = nil
164
+
165
+ ################################################################### SECURITY
166
+
167
+ # The key used to sign this gem. See Gem::Security for details.
168
+ #
169
+ # s.signing_key = nil
170
+
171
+ # The certificate chain used to sign this gem. See Gem::Security for
172
+ # details.
173
+ #
174
+ # s.cert_chain = []
175
+
176
+ ################################################################### RDOC
177
+
178
+ # An ARGV style array of options to RDoc
179
+ #
180
+ # See 'rdoc --help' about this
181
+ #
182
+ s.rdoc_options = []
183
+
184
+ # Extra files to add to RDoc such as README
185
+ #
186
+ s.extra_rdoc_files = Dir["README.md"] + Dir["CHANGELOG.md"] + Dir["LICENCE.md"]
187
+
188
+ end
data/cudd-rb.noespec ADDED
@@ -0,0 +1,30 @@
1
+ template-info:
2
+ name: "rubygem.noe"
3
+ version: 1.7.4
4
+ manifest:
5
+ tasks/debug_mail.txt:
6
+ ignore: true
7
+ tasks/debug_mail.rake:
8
+ ignore: true
9
+ variables:
10
+ lower:
11
+ cudd-rb
12
+ upper:
13
+ Cudd
14
+ version:
15
+ 0.0.1
16
+ summary: |-
17
+ A ruby bridge to the CU Decision Diagram package (CUDD).
18
+ description: |-
19
+ cudd-rb is a ruby bridge to the CU Decision Diagram (CUDD), an implementation of
20
+ Binary Decision Diagrams.
21
+ authors:
22
+ - {name: Bernard Lambeau, email: blambeau@gmail.com}
23
+ links:
24
+ - https://github.com/blambeau/cudd-rb
25
+ dependencies:
26
+ - {name: ffi, version: "~> 1.0", groups: [runtime]}
27
+ - {name: rake, version: "~> 0.9.2", groups: [development]}
28
+ - {name: rspec, version: "~> 2.11", groups: [development]}
29
+ - {name: yard, version: "~> 0.7.2", groups: [development]}
30
+ - {name: bluecloth, version: "~> 2.2", groups: [development]}
@@ -0,0 +1,68 @@
1
+ module Cudd
2
+ module BDD
3
+
4
+ def self.define_delegate_method(from, to = from)
5
+ define_method from do |*args, &bl|
6
+ manager.send(to, *([self] + args), &bl)
7
+ end
8
+ end
9
+
10
+ def self.define_delegate_methods(*methods)
11
+ methods = methods.first if methods.size==1 && methods.first.is_a?(Hash)
12
+ methods.each do |m|
13
+ define_delegate_method *Array(m)
14
+ end
15
+ end
16
+
17
+ attr_reader :manager
18
+
19
+ define_delegate_methods(:var_index, :var_name)
20
+ alias :index :var_index
21
+ alias :name :var_name
22
+
23
+ def zero?
24
+ self == manager.zero
25
+ end
26
+ alias :false? :zero?
27
+ alias :contradiction? :zero?
28
+
29
+ def one?
30
+ self == manager.one
31
+ end
32
+ alias :true? :one?
33
+ alias :tautology? :one?
34
+
35
+ define_delegate_methods(:ref, :deref)
36
+ define_delegate_methods(:is_complement?)
37
+
38
+ define_delegate_methods(:ite)
39
+ define_delegate_methods(:and, :or, :not, :nand, :nor, :xor, :xnor)
40
+ define_delegate_methods(:& => :and, :| => :or, :! => :not)
41
+ define_delegate_methods(:* => :and, :+ => :or, :~ => :not)
42
+
43
+ define_delegate_methods(:cofactor, :restrict)
44
+ define_delegate_methods(:exist_abstract, :univ_abstract, :exist, :univ, :forall)
45
+
46
+ define_delegate_methods(:eval, :satisfiable?, :satisfied?)
47
+ define_delegate_methods(:each_cube, :one_cube, :all_cubes)
48
+
49
+ define_delegate_methods(:support)
50
+
51
+ define_delegate_methods(:to_cube => :bdd2cube, :to_dnf => :bdd2dnf)
52
+
53
+ def hash
54
+ address.hash
55
+ end
56
+
57
+ def ==(other)
58
+ address==other.address
59
+ end
60
+ alias :eql? :==
61
+
62
+ def to_s
63
+ "BDD(#{address})"
64
+ end
65
+ alias :inspect :to_s
66
+
67
+ end # module BDD
68
+ end # module Cudd
@@ -0,0 +1,94 @@
1
+ module Cudd
2
+ class Cube
3
+
4
+ attr_reader :interface
5
+
6
+ def initialize(interface, a012)
7
+ @interface = interface
8
+ @a012 = a012.freeze
9
+ end
10
+
11
+ def self.new(interface, arg)
12
+ return arg if arg.is_a?(Cube)
13
+ if arg.is_a?(BDD)
14
+ super(interface, interface.bdd2cube(arg))
15
+ else
16
+ a012 = Array.new(interface.size, 2)
17
+ enum = arg.is_a?(Hash) ? arg.each_pair : arg.each_with_index
18
+ enum.each do |k,v|
19
+ k,v = v,k unless arg.is_a?(Hash)
20
+ index = [k, v].find{|x| x.is_a?(Cudd::BDD) }.index rescue k
21
+ a012[index] = truth_to_012(v)
22
+ end
23
+ super(interface, a012)
24
+ end
25
+ end
26
+
27
+ def hash
28
+ @hash ||= to_a012.hash + 37*interface.hash
29
+ end
30
+
31
+ def ==(other)
32
+ return nil unless other.is_a?(Cube) && other.interface==interface
33
+ to_a012 == other.to_a012
34
+ end
35
+
36
+ def to_cube
37
+ self
38
+ end
39
+
40
+ def to_a012
41
+ @a012
42
+ end
43
+
44
+ def to_bdd
45
+ interface.cube2bdd(to_a012)
46
+ end
47
+
48
+ def to_truths
49
+ to_a012.map{|x| Cube.arg012_to_truth(x)}
50
+ end
51
+
52
+ def to_hash
53
+ h = {}
54
+ to_a012.each_with_index do |val,index|
55
+ truth = Cube.arg012_to_truth(val)
56
+ h[interface.ith_var(index)] = truth unless truth.nil?
57
+ end
58
+ h
59
+ end
60
+
61
+ def to_dnf
62
+ buf = ""
63
+ to_a012.each_with_index do |val, index|
64
+ next if val == 2
65
+ name = interface.ith_var(index).var_name
66
+ name = name.respond_to?(:to_dnf) ? name.to_dnf : name.to_s
67
+ buf << " & " unless buf.empty?
68
+ buf << "!" if val==0
69
+ buf << name
70
+ end
71
+ buf
72
+ end
73
+ alias :to_s :to_dnf
74
+
75
+ private
76
+
77
+ def self.arg012_to_truth(arg012)
78
+ arg012 <= 1 ? (arg012 == 1) : nil
79
+ end
80
+
81
+ def self.truth_to_012(truth)
82
+ case truth
83
+ when Cudd::BDD then truth.is_complement? ? 0 : 1
84
+ when Integer then (truth >= 0 and truth <= 1) ? truth : 2
85
+ when TrueClass then 1
86
+ when FalseClass then 0
87
+ when NilClass then 2
88
+ else
89
+ raise ArgumentError, "Invalid truth value #{truth}"
90
+ end
91
+ end
92
+
93
+ end # class Cube
94
+ end # module Cudd
@@ -0,0 +1,4 @@
1
+ module Cudd
2
+ class Error < StandardError; end
3
+ class NotACubeError < StandardError; end
4
+ end