Skip to content

Commit

Permalink
c++: Add USE_LP_PARSER define (#3201)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mizux committed Mar 24, 2022
1 parent 23a295f commit c505f3d
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 7 deletions.
3 changes: 3 additions & 0 deletions cmake/cpp.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ list(APPEND OR_TOOLS_COMPILE_DEFINITIONS
"USE_BOP" # enable BOP support
"USE_GLOP" # enable GLOP support
)
if(BUILD_LP_PARSER)
list(APPEND OR_TOOLS_COMPILE_DEFINITIONS "USE_LP_PARSER")
endif()
if(USE_COINOR)
list(APPEND OR_TOOLS_COMPILE_DEFINITIONS
"USE_CBC" # enable COIN-OR CBC support
Expand Down
1 change: 1 addition & 0 deletions ortools/lp_data/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ cc_library(
"@com_google_absl//absl/strings",
"@com_google_re2//:re2",
],
defines = ["USE_LP_PARSER"],
)

#cc_library(
Expand Down
5 changes: 0 additions & 5 deletions ortools/lp_data/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
file(GLOB _SRCS "*.h" "*.cc")
if(NOT BUILD_LP_PARSER)
list(FILTER _SRCS EXCLUDE REGEX ".*/lp_parser.h")
list(FILTER _SRCS EXCLUDE REGEX ".*/lp_parser.cc")
endif()

set(NAME ${PROJECT_NAME}_lp_data)

# Will be merge in libortools.so
Expand Down
2 changes: 2 additions & 0 deletions ortools/lp_data/lp_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#if defined(USE_LP_PARSER)

#include "ortools/lp_data/lp_parser.h"

Expand Down Expand Up @@ -461,3 +462,4 @@ absl::StatusOr<MPModelProto> ModelProtoFromLpFormat(absl::string_view model) {
}

} // namespace operations_research
#endif // #if defined(USE_LP_PARSER)
4 changes: 4 additions & 0 deletions ortools/lp_data/lp_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@
#ifndef OR_TOOLS_LP_DATA_LP_PARSER_H_
#define OR_TOOLS_LP_DATA_LP_PARSER_H_

#if defined(USE_LP_PARSER)

#include <string>
#include <vector>

Expand Down Expand Up @@ -121,4 +123,6 @@ absl::StatusOr<ParsedConstraint> ParseConstraint(absl::string_view constraint);
} // namespace glop
} // namespace operations_research

#endif // #if defined(USE_LP_PARSER)

#endif // OR_TOOLS_LP_DATA_LP_PARSER_H_
2 changes: 2 additions & 0 deletions ortools/model_builder/python/pywrap_model_builder_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,12 @@ PYBIND11_MODULE(pywrap_model_builder_helper, m) {
arg("mps_string"))
.def("ImportFromMpsFile", &ModelBuilderHelper::ImportFromMpsFile,
arg("mps_file"))
#if defined(USE_LP_PARSER)
.def("ImportFromLpString", &ModelBuilderHelper::ImportFromLpString,
arg("lp_string"))
.def("ImportFromLpFile", &ModelBuilderHelper::ImportFromLpFile,
arg("lp_file"))
#endif // #if defined(USE_LP_PARSER)
.def(
"FillModelFromSparseData",
[](ModelBuilderHelper* helper,
Expand Down
4 changes: 4 additions & 0 deletions ortools/model_builder/wrappers/model_builder_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@

#include "ortools/linear_solver/linear_solver.h"
#include "ortools/linear_solver/linear_solver.pb.h"
#if defined(USE_LP_PARSER)
#include "ortools/lp_data/lp_parser.h"
#endif // #if defined(USE_LP_PARSER)
#include "ortools/lp_data/mps_reader.h"

namespace operations_research {
Expand Down Expand Up @@ -72,6 +74,7 @@ bool ModelBuilderHelper::ImportFromMpsFile(const std::string& mps_file) {
return true;
}

#if defined(USE_LP_PARSER)
bool ModelBuilderHelper::ImportFromLpString(const std::string& lp_string) {
absl::StatusOr<MPModelProto> model_or = ModelProtoFromLpFormat(lp_string);
if (!model_or.ok()) return false;
Expand All @@ -85,6 +88,7 @@ bool ModelBuilderHelper::ImportFromLpFile(const std::string& lp_file) {
*request_.mutable_model() = model_or.value();
return true;
}
#endif // #if defined(USE_LP_PARSER)

const MPModelRequest& ModelBuilderHelper::request() const { return request_; }
MPModelProto* ModelBuilderHelper::mutable_model() {
Expand Down
2 changes: 2 additions & 0 deletions ortools/model_builder/wrappers/model_builder_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ class ModelBuilderHelper {

bool ImportFromMpsString(const std::string& mps_string);
bool ImportFromMpsFile(const std::string& mps_file);
#if defined(USE_LP_PARSER)
bool ImportFromLpString(const std::string& lp_string);
bool ImportFromLpFile(const std::string& lp_file);
#endif // #if defined(USE_LP_PARSER)

const operations_research::MPModelRequest& request() const;
MPModelProto* mutable_model();
Expand Down
4 changes: 2 additions & 2 deletions tools/Makefile.cc.java.dotnet
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ ifeq ($(SYSTEM),unix)
DEBUG = -O4 -DNDEBUG
CXXFLAGS = -fPIC -std=c++17 $(DEBUG) \
-I$(INC_DIR) -I. $(ARCH) -Wno-deprecated \
-DUSE_BOP -DUSE_GLOP -DUSE_PDLP \
-DUSE_BOP -DUSE_GLOP -DUSE_PDLP -DUSE_LP_PARSER \
-DUSE_CBC -DUSE_CLP \
-DUSE_SCIP
LIB_PREFIX = lib
Expand Down Expand Up @@ -132,7 +132,7 @@ ifeq ($(SYSTEM),win)
/DPSAPI_VERSION=1 /D__WIN32__ /DNOMINMAX /DWIN32_LEAN_AND_MEAN=1 /D_CRT_SECURE_NO_WARNINGS \
/DGOOGLE_GLOG_DLL_DECL= \
/I$(INC_DIR)\\src\\windows /I$(INC_DIR) /I. \
/DUSE_BOP /DUSE_GLOP /DUSE_PDLP \
/DUSE_BOP /DUSE_GLOP /DUSE_PDLP /DUSE_LP_PARSER \
/DUSE_CBC /DUSE_CLP \
/DUSE_SCIP
LDFLAGS = psapi.lib ws2_32.lib
Expand Down

0 comments on commit c505f3d

Please sign in to comment.