mostly include/refactor

This commit is contained in:
Laurent Perron
2023-04-21 12:46:19 +02:00
parent b7b17779cc
commit dfdf042f6b
12 changed files with 38 additions and 23 deletions

View File

@@ -18,13 +18,14 @@
#include <string>
#include <vector>
#include "absl/strings/string_view.h"
#include "ortools/bop/bop_util.h"
#include "ortools/sat/boolean_problem.h"
namespace operations_research {
namespace bop {
SatCoreBasedOptimizer::SatCoreBasedOptimizer(const std::string& name)
SatCoreBasedOptimizer::SatCoreBasedOptimizer(absl::string_view name)
: BopOptimizerBase(name),
state_update_stamp_(ProblemState::kInitialStampValue),
initialized_(false),

View File

@@ -32,6 +32,7 @@
#include <string>
#include <vector>
#include "absl/strings/string_view.h"
#include "ortools/bop/bop_base.h"
#include "ortools/bop/bop_solution.h"
#include "ortools/bop/bop_types.h"
@@ -45,7 +46,7 @@ namespace bop {
// TODO(user): Merge this with the code in sat/optimization.cc
class SatCoreBasedOptimizer : public BopOptimizerBase {
public:
explicit SatCoreBasedOptimizer(const std::string& name);
explicit SatCoreBasedOptimizer(absl::string_view name);
~SatCoreBasedOptimizer() override;
protected:

View File

@@ -233,7 +233,6 @@ cc_library(
)
# Glop parameters.
proto_library(
name = "parameters_proto",
srcs = ["parameters.proto"],

View File

@@ -28,6 +28,7 @@
#include <vector>
#include "absl/strings/str_format.h"
#include "absl/strings/string_view.h"
#include "ortools/base/iterator_adaptors.h"
#include "ortools/base/strong_vector.h"
#include "ortools/glop/revised_simplex.h"
@@ -146,7 +147,7 @@ bool MainLpPreprocessor::Run(LinearProgram* lp) {
#undef RUN_PREPROCESSOR
void MainLpPreprocessor::RunAndPushIfRelevant(
std::unique_ptr<Preprocessor> preprocessor, const std::string& name,
std::unique_ptr<Preprocessor> preprocessor, absl::string_view name,
TimeLimit* time_limit, LinearProgram* lp) {
RETURN_IF_NULL(preprocessor);
RETURN_IF_NULL(time_limit);

View File

@@ -26,6 +26,7 @@
#include <string>
#include <vector>
#include "absl/strings/string_view.h"
#include "ortools/base/strong_vector.h"
#include "ortools/glop/parameters.pb.h"
#include "ortools/glop/revised_simplex.h"
@@ -125,7 +126,7 @@ class MainLpPreprocessor : public Preprocessor {
// Runs the given preprocessor and push it on preprocessors_ for the postsolve
// step when needed.
void RunAndPushIfRelevant(std::unique_ptr<Preprocessor> preprocessor,
const std::string& name, TimeLimit* time_limit,
absl::string_view name, TimeLimit* time_limit,
LinearProgram* lp);
// Stack of preprocessors currently applied to the lp that needs postsolve.

View File

@@ -89,9 +89,10 @@ static SCIP_DECL_EVENTFREE(EventFree) {
namespace operations_research {
void GScipEventHandler::Register(GScip* const gscip) {
CHECK_EQ(gscip_, nullptr) << "Already registered.";
CHECK_EQ(event_handler_, nullptr);
absl::Status GScipEventHandler::Register(GScip* const gscip) {
if (gscip_ != nullptr || event_handler_ != nullptr) {
return absl::InternalError("Already registered");
}
gscip_ = gscip;
@@ -100,17 +101,21 @@ void GScipEventHandler::Register(GScip* const gscip) {
event_handler_data->gscip = gscip;
event_handler_data->handler = this;
CHECK_OK(SCIP_TO_STATUS(SCIPincludeEventhdlrBasic(
RETURN_IF_SCIP_ERROR(SCIPincludeEventhdlrBasic(
gscip->scip(), &event_handler_, description_.name.c_str(),
description_.description.c_str(), EventExec, event_handler_data)));
CHECK_NE(event_handler_, nullptr);
description_.description.c_str(), EventExec, event_handler_data));
if (event_handler_ == nullptr) {
// This is only defensive: SCIP should return a SCIP error above instead.
return absl::InternalError("SCIP failed to create event handler");
}
CHECK_OK(SCIP_TO_STATUS(
SCIPsetEventhdlrInit(gscip->scip(), event_handler_, EventInit)));
CHECK_OK(SCIP_TO_STATUS(
SCIPsetEventhdlrExit(gscip->scip(), event_handler_, EventExit)));
CHECK_OK(SCIP_TO_STATUS(
SCIPsetEventhdlrFree(gscip->scip(), event_handler_, EventFree)));
RETURN_IF_SCIP_ERROR(
SCIPsetEventhdlrInit(gscip->scip(), event_handler_, EventInit));
RETURN_IF_SCIP_ERROR(
SCIPsetEventhdlrExit(gscip->scip(), event_handler_, EventExit));
RETURN_IF_SCIP_ERROR(
SCIPsetEventhdlrFree(gscip->scip(), event_handler_, EventFree));
return absl::OkStatus();
}
SCIP_RETCODE GScipEventHandler::CatchEvent(const SCIP_EVENTTYPE event_type) {

View File

@@ -19,6 +19,7 @@
#include <string>
#include <vector>
#include "absl/status/status.h"
#include "ortools/gscip/gscip.h"
#include "scip/type_event.h"
@@ -96,11 +97,12 @@ class GScipEventHandler {
// Registers this event handler to the given GScip.
//
// This function CHECKs that this handler has not been previously registered.
// This function returns an internal Status error if this handler has already
// been registered.
//
// The given GScip won't own this handler but will keep a pointer to it that
// will be used during the solve.
void Register(GScip* gscip);
absl::Status Register(GScip* gscip);
// Initialization of the event handler. Called after the problem was
// transformed.

View File

@@ -32,6 +32,7 @@ namespace operations_research {
bool GurobiIsCorrectlyInstalled() {
absl::StatusOr<GRBenv*> status = GetGurobiEnv();
if (!status.ok() || status.value() == nullptr) {
LOG(WARNING) << status.status();
return false;
}

View File

@@ -96,6 +96,7 @@ absl::StatusOr<MPSolutionResponse> PdlpSolveProto(
break;
default:
response.set_status(MPSOLVER_NOT_SOLVED);
break;
}
if (pdhg_result.solve_log.has_termination_string()) {
response.set_status_str(pdhg_result.solve_log.termination_string());

View File

@@ -15,6 +15,7 @@
#include <algorithm>
#include <complex>
#include <cstdlib>
#include <limits>
#include <optional>
#include <stdexcept>

View File

@@ -21,6 +21,7 @@
#include "absl/strings/numbers.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/str_split.h"
#include "absl/strings/string_view.h"
#include "google/protobuf/wrappers.pb.h"
#include "ortools/base/commandlineflags.h"
#include "ortools/base/integral_types.h"
@@ -538,13 +539,13 @@ void JsspParser::ProcessEarlyTardyLine(const std::string& line) {
}
}
int JsspParser::strtoint32(const std::string& word) {
int JsspParser::strtoint32(absl::string_view word) {
int result;
CHECK(absl::SimpleAtoi(word, &result));
return result;
}
int64_t JsspParser::strtoint64(const std::string& word) {
int64_t JsspParser::strtoint64(absl::string_view word) {
int64_t result;
CHECK(absl::SimpleAtoi(word, &result));
return result;

View File

@@ -18,6 +18,7 @@
#include <string>
#include "absl/strings/match.h"
#include "absl/strings/string_view.h"
#include "ortools/base/integral_types.h"
#include "ortools/scheduling/jobshop_scheduling.pb.h"
@@ -74,8 +75,8 @@ class JsspParser {
void SetJobs(int job_count);
void SetMachines(int machine_count);
int strtoint32(const std::string& word);
int64_t strtoint64(const std::string& word);
int strtoint32(absl::string_view word);
int64_t strtoint64(absl::string_view word);
JsspInputProblem problem_;
int declared_machine_count_ = -1;