remove stderrthreshold flag, use absl globals method

This commit is contained in:
Laurent Perron
2025-02-19 17:00:34 +01:00
parent 8fb364a103
commit 7fec12bc35
44 changed files with 159 additions and 99 deletions

View File

@@ -28,6 +28,7 @@
#include "absl/container/btree_set.h"
#include "absl/flags/flag.h"
#include "absl/log/check.h"
#include "absl/log/globals.h"
#include "absl/strings/str_cat.h"
#include "absl/types/span.h"
#include "google/protobuf/text_format.h"
@@ -555,7 +556,7 @@ void LoadAndSolve(const std::string& file_name, int instance) {
} // namespace operations_research
int main(int argc, char** argv) {
absl::SetFlag(&FLAGS_stderrthreshold, 0);
absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo);
InitGoogle(argv[0], &argc, &argv, true);
if (absl::GetFlag(FLAGS_input).empty()) {
LOG(FATAL) << "Please supply a data file with --input=";

View File

@@ -13,8 +13,12 @@
// Constraint programming example that shows how to use the API.
#include <cstdint>
#include <cstdlib>
#include <vector>
#include "absl/base/log_severity.h"
#include "absl/log/globals.h"
#include "ortools/base/init_google.h"
#include "ortools/base/logging.h"
#include "ortools/constraint_solver/constraint_solver.h"
@@ -23,12 +27,12 @@ namespace operations_research {
void RunConstraintProgrammingExample() {
// Instantiate the solver.
Solver solver("ConstraintProgrammingExample");
const int64_t numVals = 3;
const int64_t kNumVals = 3;
// Define decision variables.
IntVar* const x = solver.MakeIntVar(0, numVals - 1, "x");
IntVar* const y = solver.MakeIntVar(0, numVals - 1, "y");
IntVar* const z = solver.MakeIntVar(0, numVals - 1, "z");
IntVar* const x = solver.MakeIntVar(0, kNumVals - 1, "x");
IntVar* const y = solver.MakeIntVar(0, kNumVals - 1, "y");
IntVar* const z = solver.MakeIntVar(0, kNumVals - 1, "z");
// Define constraints.
std::vector<IntVar*> xyvars = {x, y};
@@ -57,7 +61,7 @@ void RunConstraintProgrammingExample() {
} // namespace operations_research
int main(int argc, char** argv) {
absl::SetFlag(&FLAGS_stderrthreshold, 0);
absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo);
InitGoogle(argv[0], &argc, &argv, true);
operations_research::RunConstraintProgrammingExample();
return EXIT_SUCCESS;

View File

@@ -28,7 +28,9 @@
#include <utility>
#include <vector>
#include "absl/base/log_severity.h"
#include "absl/flags/flag.h"
#include "absl/log/globals.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/str_format.h"
#include "absl/types/span.h"
@@ -297,7 +299,7 @@ void CostasBoolSoft(const int dim) {
} // namespace operations_research
int main(int argc, char** argv) {
absl::SetFlag(&FLAGS_stderrthreshold, 0);
absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo);
InitGoogle(argv[0], &argc, &argv, true);
int min = 1;

View File

@@ -28,7 +28,9 @@
#include <cstdio>
#include <vector>
#include "absl/base/log_severity.h"
#include "absl/flags/flag.h"
#include "absl/log/globals.h"
#include "absl/strings/str_format.h"
#include "google/protobuf/text_format.h"
#include "ortools/base/init_google.h"
@@ -120,7 +122,7 @@ void GolombRuler(int size) {
} // namespace operations_research
int main(int argc, char** argv) {
absl::SetFlag(&FLAGS_stderrthreshold, 0);
absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo);
InitGoogle(argv[0], &argc, &argv, true);
if (absl::GetFlag(FLAGS_size) != 0) {

View File

@@ -16,7 +16,9 @@
#include <string>
#include <vector>
#include "absl/base/log_severity.h"
#include "absl/flags/flag.h"
#include "absl/log/globals.h"
#include "absl/strings/match.h"
#include "absl/strings/string_view.h"
#include "ortools/base/init_google.h"
@@ -94,7 +96,7 @@ void RunAllExamples() {
} // namespace operations_research
int main(int argc, char** argv) {
absl::SetFlag(&FLAGS_stderrthreshold, 0);
absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo);
InitGoogle(argv[0], &argc, &argv, true);
operations_research::RunAllExamples();
return EXIT_SUCCESS;

View File

@@ -18,10 +18,12 @@
#include <string>
#include <vector>
#include "absl/base/log_severity.h"
#include "absl/container/flat_hash_map.h"
#include "absl/container/flat_hash_set.h"
#include "absl/flags/flag.h"
#include "absl/log/check.h"
#include "absl/log/globals.h"
#include "absl/strings/str_join.h"
#include "absl/types/span.h"
#include "google/protobuf/text_format.h"
@@ -848,7 +850,7 @@ void Solve(const JsspInputProblem& problem) {
} // namespace operations_research
int main(int argc, char** argv) {
absl::SetFlag(&FLAGS_stderrthreshold, 0);
absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo);
InitGoogle(argv[0], &argc, &argv, true);
if (absl::GetFlag(FLAGS_input).empty()) {

View File

@@ -21,7 +21,9 @@
#include <string>
#include <vector>
#include "absl/base/log_severity.h"
#include "absl/flags/flag.h"
#include "absl/log/globals.h"
#include "absl/types/span.h"
#include "google/protobuf/text_format.h"
#include "ortools/base/commandlineflags.h"
@@ -106,7 +108,7 @@ void CheckAndPrint2DSolution(
}
}
// Load a 2d binpacking problem and solve it as a 2d knapsack problem.
// Load a 2d bin-packing problem and solve it as a 2d knapsack problem.
// That is fit the max number of object in one box.
void LoadAndSolve(const std::string& file_name, int instance) {
packing::BinPacking2dParser parser;
@@ -226,7 +228,7 @@ void LoadAndSolve(const std::string& file_name, int instance) {
} // namespace operations_research
int main(int argc, char** argv) {
absl::SetFlag(&FLAGS_stderrthreshold, 0);
absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo);
InitGoogle(argv[0], &argc, &argv, true);
if (absl::GetFlag(FLAGS_input).empty()) {
LOG(FATAL) << "Please supply a data file with --input=";

View File

@@ -17,7 +17,9 @@
#include <string>
#include <vector>
#include "absl/base/log_severity.h"
#include "absl/flags/flag.h"
#include "absl/log/globals.h"
#include "absl/strings/match.h"
#include "absl/strings/string_view.h"
#include "ortools/base/commandlineflags.h"
@@ -122,7 +124,7 @@ void RunAllExamples() {
} // namespace operations_research
int main(int argc, char** argv) {
absl::SetFlag(&FLAGS_stderrthreshold, 0);
absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo);
InitGoogle(argv[0], &argc, &argv, true);
operations_research::RunAllExamples();
return EXIT_SUCCESS;

View File

@@ -11,15 +11,16 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include <limits>
#include <string>
#include "ortools/base/init_google.h"
#include "ortools/base/logging.h"
#include "ortools/linear_solver/linear_solver.h"
#include "ortools/linear_solver/linear_solver.pb.h"
#include "ortools/linear_solver/solve_mp_model.h"
namespace operations_research {
void BuildLinearProgrammingMaxExample(MPSolver::OptimizationProblemType type) {
void BuildLinearProgrammingMaxExample(MPModelRequest::SolverType type) {
const double kObjCoef[] = {10.0, 6.0, 4.0};
const std::string kVarName[] = {"x1", "x2", "x3"};
const int numVars = 3;
@@ -32,7 +33,7 @@ void BuildLinearProgrammingMaxExample(MPSolver::OptimizationProblemType type) {
kConstraintCoef3};
const double kConstraintUb[] = {100.0, 600.0, 300.0};
const double infinity = MPSolver::infinity();
const double infinity = std::numeric_limits<double>::infinity();
MPModelProto model_proto;
model_proto.set_name("Max_Example");
@@ -62,19 +63,9 @@ void BuildLinearProgrammingMaxExample(MPSolver::OptimizationProblemType type) {
MPModelRequest model_request;
*model_request.mutable_model() = model_proto;
#if defined(USE_GLOP)
if (type == MPSolver::GLOP_LINEAR_PROGRAMMING) {
model_request.set_solver_type(MPModelRequest::GLOP_LINEAR_PROGRAMMING);
}
#endif // USE_GLOP
#if defined(USE_CLP)
if (type == MPSolver::CLP_LINEAR_PROGRAMMING) {
model_request.set_solver_type(MPModelRequest::CLP_LINEAR_PROGRAMMING);
}
#endif // USE_CLP
model_request.set_solver_type(type);
MPSolutionResponse solution_response;
MPSolver::SolveWithProto(model_request, &solution_response);
const MPSolutionResponse solution_response = SolveMPModel(model_request);
// The problem has an optimal solution.
CHECK_EQ(MPSOLVER_OPTIMAL, solution_response.status());
@@ -89,11 +80,11 @@ void BuildLinearProgrammingMaxExample(MPSolver::OptimizationProblemType type) {
void RunAllExamples() {
#if defined(USE_GLOP)
LOG(INFO) << "----- Running Max Example with GLOP -----";
BuildLinearProgrammingMaxExample(MPSolver::GLOP_LINEAR_PROGRAMMING);
BuildLinearProgrammingMaxExample(MPModelRequest::GLOP_LINEAR_PROGRAMMING);
#endif // USE_GLOP
#if defined(USE_CLP)
LOG(INFO) << "----- Running Max Example with Coin LP -----";
BuildLinearProgrammingMaxExample(MPSolver::CLP_LINEAR_PROGRAMMING);
BuildLinearProgrammingMaxExample(MPModelRequest::CLP_LINEAR_PROGRAMMING);
#endif // USE_CLP
}
} // namespace operations_research

View File

@@ -22,7 +22,9 @@
#include <string>
#include <vector>
#include "absl/base/log_severity.h"
#include "absl/flags/flag.h"
#include "absl/log/globals.h"
#include "absl/strings/str_format.h"
#include "ortools/base/init_google.h"
#include "ortools/base/logging.h"
@@ -92,7 +94,7 @@ void MagicSequence(int size) {
} // namespace operations_research
int main(int argc, char** argv) {
absl::SetFlag(&FLAGS_stderrthreshold, 0);
absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo);
InitGoogle(argv[0], &argc, &argv, true);
operations_research::sat::MagicSequence(absl::GetFlag(FLAGS_size));

View File

@@ -14,7 +14,9 @@
#include <string>
#include <vector>
#include "absl/base/log_severity.h"
#include "absl/flags/flag.h"
#include "absl/log/globals.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/str_format.h"
#include "ortools/base/init_google.h"
@@ -101,7 +103,7 @@ void MagicSquare(int size) {
} // namespace operations_research
int main(int argc, char** argv) {
absl::SetFlag(&FLAGS_stderrthreshold, 0);
absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo);
InitGoogle(argv[0], &argc, &argv, true);
operations_research::sat::MagicSquare(absl::GetFlag(FLAGS_size));

View File

@@ -14,7 +14,9 @@
#include <utility>
#include <vector>
#include "absl/base/log_severity.h"
#include "absl/flags/flag.h"
#include "absl/log/globals.h"
#include "ortools/base/init_google.h"
#include "ortools/base/logging.h"
#include "ortools/graph/generic_max_flow.h"
@@ -64,7 +66,7 @@ void SolveMaxFlow() {
} // namespace operations_research
int main(int argc, char** argv) {
absl::SetFlag(&FLAGS_stderrthreshold, 0);
absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo);
InitGoogle(argv[0], &argc, &argv, true);
operations_research::SolveMaxFlow();
return EXIT_SUCCESS;

View File

@@ -16,7 +16,9 @@
#include <utility>
#include <vector>
#include "absl/base/log_severity.h"
#include "absl/flags/flag.h"
#include "absl/log/globals.h"
#include "ortools/base/init_google.h"
#include "ortools/base/logging.h"
@@ -73,7 +75,7 @@ void SolveMinCostFlow() {
} // namespace operations_research
int main(int argc, char** argv) {
absl::SetFlag(&FLAGS_stderrthreshold, 0);
absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo);
InitGoogle(argv[0], &argc, &argv, true);
operations_research::SolveMinCostFlow();
return EXIT_SUCCESS;

View File

@@ -28,7 +28,6 @@
#include "ortools/base/file.h"
#include "ortools/base/helpers.h"
#include "ortools/base/init_google.h"
#include "ortools/base/logging.h"
#include "ortools/base/timer.h"
#include "ortools/glop/lp_solver.h"
#include "ortools/glop/parameters.pb.h"
@@ -90,7 +89,7 @@ int main(int argc, char* argv[]) {
"The files must be in Mps or linear_solver.proto format and can be "
"compressed with gzip.",
&argc, &argv, true);
absl::SetFlag(&FLAGS_stderrthreshold, 0);
absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo);
GlopParameters parameters;
ReadGlopParameters(&parameters);

View File

@@ -23,7 +23,9 @@
#include <string>
#include <vector>
#include "absl/base/log_severity.h"
#include "absl/flags/flag.h"
#include "absl/log/globals.h"
#include "ortools/base/commandlineflags.h"
#include "ortools/base/init_google.h"
#include "ortools/base/logging.h"
@@ -33,7 +35,6 @@ ABSL_FLAG(int, size, 16, "scaling factor of the model");
ABSL_FLAG(std::string, params,
"num_workers:8,log_search_progress:true,max_time_in_seconds:10.0",
"Sat parameters");
namespace operations_research {
namespace sat {
@@ -111,7 +112,7 @@ void MultiKnapsackSat(int scaling, const std::string& params) {
} // namespace operations_research
int main(int argc, char** argv) {
absl::SetFlag(&FLAGS_stderrthreshold, 0);
absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo);
InitGoogle(argv[0], &argc, &argv, true);
operations_research::sat::MultiKnapsackSat(absl::GetFlag(FLAGS_size),
absl::GetFlag(FLAGS_params));

View File

@@ -33,10 +33,12 @@
#include <utility>
#include <vector>
#include "absl/base/log_severity.h"
#include "absl/container/btree_set.h"
#include "absl/container/flat_hash_map.h"
#include "absl/container/flat_hash_set.h"
#include "absl/flags/flag.h"
#include "absl/log/globals.h"
#include "absl/random/uniform_int_distribution.h"
#include "absl/strings/str_format.h"
#include "ortools/base/init_google.h"
@@ -673,7 +675,7 @@ class NetworkRoutingSolver {
} // namespace operations_research
int main(int argc, char** argv) {
absl::SetFlag(&FLAGS_stderrthreshold, 0);
absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo);
InitGoogle(argv[0], &argc, &argv, true);
operations_research::sat::NetworkRoutingData data;

View File

@@ -131,7 +131,7 @@ void Solve(const std::string& input, absl::string_view params_str,
} // namespace operations_research::pdlp
int main(int argc, char** argv) {
absl::SetFlag(&FLAGS_stderrthreshold, 0);
absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo);
InitGoogle(argv[0], &argc, &argv, /*remove_flags=*/true);
operations_research::pdlp::Solve(

View File

@@ -47,8 +47,10 @@
#include <vector>
#include "absl/algorithm/container.h"
#include "absl/base/log_severity.h"
#include "absl/flags/flag.h"
#include "absl/log/check.h"
#include "absl/log/globals.h"
#include "absl/strings/str_format.h"
#include "absl/strings/string_view.h"
#include "google/protobuf/text_format.h"
@@ -359,7 +361,7 @@ bool LoadAndSolve(absl::string_view pdp_file,
} // namespace operations_research
int main(int argc, char** argv) {
absl::SetFlag(&FLAGS_stderrthreshold, 0);
absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo);
InitGoogle(argv[0], &argc, &argv, true);
operations_research::routing::RoutingModelParameters model_parameters =
operations_research::routing::DefaultRoutingModelParameters();

View File

@@ -32,8 +32,10 @@
#include <string>
#include <vector>
#include "absl/base/log_severity.h"
#include "absl/container/btree_set.h"
#include "absl/flags/flag.h"
#include "absl/log/globals.h"
#include "absl/strings/numbers.h"
#include "absl/strings/str_split.h"
#include "absl/strings/string_view.h"
@@ -305,7 +307,7 @@ void LoadAndSolve(const std::string& file_name) {
} // namespace operations_research
int main(int argc, char** argv) {
absl::SetFlag(&FLAGS_stderrthreshold, 0);
absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo);
InitGoogle(argv[0], &argc, &argv, true);
if (absl::GetFlag(FLAGS_input).empty()) {

View File

@@ -46,6 +46,9 @@
#include <string>
#include <vector>
#include "absl/base/log_severity.h"
#include "absl/flags/flag.h"
#include "absl/log/globals.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/str_format.h"
#include "absl/strings/str_join.h"
@@ -321,7 +324,7 @@ static const char kUsage[] =
"There is no output besides the LOGs of the solver.";
int main(int argc, char** argv) {
absl::SetFlag(&FLAGS_stderrthreshold, 0);
absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo);
InitGoogle(kUsage, &argc, &argv, true);
CHECK_EQ(0, absl::GetFlag(FLAGS_num_teams) % 2)
<< "The number of teams must be even";

View File

@@ -606,7 +606,7 @@ int main(int argc, char** argv) {
usage += " --colgen_max_iterations <n> max columns to generate\n";
usage += " --colgen_complete generate all columns at start\n";
absl::SetFlag(&FLAGS_stderrthreshold, 0);
absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo);
InitGoogle(usage.c_str(), &argc, &argv, true);
operations_research::MPSolver::OptimizationProblemType solver_type;

View File

@@ -28,6 +28,7 @@
#include "absl/flags/flag.h"
#include "absl/flags/parse.h"
#include "absl/flags/usage.h"
#include "absl/log/globals.h"
#include "absl/log/initialize.h"
#include "absl/random/random.h"
#include "ortools/base/logging.h"
@@ -239,7 +240,7 @@ int main(int argc, char** argv) {
<< "Specify a non-null client size.";
CHECK_LT(0, absl::GetFlag(FLAGS_fix_cost))
<< "Specify a non-null client size.";
absl::SetFlag(&FLAGS_stderrthreshold, 0);
absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo);
operations_research::RunAllExamples(absl::GetFlag(FLAGS_facilities),
absl::GetFlag(FLAGS_clients),
absl::GetFlag(FLAGS_fix_cost));

View File

@@ -15,6 +15,7 @@
#include <string>
#include "absl/flags/flag.h"
#include "absl/log/globals.h"
#include "absl/status/status.h"
#include "absl/strings/match.h"
#include "absl/strings/str_cat.h"
@@ -98,7 +99,7 @@ void ParseAndSolve(const std::string& filename, absl::string_view solver,
} // namespace operations_research
int main(int argc, char** argv) {
absl::SetFlag(&FLAGS_stderrthreshold, 0);
absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo);
InitGoogle(argv[0], &argc, &argv, true);
if (absl::GetFlag(FLAGS_input).empty()) {
LOG(FATAL) << "Please supply a data file with --input=";

View File

@@ -19,6 +19,7 @@
#include "absl/flags/flag.h"
#include "absl/log/check.h"
#include "absl/log/globals.h"
#include "absl/strings/numbers.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/str_split.h"
@@ -252,7 +253,7 @@ void ParseAndSolve() {
} // namespace operations_research
int main(int argc, char** argv) {
absl::SetFlag(&FLAGS_stderrthreshold, 0);
absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo);
InitGoogle(argv[0], &argc, &argv, true);
if (absl::GetFlag(FLAGS_input).empty()) {
LOG(FATAL) << "Please supply a data file with --input=";

View File

@@ -90,7 +90,7 @@ void useXpressSolver(bool solveAsMip, bool useFactory) {
}
#define ABSL_MIN_LOG_LEVEL INFO;
int main(int argc, char** argv) {
absl::SetFlag(&FLAGS_stderrthreshold, 0);
absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo);
InitGoogle(argv[0], &argc, &argv, true);
std::cout << "start\n";
LOG(WARNING) << "start";