Repository navigation
Expand file tree
/
Copy pathlinear_solver_test.cc
More file actions
81 lines (72 loc) · 3.36 KB
/
Copy pathlinear_solver_test.cc
File metadata and controls
81 lines (72 loc) · 3.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Copyright 2010-2025 Google LLC
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// 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.
#include "ortools/linear_solver/linear_solver.h"
#include "absl/status/status.h"
#include "absl/time/clock.h"
#include "absl/time/time.h"
#include "gtest/gtest.h"
#include "ortools/linear_solver/linear_solver.pb.h"
#include "ortools/linear_solver/solve_mp_model.h"
namespace operations_research {
namespace {
TEST(LinearSolverTest, MPSolverResponseStatusToResultStatusMapping) {
EXPECT_EQ(MPSolverResponseStatusToResultStatus(MPSOLVER_OPTIMAL),
MPSolver::OPTIMAL);
EXPECT_EQ(MPSolverResponseStatusToResultStatus(MPSOLVER_FEASIBLE),
MPSolver::FEASIBLE);
EXPECT_EQ(MPSolverResponseStatusToResultStatus(MPSOLVER_INFEASIBLE),
MPSolver::INFEASIBLE);
EXPECT_EQ(MPSolverResponseStatusToResultStatus(MPSOLVER_UNBOUNDED),
MPSolver::UNBOUNDED);
EXPECT_EQ(MPSolverResponseStatusToResultStatus(MPSOLVER_ABNORMAL),
MPSolver::ABNORMAL);
EXPECT_EQ(MPSolverResponseStatusToResultStatus(MPSOLVER_MODEL_INVALID),
MPSolver::MODEL_INVALID);
EXPECT_EQ(MPSolverResponseStatusToResultStatus(
MPSOLVER_MODEL_INVALID_SOLUTION_HINT),
MPSolver::MODEL_INVALID);
EXPECT_EQ(MPSolverResponseStatusToResultStatus(
MPSOLVER_MODEL_INVALID_SOLVER_PARAMETERS),
MPSolver::MODEL_INVALID);
EXPECT_EQ(
MPSolverResponseStatusToResultStatus(MPSOLVER_SOLVER_TYPE_UNAVAILABLE),
MPSolver::MODEL_INVALID);
EXPECT_EQ(MPSolverResponseStatusToResultStatus(MPSOLVER_INCOMPATIBLE_OPTIONS),
MPSolver::MODEL_INVALID);
EXPECT_EQ(MPSolverResponseStatusToResultStatus(MPSOLVER_NOT_SOLVED),
MPSolver::NOT_SOLVED);
EXPECT_EQ(MPSolverResponseStatusToResultStatus(MPSOLVER_MODEL_IS_VALID),
MPSolver::NOT_SOLVED);
// Verifies that unknown or unmapped response statuses (such as
// MPSOLVER_UNKNOWN_STATUS = 99 or MPSOLVER_CANCELLED_BY_USER = 98) safely map
// to ABNORMAL rather than leaking raw integer values into client wrappers.
EXPECT_EQ(MPSolverResponseStatusToResultStatus(MPSOLVER_CANCELLED_BY_USER),
MPSolver::ABNORMAL);
EXPECT_EQ(MPSolverResponseStatusToResultStatus(MPSOLVER_UNKNOWN_STATUS),
MPSolver::ABNORMAL);
EXPECT_EQ(MPSolverResponseStatusToResultStatus(
static_cast<MPSolverResponseStatus>(999)),
MPSolver::ABNORMAL);
}
TEST(LinearSolverTest, LoadSolutionFromProtoWithUnknownStatus) {
MPSolver solver("test", MPSolver::GLOP_LINEAR_PROGRAMMING);
MPSolutionResponse response;
response.set_status(MPSOLVER_UNKNOWN_STATUS);
const absl::Status status = solver.LoadSolutionFromProto(response);
EXPECT_FALSE(status.ok());
MPSolutionResponse out_response;
solver.FillSolutionResponseProto(&out_response);
EXPECT_EQ(out_response.status(), MPSOLVER_ABNORMAL);
}
} // namespace
} // namespace operations_research