Skip to content

Commit

Permalink
Prune out extraneous bazel dependencies
Browse files Browse the repository at this point in the history
And add pretty-printing for non-overlapping constraint.
  • Loading branch information
irfansharif committed Oct 2, 2021
1 parent 263d25e commit 3ace05d
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 109 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
OR-Tools for Go
Solver
---

[![Go Reference](https://pkg.go.dev/badge/github.com/irfansharif/solver.svg)](https://godocs.io/github.com/irfansharif/solver)

This project contains a cgo-based API for using Google's [Operations Research
This is a SAT solver library; underneath the hood it's using cgo and links
against Google's [Operations Research
Tools](https://developers.google.com/optimization/). It exposes a high-level
package for the [CP-SAT
Solver](https://developers.google.com/optimization/cp/cp_solver), targeting the
Expand Down
111 changes: 10 additions & 101 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository", "new_git_repository")

# TODO(irfansharif): Update to latest or-tools. Some of these dependencies
# (like glog/gflags) will no longer be needed.
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")

git_repository(
name = "ortools",
Expand All @@ -11,24 +8,9 @@ git_repository(
)

git_repository(
name = "com_github_gflags_gflags",
commit = "e171aa2", # release v2.2.2
remote = "https://github.com/gflags/gflags.git",
)

git_repository(
name = "com_github_glog_glog",
commit = "96a2f23", # release v0.4.0
remote = "https://github.com/google/glog.git",
)

http_archive(
name = "bazel_skylib",
sha256 = "1c531376ac7e5a180e0237938a2536de0c54d93f5c278634818e0efc952dd56c",
urls = [
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.0.3/bazel-skylib-1.0.3.tar.gz",
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.0.3/bazel-skylib-1.0.3.tar.gz",
],
name = "com_google_absl",
commit = "e1d388e", # release 20210324.1
remote = "https://github.com/abseil/abseil-cpp.git",
)

git_repository(
Expand All @@ -37,63 +19,13 @@ git_repository(
remote = "https://github.com/protocolbuffers/protobuf.git",
)

git_repository(
name = "com_google_absl",
commit = "e1d388e", # release 20210324.1
remote = "https://github.com/abseil/abseil-cpp.git",
)

http_archive(
name = "rules_cc",
strip_prefix = "rules_cc-262ebec3c2296296526740db4aefce68c80de7fa",
urls = ["https://github.com/bazelbuild/rules_cc/archive/262ebec3c2296296526740db4aefce68c80de7fa.zip"],
)

load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")

# Load common dependencies.
# Load dependencies needed to compile protobuf.
protobuf_deps()

http_archive(
name = "gtest",
build_file = "@ortools//bazel:gtest.BUILD",
strip_prefix = "googletest-release-1.8.0/googletest",
url = "https://github.com/google/googletest/archive/release-1.8.0.zip",
)

http_archive(
name = "glpk",
build_file = "@ortools//bazel:glpk.BUILD",
sha256 = "4281e29b628864dfe48d393a7bedd781e5b475387c20d8b0158f329994721a10",
url = "http://ftp.gnu.org/gnu/glpk/glpk-4.65.tar.gz",
)

http_archive(
name = "scip",
build_file = "@ortools//bazel:scip.BUILD",
patches = ["@ortools//bazel:scip.patch"],
sha256 = "033bf240298d3a1c92e8ddb7b452190e0af15df2dad7d24d0572f10ae8eec5aa",
url = "https://github.com/google/or-tools/releases/download/v7.7/scip-7.0.1.tgz",
)

http_archive(
name = "bliss",
build_file = "@ortools//bazel:bliss.BUILD",
patches = ["@ortools//bazel:bliss-0.73.patch"],
sha256 = "f57bf32804140cad58b1240b804e0dbd68f7e6bf67eba8e0c0fa3a62fd7f0f84",
url = "http://www.tcs.hut.fi/Software/bliss/bliss-0.73.zip",
)

http_archive(
name = "zlib",
build_file = "@com_google_protobuf//:third_party/zlib.BUILD",
sha256 = "c3e5e9fdd5004dcb542feda5ee4f0ff0744628baf8ed2dd5d66f8ca1197cb1a1",
strip_prefix = "zlib-1.2.11",
urls = [
"https://mirror.bazel.build/zlib.net/zlib-1.2.11.tar.gz",
"https://zlib.net/zlib-1.2.11.tar.gz",
],
)
# TODO(irfansharif): Capture swig and protoc{-gen-go} within bazel instead of
# asking contributors to download it themselves.

http_archive(
name = "io_bazel_rules_go",
Expand All @@ -104,29 +36,6 @@ http_archive(
],
)

http_archive(
name = "swig",
build_file = "//c-deps/external:swig.BUILD",
sha256 = "58a475dbbd4a4d7075e5fe86d4e54c9edde39847cdb96a3053d87cb64a23a453",
strip_prefix = "swig-3.0.8",
urls = [
"https://storage.googleapis.com/mirror.tensorflow.org/ufpr.dl.sourceforge.net/project/swig/swig/swig-3.0.8/swig-3.0.8.tar.gz",
"https://ufpr.dl.sourceforge.net/project/swig/swig/swig-3.0.8/swig-3.0.8.tar.gz",
"https://pilotfiber.dl.sourceforge.net/project/swig/swig/swig-3.0.8/swig-3.0.8.tar.gz",
],
)

http_archive(
name = "pcre",
build_file = "//c-deps/external:pcre.BUILD",
sha256 = "69acbc2fbdefb955d42a4c606dfde800c2885711d2979e356c0636efde9ec3b5",
strip_prefix = "pcre-8.42",
urls = [
"https://storage.googleapis.com/mirror.tensorflow.org/ftp.exim.org/pub/pcre/pcre-8.42.tar.gz",
"https://ftp.exim.org/pub/pcre/pcre-8.42.tar.gz",
],
)

git_repository(
name = "bazel_gazelle",
commit = "d038863ba2e096792c6bb6afca31f6514f1aeecd",
Expand All @@ -140,12 +49,12 @@ git_repository(
# gazelle:repository_macro DEPS.bzl%go_deps
load("//:DEPS.bzl", "go_deps")

# VERY IMPORTANT that we call into this function to prefer our pinned versions
# of the dependencies to any that might be pulled in via functions like
# VERY IMPORTANT that we call into this function to prefer the pinned versions
# of our dependencies instead of any that may get pulled in through like
# `go_rules_dependencies`, `gazelle_dependencies`, etc.
go_deps()

load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")
load("@io_bazel_rules_go//go:deps.bzl", "go_rules_dependencies", "go_register_toolchains")

go_rules_dependencies()

Expand Down
8 changes: 7 additions & 1 deletion datadriven_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,12 @@ func TestDatadriven(t *testing.T) {
solver.NewProductConstraint(target, multiplands...),
)
}
case ast.NonOverlappingMethod: // constrain.non-overlapping(i, j)
argument := stmt.Argument.(*ast.VariablesArgument)
intervals := getIntervals(s, argument.Variables...)
model.AddConstraints(
solver.NewNonOverlappingConstraint(intervals...),
)
case ast.BoolsMethod: // result.bool(x,y to z)
require.True(t, solved)
argument := stmt.Argument.(*ast.VariablesArgument)
Expand All @@ -255,7 +261,7 @@ func TestDatadriven(t *testing.T) {
out.WriteString("\n")
}
}
case ast.ValuesMethod: // result.values(x,y to z)
case ast.ValuesMethod: // result.values(x, y to z)
require.True(t, solved)
argument := stmt.Argument.(*ast.VariablesArgument)
variables := getIntVars(s, argument.Variables...)
Expand Down
15 changes: 11 additions & 4 deletions model.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,17 @@ type Model struct {
minimize bool
}

// XXX: Instead of having a name parameter for everything, we could maybe have a
// .WithName(name string) method on all these types that returns the receiver
// but annotates the receiver with the name itself. It would help clean up the
// signatures by removing the debug only arguments.
// TODO(irfansharif): Add assumption literals and examples for unsat debugging.
// And add hints. Add some documentation from
// https://github.com/google/or-tools/blob/stable/ortools/sat/doc/boolean_logic.md
// (reification, channeling constraints). Export async handler to stop search
// process. Probably part of enumerator?
// TODO(irfansharif): Export solution hint/partial assignment, when previous one
// is available.
// TODO(irfansharif): Export model/result statistics. Export domain.complement
// for reification.
// TODO(irfansharif): Export verbose view of types (specifically -- include
// internal indexes, so you could debug the validation error).

// NewModel instantiates a new model.
func NewModel(name string) *Model {
Expand Down
1 change: 1 addition & 0 deletions result.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func (r Result) Feasible() bool {
return r.pb.Status == pb.CpSolverStatus_FEASIBLE
}

// Invalid is true if the model being solved was invalid.
func (r Result) Invalid() bool {
return r.pb.Status == pb.CpSolverStatus_MODEL_INVALID
}
Expand Down
4 changes: 3 additions & 1 deletion testdata/print
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ constrain.binary-op(a % b == c)
constrain.binary-op(a / b == c)
constrain.binary-op(a * b == c)
constrain.cumulative(i: d, j: e | C)
constrain.non-overlapping(i, j)
model.print()
----
model=m
Expand All @@ -57,7 +58,7 @@ model=m
intervals (num = 2)
[a, b | C]
[b, c | C]
constraints (num = 13)
constraints (num = 14)
all-different: a, b, c
all-same: a, b, c
at-most-k: x, y, z | 2
Expand All @@ -71,3 +72,4 @@ model=m
c == a / b
c == a * b
cumulative: i: d, j: e | C
non-overlapping: {a, b}, {b, c}

0 comments on commit 3ace05d

Please sign in to comment.