Repository navigation
Expand file tree
/
Copy pathglop_utils.cc
More file actions
143 lines (133 loc) · 5.18 KB
/
Copy pathglop_utils.cc
File metadata and controls
143 lines (133 loc) · 5.18 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
// 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/glop_utils.h"
#include <variant>
#include "absl/functional/overload.h"
#include "absl/log/log.h"
#include "ortools/linear_solver/linear_solver.h"
#include "ortools/lp_data/lp_types.h"
namespace operations_research {
MPSolver::ResultStatus GlopToMPSolverResultStatus(const glop::SolveStatus s) {
return std::visit(
absl::Overload{
[&](const glop::SolveStatus::Optimal&) { return MPSolver::OPTIMAL; },
[&](const glop::SolveStatus::PrimalInfeasible&) {
return MPSolver::INFEASIBLE;
},
[&](const glop::SolveStatus::DualInfeasible&) {
return MPSolver::UNBOUNDED;
},
[&](const glop::SolveStatus::InfeasibleOrUnbounded&) {
// NOTE(user): MPSolver does not have the equivalent of
// INFEASIBLE_OR_UNBOUNDED however UNBOUNDED is almost never
// relevant in applications, so we decided to report this status as
// INFEASIBLE since it should almost always be the
// case. Historically, we where reporting ABNORMAL, but that was
// more confusing than helpful.
//
// TODO(user): We could argue that it is infeasible to find the
// optimal of an unbounded problem. So it might just be simpler to
// completely get rid of the MpSolver::UNBOUNDED status that seems
// to never be used programmatically.
return MPSolver::INFEASIBLE;
},
[&](const glop::SolveStatus::PrimalUnbounded&) {
return MPSolver::UNBOUNDED;
},
[&](const glop::SolveStatus::DualUnbounded&) {
return MPSolver::INFEASIBLE;
},
[&](const glop::SolveStatus::Init&) { return MPSolver::NOT_SOLVED; },
[&](const glop::SolveStatus::PrimalFeasible&) {
return MPSolver::FEASIBLE;
},
[&](const glop::SolveStatus::DualFeasible&) {
return MPSolver::NOT_SOLVED;
},
[&](const glop::SolveStatus::Imprecise&) {
return MPSolver::ABNORMAL;
},
[&](const glop::SolveStatus::Abnormal&) {
return MPSolver::ABNORMAL;
},
[&](const glop::SolveStatus::InvalidProblem&) {
return MPSolver::ABNORMAL;
},
},
s.value);
}
MPSolver::BasisStatus GlopToMPSolverVariableStatus(glop::VariableStatus s) {
switch (s) {
case glop::VariableStatus::FREE:
return MPSolver::FREE;
case glop::VariableStatus::AT_LOWER_BOUND:
return MPSolver::AT_LOWER_BOUND;
case glop::VariableStatus::AT_UPPER_BOUND:
return MPSolver::AT_UPPER_BOUND;
case glop::VariableStatus::FIXED_VALUE:
return MPSolver::FIXED_VALUE;
case glop::VariableStatus::BASIC:
return MPSolver::BASIC;
}
LOG(DFATAL) << "Unknown variable status: " << s;
return MPSolver::FREE;
}
glop::VariableStatus MPSolverToGlopVariableStatus(MPSolver::BasisStatus s) {
switch (s) {
case MPSolver::FREE:
return glop::VariableStatus::FREE;
case MPSolver::AT_LOWER_BOUND:
return glop::VariableStatus::AT_LOWER_BOUND;
case MPSolver::AT_UPPER_BOUND:
return glop::VariableStatus::AT_UPPER_BOUND;
case MPSolver::FIXED_VALUE:
return glop::VariableStatus::FIXED_VALUE;
case MPSolver::BASIC:
return glop::VariableStatus::BASIC;
}
LOG(DFATAL) << "Unknown variable status: " << s;
return glop::VariableStatus::FREE;
}
MPSolver::BasisStatus GlopToMPSolverConstraintStatus(glop::ConstraintStatus s) {
switch (s) {
case glop::ConstraintStatus::FREE:
return MPSolver::FREE;
case glop::ConstraintStatus::AT_LOWER_BOUND:
return MPSolver::AT_LOWER_BOUND;
case glop::ConstraintStatus::AT_UPPER_BOUND:
return MPSolver::AT_UPPER_BOUND;
case glop::ConstraintStatus::FIXED_VALUE:
return MPSolver::FIXED_VALUE;
case glop::ConstraintStatus::BASIC:
return MPSolver::BASIC;
}
LOG(DFATAL) << "Unknown constraint status: " << s;
return MPSolver::FREE;
}
glop::ConstraintStatus MPSolverToGlopConstraintStatus(MPSolver::BasisStatus s) {
switch (s) {
case MPSolver::FREE:
return glop::ConstraintStatus::FREE;
case MPSolver::AT_LOWER_BOUND:
return glop::ConstraintStatus::AT_LOWER_BOUND;
case MPSolver::AT_UPPER_BOUND:
return glop::ConstraintStatus::AT_UPPER_BOUND;
case MPSolver::FIXED_VALUE:
return glop::ConstraintStatus::FIXED_VALUE;
case MPSolver::BASIC:
return glop::ConstraintStatus::BASIC;
}
LOG(DFATAL) << "Unknown constraint status: " << s;
return glop::ConstraintStatus::FREE;
}
} // namespace operations_research