idol
A C++ Framework for Optimization
Loading...
Searching...
No Matches
Osi.h
1//
2// Created by henri on 05.02.24.
3//
4
5#ifndef IDOL_OSI_H
6#define IDOL_OSI_H
7
8#include <memory>
9
10#ifdef IDOL_USE_OSI
11#include <OsiSolverInterface.hpp>
12
13#if IDOL_USE_OSI_CPLEX
14#include <OsiCpxSolverInterface.hpp>
15#endif
16
17#if IDOL_USE_GUROBI
18//#include <OsiGrbSolverInterface.hpp>
19#endif
20
21#ifdef IDOL_USE_OSI_SYMPHONY
22#include <OsiSymSolverInterface.hpp>
23#endif
24
25#ifdef IDOL_USE_OSI_CLP
26#include <OsiClpSolverInterface.hpp>
27#endif
28
29#else
30struct OsiSolverInterface {
31 virtual ~OsiSolverInterface() = default;
32 virtual OsiSolverInterface* clone() const = 0;
33};
34#endif
35
36#define ADD_SHORTCUT(name, osi_interface) \
37namespace idol { class name; } \
38class idol::name : public idol::Osi { \
39public: \
40 name() : Osi(osi_interface()) {} \
41 static Osi ContinuousRelaxation() { return Osi::ContinuousRelaxation(osi_interface()); } \
42 using OsiT = osi_interface; \
43};
44
45#define ADD_FAKE_SHORTCUT(name) \
46namespace idol { class name; } \
47class idol::name : public idol::Osi { \
48 name() : Osi(#name) {} \
49 static Osi ContinuousRelaxation() { return name(); } \
50};
51
52#include "idol/general/optimizers/OptimizerFactory.h"
53
54namespace idol {
55 class Osi;
56}
57
59 std::unique_ptr<OsiSolverInterface> m_solver_interface;
60 bool m_continuous_relaxation = false;
61
62 Osi(const OsiSolverInterface& t_solver_interface, bool t_continuous_relaxation);
63protected:
64 Osi(const std::string& t_solver);
65public:
66 Osi(const OsiSolverInterface& t_solver_interface);
67
68 Osi(const Osi& t_src);
69 Osi(Osi&&) noexcept = default;
70
71 Osi& operator=(const Osi&) = delete;
72 Osi& operator=(Osi&&) noexcept = delete;
73
74 Optimizer *operator()(const Model &t_model) const override;
75
76 OsiSolverInterface* create_osi_solver_interface() const;
77
78 static Osi ContinuousRelaxation(const OsiSolverInterface& t_solver_interface);
79
80 [[nodiscard]] Osi *clone() const override;
81
82};
83
84#ifdef IDOL_USE_OSI_CPLEX
85ADD_SHORTCUT(OsiCplex, OsiCpxSolverInterface)
86#else
87ADD_FAKE_SHORTCUT(OsiCplex)
88#endif
89
90#ifdef IDOL_USE_OSI_SYMPHONY
91ADD_SHORTCUT(OsiSymphony, OsiSymSolverInterface)
92#else
93ADD_FAKE_SHORTCUT(OsiSymphony)
94#endif
95
96#ifdef IDOL_USE_OSI_CLP
97ADD_SHORTCUT(OsiClp, OsiClpSolverInterface)
98#else
99ADD_FAKE_SHORTCUT(OsiClp)
100#endif
101
102#endif //IDOL_OSI_H
Optimizer * operator()(const Model &t_model) const override
Osi * clone() const override