Skip to content

Commit fa478b8

Browse files
committed
move sat_runner from examples/cpp to ortools/sat
1 parent 67ff825 commit fa478b8

File tree

7 files changed

+66
-66
lines changed

7 files changed

+66
-66
lines changed

examples/cpp/BUILD.bazel

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -463,38 +463,6 @@ cc_binary(
463463
],
464464
)
465465

466-
cc_binary(
467-
name = "sat_runner",
468-
srcs = [
469-
"opb_reader.h",
470-
"sat_cnf_reader.h",
471-
"sat_runner.cc",
472-
],
473-
deps = [
474-
"//ortools/algorithms:sparse_permutation",
475-
"//ortools/base",
476-
"//ortools/base:file",
477-
"//ortools/base:threadpool",
478-
"//ortools/lp_data:mps_reader",
479-
"//ortools/lp_data:proto_utils",
480-
"//ortools/sat:boolean_problem",
481-
"//ortools/sat:boolean_problem_cc_proto",
482-
"//ortools/sat:cp_model_cc_proto",
483-
"//ortools/sat:cp_model_solver",
484-
"//ortools/sat:drat_proof_handler",
485-
"//ortools/sat:lp_utils",
486-
"//ortools/sat:optimization",
487-
"//ortools/sat:sat_solver",
488-
"//ortools/sat:simplification",
489-
"//ortools/sat:symmetry",
490-
"//ortools/util:filelineiter",
491-
"//ortools/util:sigint",
492-
"//ortools/util:time_limit",
493-
"@com_google_absl//absl/status",
494-
"@com_google_absl//absl/strings",
495-
"@com_google_protobuf//:protobuf",
496-
],
497-
)
498466

