diff --git a/examples/cpp/BUILD.bazel b/examples/cpp/BUILD.bazel index c43fd9de3d..e554a93d24 100644 --- a/examples/cpp/BUILD.bazel +++ b/examples/cpp/BUILD.bazel @@ -463,38 +463,6 @@ cc_binary( ], ) -cc_binary( - name = "sat_runner", - srcs = [ - "opb_reader.h", - "sat_cnf_reader.h", - "sat_runner.cc", - ], - deps = [ - "//ortools/algorithms:sparse_permutation", - "//ortools/base", - "//ortools/base:file", - "//ortools/base:threadpool", - "//ortools/lp_data:mps_reader", - "//ortools/lp_data:proto_utils", - "//ortools/sat:boolean_problem", - "//ortools/sat:boolean_problem_cc_proto", - "//ortools/sat:cp_model_cc_proto", - "//ortools/sat:cp_model_solver", - "//ortools/sat:drat_proof_handler", - "//ortools/sat:lp_utils", - "//ortools/sat:optimization", - "//ortools/sat:sat_solver", - "//ortools/sat:simplification", - "//ortools/sat:symmetry", - "//ortools/util:filelineiter", - "//ortools/util:sigint", - "//ortools/util:time_limit", - "@com_google_absl//absl/status", - "@com_google_absl//absl/strings", - "@com_google_protobuf//:protobuf", - ], -) cc_binary( name = "shift_minimization_sat", diff --git a/examples/cpp/CMakeLists.txt b/examples/cpp/CMakeLists.txt index ca4050a32b..9a04773015 100644 --- a/examples/cpp/CMakeLists.txt +++ b/examples/cpp/CMakeLists.txt @@ -41,7 +41,6 @@ list(FILTER CXX_SRCS EXCLUDE REGEX ".*/multi_knapsack_sat.cc") # crash list(FILTER CXX_SRCS EXCLUDE REGEX ".*/network_routing_sat.cc") list(FILTER CXX_SRCS EXCLUDE REGEX ".*/pdlp_solve.cc") list(FILTER CXX_SRCS EXCLUDE REGEX ".*/pdptw.cc") -list(FILTER CXX_SRCS EXCLUDE REGEX ".*/sat_runner.cc") list(FILTER CXX_SRCS EXCLUDE REGEX ".*/shift_minimization_sat.cc") list(FILTER CXX_SRCS EXCLUDE REGEX ".*/pdlp_solve.cc") list(FILTER CXX_SRCS EXCLUDE REGEX ".*/solve.cc") @@ -52,25 +51,3 @@ list(FILTER CXX_SRCS EXCLUDE REGEX ".*/weighted_tardiness_sat.cc") foreach(SAMPLE IN LISTS CXX_SRCS) add_cxx_example(${SAMPLE}) endforeach() - -# Sat Runner -include(GNUInstallDirs) -if(APPLE) - set(CMAKE_INSTALL_RPATH - "@loader_path/../${CMAKE_INSTALL_LIBDIR};@loader_path") -elseif(UNIX) - set(CMAKE_INSTALL_RPATH - "$ORIGIN/../${CMAKE_INSTALL_LIBDIR}:$ORIGIN/../lib64:$ORIGIN/../lib:$ORIGIN") -endif() - -add_executable(sat_runner) -target_sources(sat_runner PRIVATE - "sat_runner.cc" - "opb_reader.h" - "sat_cnf_reader.h") -target_include_directories(sat_runner PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) -target_compile_features(sat_runner PRIVATE cxx_std_17) -target_link_libraries(sat_runner PRIVATE ${PROJECT_NAMESPACE}::ortools) - -install(TARGETS sat_runner) - diff --git a/ortools/sat/BUILD.bazel b/ortools/sat/BUILD.bazel index cdb9172a87..bc40dc06ef 100644 --- a/ortools/sat/BUILD.bazel +++ b/ortools/sat/BUILD.bazel @@ -1617,3 +1617,36 @@ cc_library( "@com_google_absl//absl/types:span", ], ) + +cc_binary( + name = "sat_runner", + srcs = [ + "opb_reader.h", + "sat_cnf_reader.h", + "sat_runner.cc", + ], + deps = [ + ":boolean_problem", + ":boolean_problem_cc_proto", + ":cp_model_cc_proto", + ":cp_model_solver", + ":drat_proof_handler", + ":lp_utils", + ":optimization", + ":sat_solver", + ":simplification", + ":symmetry", + "//ortools/algorithms:sparse_permutation", + "//ortools/base", + "//ortools/base:file", + "//ortools/base:threadpool", + "//ortools/lp_data:mps_reader", + "//ortools/lp_data:proto_utils", + "//ortools/util:filelineiter", + "//ortools/util:sigint", + "//ortools/util:time_limit", + "@com_google_absl//absl/status", + "@com_google_absl//absl/strings", + "@com_google_protobuf//:protobuf", + ], +) diff --git a/ortools/sat/CMakeLists.txt b/ortools/sat/CMakeLists.txt index d959ae1976..19bd83f738 100644 --- a/ortools/sat/CMakeLists.txt +++ b/ortools/sat/CMakeLists.txt @@ -12,6 +12,11 @@ # limitations under the License. file(GLOB _SRCS "*.h" "*.cc") +list(REMOVE_ITEM _SRCS + ${CMAKE_CURRENT_SOURCE_DIR}/opb_reader.h + ${CMAKE_CURRENT_SOURCE_DIR}/sat_cnf_reader.h + ${CMAKE_CURRENT_SOURCE_DIR}/sat_runner.cc +) set(NAME ${PROJECT_NAME}_sat) # Will be merge in libortools.so @@ -33,3 +38,21 @@ target_link_libraries(${NAME} PRIVATE $<$:Coin::Cbc> ${PROJECT_NAME}::proto) #add_library(${PROJECT_NAME}::sat ALIAS ${NAME}) + +# Sat Runner +include(GNUInstallDirs) +if(APPLE) + set(CMAKE_INSTALL_RPATH + "@loader_path/../${CMAKE_INSTALL_LIBDIR};@loader_path") +elseif(UNIX) + set(CMAKE_INSTALL_RPATH + "$ORIGIN/../${CMAKE_INSTALL_LIBDIR}:$ORIGIN/../lib64:$ORIGIN/../lib:$ORIGIN") +endif() + +add_executable(sat_runner) +target_sources(sat_runner PRIVATE "sat_runner.cc") +target_include_directories(sat_runner PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) +target_compile_features(sat_runner PRIVATE cxx_std_17) +target_link_libraries(sat_runner PRIVATE ${PROJECT_NAMESPACE}::ortools) + +install(TARGETS sat_runner) diff --git a/examples/cpp/opb_reader.h b/ortools/sat/opb_reader.h similarity index 100% rename from examples/cpp/opb_reader.h rename to ortools/sat/opb_reader.h diff --git a/examples/cpp/sat_cnf_reader.h b/ortools/sat/sat_cnf_reader.h similarity index 100% rename from examples/cpp/sat_cnf_reader.h rename to ortools/sat/sat_cnf_reader.h diff --git a/examples/cpp/sat_runner.cc b/ortools/sat/sat_runner.cc similarity index 96% rename from examples/cpp/sat_runner.cc rename to ortools/sat/sat_runner.cc index 8cb4d265b2..1e87bda43a 100644 --- a/examples/cpp/sat_runner.cc +++ b/ortools/sat/sat_runner.cc @@ -19,6 +19,9 @@ #include #include "absl/flags/flag.h" +#include "absl/flags/usage.h" +#include "absl/log/flags.h" +#include "absl/log/initialize.h" #include "absl/random/random.h" #include "absl/status/status.h" #include "absl/strings/match.h" @@ -26,13 +29,9 @@ #include "absl/strings/str_cat.h" #include "absl/strings/str_format.h" #include "absl/strings/string_view.h" -#include "examples/cpp/opb_reader.h" -#include "examples/cpp/sat_cnf_reader.h" -#include "google/protobuf/text_format.h" #include "ortools/algorithms/sparse_permutation.h" #include "ortools/base/helpers.h" -#include "ortools/base/init_google.h" -#include "ortools/base/logging.h" +#include "ortools/base/options.h" #include "ortools/base/timer.h" #include "ortools/linear_solver/linear_solver.pb.h" #include "ortools/lp_data/lp_data.h" @@ -44,9 +43,11 @@ #include "ortools/sat/cp_model_solver.h" #include "ortools/sat/lp_utils.h" #include "ortools/sat/model.h" +#include "ortools/sat/opb_reader.h" #include "ortools/sat/optimization.h" #include "ortools/sat/pb_constraint.h" #include "ortools/sat/sat_base.h" +#include "ortools/sat/sat_cnf_reader.h" #include "ortools/sat/sat_parameters.pb.h" #include "ortools/sat/sat_solver.h" #include "ortools/sat/simplification.h" @@ -445,13 +446,11 @@ int Run() { static const char kUsage[] = "Usage: see flags.\n" - "This program solves a given Boolean linear problem."; + "This program solves a given problem with the CP-SAT solver."; int main(int argc, char** argv) { - // By default, we want to show how the solver progress. Note that this needs - // to be set before InitGoogle() which has the nice side-effect of allowing - // the user to override it. - InitGoogle(kUsage, &argc, &argv, /*remove_flags=*/true); - absl::SetFlag(&FLAGS_logtostderr, true); + absl::InitializeLog(); + absl::SetProgramUsageMessage(kUsage); + absl::ParseCommandLine(argc, argv); return operations_research::sat::Run(); }