-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
3rd try at scenario building #2033
base: poc_linearProblem
Are you sure you want to change the base?
Changes from all commits
7c9636a
344cb17
1486321
8e1fbb3
9d89b66
28daaf3
7d23680
77074a8
08bc95c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,40 +32,54 @@ | |
|
||
namespace Antares::optim::api | ||
{ | ||
class MipSolution final | ||
class MipSolution final | ||
{ | ||
// TODO: improve this by removing dependency to OR-Tools | ||
private: | ||
operations_research::MPSolver::ResultStatus responseStatus_; | ||
std::map<std::string, double> solution_; | ||
double objectiveValue_; | ||
|
||
public: | ||
MipSolution(operations_research::MPSolver::ResultStatus responseStatus, | ||
const std::map<std::string, double>& solution, | ||
double objectiveValue) : | ||
responseStatus_(responseStatus), objectiveValue_(objectiveValue) | ||
{ | ||
// TODO: improve this by removing dependency to OR-Tools | ||
private: | ||
operations_research::MPSolver::ResultStatus responseStatus_; | ||
std::map<std::string, double> solution_; | ||
public: | ||
MipSolution(operations_research::MPSolver::ResultStatus responseStatus, const std::map<std::string, double>& solution) : responseStatus_(responseStatus) | ||
// Only store non-zero values | ||
for (const auto& varAndValue : solution) | ||
{ | ||
// Only store non-zero values | ||
for (const auto& varAndValue : solution) | ||
if (abs(varAndValue.second) > 1e-6) // TODO: is this tolerance OK? | ||
{ | ||
if (abs(varAndValue.second) > 1e-6) // TODO: is this tolerance OK? | ||
{ | ||
solution_.insert(varAndValue); | ||
} | ||
solution_.insert(varAndValue); | ||
} | ||
} | ||
} | ||
|
||
operations_research::MPSolver::ResultStatus getStatus() { return responseStatus_; } | ||
operations_research::MPSolver::ResultStatus getStatus() | ||
{ | ||
return responseStatus_; | ||
} | ||
|
||
double getOptimalValue(const std::string& variableName) | ||
{ | ||
return solution_.contains(variableName) ? solution_.at(variableName) : 0; | ||
} | ||
double getOptimalValue(const std::string& variableName) | ||
{ | ||
return solution_.contains(variableName) ? solution_.at(variableName) : 0; | ||
} | ||
|
||
std::vector<double> getOptimalValues(const std::vector<std::string>& variableNames) | ||
std::vector<double> getOptimalValues(const std::vector<std::string>& variableNames) | ||
{ | ||
std::vector<double> solution; | ||
solution.reserve(variableNames.size()); | ||
for (const auto& varName : variableNames) | ||
{ | ||
std::vector<double> solution; | ||
solution.reserve(variableNames.size()); | ||
for (const auto& varName : variableNames) { | ||
solution.push_back(getOptimalValue(varName)); | ||
} | ||
return solution; | ||
solution.push_back(getOptimalValue(varName)); | ||
} | ||
}; | ||
} | ||
return solution; | ||
} | ||
|
||
double getObjectiveValue() | ||
{ | ||
return objectiveValue_; | ||
} | ||
Comment on lines
+80
to
+83
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. MipSolution is constructed after Solve |
||
}; | ||
} // namespace Antares::optim::api |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.