499467
cc_binary(
500468
name = "shift_minimization_sat",

examples/cpp/CMakeLists.txt

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ list(FILTER CXX_SRCS EXCLUDE REGEX ".*/multi_knapsack_sat.cc") # crash
4141
list(FILTER CXX_SRCS EXCLUDE REGEX ".*/network_routing_sat.cc")
4242
list(FILTER CXX_SRCS EXCLUDE REGEX ".*/pdlp_solve.cc")
4343
list(FILTER CXX_SRCS EXCLUDE REGEX ".*/pdptw.cc")
44-
list(FILTER CXX_SRCS EXCLUDE REGEX ".*/sat_runner.cc")
4544
list(FILTER CXX_SRCS EXCLUDE REGEX ".*/shift_minimization_sat.cc")
4645
list(FILTER CXX_SRCS EXCLUDE REGEX ".*/pdlp_solve.cc")
4746
list(FILTER CXX_SRCS EXCLUDE REGEX ".*/solve.cc")
@@ -52,25 +51,3 @@ list(FILTER CXX_SRCS EXCLUDE REGEX ".*/weighted_tardiness_sat.cc")
5251
foreach(SAMPLE IN LISTS CXX_SRCS)
5352
add_cxx_example(${SAMPLE})
5453
endforeach()
55-
56-
# Sat Runner
57-
include(GNUInstallDirs)
58-
if(APPLE)
59-
set(CMAKE_INSTALL_RPATH
60-
"@loader_path/../${CMAKE_INSTALL_LIBDIR};@loader_path")
61-
elseif(UNIX)
62-
set(CMAKE_INSTALL_RPATH
63-
"$ORIGIN/../${CMAKE_INSTALL_LIBDIR}:$ORIGIN/../lib64:$ORIGIN/../lib:$ORIGIN")
64-
endif()
65-
66-
add_executable(sat_runner)
67-
target_sources(sat_runner PRIVATE
68-
"sat_runner.cc"
69-
"opb_reader.h"
70-
"sat_cnf_reader.h")
71-
target_include_directories(sat_runner PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
72-
target_compile_features(sat_runner PRIVATE cxx_std_17)
73-
target_link_libraries(sat_runner PRIVATE ${PROJECT_NAMESPACE}::ortools)
74-
75-
install(TARGETS sat_runner)
76-

ortools/sat/BUILD.bazel

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1617,3 +1617,36 @@ cc_library(
16171617
"@com_google_absl//absl/types:span",
16181618
],
16191619
)
1620+
1621+
cc_binary(
1622+
name = "sat_runner",
1623+
srcs = [
1624+
"opb_reader.h",
1625+
"sat_cnf_reader.h",
1626+
"sat_runner.cc",
1627+
],
1628+
deps = [
1629+
":boolean_problem",
1630+
":boolean_problem_cc_proto",
1631+
":cp_model_cc_proto",
1632+
":cp_model_solver",
1633+
":drat_proof_handler",
1634+
":lp_utils",
1635+
":optimization",
1636+
":sat_solver",
1637+
":simplification",
1638+
":symmetry",
1639+
"//ortools/algorithms:sparse_permutation",
1640+
"//ortools/base",
1641+
"//ortools/base:file",
1642+
"//ortools/base:threadpool",
1643+
"//ortools/lp_data:mps_reader",
1644+
"//ortools/lp_data:proto_utils",
1645+
"//ortools/util:filelineiter",
1646+
"//ortools/util:sigint",
1647+
"//ortools/util:time_limit",
1648+
"@com_google_absl//absl/status",
1649+
"@com_google_absl//absl/strings",
1650+
"@com_google_protobuf//:protobuf",
1651+
],
1652+
)

ortools/sat/CMakeLists.txt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
# limitations under the License.
1313

1414
file(GLOB _SRCS "*.h" "*.cc")
15+
list(REMOVE_ITEM _SRCS
16+
${CMAKE_CURRENT_SOURCE_DIR}/opb_reader.h
17+
${CMAKE_CURRENT_SOURCE_DIR}/sat_cnf_reader.h
18+
${CMAKE_CURRENT_SOURCE_DIR}/sat_runner.cc
19+
)
1520
set(NAME ${PROJECT_NAME}_sat)
1621

1722
# Will be merge in libortools.so
@@ -33,3 +38,21 @@ target_link_libraries(${NAME} PRIVATE
3338
$<$<BOOL:${USE_COINOR}>:Coin::Cbc>
3439
${PROJECT_NAME}::proto)
3540
#add_library(${PROJECT_NAME}::sat ALIAS ${NAME})
41+
42+
# Sat Runner
43+
include(GNUInstallDirs)
44+
if(APPLE)
45+
set(CMAKE_INSTALL_RPATH
46+
"@loader_path/../${CMAKE_INSTALL_LIBDIR};@loader_path")
47+
elseif(UNIX)
48+
set(CMAKE_INSTALL_RPATH
49+
"$ORIGIN/../${CMAKE_INSTALL_LIBDIR}:$ORIGIN/../lib64:$ORIGIN/../lib:$ORIGIN")
50+
endif()
51+
52+
add_executable(sat_runner)
53+
target_sources(sat_runner PRIVATE "sat_runner.cc")
54+
target_include_directories(sat_runner PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
55+
target_compile_features(sat_runner PRIVATE cxx_std_17)
56+
target_link_libraries(sat_runner PRIVATE ${PROJECT_NAMESPACE}::ortools)
57+
58+
install(TARGETS sat_runner)
File renamed without changes.
File renamed without changes.

examples/cpp/sat_runner.cc renamed to ortools/sat/sat_runner.cc

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,19 @@
1919
#include <vector>
2020

2121
#include "absl/flags/flag.h"
22+
#include "absl/flags/usage.h"
23+
#include "absl/log/flags.h"
24+
#include "absl/log/initialize.h"
2225
#include "absl/random/random.h"
2326
#include "absl/status/status.h"
2427
#include "absl/strings/match.h"
2528
#include "absl/strings/numbers.h"
2629
#include "absl/strings/str_cat.h"
2730
#include "absl/strings/str_format.h"
2831
#include "absl/strings/string_view.h"
29-
#include "examples/cpp/opb_reader.h"
30-
#include "examples/cpp/sat_cnf_reader.h"
31-
#include "google/protobuf/text_format.h"
3232
#include "ortools/algorithms/sparse_permutation.h"
3333
#include "ortools/base/helpers.h"
34-
#include "ortools/base/init_google.h"
35-
#include "ortools/base/logging.h"
34+
#include "ortools/base/options.h"
3635
#include "ortools/base/timer.h"
3736
#include "ortools/linear_solver/linear_solver.pb.h"
3837
#include "ortools/lp_data/lp_data.h"
@@ -44,9 +43,11 @@
4443
#include "ortools/sat/cp_model_solver.h"
4544
#include "ortools/sat/lp_utils.h"
4645
#include "ortools/sat/model.h"
46+
#include "ortools/sat/opb_reader.h"
4747
#include "ortools/sat/optimization.h"
4848
#include "ortools/sat/pb_constraint.h"
4949
#include "ortools/sat/sat_base.h"
50+
#include "ortools/sat/sat_cnf_reader.h"
5051
#include "ortools/sat/sat_parameters.pb.h"
5152
#include "ortools/sat/sat_solver.h"
5253
#include "ortools/sat/simplification.h"
@@ -445,13 +446,11 @@ int Run() {
445446

446447
static const char kUsage[] =
447448
"Usage: see flags.\n"
448-
"This program solves a given Boolean linear problem.";
449+
"This program solves a given problem with the CP-SAT solver.";
449450

450451
int main(int argc, char** argv) {
451-
// By default, we want to show how the solver progress. Note that this needs
452-
// to be set before InitGoogle() which has the nice side-effect of allowing
453-
// the user to override it.
454-
InitGoogle(kUsage, &argc, &argv, /*remove_flags=*/true);
455-
absl::SetFlag(&FLAGS_logtostderr, true);
452+
absl::InitializeLog();
453+
absl::SetProgramUsageMessage(kUsage);
454+
absl::ParseCommandLine(argc, argv);
456455
return operations_research::sat::Run();
457456
}

0 commit comments

Comments
 (0)