Skip to content

Commit

Permalink
move sat_runner from examples/cpp to ortools/sat
Browse files Browse the repository at this point in the history
  • Loading branch information
lperron committed Feb 10, 2023
1 parent 67ff825 commit fa478b8
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 66 deletions.
32 changes: 0 additions & 32 deletions examples/cpp/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
23 changes: 0 additions & 23 deletions examples/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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)

33 changes: 33 additions & 0 deletions ortools/sat/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
)
23 changes: 23 additions & 0 deletions ortools/sat/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -33,3 +38,21 @@ target_link_libraries(${NAME} PRIVATE
$<$<BOOL:${USE_COINOR}>: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)
File renamed without changes.
File renamed without changes.
21 changes: 10 additions & 11 deletions examples/cpp/sat_runner.cc → ortools/sat/sat_runner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,19 @@
#include <vector>

#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"
#include "absl/strings/numbers.h"
#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"
Expand All @@ -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"
Expand Down Expand Up @@ -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();
}

0 comments on commit fa478b8

Please sign in to comment.