Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can this be made available as a library? #7

Open
Eh2406 opened this issue Jan 16, 2018 · 4 comments
Open

Can this be made available as a library? #7

Eh2406 opened this issue Jan 16, 2018 · 4 comments

Comments

@Eh2406
Copy link

Eh2406 commented Jan 16, 2018

Hi, I am in over my head. But it comes up from time to time that cargo could use a SAT solver to get faster or more reliable results. And this is a pure rust SAT solver, so what would be involved in putting this on crates.io with an api for dynamically building up a problem? Then perhaps using it in cargo?

@mishun
Copy link
Owner

mishun commented Jan 17, 2018

Hello!
What kind of API you have in mind?

I've never put something on crates.io before, so I can't confidently answer that question :) Also I know nothing about inner workings of how cargo resolves dependencies.

@Eh2406
Copy link
Author

Eh2406 commented Jan 17, 2018

So I don't know much about SAT solvers so I don't really know what the API should look like, but hear is a straw man.

extern crate minisat;
...

let mut s = minisat::Problem::new();
let x0 = s.new_var();
let x1 = s.new_var();
let x2 = s.new_var();
s.add_clause(&[x0, x1, x2]);
s.add_clause(&[x0, !x1]);
s.add_clause(&[x1, !x2]);
s.add_clause(&[x0, !x2]);
match s.solve() {
    Ok(solution) => println!("{:}", solution),
    Err(contradiction) => println!("{:}", contradiction),
}

Publishing on crates.io is surprisingly easy. See the doc at https://doc.rust-lang.org/cargo/reference/publishing.html

I also do not know how cargo resolves dependencies, but I am trying to figure it out. I think it is trying to solve a system of constraints.

  1. Recursively all dependencies of all depended upon crates must be satisfied.
  2. Can not have 2 or more semver compatible versions of the same crate.
  3. Not yet implemented; Can not have 2 or more -sys crates that link to the same thing.
    Then, If there are multiple solutions to the system take the one with the newest releases.

@rnbguy
Copy link

rnbguy commented Jan 26, 2018

This is exactly what it should look like. This is more or less standard minisat api, except minisat offers satisfying assignment as models and also supports incremental solving. Along with this, I will suggest some convenient functions like these.

@dralley
Copy link
Contributor

dralley commented Aug 8, 2019

There's a Rust crate that wraps the original minisat library that has basically this exact API: https://github.com/luteberget/minisat-rs

It also has a couple of convenient extensions (in Rust) such as the "Symbolic" API. The sudoku example in the README is a nice use case for that.

However being able to do this with a pure Rust solution would be awesome, so +1 to the idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants