-
Notifications
You must be signed in to change notification settings - Fork 24
/
MIPSolverHighs.h
195 lines (137 loc) · 6.64 KB
/
MIPSolverHighs.h
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/**
The Supporting Hyperplane Optimization Toolkit (SHOT).
@author Andreas Lundell, Åbo Akademi University
@section LICENSE
This software is licensed under the Eclipse Public License 2.0.
Please see the README and LICENSE files for more information.
*/
#pragma once
#include "MIPSolverBase.h"
#include <optional>
#include "Highs.h"
namespace SHOT
{
class MIPSolverHighs : public IMIPSolver, MIPSolverBase
{
public:
MIPSolverHighs(EnvironmentPtr envPtr);
~MIPSolverHighs() override;
bool initializeProblem() override;
void checkParameters() override;
bool addVariable(
std::string name, E_VariableType type, double lowerBound, double upperBound, double semiBound) override;
bool initializeObjective() override;
bool addLinearTermToObjective(double coefficient, int variableIndex) override;
bool addQuadraticTermToObjective(double coefficient, int firstVariableIndex, int secondVariableIndex) override;
bool finalizeObjective(bool isMinimize, double constant = 0.0) override;
bool initializeConstraint() override;
bool addLinearTermToConstraint(double coefficient, int variableIndex) override;
bool addQuadraticTermToConstraint(double coefficient, int firstVariableIndex, int secondVariableIndex) override;
bool finalizeConstraint(std::string name, double valueLHS, double valueRHS, double constant = 0.0) override;
bool finalizeProblem() override;
void initializeSolverSettings() override;
void writeProblemToFile(std::string filename) override;
void writePresolvedToFile(std::string filename) override;
int addLinearConstraint(std::map<int, double>& elements, double constant, std::string name) override
{
return (addLinearConstraint(elements, constant, name, false, true));
}
int addLinearConstraint(
const std::map<int, double>& elements, double constant, std::string name, bool isGreaterThan) override
{
return (addLinearConstraint(elements, constant, name, isGreaterThan, true));
}
int addLinearConstraint(const std::map<int, double>& elements, double constant, std::string name,
bool isGreaterThan, bool allowRepair) override;
bool addSpecialOrderedSet(
E_SOSType type, VectorInteger variableIndexes, VectorDouble variableWeights = {}) override;
bool createHyperplane(Hyperplane hyperplane) override { return (MIPSolverBase::createHyperplane(hyperplane)); }
bool createIntegerCut(IntegerCut& integerCut) override;
bool createInteriorHyperplane(Hyperplane hyperplane) override
{
return (MIPSolverBase::createInteriorHyperplane(hyperplane));
}
std::optional<std::pair<std::map<int, double>, double>> createHyperplaneTerms(Hyperplane hyperplane) override
{
return (MIPSolverBase::createHyperplaneTerms(hyperplane));
}
void fixVariable(int varIndex, double value) override;
void fixVariables(VectorInteger variableIndexes, VectorDouble variableValues) override
{
MIPSolverBase::fixVariables(variableIndexes, variableValues);
}
void unfixVariables() override { MIPSolverBase::unfixVariables(); }
void updateVariableBound(int varIndex, double lowerBound, double upperBound) override;
void updateVariableLowerBound(int varIndex, double lowerBound) override;
void updateVariableUpperBound(int varIndex, double upperBound) override;
PairDouble getCurrentVariableBounds(int varIndex) override;
void presolveAndUpdateBounds() override { return (MIPSolverBase::presolveAndUpdateBounds()); }
std::pair<VectorDouble, VectorDouble> presolveAndGetNewBounds() override;
void activateDiscreteVariables(bool activate) override;
bool getDiscreteVariableStatus() override { return (MIPSolverBase::getDiscreteVariableStatus()); }
E_DualProblemClass getProblemClass() override { return (MIPSolverBase::getProblemClass()); }
void executeRelaxationStrategy() override { MIPSolverBase::executeRelaxationStrategy(); }
E_ProblemSolutionStatus solveProblem() override;
bool repairInfeasibility() override;
E_ProblemSolutionStatus getSolutionStatus() override;
int getNumberOfSolutions() override;
VectorDouble getVariableSolution(int solIdx) override;
std::vector<SolutionPoint> getAllVariableSolutions() override { return (MIPSolverBase::getAllVariableSolutions()); }
double getDualObjectiveValue() override;
double getObjectiveValue(int solIdx) override;
double getObjectiveValue() override { return (MIPSolverBase::getObjectiveValue()); }
int increaseSolutionLimit(int increment) override;
void setSolutionLimit(long limit) override;
int getSolutionLimit() override;
void setTimeLimit(double seconds) override;
void setCutOff(double cutOff) override;
void setCutOffAsConstraint(double cutOff) override;
void addMIPStart(VectorDouble point) override;
void deleteMIPStarts() override;
bool supportsQuadraticObjective() override;
bool supportsQuadraticConstraints() override;
double getUnboundedVariableBoundValue() override;
int getNumberOfExploredNodes() override;
int getNumberOfOpenNodes() override { return (MIPSolverBase::getNumberOfOpenNodes()); }
int getNumberOfVariables() override { return (MIPSolverBase::getNumberOfVariables()); }
bool hasDualAuxiliaryObjectiveVariable() override { return (MIPSolverBase::hasDualAuxiliaryObjectiveVariable()); }
int getDualAuxiliaryObjectiveVariableIndex() override
{
return (MIPSolverBase::getDualAuxiliaryObjectiveVariableIndex());
}
void setDualAuxiliaryObjectiveVariableIndex(int index) override
{
MIPSolverBase::setDualAuxiliaryObjectiveVariableIndex(index);
}
std::string getConstraintIdentifier(E_HyperplaneSource source) override
{
return (MIPSolverBase::getConstraintIdentifier(source));
};
std::string getSolverVersion() override;
std::vector<std::pair<double, VectorDouble>> currentSolutions;
private:
HighsModel highsModel;
Highs highsInstance;
HighsStatus highsReturnStatus;
long int solLimit;
double timeLimit = 1e100;
double cutOff;
int numberOfThreads = 1;
double objectiveConstant = 0.0;
std::vector<std::pair<std::string, double>> MIPStart;
VectorString variableNames;
VectorDouble variableLBs;
VectorDouble variableUBs;
VectorDouble constraintLBs;
VectorDouble constraintUBs;
VectorString constraintNames;
std::map<int, double> currentConstraintTerms;
VectorInteger aMatrixStart;
VectorInteger aMatrixIndex;
VectorDouble aMatrixValue;
ObjSense objectiveSense;
VectorDouble variableCosts;
protected:
std::vector<HighsVarType> variableTypesHighs;
};
} // namespace SHOT