Skip to content
This repository was archived by the owner on Aug 6, 2023. It is now read-only.

Commit 05cbeac

Browse files
committed
use assess_optim(), assess_feas() instead of operator()()
1 parent 293d9a4 commit 05cbeac

File tree

10 files changed

+103
-39
lines changed

10 files changed

+103
-39
lines changed

bench/BM_lmi.cpp

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#include <ellalgo/cutting_plane.hpp> // for cutting_plane_optim
22
#include <ellalgo/ell.hpp> // for Ell
33
#include <gsl/span> // for span
4-
#include <lmisolver/lmi_old_oracle.hpp> // for lmi_old_oracle
5-
#include <lmisolver/lmi_oracle.hpp> // for lmi_oracle
4+
#include <lmisolver/lmi_old_oracle.hpp> // for LmiOldOracle
5+
#include <lmisolver/lmi_oracle.hpp> // for LmiOracle
66
#include <tuple> // for tuple
77
#include <type_traits> // for move
88
#include <vector> // for vector
@@ -48,7 +48,7 @@ template <typename Oracle> class my_oracle {
4848
* @param[in,out] t
4949
* @return std::tuple<Cut, double>
5050
*/
51-
std::tuple<Cut, bool> operator()(const Arr &x, double &t) {
51+
std::tuple<Cut, bool> assess_optim(const Arr &x, double &t) {
5252
const auto f0 = xt::sum(this->c * x)();
5353
const auto f1 = f0 - t;
5454
if (f1 > 0) {
@@ -65,6 +65,17 @@ template <typename Oracle> class my_oracle {
6565
t = f0;
6666
return {{this->c, 0.0}, true};
6767
}
68+
69+
/**
70+
* @brief
71+
*
72+
* @param[in] x
73+
* @param[in,out] t
74+
* @return std::tuple<Cut, double>
75+
*/
76+
std::tuple<Cut, bool> operator()(const Arr &x, double &t) {
77+
return this->assess_optim(x, t);
78+
}
6879
};
6980

7081
/**
@@ -87,7 +98,7 @@ static void LMI_Lazy(benchmark::State &state) {
8798
const auto B2 = Arr{{14.0, 9.0, 40.0}, {9.0, 91.0, 10.0}, {40.0, 10.0, 15.0}};
8899

89100
while (state.KeepRunning()) {
90-
auto P = my_oracle<lmi_oracle<Arr>>(F1, B1, F2, B2, Arr{1.0, -1.0, 1.0});
101+
auto P = my_oracle<LmiOracle<Arr>>(F1, B1, F2, B2, Arr{1.0, -1.0, 1.0});
91102
auto E = Ell(10.0, Arr{0.0, 0.0, 0.0});
92103
auto t = 1e100; // std::numeric_limits<double>::max()
93104
[[maybe_unused]] const auto rslt = cutting_plane_optim(P, E, t);
@@ -120,7 +131,7 @@ static void LMI_old(benchmark::State &state) {
120131

121132
while (state.KeepRunning()) {
122133
auto P =
123-
my_oracle<lmi_old_oracle<Arr>>(F1, B1, F2, B2, Arr{1.0, -1.0, 1.0});
134+
my_oracle<LmiOldOracle<Arr>>(F1, B1, F2, B2, Arr{1.0, -1.0, 1.0});
124135
auto E = Ell(10.0, Arr{0.0, 0.0, 0.0});
125136
auto t = 1e100; // std::numeric_limits<double>::max()
126137
[[maybe_unused]] const auto rslt = cutting_plane_optim(P, E, t);
@@ -148,7 +159,7 @@ static void LMI_No_Trick(benchmark::State &state) {
148159
const auto B2 = Arr{{14.0, 9.0, 40.0}, {9.0, 91.0, 10.0}, {40.0, 10.0, 15.0}};
149160

150161
while (state.KeepRunning()) {
151-
auto P = my_oracle<lmi_oracle<Arr>>(F1, B1, F2, B2, Arr{1.0, -1.0, 1.0});
162+
auto P = my_oracle<LmiOracle<Arr>>(F1, B1, F2, B2, Arr{1.0, -1.0, 1.0});
152163
auto E = Ell(10.0, Arr{0.0, 0.0, 0.0});
153164
E.no_defer_trick = true;
154165
auto t = 1e100; // std::numeric_limits<double>::max()

include/lmisolver/lmi0_oracle.hpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* find x
1717
* s.t. F * x >= 0
1818
*/
19-
template <typename Arr036> class lmi0_oracle {
19+
template <typename Arr036> class Lmi0Oracle {
2020
using Cut = std::pair<Arr036, double>;
2121

2222
private:
@@ -31,13 +31,23 @@ template <typename Arr036> class lmi0_oracle {
3131
*
3232
* @param[in] F
3333
*/
34-
explicit lmi0_oracle(gsl::span<const Arr036> F);
34+
explicit Lmi0Oracle(gsl::span<const Arr036> F);
3535

3636
/**
3737
* @brief
3838
*
3939
* @param[in] x
4040
* @return std::optional<Cut>
4141
*/
42-
auto operator()(const Arr036 &x) -> std::optional<Cut>;
42+
auto assess_feas(const Arr036 &x) -> std::optional<Cut>;
43+
44+
/**
45+
* @brief
46+
*
47+
* @param[in] x
48+
* @return std::optional<Cut>
49+
*/
50+
auto operator()(const Arr036 &x) -> std::optional<Cut> {
51+
return assess_feas(x);
52+
}
4353
};

include/lmisolver/lmi_old_oracle.hpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* find x
1515
* s.t. (B - F * x) >= 0
1616
*/
17-
template <typename Arr036> class lmi_old_oracle {
17+
template <typename Arr036> class LmiOldOracle {
1818
// using Arr = xt::xarray<double, xt::layout_type::row_major>;
1919
using Cut = std::pair<Arr036, double>;
2020

@@ -30,13 +30,23 @@ template <typename Arr036> class lmi_old_oracle {
3030
* @param[in] F
3131
* @param[in] B
3232
*/
33-
lmi_old_oracle(gsl::span<const Arr036> F, Arr036 B);
33+
LmiOldOracle(gsl::span<const Arr036> F, Arr036 B);
3434

3535
/**
3636
* @brief
3737
*
3838
* @param[in] x
3939
* @return std::optional<Cut>
4040
*/
41-
auto operator()(const Arr036 &x) -> std::optional<Cut>;
41+
auto assess_feas(const Arr036 &x) -> std::optional<Cut>;
42+
43+
/**
44+
* @brief
45+
*
46+
* @param[in] x
47+
* @return std::optional<Cut>
48+
*/
49+
auto operator()(const Arr036 &x) -> std::optional<Cut> {
50+
return assess_feas(x);
51+
}
4252
};

include/lmisolver/lmi_oracle.hpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* find x
1515
* s.t. (B - F * x) >= 0
1616
*/
17-
template <typename Arr036> class lmi_oracle {
17+
template <typename Arr036> class LmiOracle {
1818
// using Arr = xt::xarray<double, xt::layout_type::row_major>;
1919
using Cut = std::pair<Arr036, double>;
2020

@@ -30,13 +30,23 @@ template <typename Arr036> class lmi_oracle {
3030
* @param[in] F
3131
* @param[in] B
3232
*/
33-
lmi_oracle(gsl::span<const Arr036> F, Arr036 B);
33+
LmiOracle(gsl::span<const Arr036> F, Arr036 B);
3434

3535
/**
3636
* @brief
3737
*
3838
* @param[in] x
3939
* @return std::optional<Cut>
4040
*/
41-
auto operator()(const Arr036 &x) -> std::optional<Cut>;
41+
auto assess_feas(const Arr036 &x) -> std::optional<Cut>;
42+
43+
/**
44+
* @brief
45+
*
46+
* @param[in] x
47+
* @return std::optional<Cut>
48+
*/
49+
auto operator()(const Arr036 &x) -> std::optional<Cut> {
50+
return assess_feas(x);
51+
}
4252
};

source/lmi0_oracle.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include <stddef.h> // for size_t
22

33
#include <gsl/span> // for span, span<>::element_type
4-
#include <lmisolver/lmi0_oracle.hpp> // for lmi0_oracle::Arr, lmi0_oracle...
4+
#include <lmisolver/lmi0_oracle.hpp> // for Lmi0Oracle::Arr, Lmi0Oracle...
55
#include <optional> // for optional
66
#include <tuple> // for tuple
77
#include <type_traits> // for move
@@ -19,7 +19,7 @@
1919
* @param[in] F
2020
*/
2121
template <typename Arr036>
22-
lmi0_oracle<Arr036>::lmi0_oracle(gsl::span<const Arr036> F)
22+
Lmi0Oracle<Arr036>::Lmi0Oracle(gsl::span<const Arr036> F)
2323
: _F{F}, _n{F[0].shape()[0]}, _Q(_n) {}
2424

2525
/**
@@ -29,8 +29,8 @@ lmi0_oracle<Arr036>::lmi0_oracle(gsl::span<const Arr036> F)
2929
* @return auto
3030
*/
3131
template <typename Arr036>
32-
auto lmi0_oracle<Arr036>::operator()(const Arr036 &x)
33-
-> std::optional<typename lmi0_oracle<Arr036>::Cut> {
32+
auto Lmi0Oracle<Arr036>::assess_feas(const Arr036 &x)
33+
-> std::optional<typename Lmi0Oracle<Arr036>::Cut> {
3434
auto n = x.size();
3535

3636
auto getA = [&, this](size_t i, size_t j) -> double {
@@ -53,4 +53,4 @@ auto lmi0_oracle<Arr036>::operator()(const Arr036 &x)
5353
}
5454

5555
using Arr = xt::xarray<double, xt::layout_type::row_major>;
56-
template class lmi0_oracle<Arr>;
56+
template class Lmi0Oracle<Arr>;

source/lmi_old_oracle.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
// #include <ellalgo/utility.hpp> // for zeros
44
#include <gsl/span> // for span, span<>::element_type
5-
#include <lmisolver/lmi_old_oracle.hpp> // for lmi_old_oracle<Arr036>::Arr, lmi_old_oracle<Arr036>::Cut
5+
#include <lmisolver/lmi_old_oracle.hpp> // for LmiOldOracle<Arr036>::Arr, LmiOldOracle<Arr036>::Cut
66
#include <optional> // for optional
77
#include <tuple> // for tuple
88
#include <type_traits> // for move
@@ -21,7 +21,7 @@
2121
* @param[in] B
2222
*/
2323
template <typename Arr036>
24-
lmi_old_oracle<Arr036>::lmi_old_oracle(gsl::span<const Arr036> F, Arr036 B)
24+
LmiOldOracle<Arr036>::LmiOldOracle(gsl::span<const Arr036> F, Arr036 B)
2525
: _F{F}, _F0{std::move(B)}, _Q{this->_F0.shape()[0]} {}
2626

2727
/**
@@ -31,8 +31,8 @@ lmi_old_oracle<Arr036>::lmi_old_oracle(gsl::span<const Arr036> F, Arr036 B)
3131
* @return std::optional<Cut>
3232
*/
3333
template <typename Arr036>
34-
auto lmi_old_oracle<Arr036>::operator()(const Arr036 &x)
35-
-> std::optional<typename lmi_old_oracle<Arr036>::Cut> {
34+
auto LmiOldOracle<Arr036>::assess_feas(const Arr036 &x)
35+
-> std::optional<typename LmiOldOracle<Arr036>::Cut> {
3636
const auto n = x.size();
3737

3838
auto A = Arr036{this->_F0};
@@ -53,4 +53,4 @@ auto lmi_old_oracle<Arr036>::operator()(const Arr036 &x)
5353
}
5454

5555
using Arr = xt::xarray<double, xt::layout_type::row_major>;
56-
template class lmi_old_oracle<Arr>;
56+
template class LmiOldOracle<Arr>;

source/lmi_oracle.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
// #include <ellalgo/utility.hpp> // for zeros
44
#include <gsl/span> // for span, span<>::element_type
5-
#include <lmisolver/lmi_oracle.hpp> // for lmi_oracle<Arr036>::Arr, lmi_oracle<Arr036>::Cut
5+
#include <lmisolver/lmi_oracle.hpp> // for LmiOracle<Arr036>::Arr, LmiOracle<Arr036>::Cut
66
#include <optional> // for optional
77
#include <tuple> // for tuple
88
#include <type_traits> // for move
@@ -21,7 +21,7 @@
2121
* @param[in] B
2222
*/
2323
template <typename Arr036>
24-
lmi_oracle<Arr036>::lmi_oracle(gsl::span<const Arr036> F, Arr036 B)
24+
LmiOracle<Arr036>::LmiOracle(gsl::span<const Arr036> F, Arr036 B)
2525
: _F{F}, _F0{std::move(B)}, _Q{this->_F0.shape()[0]} {}
2626

2727
/**
@@ -31,8 +31,8 @@ lmi_oracle<Arr036>::lmi_oracle(gsl::span<const Arr036> F, Arr036 B)
3131
* @return std::optional<Cut>
3232
*/
3333
template <typename Arr036>
34-
auto lmi_oracle<Arr036>::operator()(const Arr036 &x)
35-
-> std::optional<typename lmi_oracle<Arr036>::Cut> {
34+
auto LmiOracle<Arr036>::assess_feas(const Arr036 &x)
35+
-> std::optional<typename LmiOracle<Arr036>::Cut> {
3636
const auto n = x.size();
3737

3838
auto getA = [&, this](size_t i, size_t j) -> double {
@@ -55,4 +55,4 @@ auto lmi_oracle<Arr036>::operator()(const Arr036 &x)
5555
}
5656

5757
using Arr = xt::xarray<double, xt::layout_type::row_major>;
58-
template class lmi_oracle<Arr>;
58+
template class LmiOracle<Arr>;

specific.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ endif(xtensor_ADDED)
1919

2020
CPMAddPackage(
2121
NAME EllAlgo
22-
GIT_TAG 1.3.1
22+
GIT_TAG 1.3.2
2323
GITHUB_REPOSITORY luk036/ellalgo-cpp
2424
OPTIONS "INSTALL_ONLY YES" # create an installable target
2525
)

test/source/test_lmi.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include <ellalgo/cutting_plane.hpp> // for cutting_plane_optim
77
#include <ellalgo/ell.hpp> // for Ell
88
#include <ellalgo/ell_stable.hpp> // for EllStable
9-
#include <lmisolver/lmi_oracle.hpp> // for lmi_oracle
9+
#include <lmisolver/lmi_oracle.hpp> // for LmiOracle
1010
#include <xtensor/xarray.hpp> // for xarray_container
1111
#include <xtensor/xlayout.hpp> // for layout_type, layout_type::row...
1212
#include <xtensor/xmath.hpp> // for sum
@@ -33,8 +33,8 @@ class my_oracle {
3333
using Cut = std::pair<Arr, double>;
3434

3535
private:
36-
lmi_oracle<Arr> lmi1;
37-
lmi_oracle<Arr> lmi2;
36+
LmiOracle<Arr> lmi1;
37+
LmiOracle<Arr> lmi2;
3838
const Arr c;
3939

4040
public:
@@ -58,7 +58,7 @@ class my_oracle {
5858
* @param[in,out] t
5959
* @return std::tuple<Cut, double>
6060
*/
61-
auto operator()(const Arr &x, double &t) -> std::tuple<Cut, bool> {
61+
auto assess_optim(const Arr &x, double &t) -> std::tuple<Cut, bool> {
6262
const auto cut1 = this->lmi1(x);
6363
if (cut1) {
6464
return {*cut1, false};
@@ -75,6 +75,17 @@ class my_oracle {
7575
t = f0;
7676
return {{this->c, 0.0}, true};
7777
}
78+
79+
/**
80+
* @brief
81+
*
82+
* @param[in] x
83+
* @param[in,out] t the best-so-far optimal value
84+
* @return std::tuple<Cut, double>
85+
*/
86+
auto operator()(const Arr &x, double &t) -> std::tuple<Cut, bool> {
87+
return this->assess_optim(x, t);
88+
}
7889
};
7990

8091
TEST_CASE("LMI test (stable)") {

test/source/test_lmi_old.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include <ellalgo/ell.hpp> // for Ell
88
#include <ellalgo/ell_stable.hpp> // for EllStable
99
#include <gsl/span> // for span
10-
#include <lmisolver/lmi_old_oracle.hpp> // for lmi_old_oracle
10+
#include <lmisolver/lmi_old_oracle.hpp> // for LmiOldOracle
1111
#include <optional> // for optional
1212
#include <tuple> // for tuple_element<>::type
1313
#include <type_traits> // for move, add_const<>::type
@@ -31,8 +31,8 @@ class my_old_oracle {
3131
using Cut = std::pair<Arr, double>;
3232

3333
private:
34-
lmi_old_oracle<Arr> lmi1;
35-
lmi_old_oracle<Arr> lmi2;
34+
LmiOldOracle<Arr> lmi1;
35+
LmiOldOracle<Arr> lmi2;
3636
const Arr c;
3737

3838
public:
@@ -56,7 +56,7 @@ class my_old_oracle {
5656
* @param[in,out] t the best-so-far optimal value
5757
* @return std::tuple<Cut, double>
5858
*/
59-
auto operator()(const Arr &x, double &t) -> std::tuple<Cut, bool> {
59+
auto assess_optim(const Arr &x, double &t) -> std::tuple<Cut, bool> {
6060
const auto cut1 = this->lmi1(x);
6161
if (cut1) {
6262
return {*cut1, false};
@@ -73,6 +73,18 @@ class my_old_oracle {
7373
t = f0;
7474
return {{this->c, 0.0}, true};
7575
}
76+
77+
/**
78+
* @brief
79+
*
80+
* @param[in] x
81+
* @param[in,out] t the best-so-far optimal value
82+
* @return std::tuple<Cut, double>
83+
*/
84+
auto operator()(const Arr &x, double &t) -> std::tuple<Cut, bool> {
85+
return this->assess_optim(x, t);
86+
}
87+
7688
};
7789

7890
TEST_CASE("LMI (old) test") {

0 commit comments

Comments
 (0)