irfansharif / solver

SAT solver library in Go; wraps around Google's Operational Research Tools
Apache License 2.0
23 stars 9 forks source link

Support CMake/Make in addition to Bazel #5

Open solanu opened 3 years ago

solanu commented 3 years ago

I get the following error when I run the example of the readme.md:

$ go run main.go 
# github.com/irfansharif/solver/internal
wrapper.cc:355:10: fatal error: ortools/base/basictypes.h: No such file or directory
 #include "ortools/base/basictypes.h"
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
irfansharif commented 3 years ago

Are you using bazel for your build? For now this library comes with the caveat that you need to use bazel (though PRs to make it work with make/etc. are welcome, just not something I'll get to until a month or two). https://github.com/irfansharif/allocator/tree/210808.debuggability is an example of a package that uses this library if you want pointers on how.

RobinKamps commented 2 years ago

Can you please give an example/advice how to build a project with this library as a dependency? (with the included top Makefile a project like the following main.go is not working)

package main

import (
    "github.com/irfansharif/solver"
    "log"
)

func main() {
    model := solver.NewModel("test")

    var numVals int64 = 3
    x := model.NewIntVar(0, numVals-1, "x")
    y := model.NewIntVar(0, numVals-1, "y")
    z := model.NewIntVar(0, numVals-1, "z")

    ct := solver.NewAllDifferentConstraint(x, y, z)
    model.AddConstraints(ct)

    result := model.Solve()
    log.Printf("optimal result: %v", result.Optimal())
    log.Printf("x: %v, y: %v, z: %v", result.Value(x), result.Value(y), result.Value(z))
}
irfansharif commented 2 years ago

https://github.com/irfansharif/allocator is one example (https://github.com/irfansharif/allocator/tree/210808.debuggability is a branch using a more recent version of this library).

RobinKamps commented 2 years ago

Thank you very much.

thomaspeugeot commented 2 years ago

I agree with @RobinKamps , it would be most welcomed to have something simpler for compiling with dependencies. Go is the promise of a simple toolchain and I feel like "pre go" times with bazel & makefile & long compile time. I would have contributed for this with pleasure but I am not at all familiar with the techniques involved.

irfansharif commented 2 years ago

There’s a C++ dependency involved, and consequently cgo; some of this pain is unavoidable. What I’ve seen work for dependencies like this is linking against pre-built binary archives for various architectures and distributing that as part of the library itself. That’s a sizeable amount of work however and I’m unlikely to be able to do it.

thomaspeugeot commented 2 years ago

Ok, I understand. I surmise this is the kind of work they have done with the sqlite3 wrap. Thks for your answer.