delpi  0.0.1
DElta-complete LP solver
Loading...
Searching...
No Matches
qsopt_ex.h
1
11#pragma once
12
13#ifndef DELPI_ENABLED_QSOPTEX
14#error QSopt_ex is not enabled. Please enable it by adding "--//tools:enable_qsoptex" to the bazel command.
15#endif
16
17#include <gmpxx.h>
18
19extern "C" {
20#include <qsopt_ex/QSopt_ex.h> // IWYU pragma: export
21}
22
23// These #defines from <qsopt_ex/QSopt_ex.h> cause problems for us
24// because they mess with SoPlex's enums.
25#undef OPTIMAL
26#undef DUAL_INFEASIBLE
27
28#include <iosfwd>
29#include <string>
30
32namespace delpi::qsopt_ex {
33
40mpq_class *StringToMpqPtr(const std::string &str);
46mpq_class StringToMpq(const std::string &str);
53mpq_class *CStringToMpqPtr(const char str[]);
59mpq_class CStringToMpq(const char str[]);
60
66class MpqArray {
67 public:
72 explicit MpqArray(size_t n_elements = 0);
73 MpqArray(const MpqArray &) = delete;
74 MpqArray(MpqArray &&) = delete;
75 MpqArray &operator=(const MpqArray &) = delete;
76 MpqArray &operator=(MpqArray &&) = delete;
78 ~MpqArray();
79
84 operator const mpq_t * const *() const { return &array_; }
89 operator mpq_t **() { return &(array_); }
90
95 operator const mpq_t *() const { return array_; }
96
101 operator mpq_t *() { return array_; }
102
103 mpq_t &operator[](const int idx) { return array_[idx]; }
104 const mpq_t &operator[](const int idx) const { return array_[idx]; }
105 mpq_t &operator[](const std::size_t idx) { return array_[idx]; }
106 const mpq_t &operator[](const std::size_t idx) const { return array_[idx]; }
107
109 [[nodiscard]] size_t size() const { return array_ ? reinterpret_cast<size_t *>(array_)[-1] : 0; }
110
117 void Resize(size_t nElements);
118
119 private:
120 mpq_t *array_;
121
129 void AllocateMpqArray(size_t n_elements);
130
132 void FreeMpqArray();
133};
134
135std::ostream &operator<<(std::ostream &os, const MpqArray &array);
136
137void QSXStart();
138void QSXFinish();
139
140} // namespace delpi::qsopt_ex
141
142#ifdef DELPI_INCLUDE_FMT
143
144#include "delpi/util/logging.h"
145
146OSTREAM_FORMATTER(delpi::qsopt_ex::MpqArray);
147
148#endif
A wrapper around an array of mpq_t elements.
Definition qsopt_ex.h:66
void Resize(size_t nElements)
Resize the array to have nElements elements.
Definition qsopt_ex.cpp:64
mpq_t * array_
array of mpq_t. It is allocated by AllocateMpqArray() and freed by FreeMpqArray().
Definition qsopt_ex.h:120
~MpqArray()
Destroy the MpqArray object, freeing the array.
Definition qsopt_ex.cpp:62
void FreeMpqArray()
Free the array of mpq_t.
Definition qsopt_ex.cpp:50
void AllocateMpqArray(size_t n_elements)
Allocate the array with n_elements elements.
Definition qsopt_ex.cpp:34
MpqArray(size_t n_elements=0)
Construct a new MpqArray object, allocating the array with n_elements elements.
Definition qsopt_ex.cpp:60
Namespace containing all the utility functions to interact with the QSopt_ex solver.
Definition qsopt_ex.cpp:13
mpq_class StringToMpq(const std::string &str)
Convert a string to a mpq_class.
Definition qsopt_ex.cpp:16
mpq_class * StringToMpqPtr(const std::string &str)
Convert a string to a mpq_class.
Definition qsopt_ex.cpp:15
mpq_class * CStringToMpqPtr(const char str[])
Convert a C-string to a mpq_class.
Definition qsopt_ex.cpp:17
mpq_class CStringToMpq(const char str[])
Convert a string to a mpq_class.
Definition qsopt_ex.cpp:25