SCIP++ refs/heads/main
 
Loading...
Searching...
No Matches
lin_expr.hpp
1#pragma once
2
3#include <vector>
4
5#include "scippp/var.hpp"
6
7namespace scippp {
8
13class LinExpr {
14 friend class Model;
16 double m_constant { 0.0 };
18 std::vector<Var> m_vars {};
20 std::vector<double> m_coeffs {};
21
22public:
27 LinExpr() = default;
36 template <typename Arithmetic, std::enable_if_t<std::is_arithmetic_v<Arithmetic>, bool> = true>
37 LinExpr(Arithmetic constant)
38 : m_constant { static_cast<double>(constant) }
39 {
40 }
47 LinExpr(const Var& var);
48
54 [[nodiscard]] double getConstant() const;
55
62 LinExpr& operator+=(const LinExpr& expr);
69 LinExpr& operator-=(const LinExpr& expr);
76 LinExpr& operator*=(double factor);
77};
78
86LinExpr operator*(double factor, LinExpr rhs);
87
96
105
106}
Represents a linear combination of variables plus a constant term.
Definition: lin_expr.hpp:13
LinExpr & operator*=(double factor)
Multiply all coefficients.
LinExpr(const Var &var)
Creates a linear expression with zero as constant the given variable with coefficient one.
LinExpr & operator+=(const LinExpr &expr)
Add another linear expression to this.
LinExpr(Arithmetic constant)
Creates a linear expression with no variables.
Definition: lin_expr.hpp:37
LinExpr & operator-=(const LinExpr &expr)
Subtract another expression from this.
LinExpr()=default
Sets constant term and linear combination to zero.
double getConstant() const
Returns the constant term of the expression.
A SCIP optimization model.
Definition: model.hpp:39
C++ wrapper for SCIP.
LinExpr operator*(double factor, LinExpr rhs)
Scales a linear expression by a factor.
LinExpr operator+(LinExpr lhs, const LinExpr &rhs)
Creates a new linear expression as the sum of two.
LinExpr operator-(LinExpr lhs, const LinExpr &rhs)
Creates the new linear expression lhs - rhs.
Wrapper for a SCIP variable.
Definition: var.hpp:17