prop_logic-minisat 0.1.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 58166c821ac76416df796855ec4d203773622c36
4
+ data.tar.gz: 043106dc5a4e9a44dd5e019b451fc39afdb3ffec
5
+ SHA512:
6
+ metadata.gz: fafbfa7566a822727b7b14c1249a64a3759c61c34da2f88c04593055aeffa4009e7bf3e9f417c5b177443508d261881d71f7acb8bd6897667c144b4c2b8f788c
7
+ data.tar.gz: 974fa6a311e00da20d0b70bf2969e428ab409fafba8136287cb2427a3acb952aa54f10bf6cb5c2a9ff2dec34bd85d730b4c72335dafad9e32ae13282a52b32eb
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /vendor
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,11 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.0
4
+ - 2.1.6
5
+ - 2.0.0
6
+ - rbx-3.9
7
+ matrix:
8
+ allow_failures:
9
+ - rvm: rbx-3.9
10
+ before_install: gem install bundler -v 1.11.2
11
+
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in prop_logic-minisat.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Jkr2255
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,49 @@
1
+ # PropLogic::Minisat
2
+ Using MiniSat solver to boost [PropLogic](https://github.com/jkr2255/prop_logic), to practical level.
3
+
4
+ ## Installation
5
+
6
+ Add this line to your application's Gemfile:
7
+
8
+ ```ruby
9
+ gem 'prop_logic-minisat'
10
+ ```
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install prop_logic-minisat
19
+
20
+ ### for Windows users using MinGW Ruby (RubyInstaller & DevKit)
21
+ This gem uses [ruby-minisat](https://github.com/mame/ruby-minisat), which is hard to install in DevKit environment.
22
+
23
+ A modified edition of ruby-minisat for Windows is available in [jkr2255/ruby-minisat](https://github.com/jkr2255/ruby-minisat). You can use from Gemfile:
24
+
25
+ ```ruby
26
+ gem 'ruby-minisat', github: 'jkr2255/ruby-minisat'
27
+ gem 'prop_logic-minisat'
28
+ ```
29
+
30
+ ## Usage
31
+ This gem internally require [PropLogic](https://github.com/jkr2255/prop_logic) gem, and automatically replaces `PropLogic.sat_sovler` to this gem's `PropLogic::Minisat::Solver`.
32
+
33
+ Once loaded, you can benefit from MiniSat speed without rewriting codes for PropLogic.
34
+
35
+ ## Development
36
+
37
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
38
+
39
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
40
+
41
+ ## Contributing
42
+
43
+ Bug reports and pull requests are welcome on GitHub at https://github.com/jkr2255/prop_logic-minisat.
44
+
45
+
46
+ ## License
47
+
48
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
49
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "prop_logic/minisat"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,62 @@
1
+ require 'prop_logic'
2
+ require 'minisat'
3
+ require "prop_logic/minisat/version"
4
+
5
+ module PropLogic
6
+ module Minisat
7
+ class Solver
8
+ def self.call(term)
9
+ new.sat?(term)
10
+ end
11
+
12
+ private_class_method :new
13
+
14
+ def initialize
15
+ @solver = ::MiniSat::Solver.new
16
+ end
17
+
18
+ def parse_variable_or_not(term)
19
+ if term.is_a?(Variable)
20
+ @variable_map[term]
21
+ else
22
+ -(@variable_map[term.terms[0]])
23
+ end
24
+ end
25
+
26
+ def parse_or_term(term)
27
+ if term.is_a?(OrTerm)
28
+ @solver << term.terms.map{ |t| parse_variable_or_not(t) }
29
+ else
30
+ @solver << parse_variable_or_not(term)
31
+ end
32
+ end
33
+
34
+ def sat?(term)
35
+ cnf = term.to_cnf
36
+ orig_variables = term.variables
37
+ # no need to use SAT solver
38
+ return false if cnf == False
39
+ if cnf == True
40
+ return True if orig_variables.length == 0
41
+ return PropLogic.all_and(*orig_variables)
42
+ end
43
+ #prepare for solver
44
+ using_variables = cnf.variables
45
+ @variable_map = {}
46
+ using_variables.each{ |v| @variable_map[v] = @solver.new_var }
47
+ if cnf.is_a?(AndTerm)
48
+ cnf.terms.each{ |t| parse_or_term t}
49
+ else
50
+ parse_or_term term
51
+ end
52
+ return false unless @solver.solve
53
+ # return value generation
54
+ assign_variables = using_variables & orig_variables
55
+ extra_variables = orig_variables - assign_variables
56
+ PropLogic.all_and(*assign_variables.map{ |v| @solver[@variable_map[v]] ? v : -v }, *extra_variables)
57
+ end
58
+
59
+ end
60
+ end
61
+ PropLogic.sat_solver = Minisat::Solver
62
+ end
@@ -0,0 +1,5 @@
1
+ module PropLogic
2
+ module Minisat
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'prop_logic/minisat/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "prop_logic-minisat"
8
+ spec.version = PropLogic::Minisat::VERSION
9
+ spec.authors = ["Jkr2255"]
10
+ spec.email = ["magnesium.oxide.play@gmail.com"]
11
+
12
+ spec.summary = 'Minisat binding for PropLogic'
13
+ spec.homepage = "https://github.com/jkr2255/prop_logic-minisat"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "prop_logic", '>= 0.1.1'
22
+ spec.add_dependency "ruby-minisat", '>= 2.2.0'
23
+ spec.required_ruby_version = '>= 2.0.0'
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.11"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "rspec", "~> 3.0"
28
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: prop_logic-minisat
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jkr2255
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-01-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: prop_logic
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.1.1
20
+ version_requirements: !ruby/object:Gem::Requirement
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: 0.1.1
25
+ prerelease: false
26
+ type: :runtime
27
+ - !ruby/object:Gem::Dependency
28
+ name: ruby-minisat
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 2.2.0
34
+ version_requirements: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: 2.2.0
39
+ prerelease: false
40
+ type: :runtime
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.11'
48
+ version_requirements: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - "~>"
51
+ - !ruby/object:Gem::Version
52
+ version: '1.11'
53
+ prerelease: false
54
+ type: :development
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ version_requirements: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - "~>"
65
+ - !ruby/object:Gem::Version
66
+ version: '10.0'
67
+ prerelease: false
68
+ type: :development
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ version_requirements: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - "~>"
79
+ - !ruby/object:Gem::Version
80
+ version: '3.0'
81
+ prerelease: false
82
+ type: :development
83
+ description:
84
+ email:
85
+ - magnesium.oxide.play@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - bin/console
98
+ - bin/setup
99
+ - lib/prop_logic/minisat.rb
100
+ - lib/prop_logic/minisat/version.rb
101
+ - prop_logic-minisat.gemspec
102
+ homepage: https://github.com/jkr2255/prop_logic-minisat
103
+ licenses:
104
+ - MIT
105
+ metadata: {}
106
+ post_install_message:
107
+ rdoc_options: []
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: 2.0.0
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ requirements: []
121
+ rubyforge_project:
122
+ rubygems_version: 2.5.1
123
+ signing_key:
124
+ specification_version: 4
125
+ summary: Minisat binding for PropLogic
126
+ test_files: []