8#include "idol/general/utils/SparseVector.h"
9#include "idol/general/utils/IteratorForward.h"
10#include "idol/general/utils/exceptions/Exception.h"
20 template<
class KeyT,
class ValueT>
27template<
class KeyT =
idol::Var,
class ValueT =
double>
32 LinExpr(SparseVector<KeyT, ValueT> t_vector) : SparseVector<KeyT, ValueT>(std::move(t_vector)) {}
33 LinExpr(
const ValueT& t_factor,
const KeyT& t_key);
34 LinExpr(ValueT&& t_factor,
const KeyT& t_key);
36 LinExpr(
const LinExpr<KeyT, ValueT>&) =
default;
37 LinExpr(LinExpr<KeyT, ValueT>&&) =
default;
39 LinExpr& operator=(
const LinExpr<KeyT, ValueT>&)
noexcept =
default;
40 LinExpr& operator=(LinExpr<KeyT, ValueT>&&)
noexcept =
default;
42 virtual LinExpr& operator+=(
const LinExpr<KeyT, ValueT>& t_rhs);
43 LinExpr& operator+=(
const KeyT& t_rhs);
45 LinExpr& operator-=(
const LinExpr<KeyT, ValueT>& t_rhs);
46 LinExpr& operator-=(
const KeyT& t_rhs);
48 static LinExpr<KeyT, ValueT> Zero;
53template<
class KeyT,
class ValueT>
55 SparseVector<KeyT, ValueT>::operator-=(SparseVector<KeyT, ValueT>(t_rhs, 1));
59template<
class KeyT,
class ValueT>
61 SparseVector<KeyT, ValueT>::operator-=((SparseVector<KeyT, ValueT>&) t_rhs);
65template<
class KeyT,
class ValueT>
67 SparseVector<KeyT, ValueT>::operator+=(SparseVector<KeyT, ValueT>(t_rhs, 1));
71template<
class Key,
class ValueT>
73 SparseVector<Key, ValueT>::operator+=((SparseVector<Key, ValueT>&) t_rhs);
77template<
class Key,
class ValueT>
78idol::LinExpr<Key, ValueT>::LinExpr(ValueT &&t_factor,
const Key &t_key) : SparseVector<Key, ValueT>(t_key, std::move(t_factor)) {
82template<
class Key,
class ValueT>
83idol::LinExpr<Key, ValueT>::LinExpr(Key t_key) :
SparseVector<Key, double>(t_key, 1.) {
87template<
class Key,
class ValueT>
88idol::LinExpr<Key, ValueT>::LinExpr(
const ValueT& t_factor,
const Key &t_key) :
SparseVector<Key, ValueT>(t_key, t_factor) {
92 template<
class KeyT,
class ValueT>
99 auto it = t_expr.begin();
100 if constexpr (std::is_same_v<ValueT, double>) {
105 t_os <<
"[ " << it->second <<
" ] " << it->first;
108 for (
const auto end = t_expr.end() ; it != end ; ++it) {
110 if constexpr (std::is_same_v<ValueT, double>) {
111 t_os << it->second <<
" " << it->first;
113 t_os <<
"[ " << it->second <<
" ] " << it->first;