From 7182abb8643ec63c2e39312d4dc8096275fe695f Mon Sep 17 00:00:00 2001 From: Vincent Furnon Date: Tue, 16 Jun 2015 10:08:44 +0200 Subject: [PATCH] Renamed the linear solver protocol buffer and removed the new_proto namespace. --- examples/cpp/linear_programming.cc | 2 +- .../cpp/linear_solver_protocol_buffers.cc | 23 ++++---- examples/cpp/mps_driver.cc | 4 +- examples/cpp/solve.cc | 19 +++---- examples/python/linear_programming.py | 4 +- examples/tests/pywraplp_test.py | 6 +- examples/tests/remote/linear_programming.cc | 2 +- examples/tests/test_lp_api.py | 6 +- makefiles/Makefile.cpp.mk | 28 ++++----- makefiles/Makefile.csharp.mk | 2 +- makefiles/Makefile.java.mk | 2 +- makefiles/Makefile.python.mk | 8 +-- src/glop/lp_solver.cc | 2 +- src/glop/proto_driver.cc | 4 +- src/glop/proto_utils.cc | 12 ++-- src/glop/proto_utils.h | 6 +- src/linear_solver/csharp/linear_solver.swig | 2 +- src/linear_solver/java/linear_solver.swig | 2 +- src/linear_solver/linear_solver.cc | 57 ++++++++----------- src/linear_solver/linear_solver.h | 33 +++++------ ...near_solver2.proto => linear_solver.proto} | 2 +- src/linear_solver/model_exporter.cc | 10 +--- src/linear_solver/model_exporter.h | 10 ++-- src/linear_solver/python/linear_solver.swig | 8 +-- src/sat/lp_utils.cc | 10 ++-- src/sat/lp_utils.h | 6 +- 26 files changed, 126 insertions(+), 144 deletions(-) rename src/linear_solver/{linear_solver2.proto => linear_solver.proto} (99%) diff --git a/examples/cpp/linear_programming.cc b/examples/cpp/linear_programming.cc index f06e4100a3..c48e9d4bda 100644 --- a/examples/cpp/linear_programming.cc +++ b/examples/cpp/linear_programming.cc @@ -18,7 +18,7 @@ #include "base/commandlineflags.h" #include "base/logging.h" #include "linear_solver/linear_solver.h" -#include "linear_solver/linear_solver2.pb.h" +#include "linear_solver/linear_solver.pb.h" namespace operations_research { void RunLinearProgrammingExample( diff --git a/examples/cpp/linear_solver_protocol_buffers.cc b/examples/cpp/linear_solver_protocol_buffers.cc index c8a622d55a..e88fa2aef1 100644 --- a/examples/cpp/linear_solver_protocol_buffers.cc +++ b/examples/cpp/linear_solver_protocol_buffers.cc @@ -17,7 +17,7 @@ #include "base/commandlineflags.h" #include "base/logging.h" #include "linear_solver/linear_solver.h" -#include "linear_solver/linear_solver2.pb.h" +#include "linear_solver/linear_solver.pb.h" namespace operations_research { void BuildLinearProgrammingMaxExample(MPSolver::OptimizationProblemType type) { @@ -34,12 +34,12 @@ void BuildLinearProgrammingMaxExample(MPSolver::OptimizationProblemType type) { const double kConstraintUb[] = {100.0, 600.0, 300.0}; const double infinity = MPSolver::infinity(); - new_proto::MPModelProto model_proto; + MPModelProto model_proto; model_proto.set_name("Max_Example"); // Create variables and objective function for (int j = 0; j < numVars; ++j) { - new_proto::MPVariableProto* x = model_proto.add_variable(); + MPVariableProto* x = model_proto.add_variable(); x->set_name(kVarName[j]); // Could be skipped (optional). x->set_lower_bound(0.0); x->set_upper_bound(infinity); // Could be skipped (default value). @@ -50,8 +50,7 @@ void BuildLinearProgrammingMaxExample(MPSolver::OptimizationProblemType type) { // Create constraints for (int i = 0; i < kNumConstraints; ++i) { - new_proto::MPConstraintProto* constraint_proto = - model_proto.add_constraint(); + MPConstraintProto* constraint_proto = model_proto.add_constraint(); constraint_proto->set_name(kConstraintName[i]); // Could be skipped. constraint_proto->set_lower_bound(-infinity); // Could be skipped. constraint_proto->set_upper_bound(kConstraintUb[i]); @@ -62,26 +61,24 @@ void BuildLinearProgrammingMaxExample(MPSolver::OptimizationProblemType type) { } } - new_proto::MPModelRequest model_request; - model_request.mutable_model()->CopyFrom(model_proto); + MPModelRequest model_request; + *model_request.mutable_model() = model_proto; #if defined(USE_GLOP) if (type == MPSolver::GLOP_LINEAR_PROGRAMMING) { - model_request.set_solver_type( - new_proto::MPModelRequest::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( - new_proto::MPModelRequest::CLP_LINEAR_PROGRAMMING); + model_request.set_solver_type(MPModelRequest::CLP_LINEAR_PROGRAMMING); } #endif // USE_CLP - new_proto::MPSolutionResponse solution_response; + MPSolutionResponse solution_response; MPSolver::SolveWithProto(model_request, &solution_response); // The problem has an optimal solution. - CHECK_EQ(new_proto::MPSolutionResponse::OPTIMAL, solution_response.status()); + CHECK_EQ(MPSolutionResponse::OPTIMAL, solution_response.status()); LOG(INFO) << "objective = " << solution_response.objective_value(); for (int j = 0; j < numVars; ++j) { diff --git a/examples/cpp/mps_driver.cc b/examples/cpp/mps_driver.cc index 846f200e4c..ce2ec992e0 100644 --- a/examples/cpp/mps_driver.cc +++ b/examples/cpp/mps_driver.cc @@ -13,7 +13,7 @@ // Driver for reading and solving files in the MPS format and in -// the linear_solver2.proto format. +// the linear_solver.proto format. #include #include @@ -99,7 +99,7 @@ int main(int argc, char* argv[]) { for (int i = 0; i < file_list.size(); ++i) { const std::string& file_name = file_list[i]; MPSReader mps_reader; - operations_research::new_proto::MPModelProto model_proto; + operations_research::MPModelProto model_proto; if (HasSuffixString(file_name, ".mps") || HasSuffixString(file_name, ".mps.gz")) { if (!mps_reader.LoadFileAndTryFreeFormOnFail(file_name, diff --git a/examples/cpp/solve.cc b/examples/cpp/solve.cc index e7947c52a8..3eb0344f1e 100644 --- a/examples/cpp/solve.cc +++ b/examples/cpp/solve.cc @@ -24,7 +24,7 @@ #include "base/strutil.h" #include "glop/proto_utils.h" #include "linear_solver/linear_solver.h" -#include "linear_solver/linear_solver2.pb.h" +#include "linear_solver/linear_solver.pb.h" #include "lp_data/mps_reader.h" #include "util/proto_tools.h" @@ -43,7 +43,7 @@ static const char kUsageStr[] = " - an MPModelProto (binary or text, possibly gzipped),\n" " - an MPModelRequest (binary or text, possibly gzipped).\n" "MPModelProto and MPModelRequest files can comply with either the " - "linear_solver.proto or the linear_solver2.proto format."; + "linear_solver.proto or the linear_solver.proto format."; namespace operations_research { namespace { @@ -106,14 +106,13 @@ void Run() { CHECK(solver.SetSolverSpecificParametersAsString(FLAGS_params)) << "Wrong --params format."; } - printf("%-12s: %s\n", "Solver", - new_proto::MPModelRequest::SolverType_Name( - static_cast( - solver.ProblemType())).c_str()); + printf("%-12s: %s\n", "Solver", MPModelRequest::SolverType_Name( + static_cast( + solver.ProblemType())).c_str()); // Load the problem into an MPModelProto. - new_proto::MPModelProto model_proto; - new_proto::MPModelRequest request_proto; + MPModelProto model_proto; + MPModelRequest request_proto; if (HasSuffixString(FLAGS_input, ".mps") || HasSuffixString(FLAGS_input, ".mps.gz")) { glop::LinearProgram linear_program_fixed; @@ -178,8 +177,8 @@ void Run() { } printf("%-12s: %s\n", "Status", - new_proto::MPSolutionResponse::Status_Name( - static_cast(solve_status)) + MPSolutionResponse::Status_Name( + static_cast(solve_status)) .c_str()); printf("%-12s: %15.15e\n", "Objective", solver.Objective().Value()); printf("%-12s: %-6.4g\n", "Time", solving_time_in_sec); diff --git a/examples/python/linear_programming.py b/examples/python/linear_programming.py index da32774424..4cb834e0a3 100644 --- a/examples/python/linear_programming.py +++ b/examples/python/linear_programming.py @@ -16,7 +16,7 @@ from google.apputils import app -from ortools.linear_solver import linear_solver2_pb2 +from ortools.linear_solver import linear_solver_pb2 from ortools.linear_solver import pywraplp @@ -114,7 +114,7 @@ def SolveAndPrint(solver, variable_list, constraint_list): def main(unused_argv): all_names_and_problem_types = ( - linear_solver2_pb2.MPModelRequest.SolverType.items()) + linear_solver_pb2.MPModelRequest.SolverType.items()) for name, problem_type in all_names_and_problem_types: # Skip non-LP problem types. if not name.endswith('LINEAR_PROGRAMMING'): diff --git a/examples/tests/pywraplp_test.py b/examples/tests/pywraplp_test.py index a687d7f4d8..e76777e34d 100644 --- a/examples/tests/pywraplp_test.py +++ b/examples/tests/pywraplp_test.py @@ -14,7 +14,7 @@ import types -from ortools.linear_solver import linear_solver2_pb2 +from ortools.linear_solver import linear_solver_pb2 from ortools.linear_solver import pywraplp from google.protobuf import text_format @@ -50,7 +50,7 @@ model < def test_proto(): - input_proto = linear_solver2_pb2.MPModelRequest() + input_proto = linear_solver_pb2.MPModelRequest() text_format.Merge(text_model, input_proto) solver = pywraplp.Solver('solveFromProto', pywraplp.Solver.CBC_MIXED_INTEGER_PROGRAMMING) @@ -60,7 +60,7 @@ def test_proto(): solver.EnableOutput() solver.Solve() # Fill solution - solution = linear_solver2_pb2.MPSolutionResponse() + solution = linear_solver_pb2.MPSolutionResponse() solver.FillSolutionResponseProto(solution) print solution diff --git a/examples/tests/remote/linear_programming.cc b/examples/tests/remote/linear_programming.cc index 1587bb07d2..2c9e739cff 100644 --- a/examples/tests/remote/linear_programming.cc +++ b/examples/tests/remote/linear_programming.cc @@ -17,7 +17,7 @@ #include "base/commandlineflags.h" #include "base/logging.h" #include "linear_solver/linear_solver.h" -#include "linear_solver/linear_solver2.pb.h" +#include "linear_solver/linear_solver.pb.h" namespace operations_research { void RunLinearProgrammingExample( diff --git a/examples/tests/test_lp_api.py b/examples/tests/test_lp_api.py index 2dba7faee5..a4315e0f0c 100644 --- a/examples/tests/test_lp_api.py +++ b/examples/tests/test_lp_api.py @@ -1,6 +1,6 @@ from google.protobuf import text_format from ortools.linear_solver import pywraplp -from ortools.linear_solver import linear_solver2_pb2 +from ortools.linear_solver import linear_solver_pb2 import sys import types @@ -35,7 +35,7 @@ model < def test_proto(): - input_proto = linear_solver2_pb2.MPModelRequest() + input_proto = linear_solver_pb2.MPModelRequest() text_format.Merge(text_model, input_proto) solver = pywraplp.Solver('solveFromProto', pywraplp.Solver.CBC_MIXED_INTEGER_PROGRAMMING) @@ -45,7 +45,7 @@ def test_proto(): solver.EnableOutput() solver.Solve() # Fill solution - solution = linear_solver2_pb2.MPSolutionResponse() + solution = linear_solver_pb2.MPSolutionResponse() solver.FillSolutionResponseProto(solution) print solution diff --git a/makefiles/Makefile.cpp.mk b/makefiles/Makefile.cpp.mk index 4f8bbc00a4..d319133e67 100644 --- a/makefiles/Makefile.cpp.mk +++ b/makefiles/Makefile.cpp.mk @@ -51,7 +51,7 @@ DYNAMIC_GRAPH_DEPS = $(DYNAMIC_GRAPH_LIBS) \ $(DYNAMIC_BASE_DEPS) DYNAMIC_LP_DEPS = \ - $(GEN_DIR)/linear_solver/linear_solver2.pb.h \ + $(GEN_DIR)/linear_solver/linear_solver.pb.h \ $(DYNAMIC_LP_LIBS) \ $(DYNAMIC_SAT_LIBS) \ $(DYNAMIC_SPLIT_LIBS) \ @@ -83,8 +83,8 @@ DYNAMIC_FLATZINC_DEPS = $(DYNAMIC_FLATZINC_LIBS) \ DYNAMIC_DIMACS_DEPS = $(DYNAMIC_DIMACS_LIBS) \ $(DYNAMIC_BASE_DEPS) \ $(DYNAMIC_GRAPH_DEPS) \ - $(DYNAMIC_ALGORITHMS_DEPS) \ - $(DYNAMIC_LP_DEPS) + $(DYNAMIC_LP_DEPS) \ + $(DYNAMIC_ALGORITHMS_DEPS) DYNAMIC_FAP_DEPS = $(DYNAMIC_FAP_LIBS) \ $(DYNAMIC_BASE_DEPS) \ @@ -634,7 +634,7 @@ LINEAR_SOLVER_LIB_OBJS = \ $(OBJ_DIR)/linear_solver/glpk_interface.$O \ $(OBJ_DIR)/linear_solver/gurobi_interface.$O \ $(OBJ_DIR)/linear_solver/linear_solver.$O \ - $(OBJ_DIR)/linear_solver/linear_solver2.pb.$O \ + $(OBJ_DIR)/linear_solver/linear_solver.pb.$O \ $(OBJ_DIR)/linear_solver/model_exporter.$O \ $(OBJ_DIR)/linear_solver/scip_interface.$O \ $(OBJ_DIR)/linear_solver/sulum_interface.$O @@ -661,18 +661,18 @@ $(OBJ_DIR)/linear_solver/glpk_interface.$O:$(SRC_DIR)/linear_solver/glpk_interfa $(OBJ_DIR)/linear_solver/gurobi_interface.$O:$(SRC_DIR)/linear_solver/gurobi_interface.cc $(CCC) $(CFLAGS) -c $(SRC_DIR)$Slinear_solver$Sgurobi_interface.cc $(OBJ_OUT)$(OBJ_DIR)$Slinear_solver$Sgurobi_interface.$O -$(OBJ_DIR)/linear_solver/linear_solver.$O:$(SRC_DIR)/linear_solver/linear_solver.cc $(GEN_DIR)/linear_solver/linear_solver2.pb.h $(GEN_DIR)/glop/parameters.pb.h +$(OBJ_DIR)/linear_solver/linear_solver.$O:$(SRC_DIR)/linear_solver/linear_solver.cc $(GEN_DIR)/linear_solver/linear_solver.pb.h $(GEN_DIR)/glop/parameters.pb.h $(GEN_DIR)/bop/bop_parameters.pb.h $(CCC) $(CFLAGS) -c $(SRC_DIR)$Slinear_solver$Slinear_solver.cc $(OBJ_OUT)$(OBJ_DIR)$Slinear_solver$Slinear_solver.$O -$(OBJ_DIR)/linear_solver/linear_solver2.pb.$O:$(GEN_DIR)/linear_solver/linear_solver2.pb.cc - $(CCC) $(CFLAGS) -c $(GEN_DIR)$Slinear_solver$Slinear_solver2.pb.cc $(OBJ_OUT)$(OBJ_DIR)$Slinear_solver$Slinear_solver2.pb.$O +$(OBJ_DIR)/linear_solver/linear_solver.pb.$O:$(GEN_DIR)/linear_solver/linear_solver.pb.cc + $(CCC) $(CFLAGS) -c $(GEN_DIR)$Slinear_solver$Slinear_solver.pb.cc $(OBJ_OUT)$(OBJ_DIR)$Slinear_solver$Slinear_solver.pb.$O -$(GEN_DIR)/linear_solver/linear_solver2.pb.cc:$(SRC_DIR)/linear_solver/linear_solver2.proto - $(PROTOBUF_DIR)$Sbin$Sprotoc --proto_path=$(INC_DIR) --cpp_out=$(GEN_DIR) $(SRC_DIR)$Slinear_solver$Slinear_solver2.proto +$(GEN_DIR)/linear_solver/linear_solver.pb.cc:$(SRC_DIR)/linear_solver/linear_solver.proto + $(PROTOBUF_DIR)$Sbin$Sprotoc --proto_path=$(INC_DIR) --cpp_out=$(GEN_DIR) $(SRC_DIR)$Slinear_solver$Slinear_solver.proto -$(GEN_DIR)/linear_solver/linear_solver2.pb.h:$(GEN_DIR)/linear_solver/linear_solver2.pb.cc +$(GEN_DIR)/linear_solver/linear_solver.pb.h:$(GEN_DIR)/linear_solver/linear_solver.pb.cc -$(OBJ_DIR)/linear_solver/model_exporter.$O:$(SRC_DIR)/linear_solver/model_exporter.cc $(GEN_DIR)/linear_solver/linear_solver2.pb.h +$(OBJ_DIR)/linear_solver/model_exporter.$O:$(SRC_DIR)/linear_solver/model_exporter.cc $(GEN_DIR)/linear_solver/linear_solver.pb.h $(CCC) $(CFLAGS) -c $(SRC_DIR)$Slinear_solver$Smodel_exporter.cc $(OBJ_OUT)$(OBJ_DIR)$Slinear_solver$Smodel_exporter.$O $(OBJ_DIR)/linear_solver/scip_interface.$O:$(SRC_DIR)/linear_solver/scip_interface.cc @@ -718,7 +718,7 @@ $(OBJ_DIR)/util/graph_export.$O:$(SRC_DIR)/util/graph_export.cc $(OBJ_DIR)/util/piecewise_linear_function.$O:$(SRC_DIR)/util/piecewise_linear_function.cc $(CCC) $(CFLAGS) -c $(SRC_DIR)/util/piecewise_linear_function.cc $(OBJ_OUT)$(OBJ_DIR)$Sutil$Spiecewise_linear_function.$O -$(OBJ_DIR)/util/proto_tools.$O:$(SRC_DIR)/util/proto_tools.cc $(GEN_DIR)/linear_solver/linear_solver2.pb.h +$(OBJ_DIR)/util/proto_tools.$O:$(SRC_DIR)/util/proto_tools.cc $(GEN_DIR)/linear_solver/linear_solver.pb.h $(CCC) $(CFLAGS) -c $(SRC_DIR)$Sutil$Sproto_tools.cc $(OBJ_OUT)$(OBJ_DIR)$Sutil$Sproto_tools.$O $(OBJ_DIR)/util/rational_approximation.$O:$(SRC_DIR)/util/rational_approximation.cc @@ -1031,7 +1031,7 @@ $(OBJ_DIR)/glop/entering_variable.$O:$(SRC_DIR)/glop/entering_variable.cc $(OBJ_DIR)/glop/initial_basis.$O:$(SRC_DIR)/glop/initial_basis.cc $(CCC) $(CFLAGS) -c $(SRC_DIR)$Sglop$Sinitial_basis.cc $(OBJ_OUT)$(OBJ_DIR)$Sglop$Sinitial_basis.$O -$(OBJ_DIR)/glop/lp_solver.$O:$(SRC_DIR)/glop/lp_solver.cc $(GEN_DIR)/linear_solver/linear_solver2.pb.h +$(OBJ_DIR)/glop/lp_solver.$O:$(SRC_DIR)/glop/lp_solver.cc $(GEN_DIR)/linear_solver/linear_solver.pb.h $(CCC) $(CFLAGS) -c $(SRC_DIR)$Sglop$Slp_solver.cc $(OBJ_OUT)$(OBJ_DIR)$Sglop$Slp_solver.$O $(OBJ_DIR)/glop/lu_factorization.$O:$(SRC_DIR)/glop/lu_factorization.cc @@ -1087,7 +1087,7 @@ $(OBJ_DIR)/glop/mps_driver.$O:$(EX_DIR)/cpp/mps_driver.cc $(GEN_DIR)/glop/parame $(BIN_DIR)/mps_driver$E: $(OBJ_DIR)/glop/mps_driver.$O $(STATIC_LP_DEPS) $(CCC) $(CFLAGS) $(OBJ_DIR)$Sglop$Smps_driver.$O $(STATIC_LP_LNK) $(STATIC_LD_FLAGS) $(EXE_OUT)$(BIN_DIR)$Smps_driver$E -$(OBJ_DIR)/glop/solve.$O:$(EX_DIR)/cpp/solve.cc $(GEN_DIR)/glop/parameters.pb.h $(GEN_DIR)/linear_solver/linear_solver2.pb.h +$(OBJ_DIR)/glop/solve.$O:$(EX_DIR)/cpp/solve.cc $(GEN_DIR)/glop/parameters.pb.h $(GEN_DIR)/linear_solver/linear_solver.pb.h $(CCC) $(CFLAGS) -c $(EX_DIR)$Scpp$Ssolve.cc $(OBJ_OUT)$(OBJ_DIR)$Sglop$Ssolve.$O $(BIN_DIR)/solve$E: $(OBJ_DIR)/glop/solve.$O $(STATIC_LP_DEPS) diff --git a/makefiles/Makefile.csharp.mk b/makefiles/Makefile.csharp.mk index 96e237d1f6..fa761755d9 100644 --- a/makefiles/Makefile.csharp.mk +++ b/makefiles/Makefile.csharp.mk @@ -134,7 +134,7 @@ $(GEN_DIR)/linear_solver/linear_solver_csharp_wrap.cc: \ $(SRC_DIR)/linear_solver/csharp/linear_solver.swig \ $(SRC_DIR)/base/base.swig $(SRC_DIR)/util/csharp/data.swig \ $(SRC_DIR)/linear_solver/linear_solver.h \ - $(GEN_DIR)/linear_solver/linear_solver2.pb.h + $(GEN_DIR)/linear_solver/linear_solver.pb.h $(SWIG_BINARY) $(SWIG_INC) -I$(INC_DIR) -c++ -csharp -o $(GEN_DIR)$Slinear_solver$Slinear_solver_csharp_wrap.cc -module operations_research_linear_solver -namespace $(CLR_DLL_NAME).LinearSolver -dllimport "$(CLR_DLL_NAME).$(DYNAMIC_SWIG_LIB_SUFFIX)" -outdir $(GEN_DIR)$Scom$Sgoogle$Sortools$Slinearsolver $(SRC_DIR)/linear_solver$Scsharp$Slinear_solver.swig $(OBJ_DIR)/swig/linear_solver_csharp_wrap.$O: $(GEN_DIR)/linear_solver/linear_solver_csharp_wrap.cc diff --git a/makefiles/Makefile.java.mk b/makefiles/Makefile.java.mk index 726c38abab..bf76b9da09 100644 --- a/makefiles/Makefile.java.mk +++ b/makefiles/Makefile.java.mk @@ -47,7 +47,7 @@ $(OBJ_DIR)/swig/knapsack_solver_java_wrap.$O: $(GEN_DIR)/algorithms/knapsack_sol $(GEN_DIR)/graph/graph_java_wrap.cc: $(SRC_DIR)/graph/java/graph.swig $(SRC_DIR)/base/base.swig $(SRC_DIR)/util/java/data.swig $(SRC_DIR)/graph/max_flow.h $(SRC_DIR)/graph/min_cost_flow.h $(SRC_DIR)/graph/linear_assignment.h $(SWIG_BINARY) -I$(INC_DIR) -c++ -java -o $(GEN_DIR)$Sgraph$Sgraph_java_wrap.cc -package com.google.ortools.graph -module operations_research_graph -outdir $(GEN_DIR)$Scom$Sgoogle$Sortools$Sgraph $(SRC_DIR)$Sgraph$Sjava$Sgraph.swig -$(GEN_DIR)/linear_solver/linear_solver_java_wrap.cc: $(SRC_DIR)/linear_solver/java/linear_solver.swig $(SRC_DIR)/base/base.swig $(SRC_DIR)/util/java/data.swig $(SRC_DIR)/linear_solver/linear_solver.h $(GEN_DIR)/linear_solver/linear_solver2.pb.h +$(GEN_DIR)/linear_solver/linear_solver_java_wrap.cc: $(SRC_DIR)/linear_solver/java/linear_solver.swig $(SRC_DIR)/base/base.swig $(SRC_DIR)/util/java/data.swig $(SRC_DIR)/linear_solver/linear_solver.h $(GEN_DIR)/linear_solver/linear_solver.pb.h $(SWIG_BINARY) $(SWIG_INC) -I$(INC_DIR) -c++ -java -o $(GEN_DIR)$Slinear_solver$Slinear_solver_java_wrap.cc -package com.google.ortools.linearsolver -module operations_research_linear_solver -outdir $(GEN_DIR)$Scom$Sgoogle$Sortools$Slinearsolver $(SRC_DIR)$Slinear_solver$Sjava$Slinear_solver.swig $(OBJ_DIR)/swig/linear_solver_java_wrap.$O: $(GEN_DIR)/linear_solver/linear_solver_java_wrap.cc diff --git a/makefiles/Makefile.python.mk b/makefiles/Makefile.python.mk index 747c6e9766..cba3d0626d 100644 --- a/makefiles/Makefile.python.mk +++ b/makefiles/Makefile.python.mk @@ -132,16 +132,16 @@ endif pylp: $(LIB_DIR)/_pywraplp.$(DYNAMIC_SWIG_LIB_SUFFIX) $(GEN_DIR)/ortools/linear_solver/pywraplp.py -$(GEN_DIR)/ortools/linear_solver/linear_solver2_pb2.py: $(SRC_DIR)/linear_solver/linear_solver2.proto - $(PROTOBUF_DIR)/bin/protoc --proto_path=$(SRC_DIR) --python_out=$(GEN_DIR)$Sortools $(SRC_DIR)/linear_solver/linear_solver2.proto +$(GEN_DIR)/ortools/linear_solver/linear_solver_pb2.py: $(SRC_DIR)/linear_solver/linear_solver.proto + $(PROTOBUF_DIR)/bin/protoc --proto_path=$(SRC_DIR) --python_out=$(GEN_DIR)$Sortools $(SRC_DIR)/linear_solver/linear_solver.proto $(GEN_DIR)/ortools/linear_solver/pywraplp.py: \ $(SRC_DIR)/base/base.swig \ $(SRC_DIR)/util/python/data.swig \ $(SRC_DIR)/linear_solver/python/linear_solver.swig \ $(SRC_DIR)/linear_solver/linear_solver.h \ - $(GEN_DIR)/linear_solver/linear_solver2.pb.h \ - $(GEN_DIR)/ortools/linear_solver/linear_solver2_pb2.py + $(GEN_DIR)/linear_solver/linear_solver.pb.h \ + $(GEN_DIR)/ortools/linear_solver/linear_solver_pb2.py $(SWIG_BINARY) $(SWIG_INC) -I$(INC_DIR) -c++ -python $(SWIG_PYTHON3_FLAG) -o $(GEN_DIR)$Sortools$Slinear_solver$Slinear_solver_python_wrap.cc -module pywraplp $(SRC_DIR)/linear_solver$Spython$Slinear_solver.swig $(GEN_DIR)/ortools/linear_solver/linear_solver_python_wrap.cc: $(GEN_DIR)/ortools/linear_solver/pywraplp.py diff --git a/src/glop/lp_solver.cc b/src/glop/lp_solver.cc index 514628f5bc..df3403b2ee 100644 --- a/src/glop/lp_solver.cc +++ b/src/glop/lp_solver.cc @@ -78,7 +78,7 @@ void DumpLinearProgramIfRequiredByFlags(const LinearProgram& linear_program, FLAGS_lp_dump_file_number >= 0 ? FLAGS_lp_dump_file_number : num; StringAppendF(&filename, "-%06d.pb", file_num); const std::string filespec = StrCat(FLAGS_lp_dump_dir, "/", filename); - new_proto::MPModelProto proto; + MPModelProto proto; LinearProgramToMPModelProto(linear_program, &proto); if (!WriteProtoToFile(filespec, proto, FLAGS_lp_dump_binary_file, FLAGS_lp_dump_compressed_file)) { diff --git a/src/glop/proto_driver.cc b/src/glop/proto_driver.cc index 189fb91f51..f5f534eda7 100644 --- a/src/glop/proto_driver.cc +++ b/src/glop/proto_driver.cc @@ -32,7 +32,7 @@ #include "util/gzip/gzipstring.h" #include "glop/lp_solver.h" #include "linear_solver/linear_solver.h" -#include "linear_solver/linear_solver2.pb.h" +#include "linear_solver/linear_solver.pb.h" #include "util/fp_utils.h" #include "util/stats.h" #include "base/status.h" @@ -79,7 +79,7 @@ void Solve(MPSolver::OptimizationProblemType type, const std::string& file_name, if (!GunzipString(raw_data, &uncompressed)) { uncompressed = raw_data; } - new_proto::MPModelProto proto; + MPModelProto proto; { ScopedWallTime timer(&(result->parsing_time_in_sec)); if (!proto.ParseFromString(uncompressed)) { diff --git a/src/glop/proto_utils.cc b/src/glop/proto_utils.cc index 157a69e30f..bba52bc328 100644 --- a/src/glop/proto_utils.cc +++ b/src/glop/proto_utils.cc @@ -18,13 +18,13 @@ namespace glop { // Converts a LinearProgram to a MPModelProto. void LinearProgramToMPModelProto(const LinearProgram& input, - new_proto::MPModelProto* output) { + MPModelProto* output) { output->Clear(); output->set_name(input.name()); output->set_maximize(input.IsMaximizationProblem()); output->set_objective_offset(input.objective_offset()); for (ColIndex col(0); col < input.num_variables(); ++col) { - new_proto::MPVariableProto* variable = output->add_variable(); + MPVariableProto* variable = output->add_variable(); variable->set_lower_bound(input.variable_lower_bounds()[col]); variable->set_upper_bound(input.variable_upper_bounds()[col]); variable->set_name(input.GetVariableName(col)); @@ -36,7 +36,7 @@ void LinearProgramToMPModelProto(const LinearProgram& input, SparseMatrix transpose; transpose.PopulateFromTranspose(input.GetSparseMatrix()); for (RowIndex row(0); row < input.num_constraints(); ++row) { - new_proto::MPConstraintProto* constraint = output->add_constraint(); + MPConstraintProto* constraint = output->add_constraint(); constraint->set_lower_bound(input.constraint_lower_bounds()[row]); constraint->set_upper_bound(input.constraint_upper_bounds()[row]); constraint->set_name(input.GetConstraintName(row)); @@ -48,7 +48,7 @@ void LinearProgramToMPModelProto(const LinearProgram& input, } // Converts a MPModelProto to a LinearProgram. -void MPModelProtoToLinearProgram(const new_proto::MPModelProto& input, +void MPModelProtoToLinearProgram(const MPModelProto& input, LinearProgram* output) { output->Clear(); output->SetName(input.name()); @@ -56,7 +56,7 @@ void MPModelProtoToLinearProgram(const new_proto::MPModelProto& input, output->SetObjectiveOffset(input.objective_offset()); // TODO(user,user): clean up loops to use natural range iteration. for (int i = 0; i < input.variable_size(); ++i) { - const new_proto::MPVariableProto& var = input.variable(i); + const MPVariableProto& var = input.variable(i); const ColIndex col = output->CreateNewVariable(); output->SetVariableName(col, var.name()); output->SetVariableBounds(col, var.lower_bound(), var.upper_bound()); @@ -64,7 +64,7 @@ void MPModelProtoToLinearProgram(const new_proto::MPModelProto& input, output->SetVariableIntegrality(col, var.is_integer()); } for (int j = 0; j < input.constraint_size(); ++j) { - const new_proto::MPConstraintProto& cst = input.constraint(j); + const MPConstraintProto& cst = input.constraint(j); const RowIndex row = output->CreateNewConstraint(); output->SetConstraintName(row, cst.name()); output->SetConstraintBounds(row, cst.lower_bound(), cst.upper_bound()); diff --git a/src/glop/proto_utils.h b/src/glop/proto_utils.h index 7f26a714ef..0d8de0d17c 100644 --- a/src/glop/proto_utils.h +++ b/src/glop/proto_utils.h @@ -14,7 +14,7 @@ #ifndef OR_TOOLS_GLOP_PROTO_UTILS_H_ #define OR_TOOLS_GLOP_PROTO_UTILS_H_ -#include "linear_solver/linear_solver2.pb.h" +#include "linear_solver/linear_solver.pb.h" #include "lp_data/lp_data.h" namespace operations_research { @@ -22,10 +22,10 @@ namespace glop { // Converts a LinearProgram to a MPModelProto. void LinearProgramToMPModelProto(const LinearProgram& input, - new_proto::MPModelProto* output); + MPModelProto* output); // Converts a MPModelProto to a LinearProgram. -void MPModelProtoToLinearProgram(const new_proto::MPModelProto& input, +void MPModelProtoToLinearProgram(const MPModelProto& input, LinearProgram* output); } // namespace glop diff --git a/src/linear_solver/csharp/linear_solver.swig b/src/linear_solver/csharp/linear_solver.swig index 927f4d328b..5a1310f2e3 100644 --- a/src/linear_solver/csharp/linear_solver.swig +++ b/src/linear_solver/csharp/linear_solver.swig @@ -31,7 +31,7 @@ %{ #include "linear_solver/linear_solver.h" -#include "linear_solver/linear_solver2.pb.h" +#include "linear_solver/linear_solver.pb.h" #include "linear_solver/linear_solver_ext.h" %} diff --git a/src/linear_solver/java/linear_solver.swig b/src/linear_solver/java/linear_solver.swig index eca3918565..1643117ec5 100644 --- a/src/linear_solver/java/linear_solver.swig +++ b/src/linear_solver/java/linear_solver.swig @@ -32,7 +32,7 @@ %{ #include "linear_solver/linear_solver.h" -#include "linear_solver/linear_solver2.pb.h" +#include "linear_solver/linear_solver.pb.h" #include "linear_solver/linear_solver_ext.h" %} diff --git a/src/linear_solver/linear_solver.cc b/src/linear_solver/linear_solver.cc index 6397d11f09..f4537e25fe 100644 --- a/src/linear_solver/linear_solver.cc +++ b/src/linear_solver/linear_solver.cc @@ -34,7 +34,7 @@ #include "base/stl_util.h" #include "base/hash.h" #include "base/accurate_sum.h" -#include "linear_solver/linear_solver2.pb.h" +#include "linear_solver/linear_solver.pb.h" #include "linear_solver/model_exporter.h" #include "util/fp_utils.h" #include "util/proto_tools.h" @@ -57,10 +57,6 @@ DEFINE_bool(linear_solver_enable_verbose_output, false, // operations_research namespace in open_source/base). namespace operations_research { -using new_proto::Error; -using new_proto::MPModelProto; -using new_proto::MPModelRequest; -using new_proto::MPSolutionResponse; double MPConstraint::GetCoefficient(const MPVariable* const var) const { DLOG_IF(DFATAL, !interface_->solver_->OwnsVariable(var)) << var; @@ -486,10 +482,10 @@ MPConstraint* MPSolver::LookupConstraintOrNull(const std::string& constraint_nam // ----- Methods using protocol buffers ----- MPSolver::LoadStatus MPSolver::LoadModelFromProto( - const new_proto::MPModelProto& input_model) { + const MPModelProto& input_model) { MPObjective* const objective = MutableObjective(); for (int i = 0; i < input_model.variable_size(); ++i) { - const new_proto::MPVariableProto& var_proto = input_model.variable(i); + const MPVariableProto& var_proto = input_model.variable(i); // TODO(user): The variable name var_proto.name() is lost at this point. // This is because MPSolver has no notion of name, just of ids, and these @@ -505,7 +501,7 @@ MPSolver::LoadStatus MPSolver::LoadModelFromProto( } for (int i = 0; i < input_model.constraint_size(); ++i) { - const new_proto::MPConstraintProto& ct_proto = input_model.constraint(i); + const MPConstraintProto& ct_proto = input_model.constraint(i); MPConstraint* const ct = MakeRowConstraint( ct_proto.lower_bound(), ct_proto.upper_bound(), ct_proto.name()); ct->set_is_lazy(ct_proto.is_lazy()); @@ -537,27 +533,26 @@ MPSolver::LoadStatus MPSolver::LoadModelFromProto( } namespace { -new_proto::MPSolutionResponse::Status ResultStatusToMPSolutionResponse( +MPSolutionResponse::Status ResultStatusToMPSolutionResponse( MPSolver::ResultStatus status) { switch (status) { case MPSolver::OPTIMAL: - return new_proto::MPSolutionResponse::OPTIMAL; + return MPSolutionResponse::OPTIMAL; case MPSolver::FEASIBLE: - return new_proto::MPSolutionResponse::FEASIBLE; + return MPSolutionResponse::FEASIBLE; case MPSolver::INFEASIBLE: - return new_proto::MPSolutionResponse::INFEASIBLE; + return MPSolutionResponse::INFEASIBLE; case MPSolver::UNBOUNDED: - return new_proto::MPSolutionResponse::UNBOUNDED; + return MPSolutionResponse::UNBOUNDED; case MPSolver::ABNORMAL: - return new_proto::MPSolutionResponse::ABNORMAL; + return MPSolutionResponse::ABNORMAL; default: - return new_proto::MPSolutionResponse::UNKNOWN; + return MPSolutionResponse::UNKNOWN; } } } // namespace -void MPSolver::FillSolutionResponseProto( - new_proto::MPSolutionResponse* response) const { +void MPSolver::FillSolutionResponseProto(MPSolutionResponse* response) const { CHECK_NOTNULL(response); response->Clear(); response->set_status( @@ -576,10 +571,10 @@ void MPSolver::FillSolutionResponseProto( } // static -void MPSolver::SolveWithProto(const new_proto::MPModelRequest& model_request, - new_proto::MPSolutionResponse* response) { +void MPSolver::SolveWithProto(const MPModelRequest& model_request, + MPSolutionResponse* response) { CHECK_NOTNULL(response); - const new_proto::MPModelProto& model = model_request.model(); + const MPModelProto& model = model_request.model(); MPSolver solver(model.name(), static_cast( model_request.solver_type())); const MPSolver::LoadStatus loadStatus = solver.LoadModelFromProto(model); @@ -588,7 +583,7 @@ void MPSolver::SolveWithProto(const new_proto::MPModelRequest& model_request, << "load status = " << Error::Code_Name(static_cast(loadStatus)) << " (" << loadStatus << ")"; - response->set_status(new_proto::MPSolutionResponse::ABNORMAL); + response->set_status(MPSolutionResponse::ABNORMAL); return; } if (model_request.has_solver_time_limit_seconds()) { @@ -601,8 +596,7 @@ void MPSolver::SolveWithProto(const new_proto::MPModelRequest& model_request, solver.FillSolutionResponseProto(response); } -void MPSolver::ExportModelToNewProto(new_proto::MPModelProto* output_model) - const { +void MPSolver::ExportModelToProto(MPModelProto* output_model) const { DCHECK(output_model != NULL); output_model->Clear(); // Name @@ -610,8 +604,7 @@ void MPSolver::ExportModelToNewProto(new_proto::MPModelProto* output_model) // Variables for (int j = 0; j < variables_.size(); ++j) { const MPVariable* const var = variables_[j]; - new_proto::MPVariableProto* const variable_proto = - output_model->add_variable(); + MPVariableProto* const variable_proto = output_model->add_variable(); // TODO(user): Add option to avoid filling the var name to avoid overly // large protocol buffers. variable_proto->set_name(var->name()); @@ -638,8 +631,7 @@ void MPSolver::ExportModelToNewProto(new_proto::MPModelProto* output_model) // Constraints for (int i = 0; i < constraints_.size(); ++i) { MPConstraint* const constraint = constraints_[i]; - new_proto::MPConstraintProto* const constraint_proto = - output_model->add_constraint(); + MPConstraintProto* const constraint_proto = output_model->add_constraint(); constraint_proto->set_name(constraint->name()); constraint_proto->set_lower_bound(constraint->lb()); constraint_proto->set_upper_bound(constraint->ub()); @@ -667,11 +659,10 @@ void MPSolver::ExportModelToNewProto(new_proto::MPModelProto* output_model) output_model->set_objective_offset(Objective().offset()); } -bool MPSolver::LoadSolutionFromNewProto( - const new_proto::MPSolutionResponse& response) { +bool MPSolver::LoadSolutionFromProto(const MPSolutionResponse& response) { interface_->result_status_ = static_cast(response.status()); - if (response.status() != new_proto::MPSolutionResponse::OPTIMAL && - response.status() != new_proto::MPSolutionResponse::FEASIBLE) { + if (response.status() != MPSolutionResponse::OPTIMAL && + response.status() != MPSolutionResponse::FEASIBLE) { LOG(ERROR) << "Cannot load a solution unless its status is OPTIMAL or FEASIBLE."; return false; @@ -1102,7 +1093,7 @@ bool MPSolver::OwnsVariable(const MPVariable* var) const { bool MPSolver::ExportModelAsLpFormat(bool obfuscate, std::string* output) { MPModelProto proto; - ExportModelToNewProto(&proto); + ExportModelToProto(&proto); MPModelProtoExporter exporter(proto); return exporter.ExportModelAsLpFormat(obfuscate, output); } @@ -1110,7 +1101,7 @@ bool MPSolver::ExportModelAsLpFormat(bool obfuscate, std::string* output) { bool MPSolver::ExportModelAsMpsFormat(bool fixed_format, bool obfuscate, std::string* output) { MPModelProto proto; - ExportModelToNewProto(&proto); + ExportModelToProto(&proto); MPModelProtoExporter exporter(proto); return exporter.ExportModelAsMpsFormat(fixed_format, obfuscate, output); } diff --git a/src/linear_solver/linear_solver.h b/src/linear_solver/linear_solver.h index 0bce27d9d9..7be328ad89 100644 --- a/src/linear_solver/linear_solver.h +++ b/src/linear_solver/linear_solver.h @@ -153,13 +153,10 @@ class MPSolverInterface; class MPSolverParameters; class MPVariable; -// The new MP protocol buffer format. New clients that want to work with -// protocol buffers should use this. -namespace new_proto { +// Forward declarations needed by SWIG. See java/linear_solver.swig for details. class MPModelProto; class MPModelRequest; class MPSolutionResponse; -} // namespace new_proto // This mathematical programming (MP) solver class is the main class // though which users build and solve problems. @@ -303,7 +300,7 @@ class MPSolver { // The status of solving the problem. The straightforward translation to // homonymous enum values of MPSolutionResponse::Status - // (see ./linear_solver2.proto) is guaranteed by ./enum_consistency_test.cc, + // (see ./linear_solver.proto) is guaranteed by ./enum_consistency_test.cc, // you may rely on it. // TODO(user): Figure out once and for all what the status of // underlying solvers exactly mean, especially for feasible and @@ -363,12 +360,12 @@ class MPSolver { }; // Loads model from protocol buffer. - LoadStatus LoadModelFromProto(const new_proto::MPModelProto& input_model); + LoadStatus LoadModelFromProto(const MPModelProto& input_model); // Encodes the current solution in a solution response protocol buffer. // Only nonzero variable values are stored in order to reduce the // size of the MPSolutionResponse protocol buffer. - void FillSolutionResponseProto(new_proto::MPSolutionResponse* response) const; + void FillSolutionResponseProto(MPSolutionResponse* response) const; // Solves the model encoded by a MPModelRequest protocol buffer and // fills the solution encoded as a MPSolutionResponse. @@ -376,12 +373,13 @@ class MPSolver { // end. If you want to keep the MPSolver alive (for debugging, or for // incremental solving), you should write another version of this function // that creates the MPSolver object on the heap and returns it. - static void SolveWithProto(const new_proto::MPModelRequest& model_request, - new_proto::MPSolutionResponse* response); + // + // TODO(user): populate an error message in the response. + static void SolveWithProto(const MPModelRequest& model_request, + MPSolutionResponse* response); // Exports model to protocol buffer. - // TODO(user): rename to ExportModelToProto when possible. - void ExportModelToNewProto(new_proto::MPModelProto* output_model) const; + void ExportModelToProto(MPModelProto* output_model) const; // Load a solution encoded in a protocol buffer onto this solver for easy // access via the MPSolver interface. @@ -390,13 +388,13 @@ class MPSolver { // following this example: // MPSolver my_solver; // ... add variables and constraints ... - // new_proto::MPModelProto model_proto; - // my_solver.ExportModelToNewProto(&model_proto); - // new_proto::MPSolutionResponse solver_response; + // MPModelProto model_proto; + // my_solver.ExportModelToProto(&model_proto); + // MPSolutionResponse solver_response; // // This can be replaced by a stubby call to the linear solver server. // MPSolver::SolveWithProto(model_proto, &solver_response); // if (solver_response.result_status() == MPSolutionResponse::OPTIMAL) { - // CHECK(my_solver.LoadSolutionFromNewProto(solver_response)); + // CHECK(my_solver.LoadSolutionFromProto(solver_response)); // ... inspect the solution using the usual API: solution_value(), etc... // } // @@ -412,13 +410,12 @@ class MPSolver { // - loading a solution with a status other than OPTIMAL / FEASIBLE. // Note: the variable and objective values aren't checked. You can use // VerifySolution() for that. - // TODO(user): rename to LoadSolutionFromProto when possible. - bool LoadSolutionFromNewProto(const new_proto::MPSolutionResponse& response); + bool LoadSolutionFromProto(const MPSolutionResponse& response); // ----- Export model to files or strings ----- // Shortcuts to the homonymous MPModelProtoExporter methods, via - // exporting to a MPModelProto with ExportModelToNewProto() (see above). + // exporting to a MPModelProto with ExportModelToProto() (see above). bool ExportModelAsLpFormat(bool obfuscated, std::string* model_str); bool ExportModelAsMpsFormat(bool fixed_format, bool obfuscated, std::string* model_str); diff --git a/src/linear_solver/linear_solver2.proto b/src/linear_solver/linear_solver.proto similarity index 99% rename from src/linear_solver/linear_solver2.proto rename to src/linear_solver/linear_solver.proto index 1b58fdbb18..601073cd79 100644 --- a/src/linear_solver/linear_solver2.proto +++ b/src/linear_solver/linear_solver.proto @@ -32,7 +32,7 @@ syntax = "proto2"; option java_package = "com.google.ortools.linearsolver"; option java_multiple_files = true; -package operations_research.new_proto; +package operations_research; // A variable is always constrained in the form: // lower_bound <= x <= upper_bound diff --git a/src/linear_solver/model_exporter.cc b/src/linear_solver/model_exporter.cc index d1ac97f7f8..8df595948d 100644 --- a/src/linear_solver/model_exporter.cc +++ b/src/linear_solver/model_exporter.cc @@ -23,7 +23,7 @@ #include "base/join.h" #include "base/strutil.h" #include "base/map_util.h" -#include "linear_solver/linear_solver2.pb.h" +#include "linear_solver/linear_solver.pb.h" #include "util/fp_utils.h" DEFINE_bool(lp_shows_unused_variables, false, @@ -39,10 +39,6 @@ DEFINE_bool(lp_log_invalid_name, false, namespace operations_research { -using new_proto::MPConstraintProto; -using new_proto::MPModelProto; -using new_proto::MPVariableProto; - MPModelProtoExporter::MPModelProtoExporter(const MPModelProto& proto) : proto_(proto), var_id_to_index_map_(), @@ -91,7 +87,7 @@ bool MPModelProtoExporter::CheckNameValidity(const std::string& name) { } std::string MPModelProtoExporter::GetVariableName(int var_index) const { - const new_proto::MPVariableProto& var_proto = proto_.variable(var_index); + const MPVariableProto& var_proto = proto_.variable(var_index); if (use_obfuscated_names_ || !var_proto.has_name()) { return StringPrintf("V%0*d", num_digits_for_variables_, var_index); } else { @@ -173,7 +169,7 @@ void LineBreaker::Append(const std::string& s) { } // namespace bool MPModelProtoExporter::WriteLpTerm(int var_index, double coefficient, - std::string* output) const { + std::string* output) const { output->clear(); if (var_index < 0 || var_index >= proto_.variable_size()) { LOG(DFATAL) << "Reference to out-of-bounds variable index # " << var_index; diff --git a/src/linear_solver/model_exporter.h b/src/linear_solver/model_exporter.h index 63203c6a3f..34a64b250a 100644 --- a/src/linear_solver/model_exporter.h +++ b/src/linear_solver/model_exporter.h @@ -25,22 +25,22 @@ class MPConstraint; class MPObjective; class MPVariable; -namespace new_proto { class MPModelProto; -} // namespace new_proto class MPModelProtoExporter { public: // The argument must live as long as this class is active. - explicit MPModelProtoExporter(const new_proto::MPModelProto& proto); + explicit MPModelProtoExporter(const MPModelProto& proto); // Outputs the current model (variables, constraints, objective) as a std::string // encoded in the so-called "CPLEX LP file format" as generated by SCIP. // The LP file format is easily readable by a human. + // // Returns false if some error has occurred during execution. // If obfuscated is true, the variable and constraint names of proto_ // are not used. Variable and constraint names of the form "V12345" // and "C12345" are used instead. + // // For more information about the different LP file formats: // http://lpsolve.sourceforge.net/5.5/lp-format.htm // The following give a reasonable idea of the CPLEX LP file format: @@ -52,7 +52,9 @@ class MPModelProtoExporter { // Outputs the current model (variables, constraints, objective) as a std::string // encoded in MPS file format, using the "fixed" MPS format if possible, // and the "free" MPS format otherwise. + // // Returns false if some error has occurred during execution. + // // If fixed_format is true, the method tries to use the MPS fixed format (the // use of which is discouraged as coefficients are printed with less // precision). If it is not possible to use the fixed format, the method falls @@ -165,7 +167,7 @@ class MPModelProtoExporter { void AppendMpsBound(const std::string& bound_type, const std::string& name, double value, std::string* output) const; - const new_proto::MPModelProto& proto_; + const MPModelProto& proto_; // Maps a variable id to its index in the protobuf. hash_map var_id_to_index_map_; diff --git a/src/linear_solver/python/linear_solver.swig b/src/linear_solver/python/linear_solver.swig index 8b17dfaccc..84030c2f4a 100644 --- a/src/linear_solver/python/linear_solver.swig +++ b/src/linear_solver/python/linear_solver.swig @@ -27,11 +27,11 @@ // // TODO(user): test all the APIs that are currently marked as 'untested'. -%include base/base.swig +%include "base/base.swig" %{ -#include "linear_solver/linear_solver2.pb.h" +#include "linear_solver/linear_solver.pb.h" #include "linear_solver/linear_solver.h" %} @@ -48,10 +48,10 @@ from ortools.linear_solver.linear_solver_natural_api import LinearConstraint %extend MPVariable { std::string __str__() { - return self->name(); + return $self->name(); } std::string __repr__() { - return self->name(); + return $self->name(); } // Note(user): the 74 lines below are a pure duplication of code from diff --git a/src/sat/lp_utils.cc b/src/sat/lp_utils.cc index fcc0c98b93..41ab65d82a 100644 --- a/src/sat/lp_utils.cc +++ b/src/sat/lp_utils.cc @@ -26,12 +26,12 @@ using glop::Fractional; using glop::RowIndex; using glop::kInfinity; -using operations_research::new_proto::MPConstraintProto; -using operations_research::new_proto::MPModelProto; -using operations_research::new_proto::MPVariableProto; +using operations_research::MPConstraintProto; +using operations_research::MPModelProto; +using operations_research::MPVariableProto; -bool ConvertBinaryMPModelProtoToBooleanProblem( - const new_proto::MPModelProto& mp_model, LinearBooleanProblem* problem) { +bool ConvertBinaryMPModelProtoToBooleanProblem(const MPModelProto& mp_model, + LinearBooleanProblem* problem) { CHECK(problem != nullptr); problem->Clear(); problem->set_name(mp_model.name()); diff --git a/src/sat/lp_utils.h b/src/sat/lp_utils.h index 297039b6d7..fab702b575 100644 --- a/src/sat/lp_utils.h +++ b/src/sat/lp_utils.h @@ -17,7 +17,7 @@ #define OR_TOOLS_SAT_LP_UTILS_H_ #include "sat/boolean_problem.pb.h" -#include "linear_solver/linear_solver2.pb.h" +#include "linear_solver/linear_solver.pb.h" #include "lp_data/lp_data.h" #include "sat/sat_solver.h" @@ -28,8 +28,8 @@ namespace sat { // optimization problem. Returns false if the problem didn't contains only // binary integer variable, or if the coefficients couldn't be converted to // integer with a good enough precision. -bool ConvertBinaryMPModelProtoToBooleanProblem( - const new_proto::MPModelProto& mp_model, LinearBooleanProblem* problem); +bool ConvertBinaryMPModelProtoToBooleanProblem(const MPModelProto& mp_model, + LinearBooleanProblem* problem); // Converts a Boolean optimization problem to its lp formulation. void ConvertBooleanProblemToLinearProgram(const LinearBooleanProblem& problem,