diff --git a/examples/WORKSPACE b/examples/WORKSPACE index 6811e9cd17..93076a03d4 100644 --- a/examples/WORKSPACE +++ b/examples/WORKSPACE @@ -28,3 +28,11 @@ http_archive( strip_prefix = "protobuf-b4b0e304be5a68de3d0ee1af9b286f958750f5e4", sha256 = "ff771a662fb6bd4d3cc209bcccedef3e93980a49f71df1e987f6afa3bcdcba3a", ) + +new_http_archive( + name = "glpk", + url = "http://ftp.gnu.org/gnu/glpk/glpk-4.47.tar.gz", + sha256 = "c35438e3ba74a8d85236810e6b84879272c87cfa7473b4075201e2967839f48d", + build_file = "../src/glpk.BUILD", +) + diff --git a/src/WORKSPACE b/src/WORKSPACE index afd58b41ec..fe44fa6938 100644 --- a/src/WORKSPACE +++ b/src/WORKSPACE @@ -30,4 +30,12 @@ new_http_archive( url = "https://github.com/google/googletest/archive/release-1.8.0.zip", build_file = "gtest.BUILD", strip_prefix = "googletest-release-1.8.0/googletest", -) \ No newline at end of file +) + +new_http_archive( + name = "glpk", + url = "http://ftp.gnu.org/gnu/glpk/glpk-4.47.tar.gz", + sha256 = "c35438e3ba74a8d85236810e6b84879272c87cfa7473b4075201e2967839f48d", + build_file = "glpk.BUILD", +) + diff --git a/src/glpk.BUILD b/src/glpk.BUILD new file mode 100644 index 0000000000..b7c6847948 --- /dev/null +++ b/src/glpk.BUILD @@ -0,0 +1,20 @@ +cc_library( + name = "glpk", + srcs = glob([ + "glpk-4.47/src/*.c", + "glpk-4.47/src/*/*.c", + "glpk-4.47/src/*.h", + "glpk-4.47/src/*/*.h", + ]), + hdrs = [ + "glpk-4.47/src/glpk.h", + ], + copts = [ + "-Wno-error", + "-w", + "-Iexternal/glpk/glpk-4.47/src", + "-DHAVE_ZLIB", + ], + includes=["glpk-4.47/src"], + visibility = ["//visibility:public"], +) diff --git a/src/linear_solver/BUILD b/src/linear_solver/BUILD index 3e9fdfb6c8..bfb809c35c 100644 --- a/src/linear_solver/BUILD +++ b/src/linear_solver/BUILD @@ -1,5 +1,12 @@ package(default_visibility = ["//visibility:public"]) +# If you want to use the GLPK solver, build with '--define USE_GLPK=' (or add +# it to your bazel.rc file). This will download, build and link to GLPK. +config_setting( + name = "with_glpk", + values = { "define": "USE_GLPK=" } +) + proto_library( name = "linear_solver_proto", srcs = ["linear_solver.proto"], @@ -20,7 +27,10 @@ cc_library( "linear_solver.cc", "model_exporter.cc", "model_validator.cc", - ], + ] + select({ + ":with_glpk": ["glpk_interface.cc"], + "//conditions:default": [], + }), hdrs = [ "glop_utils.h", "linear_expr.h", @@ -32,13 +42,21 @@ cc_library( "-DUSE_GLOP", "-DUSE_BOP", ], + defines = [ + "HAVE_CONFIG_H" + ] + select({ + ":with_glpk": ["USE_GLPK"], + "//conditions:default": [], + }), visibility = ["//visibility:public"], deps = [ ":linear_solver_cc_proto", + "//base:timer", "//base", "//base:file", "//base:hash", "//base:map_util", + "//base:stl_util", "//base:random", "//bop:bop_parameters_cc_proto", "//bop:integral_solver", @@ -47,5 +65,9 @@ cc_library( "//lp_data", "//util:fp_utils", "//util:proto_tools", - ], + ] + select({ + ":with_glpk": ["@glpk//:glpk"], + "//conditions:default": [], + }), ) + diff --git a/src/linear_solver/linear_solver.h b/src/linear_solver/linear_solver.h index 9adde73ce3..aa97f9eb8f 100644 --- a/src/linear_solver/linear_solver.h +++ b/src/linear_solver/linear_solver.h @@ -149,7 +149,6 @@ #include "base/integral_types.h" #include "base/logging.h" #include "base/timer.h" -#include "glop/parameters.pb.h" #include "linear_solver/linear_expr.h" #include "linear_solver/linear_solver.pb.h"