From ef4106b549ba812e52f00cb842b120c194abbcb5 Mon Sep 17 00:00:00 2001 From: Laurent Perron Date: Wed, 8 Dec 2021 11:48:14 +0100 Subject: [PATCH] [CP-SAT] fix int_prod presolve; better checker; better treatment of floating point constraints (from the linear solver) and objective --- ortools/linear_solver/sat_proto_solver.cc | 23 ++++++----------------- ortools/linear_solver/sat_proto_solver.h | 1 + ortools/linear_solver/scip_proto_solver.h | 2 ++ 3 files changed, 9 insertions(+), 17 deletions(-) diff --git a/ortools/linear_solver/sat_proto_solver.cc b/ortools/linear_solver/sat_proto_solver.cc index c575af026d..fbc6fb84c4 100644 --- a/ortools/linear_solver/sat_proto_solver.cc +++ b/ortools/linear_solver/sat_proto_solver.cc @@ -166,24 +166,13 @@ absl::StatusOr SatSolveProto( } return response; } - MPModelProto* const mp_model = request.mutable_model(); - // Abort if there is constraint type we don't currently support. - for (const MPGeneralConstraintProto& general_constraint : - mp_model->general_constraint()) { - switch (general_constraint.general_constraint_case()) { - case MPGeneralConstraintProto::kIndicatorConstraint: - break; - case MPGeneralConstraintProto::kAndConstraint: - break; - case MPGeneralConstraintProto::kOrConstraint: - break; - default: - SOLVER_LOG(&logger, "General constraints of type ", - general_constraint.general_constraint_case(), - " are not supported."); - return ModelInvalidResponse(logger, "Unsupported constraint type"); - } + // We start by some extra validation since our code do not accept any kind + // of input. + MPModelProto* const mp_model = request.mutable_model(); + if (!sat::MPModelProtoValidationBeforeConversion(params, *mp_model, + &logger)) { + return ModelInvalidResponse(logger, "Extra CP-SAT validation failed."); } // This is good to do before any presolve. diff --git a/ortools/linear_solver/sat_proto_solver.h b/ortools/linear_solver/sat_proto_solver.h index 00c77e0089..404f2da4e0 100644 --- a/ortools/linear_solver/sat_proto_solver.h +++ b/ortools/linear_solver/sat_proto_solver.h @@ -15,6 +15,7 @@ #define OR_TOOLS_LINEAR_SOLVER_SAT_PROTO_SOLVER_H_ #include +#include #include "absl/status/statusor.h" #include "ortools/linear_solver/linear_solver.pb.h" diff --git a/ortools/linear_solver/scip_proto_solver.h b/ortools/linear_solver/scip_proto_solver.h index 0b197954fd..86b829236d 100644 --- a/ortools/linear_solver/scip_proto_solver.h +++ b/ortools/linear_solver/scip_proto_solver.h @@ -14,6 +14,8 @@ #ifndef OR_TOOLS_LINEAR_SOLVER_SCIP_PROTO_SOLVER_H_ #define OR_TOOLS_LINEAR_SOLVER_SCIP_PROTO_SOLVER_H_ +#include + #include "absl/status/statusor.h" #include "ortools/linear_solver/linear_solver.pb.h" #include "scip/type_scip.h"