https://github.com/tenderlove/ricosat
A wrapper around PicoSAT for Ruby
https://github.com/tenderlove/ricosat
ruby sat
Last synced: 10 months ago
JSON representation
A wrapper around PicoSAT for Ruby
- Host: GitHub
- URL: https://github.com/tenderlove/ricosat
- Owner: tenderlove
- Created: 2017-02-19T22:18:31.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-02-25T21:07:15.000Z (over 9 years ago)
- Last Synced: 2024-05-09T21:22:51.244Z (about 2 years ago)
- Topics: ruby, sat
- Language: C
- Size: 88.9 KB
- Stars: 2
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# ricosat
* https://github.com/tenderlove/ricosat
## DESCRIPTION:
RicoSAT is a wrapper around [PicoSAT](http://fmv.jku.at/picosat/). It lets
you use the PicoSAT solver from Ruby!
## FEATURES/PROBLEMS:
* It's a SAT solver! Not SAT like the tests, but the [Boolean satisfiability problem](https://en.wikipedia.org/wiki/Boolean_satisfiability_problem)
## INSTALLATION:
PicoSAT depends on [gmp](https://gmplib.org) and
[gperftools](https://github.com/gperftools/gperftools). On a Mac, these can be
installed in one shot with homebrew via `brew install gmp gperftools`.
Once you have those:
``` ruby
$ gem install ricosat
```
## SYNOPSIS:
Solve the problem (A and NOT B):
```ruby
A = 1
B = 2
sat = RicoSAT.new
sat.add(A); sat.add(0) # Rules must always end with 0
sat.add(-B); sat.add(0) # Negative means "not"
case sat.solve(-1)
when RicoSAT::SATISFIABLE
sat.variables.times.each do |i|
p((i + 1) => sat.deref(i + 1))
end
when RicoSAT::UNSATISFIABLE
raise "idk"
else
end
```
A is true, and B is false.
Solve the problem (A and NOT A):
```ruby
A = 1
sat = RicoSAT.new
sat.enable_trace_generation # Get access to SAT proofs
sat.add(A); sat.add(0) # Rules must always end with 0
sat.add(-A); sat.add(0) # Negative means "not"
case sat.solve(-1)
when RicoSAT::SATISFIABLE
raise "should not work"
when RicoSAT::UNSATISFIABLE
sat.added_original_clauses.times do |i|
if sat.coreclause(i) == 1
p [:clause, i, sat.corelit(1)]
end
end
sat.write_extended_trace $stdout
else
end
```
It's not solvable!
## INSTALL:
* gem install ricosat
## LICENSE:
(The MIT License)
Copyright (c) 2017 Aaron Patterson
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.