SCIP++ refs/heads/main
 
Loading...
Searching...
No Matches
scippp::LinExpr Class Reference

Represents a linear combination of variables plus a constant term. More...

#include <lin_expr.hpp>

Public Member Functions

 LinExpr ()=default
 Sets constant term and linear combination to zero.
 
template<typename Arithmetic , std::enable_if_t< std::is_arithmetic_v< Arithmetic >, bool > = true>
 LinExpr (Arithmetic constant)
 Creates a linear expression with no variables.
 
template<std::size_t N>
 LinExpr (const std::array< Var, N > &vars)
 Creates a linear expression with zero as constant and the given variables with coefficient one.
 
template<std::size_t N>
 LinExpr (const std::array< Var, N > &vars, std::array< double, N > &coeffs)
 Creates a linear expression with zero as constant and the given variables with the provided coefficients.
 
 LinExpr (const std::vector< Var > &vars)
 Creates a linear expression with zero as constant and the given variables with coefficient one.
 
 LinExpr (const std::vector< Var > &vars, const std::vector< double > &coeffs)
 Creates a linear expression with zero as constant and the given variables with the provided coefficients.
 
 LinExpr (const Var &var)
 Creates a linear expression with zero as constant and the given variable with coefficient one.
 
 LinExpr (std::initializer_list< Var > vars)
 Creates a linear expression with zero as constant and the given variables with coefficient one.
 
 LinExpr (std::initializer_list< Var > vars, std::initializer_list< double > coeffs)
 Creates a linear expression with zero as constant and the given variables with the provided coefficients.
 
double getConstant () const
 Returns the constant term of the expression.
 
LinExproperator*= (double factor)
 Multiply all coefficients.
 
LinExproperator+= (const LinExpr &expr)
 Add another linear expression to this.
 
LinExproperator-= (const LinExpr &expr)
 Subtract another expression from this.
 

Friends

struct LinExpression::CheckInternalsUsingFriendStruct
 
class Model
 

Detailed Description

Represents a linear combination of variables plus a constant term.

Since
1.0.0

Definition at line 18 of file lin_expr.hpp.

Constructor & Destructor Documentation

◆ LinExpr() [1/9]

scippp::LinExpr::LinExpr ( )
default

Sets constant term and linear combination to zero.

Since
1.0.0

◆ LinExpr() [2/9]

template<typename Arithmetic , std::enable_if_t< std::is_arithmetic_v< Arithmetic >, bool > = true>
scippp::LinExpr::LinExpr ( Arithmetic constant)
inline

Creates a linear expression with no variables.

Since
1.0.0
Remarks
This is on purpose not an explicit c'tor to allow expressions like x <= 1.
Template Parameters
Arithmetictype that will be casted to double.
Warning
Arithmetic is casted to double without creating a narrowing warning!
Parameters
constantConstant term to set.

Definition at line 43 of file lin_expr.hpp.

◆ LinExpr() [3/9]

scippp::LinExpr::LinExpr ( const Var & var)

Creates a linear expression with zero as constant and the given variable with coefficient one.

Since
1.0.0
Remarks
This is on purpose not an explicit c'tor to allow expressions like x <= 1.
Parameters
varVariable to store with coefficient one in the expression.

◆ LinExpr() [4/9]

scippp::LinExpr::LinExpr ( std::initializer_list< Var > vars)

Creates a linear expression with zero as constant and the given variables with coefficient one.

Since
1.3.0
Remarks
This is on purpose not an explicit c'tor to allow expressions like ... + {x1, x2}.
Parameters
varsVariables to store with coefficient one in the expression.

◆ LinExpr() [5/9]

scippp::LinExpr::LinExpr ( std::initializer_list< Var > vars,
std::initializer_list< double > coeffs )

Creates a linear expression with zero as constant and the given variables with the provided coefficients.

Since
1.3.0
Parameters
varsVariables to store in the expression.
coeffsCoefficients to store in the expression.
Precondition
vars and coeffs have the same length.

◆ LinExpr() [6/9]

template<std::size_t N>
scippp::LinExpr::LinExpr ( const std::array< Var, N > & vars)
inline

Creates a linear expression with zero as constant and the given variables with coefficient one.

Since
1.3.0
Remarks
This is on purpose not an explicit c'tor to allow expressions like ... + vars.
Template Parameters
NSize of the array vars.
Parameters
varsVariables to store with coefficient one in the expression.

Definition at line 77 of file lin_expr.hpp.

◆ LinExpr() [7/9]

template<std::size_t N>
scippp::LinExpr::LinExpr ( const std::array< Var, N > & vars,
std::array< double, N > & coeffs )
inline

Creates a linear expression with zero as constant and the given variables with the provided coefficients.

Since
1.3.0
Template Parameters
NSize of the arrays vars and coeffs.
Parameters
varsVariables to store in the expression.
coeffsCoefficients to store in the expression.

Definition at line 90 of file lin_expr.hpp.

◆ LinExpr() [8/9]

scippp::LinExpr::LinExpr ( const std::vector< Var > & vars)

Creates a linear expression with zero as constant and the given variables with coefficient one.

Since
1.3.0
Remarks
This is on purpose not an explicit c'tor to allow expressions like ... + vars.
Parameters
varsVariables to store with coefficient one in the expression.

◆ LinExpr() [9/9]

scippp::LinExpr::LinExpr ( const std::vector< Var > & vars,
const std::vector< double > & coeffs )

Creates a linear expression with zero as constant and the given variables with the provided coefficients.

Since
1.3.0
Parameters
varsVariables to store in the expression.
coeffsCoefficients to store in the expression.

Member Function Documentation

◆ getConstant()

double scippp::LinExpr::getConstant ( ) const
nodiscard

Returns the constant term of the expression.

Since
1.0.0
Returns
the constant term of the expression.

◆ operator*=()

LinExpr & scippp::LinExpr::operator*= ( double factor)

Multiply all coefficients.

Since
1.0.0
Parameters
factorto multiply all coefficients with.
Returns
Scaled expression.

◆ operator+=()

LinExpr & scippp::LinExpr::operator+= ( const LinExpr & expr)

Add another linear expression to this.

Since
1.0.0
Parameters
exprOther linear expression to add.
Returns
Updated sum.

◆ operator-=()

LinExpr & scippp::LinExpr::operator-= ( const LinExpr & expr)

Subtract another expression from this.

Since
1.0.0
Parameters
exprRight-hand-side of the subtraction.
Returns
Updated expression.

Friends And Related Symbol Documentation

◆ LinExpression::CheckInternalsUsingFriendStruct

friend struct LinExpression::CheckInternalsUsingFriendStruct
friend

Definition at line 20 of file lin_expr.hpp.

◆ Model

friend class Model
friend

Definition at line 19 of file lin_expr.hpp.


The documentation for this class was generated from the following file: