Skip to content

Commit

Permalink
clang
Browse files Browse the repository at this point in the history
  • Loading branch information
pet-mit committed Apr 19, 2024
1 parent 77074a8 commit 39d9f3b
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 32 deletions.
70 changes: 40 additions & 30 deletions src/solver/optim/api/include/antares/optim/api/MipSolution.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,44 +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_;
double objectiveValue_;
public:
MipSolution(operations_research::MPSolver::ResultStatus responseStatus, const std::map<std::string, double>& solution, double objectiveValue) :
responseStatus_(responseStatus), objectiveValue_(objectiveValue)
// 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_; }
};
}
double getObjectiveValue()
{
return objectiveValue_;
}
};
} // namespace Antares::optim::api
2 changes: 1 addition & 1 deletion src/solver/optim/impl/LinearProblemImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ void LinearProblemImpl::setMinimization(bool isMinim)

MipSolution LinearProblemImpl::solve(const operations_research::MPSolverParameters& param)
{
//mpSolver->EnableOutput();
// mpSolver->EnableOutput();
// std::string model;
// std::ofstream m("/tmp/model.lp");
// if (m && mpSolver->ExportModelAsLpFormat(false, &model))
Expand Down

0 comments on commit 39d9f3b

Please sign in to comment.