LinExpr

This class is used to represent linear expressions in the modeling interface of idol.

It consists in a set of linear terms which represent products of keys (typically, variables) and scalars.

Example

In this example, we create a linear expression representing the following linear expression.

\[3 x_0 + 2 x_1\]
auto x = model.add_vars(Dim<1>(2), 0, Inf, Continuous, "x");

LinExpr lin_expr = 3 * x[0] + 2 * x[1];

Doxygen

template<class KeyT = idol::Var, class ValueT = double>
class LinExpr : public idol::SparseVector<idol::Var, double>
Template Parameters:

KeyT – the class representing keys

Subclassed by idol::QuadExpr< idol::Var, idol::QuadExpr< idol::Var > >, idol::QuadExpr< idol::Var >, idol::QuadExpr< idol::Var, double >, idol::QuadExpr< KeyT, ValueT >

Public Types

using iterator = typename map_t::iterator
using const_iterator = typename map_t::const_iterator

Public Functions

LinExpr() = default
LinExpr(KeyT t_key)
inline LinExpr(SparseVector<KeyT, ValueT> t_vector)
LinExpr(const ValueT &t_factor, const KeyT &t_key)
LinExpr(ValueT &&t_factor, const KeyT &t_key)
LinExpr(const LinExpr<KeyT, ValueT>&) = default
LinExpr(LinExpr<KeyT, ValueT>&&) = default
LinExpr &operator=(const LinExpr<KeyT, ValueT>&) noexcept = default
LinExpr &operator=(LinExpr<KeyT, ValueT>&&) noexcept = default
LinExpr &operator+=(const LinExpr<KeyT, ValueT> &t_rhs)
LinExpr &operator+=(const KeyT &t_rhs)
LinExpr &operator-=(const LinExpr<KeyT, ValueT> &t_rhs)
LinExpr &operator-=(const KeyT &t_rhs)
virtual SparseVector &operator+=(const SparseVector &t_vector)
virtual SparseVector &operator-=(const SparseVector &t_vector)
virtual SparseVector &operator*=(std::conditional_t<std::is_arithmetic_v<ValueT>, ValueT, double> t_scalar)
virtual SparseVector &operator/=(std::conditional_t<std::is_arithmetic_v<ValueT>, ValueT, double> t_scalar)
SparseVector operator-() const
inline unsigned int size() const
inline bool empty() const
inline bool has_index(const IndexT &t_index) const
const ValueT &get(const IndexT &t_index1) const
void set(const IndexT &t_index, const ValueT &t_value)
virtual bool is_zero(double t_tolerance) const
inline void remove(const IndexT &t_index)
inline void clear()
inline void reserve(unsigned int t_capacity)
inline iterator begin()
inline const_iterator begin() const
inline iterator end()
inline const_iterator end() const
inline const_iterator cbegin() const
inline const_iterator cend() const
SparseVector &merge_without_conflict(const SparseVector &t_vec)

Public Static Attributes

static LinExpr<KeyT, ValueT> Zero = {}