prop_logic-sat4j 2.3.5.0-java
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 +7 -0
- data/.gitignore +11 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/CHANGELOG.md +2 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +33 -0
- data/README.md +54 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/org.sat4j.core.jar +0 -0
- data/lib/prop_logic/sat4j.rb +18 -0
- data/lib/prop_logic/sat4j/incremental_solver.rb +123 -0
- data/lib/prop_logic/sat4j/version.rb +5 -0
- data/prop_logic-sat4j.gemspec +28 -0
- metadata +115 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 695569e820c24ec124376c66e80974094ea7a2fe
|
4
|
+
data.tar.gz: 800a825c3376128afc5f63fd597d013e30498054
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a1a9526bf9d933fa88bdaa7e5980fac78149635ea09e3cb206884ccc0eddb8725a0b88916424b7885a63690e8cb0310a95e74d4cec42061eec73a593d0057235
|
7
|
+
data.tar.gz: 75dc2a52993e5a36ed1d299f4424d7e4fe48663d2ddca1b868e6dc47009fcd2d098c44ab030833c752559f71a825dd56bdbf31057d6117caded8757307e00fa4
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
Sat4j license is as follows:
|
2
|
+
/*******************************************************************************
|
3
|
+
* SAT4J: a SATisfiability library for Java Copyright (C) 2004, 2012 Artois University and CNRS
|
4
|
+
*
|
5
|
+
* All rights reserved. This program and the accompanying materials
|
6
|
+
* are made available under the terms of the Eclipse Public License v1.0
|
7
|
+
* which accompanies this distribution, and is available at
|
8
|
+
* http://www.eclipse.org/legal/epl-v10.html
|
9
|
+
*
|
10
|
+
* Alternatively, the contents of this file may be used under the terms of
|
11
|
+
* either the GNU Lesser General Public License Version 2.1 or later (the
|
12
|
+
* "LGPL"), in which case the provisions of the LGPL are applicable instead
|
13
|
+
* of those above. If you wish to allow use of your version of this file only
|
14
|
+
* under the terms of the LGPL, and not to allow others to use your version of
|
15
|
+
* this file under the terms of the EPL, indicate your decision by deleting
|
16
|
+
* the provisions above and replace them with the notice and other provisions
|
17
|
+
* required by the LGPL. If you do not delete the provisions above, a recipient
|
18
|
+
* may use your version of this file under the terms of the EPL or the LGPL.
|
19
|
+
*
|
20
|
+
* Based on the original MiniSat specification from:
|
21
|
+
*
|
22
|
+
* An extensible SAT solver. Niklas Een and Niklas Sorensson. Proceedings of the
|
23
|
+
* Sixth International Conference on Theory and Applications of Satisfiability
|
24
|
+
* Testing, LNCS 2919, pp 502-518, 2003.
|
25
|
+
*
|
26
|
+
* See www.minisat.se for the original solver in C++.
|
27
|
+
*
|
28
|
+
* Contributors:
|
29
|
+
* CRIL - initial API and implementation
|
30
|
+
*******************************************************************************/
|
31
|
+
|
32
|
+
Ruby part is (c) 2016, Jkr2255
|
33
|
+
The same license as Sat4j is applied.
|
data/README.md
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# PropLogic::Sat4j
|
2
|
+
|
3
|
+
Using [Sat4j](http://www.sat4j.org/) solver to boost [PropLogic](https://github.com/jkr2255/prop_logic), to practical level.
|
4
|
+
|
5
|
+
Note: This gem works only on JRuby.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'prop_logic-sat4j'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install prop_logic-sat4j
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
This gem internally require [PropLogic](https://github.com/jkr2255/prop_logic) gem, and automatically replaces `PropLogic.sat_sovler` to this gem's `PropLogic::Sat4j::Solver`.
|
25
|
+
|
26
|
+
Once loaded, you can benefit from Sat4j speed without rewriting codes for PropLogic.
|
27
|
+
|
28
|
+
### Incremental solver
|
29
|
+
In `PropLogic.sat_loop` and `PropLogic::Term#each_sat`, `PropLogic::Sat4j::IncrementalSolver#add` performs real incremental addition,
|
30
|
+
keeping learnt clauses.
|
31
|
+
|
32
|
+
## Development
|
33
|
+
|
34
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
35
|
+
|
36
|
+
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` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
37
|
+
|
38
|
+
## Versioning
|
39
|
+
This gem is versioned respecting Sat4j's: Ver. a.b.c.d includes Sat4j Ver. a.b.c .
|
40
|
+
|
41
|
+
## Contributing
|
42
|
+
|
43
|
+
1. Fork it ( https://github.com/jkr2255/prop_logic-sat4j/fork )
|
44
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
45
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
46
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
47
|
+
5. Create a new Pull Request
|
48
|
+
|
49
|
+
## License
|
50
|
+
|
51
|
+
The same license as Sat4j ([EPL 1.0](http://www.eclipse.org/legal/epl-v10.html)/LGPL >= 2.1) is applied to this gem.
|
52
|
+
|
53
|
+
This gem includes Sat4j Ver. 2.3.5 binary with no modifications. The source code of Sat4j is available at [Sat4j project site](http://www.sat4j.org/).
|
54
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "prop_logic/sat4j"
|
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
Binary file
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require "prop_logic/sat4j/version"
|
2
|
+
require 'java'
|
3
|
+
require 'org.sat4j.core'
|
4
|
+
require 'prop_logic'
|
5
|
+
require 'prop_logic/sat4j/incremental_solver'
|
6
|
+
|
7
|
+
|
8
|
+
module PropLogic
|
9
|
+
module Sat4j
|
10
|
+
module Solver
|
11
|
+
def self.call(term)
|
12
|
+
IncrementalSolver.new(term).sat?
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
PropLogic.sat_solver = Sat4j::Solver
|
17
|
+
PropLogic.incremental_solver = Sat4j::IncrementalSolver
|
18
|
+
end
|
@@ -0,0 +1,123 @@
|
|
1
|
+
module PropLogic
|
2
|
+
module Sat4j
|
3
|
+
#
|
4
|
+
# Incremental solver using Sat4j.
|
5
|
+
#
|
6
|
+
class IncrementalSolver
|
7
|
+
|
8
|
+
# shorthand for Java class
|
9
|
+
VecInt = org.sat4j.core.VecInt
|
10
|
+
ContradictionException = Java::OrgSat4jSpecs::ContradictionException
|
11
|
+
|
12
|
+
# constructor.
|
13
|
+
# @param [Term] initial term for starting SAT solver.
|
14
|
+
def initialize(initial_term)
|
15
|
+
@solver = Java::OrgSat4jMinisat::SolverFactory.newDefault
|
16
|
+
@solver.newVar initial_term.variables.length
|
17
|
+
# automagically add variable in Hash
|
18
|
+
@variables_map = Hash.new { |h, k| h[k] = h.length + 1 }
|
19
|
+
@terms = []
|
20
|
+
@variables = []
|
21
|
+
@reversed_count = 0
|
22
|
+
# true if False was added
|
23
|
+
@contradicted = false
|
24
|
+
add initial_term
|
25
|
+
end
|
26
|
+
|
27
|
+
# @return [Array] containing variables
|
28
|
+
def variables
|
29
|
+
@variables.dup
|
30
|
+
end
|
31
|
+
|
32
|
+
def term
|
33
|
+
return False if @contradicted
|
34
|
+
return True if @terms.empty?
|
35
|
+
PropLogic.all_and(*@terms)
|
36
|
+
end
|
37
|
+
|
38
|
+
# add terms to this solver.
|
39
|
+
# @return [IncrementalSolver] returns self
|
40
|
+
def add(*terms)
|
41
|
+
terms.each { |term| add_one_term term }
|
42
|
+
self
|
43
|
+
end
|
44
|
+
|
45
|
+
alias_method :<<, :add
|
46
|
+
|
47
|
+
# check if terms are satisfiable.
|
48
|
+
# @return [Term] term satisfying conditions.
|
49
|
+
# @return [false] if unsatisfied.
|
50
|
+
def sat?
|
51
|
+
return false if @contradicted
|
52
|
+
return True if variables.empty?
|
53
|
+
solver_vars = []
|
54
|
+
unless @terms.empty?
|
55
|
+
return false unless @solver.satisfiable?
|
56
|
+
sat_model = @solver.model.to_a
|
57
|
+
solver_vars = sat_model.map { |i| variable_from_int i }.compact
|
58
|
+
end
|
59
|
+
solver_true_vars = solver_vars.map do |v|
|
60
|
+
v.is_a?(NotTerm) ? v.terms[0] : v
|
61
|
+
end
|
62
|
+
extra_vars = variables - solver_true_vars
|
63
|
+
PropLogic.all_and(*solver_vars, *extra_vars)
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
def generate_inverse_map
|
69
|
+
return unless @reversed_count != @variables_map.length
|
70
|
+
@reversed_vars = {}
|
71
|
+
set_vars = @variables_map.keys & variables
|
72
|
+
set_vars.each { |v| @reversed_vars[@variables_map[v]] = v }
|
73
|
+
@reversed_count = @variables_map.length
|
74
|
+
end
|
75
|
+
|
76
|
+
def variable_from_int(num)
|
77
|
+
generate_inverse_map
|
78
|
+
var = @reversed_vars[num.abs]
|
79
|
+
return unless var
|
80
|
+
num > 0 ? var : ~var
|
81
|
+
end
|
82
|
+
|
83
|
+
def sat_variable(maybe_inversed_variable)
|
84
|
+
case maybe_inversed_variable
|
85
|
+
when Variable
|
86
|
+
@variables_map[maybe_inversed_variable]
|
87
|
+
when NotTerm
|
88
|
+
-@variables_map[maybe_inversed_variable.terms[0]]
|
89
|
+
else
|
90
|
+
raise TypeError
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def add_or_term(term)
|
95
|
+
vars = if term.is_a?(OrTerm)
|
96
|
+
term.terms.map { |v| sat_variable v }
|
97
|
+
else
|
98
|
+
[sat_variable(term)]
|
99
|
+
end
|
100
|
+
@terms << term
|
101
|
+
@solver.addClause VecInt.new(vars.to_java(Java::int))
|
102
|
+
rescue ContradictionException
|
103
|
+
@contradicted = true
|
104
|
+
end
|
105
|
+
|
106
|
+
def add_one_term(term)
|
107
|
+
@variables |= term.variables
|
108
|
+
term = term.to_cnf
|
109
|
+
return if term == True
|
110
|
+
if term == False
|
111
|
+
@contradicted = true
|
112
|
+
return
|
113
|
+
end
|
114
|
+
if term.is_a?(AndTerm)
|
115
|
+
term.terms.each { |t| add_or_term t }
|
116
|
+
else
|
117
|
+
add_or_term term
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|
122
|
+
end
|
123
|
+
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/sat4j/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "prop_logic-sat4j"
|
8
|
+
spec.version = PropLogic::Sat4j::VERSION
|
9
|
+
spec.authors = ["Jkr2255"]
|
10
|
+
spec.email = ["magnesium.oxide.play@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = 'Sat4j bindings for prop_logic'
|
13
|
+
spec.homepage = "https://github.com/jkr2255/prop_logic-sat4j"
|
14
|
+
spec.license = "EPL/LGPL"
|
15
|
+
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_dependency "prop_logic", '>= 0.2.0'
|
23
|
+
spec.platform = 'java'
|
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,115 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: prop_logic-sat4j
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.3.5.0
|
5
|
+
platform: java
|
6
|
+
authors:
|
7
|
+
- Jkr2255
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-04-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
15
|
+
requirements:
|
16
|
+
- - ">="
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: 0.2.0
|
19
|
+
name: prop_logic
|
20
|
+
prerelease: false
|
21
|
+
type: :runtime
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.2.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - "~>"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '1.11'
|
33
|
+
name: bundler
|
34
|
+
prerelease: false
|
35
|
+
type: :development
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.11'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '10.0'
|
47
|
+
name: rake
|
48
|
+
prerelease: false
|
49
|
+
type: :development
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '3.0'
|
61
|
+
name: rspec
|
62
|
+
prerelease: false
|
63
|
+
type: :development
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
- magnesium.oxide.play@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- ".travis.yml"
|
79
|
+
- CHANGELOG.md
|
80
|
+
- Gemfile
|
81
|
+
- LICENSE.txt
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- bin/console
|
85
|
+
- bin/setup
|
86
|
+
- lib/org.sat4j.core.jar
|
87
|
+
- lib/prop_logic/sat4j.rb
|
88
|
+
- lib/prop_logic/sat4j/incremental_solver.rb
|
89
|
+
- lib/prop_logic/sat4j/version.rb
|
90
|
+
- prop_logic-sat4j.gemspec
|
91
|
+
homepage: https://github.com/jkr2255/prop_logic-sat4j
|
92
|
+
licenses:
|
93
|
+
- EPL/LGPL
|
94
|
+
metadata: {}
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options: []
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
requirements: []
|
110
|
+
rubyforge_project:
|
111
|
+
rubygems_version: 2.4.8
|
112
|
+
signing_key:
|
113
|
+
specification_version: 4
|
114
|
+
summary: Sat4j bindings for prop_logic
|
115
|
+
test_files: []
|