EllAlgo 1.6.13
Loading...
Searching...
No Matches
profit_oracle.hpp
Go to the documentation of this file.
1
6// -*- coding: utf-8 -*-
7#pragma once
8
9#include <cmath> // for log
10#include <tuple> // for tuple
11#include <valarray>
12
13#include "../round_robin.hpp"
14
40 using Vec = std::valarray<double>;
41 using Cut = std::pair<Vec, double>;
42
43 RoundRobin _rr{2};
44 const double _log_pA;
45 const double _log_k;
46 const Vec _price_out;
47 double _log_Cobb = 0.0;
48 double _vx = 0.0;
49 Vec _elasticities;
50
59 auto _constraint_capacity(const Vec& y, const Vec&, const double) -> Cut*;
60
69 auto _constraint_profit(const Vec& y, const Vec& x, const double gamma) -> Cut*;
70
71 public:
81 ProfitOracle(double p, double A, double k, const Vec& a, const Vec& v)
82 : _log_pA{std::log(p * A)}, _log_k{std::log(k)}, _price_out{v}, _elasticities{a} {}
83
88 ProfitOracle(const ProfitOracle&) = delete;
92 ~ProfitOracle() = default;
93
99 auto set_elasticities(const Vec& elasticities) { this->_elasticities = elasticities; }
100
110 auto assess_feas(const Vec& y, const double& gamma) -> Cut*;
111
119 auto assess_optim(const Vec& y, double& gamma) -> std::tuple<Cut, bool>;
120};
121
140 using Vec = std::valarray<double>;
141 using Cut = std::pair<Vec, double>;
142
143 const Vec _uie;
144 Vec _elasticities;
145 ProfitOracle P;
146
147 public:
159 ProfitOracleRb(double p, double A, double k, const Vec& a, const Vec& v, const Vec& e,
160 double e3)
161 : _uie{e}, _elasticities{a}, P(p - e3, A, k - e3, a, v + Vec{e3, e3}) {}
162
172 auto assess_optim(const Vec& y, double& gamma) -> std::tuple<Cut, bool> {
173 auto a_rb = this->_elasticities;
174 a_rb[0] += y[0] > 0.0 ? -this->_uie[0] : this->_uie[0];
175 a_rb[1] += y[1] > 0.0 ? -this->_uie[1] : this->_uie[1];
176 this->P.set_elasticities(a_rb);
177 return this->P.assess_optim(y, gamma);
178 }
179};
180
202 using Vec = std::valarray<double>;
203 using Cut = std::pair<Vec, double>;
204
205 ProfitOracle P;
206 Vec _yd;
207
208 public:
218 ProfitOracleQ(double p, double A, double k, const Vec& a, const Vec& v) : P{p, A, k, a, v} {}
219
230 auto assess_optim_q(const Vec& y, double& gamma, bool retry)
231 -> std::tuple<Cut, bool, Vec, bool>;
232};
Arr log(const Arr &a)
Element-wise natural logarithm.
Definition arr.hpp:235
Oracle for profit maximization problem (discrete version)
Definition profit_oracle.hpp:201
auto assess_optim_q(const Vec &y, double &gamma, bool retry) -> std::tuple< Cut, bool, Vec, bool >
Make object callable for cutting_plane_optim_q()
ProfitOracleQ(double p, double A, double k, const Vec &a, const Vec &v)
Construct a new profit q oracle object.
Definition profit_oracle.hpp:218
Oracle for a profit maximization problem (robust version)
Definition profit_oracle.hpp:139
auto assess_optim(const Vec &y, double &gamma) -> std::tuple< Cut, bool >
Make object callable for cutting_plane_optim()
Definition profit_oracle.hpp:172
ProfitOracleRb(double p, double A, double k, const Vec &a, const Vec &v, const Vec &e, double e3)
Construct a new profit rb oracle object.
Definition profit_oracle.hpp:159
Oracle for a profit maximization problem.
Definition profit_oracle.hpp:39
ProfitOracle(ProfitOracle &&)=delete
ProfitOracle(const ProfitOracle &)=delete
Construct a new profit oracle object (only explicitly)
auto set_elasticities(const Vec &elasticities)
Definition profit_oracle.hpp:99
ProfitOracle & operator=(ProfitOracle &&)=delete
ProfitOracle & operator=(const ProfitOracle &)=delete
auto assess_optim(const Vec &y, double &gamma) -> std::tuple< Cut, bool >
~ProfitOracle()=default
auto assess_feas(const Vec &y, const double &gamma) -> Cut *
Assess feasibility of a given input quantity.
ProfitOracle(double p, double A, double k, const Vec &a, const Vec &v)
Construct a new profit oracle object.
Definition profit_oracle.hpp:81
Round-robin index generator over a half-open range [lo, hi)
Definition round_robin.hpp:18
auto invalid_value() -> T
Return an invalid/sentinel value for type T.
Definition cutting_plane.hpp:27