-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
210 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// | ||
// Created by henri on 21.10.24. | ||
// | ||
|
||
#ifndef IDOL_UUID_H | ||
#define IDOL_UUID_H | ||
|
||
#include <string> | ||
#include <random> | ||
#include <sstream> | ||
|
||
namespace idol { | ||
std::string generate_uuid_v4(); | ||
} | ||
|
||
#endif //IDOL_UUID_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 8 additions & 42 deletions
50
lib/include/idol/optimizers/bilevel-optimization/wrappers/MibS/impl_MibS.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,29 @@ | ||
// | ||
// Created by henri on 01.02.24. | ||
// Created by henri on 21.10.24. | ||
// | ||
|
||
#ifdef IDOL_USE_MIBS | ||
|
||
#ifndef IDOL_IMPL_MIBS_H | ||
#define IDOL_IMPL_MIBS_H | ||
|
||
#include "idol/modeling/models/Model.h" | ||
|
||
#include "MibSModel.hpp" | ||
#include "idol/modeling/bilevel-optimization/LowerLevelDescription.h" | ||
|
||
namespace idol::impl { | ||
class MibS; | ||
} | ||
|
||
class idol::impl::MibS { | ||
const idol::Model& m_model; | ||
const idol::Bilevel::LowerLevelDescription& m_description; | ||
const bool m_logs; | ||
|
||
MibSModel m_mibs; | ||
std::unique_ptr<AlpsKnowledgeBroker> m_broker; | ||
std::unique_ptr<OsiSolverInterface> m_osi_solver; | ||
|
||
static char to_mibs_type(VarType t_type); | ||
|
||
void load_auxiliary_data(); | ||
std::pair<std::vector<int>, std::vector<int>> dispatch_variable_indices(); | ||
std::pair<std::vector<int>, std::vector<int>> dispatch_constraint_indices(); | ||
std::vector<double> find_lower_level_objective_coefficients(const std::vector<int>& t_lower_level_variables_indices); | ||
std::pair<std::vector<double>, std::vector<double>> find_lower_level_bounds(const std::vector<int>& t_lower_level_variables_indices); | ||
|
||
void load_problem_data(); | ||
std::tuple<std::vector<double>, std::vector<double>, std::vector<char>> parse_variables(); | ||
std::tuple<std::vector<double>, std::vector<double>, std::vector<char>> parse_constraints(); | ||
CoinPackedMatrix parse_matrix(); | ||
std::vector<double> parse_objective(); | ||
public: | ||
MibS(const idol::Model& t_model, | ||
const idol::Bilevel::LowerLevelDescription& t_description, | ||
OsiSolverInterface* t_osi_solver, | ||
bool t_logs); | ||
virtual ~MibS() = default; | ||
|
||
void solve(); | ||
virtual SolutionStatus get_status() const = 0; | ||
|
||
double get_best_obj() const; | ||
virtual SolutionReason get_reason() const = 0; | ||
|
||
double get_best_bound() const; | ||
virtual double get_best_obj() const = 0; | ||
|
||
double get_var_primal(const Var& t_var) const; | ||
virtual double get_best_bound() const = 0; | ||
|
||
idol::SolutionStatus get_status() const; | ||
|
||
idol::SolutionReason get_reason() const; | ||
virtual double get_var_primal(const Var& t_var) const = 0; | ||
|
||
virtual void solve() = 0; | ||
}; | ||
|
||
#endif | ||
|
||
#endif //IDOL_IMPL_MIBS_H |
64 changes: 64 additions & 0 deletions
64
lib/include/idol/optimizers/bilevel-optimization/wrappers/MibS/impl_MibSFromAPI.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// | ||
// Created by henri on 01.02.24. | ||
// | ||
|
||
#ifdef IDOL_USE_MIBS | ||
|
||
#ifndef IDOL_IMPL_MIBS_FROM_API_H | ||
#define IDOL_IMPL_MIBS_FROM_API_H | ||
|
||
#include "idol/modeling/models/Model.h" | ||
|
||
#include "MibSModel.hpp" | ||
#include "idol/modeling/bilevel-optimization/LowerLevelDescription.h" | ||
#include "impl_MibS.h" | ||
|
||
namespace idol::impl { | ||
class MibSFromAPI; | ||
} | ||
|
||
class idol::impl::MibSFromAPI : public idol::impl::MibS { | ||
const idol::Model& m_model; | ||
const idol::Bilevel::LowerLevelDescription& m_description; | ||
const bool m_logs; | ||
|
||
MibSModel m_mibs; | ||
std::unique_ptr<AlpsKnowledgeBroker> m_broker; | ||
std::unique_ptr<OsiSolverInterface> m_osi_solver; | ||
|
||
static char to_mibs_type(VarType t_type); | ||
|
||
void load_auxiliary_data(); | ||
std::pair<std::vector<int>, std::vector<int>> dispatch_variable_indices(); | ||
std::pair<std::vector<int>, std::vector<int>> dispatch_constraint_indices(); | ||
std::vector<double> find_lower_level_objective_coefficients(const std::vector<int>& t_lower_level_variables_indices); | ||
std::pair<std::vector<double>, std::vector<double>> find_lower_level_bounds(const std::vector<int>& t_lower_level_variables_indices); | ||
|
||
void load_problem_data(); | ||
std::tuple<std::vector<double>, std::vector<double>, std::vector<char>> parse_variables(); | ||
std::tuple<std::vector<double>, std::vector<double>, std::vector<char>> parse_constraints(); | ||
CoinPackedMatrix parse_matrix(); | ||
std::vector<double> parse_objective(); | ||
public: | ||
MibSFromAPI(const idol::Model& t_model, | ||
const idol::Bilevel::LowerLevelDescription& t_description, | ||
OsiSolverInterface* t_osi_solver, | ||
bool t_logs); | ||
|
||
void solve() override; | ||
|
||
double get_best_obj() const override; | ||
|
||
double get_best_bound() const override; | ||
|
||
double get_var_primal(const Var& t_var) const override; | ||
|
||
idol::SolutionStatus get_status() const override; | ||
|
||
idol::SolutionReason get_reason() const override; | ||
|
||
}; | ||
|
||
#endif | ||
|
||
#endif //IDOL_IMPL_MIBS_FROM_API_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// | ||
// Created by henri on 21.10.24. | ||
// | ||
#include "idol/containers/uuid.h" | ||
|
||
std::string idol::generate_uuid_v4() { | ||
std::random_device rd; | ||
std::uniform_int_distribution<int> dist(0, 15); | ||
std::uniform_int_distribution<int> dist2(8, 11); | ||
|
||
std::stringstream ss; | ||
ss << std::hex; | ||
for (int i = 0; i < 8; i++) ss << dist(rd); | ||
ss << "-"; | ||
for (int i = 0; i < 4; i++) ss << dist(rd); | ||
ss << "-4"; // UUID version 4 | ||
for (int i = 0; i < 3; i++) ss << dist(rd); | ||
ss << "-"; | ||
ss << dist2(rd); // UUID variant 1 | ||
for (int i = 0; i < 3; i++) ss << dist(rd); | ||
ss << "-"; | ||
for (int i = 0; i < 12; i++) ss << dist(rd); | ||
return ss.str(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.