7#include <initializer_list>
43 explicit constexpr Variable(std::nullptr_t) : expr{nullptr} {}
51 : expr{detail::MakeExpressionPtr<detail::ConstExpression>(value)} {}
59 : expr{detail::MakeExpressionPtr<detail::ConstExpression>(value)} {}
74 : expr{std::move(expr)} {}
82 expr = detail::MakeExpressionPtr<detail::ConstExpression>(value);
93 if (expr->IsConstant(0.0)) {
94 expr = detail::MakeExpressionPtr<detail::ConstExpression>(value);
98 if (expr->args[0] !=
nullptr && !expr->args[0]->IsConstant(0.0)) {
101 "WARNING: {}:{}: Modified the value of a dependent variable",
116 return Variable{lhs.expr * rhs.expr};
137 return Variable{lhs.expr / rhs.expr};
158 return Variable{lhs.expr + rhs.expr};
179 return Variable{lhs.expr - rhs.expr};
224 detail::MakeExpressionPtr<detail::DecisionVariableExpression>();
455template <
typename LHS,
typename RHS>
458 (!std::same_as<std::decay_t<LHS>,
double> ||
459 !std::same_as<std::decay_t<RHS>,
double>)
480 for (
int row = 0; row <
rows; ++row) {
500 for (
int row = 0; row <
rows; ++row) {
533 for (
int row = 0; row <
lhsRows; ++row) {
557 std::initializer_list<EqualityConstraints> equalityConstraints) {
558 for (
const auto& elem : equalityConstraints) {
559 constraints.
insert(constraints.
end(), elem.constraints.begin(),
560 elem.constraints.end());
572 const std::vector<EqualityConstraints>& equalityConstraints) {
573 for (
const auto& elem : equalityConstraints) {
574 constraints.
insert(constraints.
end(), elem.constraints.begin(),
575 elem.constraints.end());
588 template <
typename LHS,
typename RHS>
591 (!std::same_as<std::decay_t<LHS>,
double> ||
592 !std::same_as<std::decay_t<RHS>,
double>)
601 constraints.
begin(), constraints.
end(),
602 [](
auto& constraint) { return constraint.Value() == 0.0; });
620 std::initializer_list<InequalityConstraints> inequalityConstraints) {
621 for (
const auto& elem : inequalityConstraints) {
622 constraints.
insert(constraints.
end(), elem.constraints.begin(),
623 elem.constraints.end());
636 const std::vector<InequalityConstraints>& inequalityConstraints) {
637 for (
const auto& elem : inequalityConstraints) {
638 constraints.
insert(constraints.
end(), elem.constraints.begin(),
639 elem.constraints.end());
652 template <
typename LHS,
typename RHS>
655 (!std::same_as<std::decay_t<LHS>,
double> ||
656 !std::same_as<std::decay_t<RHS>,
double>)
665 constraints.
begin(), constraints.
end(),
666 [](
auto& constraint) { return constraint.Value() >= 0.0; });
676template <
typename LHS,
typename RHS>
678 (ScalarLike<std::decay_t<RHS>> || MatrixLike<std::decay_t<RHS>>) &&
679 (!std::same_as<std::decay_t<LHS>,
double> ||
680 !std::same_as<std::decay_t<RHS>,
double>)
692template <
typename LHS,
typename RHS>
694 (ScalarLike<std::decay_t<RHS>> || MatrixLike<std::decay_t<RHS>>) &&
695 (!std::same_as<std::decay_t<LHS>,
double> ||
696 !std::same_as<std::decay_t<RHS>,
double>)
708template <
typename LHS,
typename RHS>
710 (ScalarLike<std::decay_t<RHS>> || MatrixLike<std::decay_t<RHS>>) &&
711 (!std::same_as<std::decay_t<LHS>,
double> ||
712 !std::same_as<std::decay_t<RHS>,
double>)
724template <
typename LHS,
typename RHS>
726 (ScalarLike<std::decay_t<RHS>> || MatrixLike<std::decay_t<RHS>>) &&
727 (!std::same_as<std::decay_t<LHS>,
double> ||
728 !std::same_as<std::decay_t<RHS>,
double>)
740template <
typename LHS,
typename RHS>
742 (ScalarLike<std::decay_t<RHS>> || MatrixLike<std::decay_t<RHS>>) &&
743 (!std::same_as<std::decay_t<LHS>,
double> ||
744 !std::same_as<std::decay_t<RHS>,
double>)
757struct NumTraits<
sleipnir::Variable> : NumTraits<double> {
766 RequireInitialization = 1,
#define Assert(condition)
Definition Assert.hpp:24
#define SLEIPNIR_DLLEXPORT
Definition SymbolExports.hpp:34
Definition Hessian.hpp:24
Definition Jacobian.hpp:25
Definition Variable.hpp:33
friend SLEIPNIR_DLLEXPORT Variable operator+(const Variable &lhs)
Definition Variable.hpp:206
friend SLEIPNIR_DLLEXPORT Variable operator*(const Variable &lhs, const Variable &rhs)
Definition Variable.hpp:114
Variable & operator*=(const Variable &rhs)
Definition Variable.hpp:124
friend SLEIPNIR_DLLEXPORT Variable operator-(const Variable &lhs)
Definition Variable.hpp:197
friend SLEIPNIR_DLLEXPORT Variable operator+(const Variable &lhs, const Variable &rhs)
Definition Variable.hpp:156
friend SLEIPNIR_DLLEXPORT Variable operator-(const Variable &lhs, const Variable &rhs)
Definition Variable.hpp:177
ExpressionType Type() const
Definition Variable.hpp:219
Variable(std::floating_point auto value)
Definition Variable.hpp:50
Variable & operator=(double value)
Definition Variable.hpp:81
constexpr Variable(std::nullptr_t)
Definition Variable.hpp:43
Variable & operator-=(const Variable &rhs)
Definition Variable.hpp:187
Variable(const detail::ExpressionPtr &expr)
Definition Variable.hpp:66
friend SLEIPNIR_DLLEXPORT Variable operator/(const Variable &lhs, const Variable &rhs)
Definition Variable.hpp:135
Variable(std::integral auto value)
Definition Variable.hpp:58
Variable & operator+=(const Variable &rhs)
Definition Variable.hpp:166
Variable & operator/=(const Variable &rhs)
Definition Variable.hpp:145
void SetValue(double value)
Definition Variable.hpp:92
constexpr Variable(detail::ExpressionPtr &&expr)
Definition Variable.hpp:73
Definition ExpressionGraph.hpp:19
Definition small_vector.hpp:3616
constexpr iterator insert(const_iterator pos, const_reference value) &&CopyAssignable
Definition small_vector.hpp:3981
constexpr void reserve(size_type new_capacity)
Definition small_vector.hpp:4082
::value &&MoveInsertable constexpr reference emplace_back(Args &&... args)
Definition small_vector.hpp:4071
constexpr iterator end() noexcept
Definition small_vector.hpp:3898
constexpr iterator begin() noexcept
Definition small_vector.hpp:3890
Definition Concepts.hpp:25
Definition Concepts.hpp:28
Definition Concepts.hpp:12
Definition Variable.hpp:751
ExpressionPtr abs(const ExpressionPtr &x)
Definition Expression.hpp:736
ExpressionPtr log(const ExpressionPtr &x)
Definition Expression.hpp:1238
ExpressionPtr exp(const ExpressionPtr &x)
Definition Expression.hpp:1129
ExpressionPtr tanh(const ExpressionPtr &x)
Definition Expression.hpp:1683
ExpressionPtr atan(const ExpressionPtr &x)
Definition Expression.hpp:879
ExpressionPtr sinh(const ExpressionPtr &x)
Definition Expression.hpp:1538
ExpressionPtr log10(const ExpressionPtr &x)
Definition Expression.hpp:1286
ExpressionPtr pow(const ExpressionPtr &base, const ExpressionPtr &power)
Definition Expression.hpp:1370
ExpressionPtr sign(const ExpressionPtr &x)
Definition Expression.hpp:1443
ExpressionPtr atan2(const ExpressionPtr &y, const ExpressionPtr &x)
Definition Expression.hpp:939
ExpressionPtr asin(const ExpressionPtr &x)
Definition Expression.hpp:832
ExpressionPtr erf(const ExpressionPtr &x)
Definition Expression.hpp:1082
ExpressionPtr sin(const ExpressionPtr &x)
Definition Expression.hpp:1491
ExpressionPtr tan(const ExpressionPtr &x)
Definition Expression.hpp:1635
ExpressionPtr acos(const ExpressionPtr &x)
Definition Expression.hpp:785
ExpressionPtr cosh(const ExpressionPtr &x)
Definition Expression.hpp:1034
ExpressionPtr cos(const ExpressionPtr &x)
Definition Expression.hpp:988
ExpressionPtr sqrt(const ExpressionPtr &x)
Definition Expression.hpp:1586
ExpressionPtr hypot(const ExpressionPtr &x, const ExpressionPtr &y)
Definition Expression.hpp:1190
Definition Expression.hpp:18
IntrusiveSharedPtr< T > AllocateIntrusiveShared(Alloc alloc, Args &&... args)
Definition IntrusiveSharedPtr.hpp:275
SLEIPNIR_DLLEXPORT Variable sin(const Variable &x)
Definition Variable.hpp:391
SLEIPNIR_DLLEXPORT Variable tanh(const Variable &x)
Definition Variable.hpp:427
SLEIPNIR_DLLEXPORT Variable asin(const Variable &x)
Definition Variable.hpp:279
SLEIPNIR_DLLEXPORT Variable cosh(const Variable &x)
Definition Variable.hpp:316
SLEIPNIR_DLLEXPORT Variable sign(const Variable &x)
Definition Variable.hpp:382
ExpressionType
Definition ExpressionType.hpp:14
SLEIPNIR_DLLEXPORT Variable atan2(const Variable &y, const Variable &x)
Definition Variable.hpp:298
SLEIPNIR_DLLEXPORT Variable erf(const Variable &x)
Definition Variable.hpp:325
SLEIPNIR_DLLEXPORT Variable sinh(const Variable &x)
Definition Variable.hpp:400
void println(std::format_string< T... > fmt, T &&... args)
Definition Print.hpp:38
SLEIPNIR_DLLEXPORT Variable abs(const Variable &x)
Definition Variable.hpp:261
small_vector< Variable > MakeConstraints(LHS &&lhs, RHS &&rhs)
Definition Variable.hpp:460
SLEIPNIR_DLLEXPORT Variable log(const Variable &x)
Definition Variable.hpp:364
SLEIPNIR_DLLEXPORT Variable pow(const Variable &base, const Variable &power)
Definition Variable.hpp:354
SLEIPNIR_DLLEXPORT Variable hypot(const Variable &x, const Variable &y)
Definition Variable.hpp:344
SLEIPNIR_DLLEXPORT Variable atan(const Variable &x)
Definition Variable.hpp:288
SLEIPNIR_DLLEXPORT Variable cos(const Variable &x)
Definition Variable.hpp:307
SLEIPNIR_DLLEXPORT Variable tan(const Variable &x)
Definition Variable.hpp:418
SLEIPNIR_DLLEXPORT Variable sqrt(const Variable &x)
Definition Variable.hpp:409
SLEIPNIR_DLLEXPORT Variable exp(const Variable &x)
Definition Variable.hpp:334
SLEIPNIR_DLLEXPORT Variable log10(const Variable &x)
Definition Variable.hpp:373
SLEIPNIR_DLLEXPORT Variable acos(const Variable &x)
Definition Variable.hpp:270
Definition Variable.hpp:547
EqualityConstraints(std::initializer_list< EqualityConstraints > equalityConstraints)
Definition Variable.hpp:556
EqualityConstraints(LHS &&lhs, RHS &&rhs)
Definition Variable.hpp:593
EqualityConstraints(const std::vector< EqualityConstraints > &equalityConstraints)
Definition Variable.hpp:571
small_vector< Variable > constraints
A vector of scalar equality constraints.
Definition Variable.hpp:549
Definition Variable.hpp:609
small_vector< Variable > constraints
A vector of scalar inequality constraints.
Definition Variable.hpp:611
InequalityConstraints(std::initializer_list< InequalityConstraints > inequalityConstraints)
Definition Variable.hpp:619
InequalityConstraints(LHS &&lhs, RHS &&rhs)
Definition Variable.hpp:657
InequalityConstraints(const std::vector< InequalityConstraints > &inequalityConstraints)
Definition Variable.hpp:635