7template <
typename Derived>
8auto blockMatrixGetRow(
const Eigen::MatrixBase<Derived> &matrix,
9 const std::vector<Eigen::Index> &rowBlockSizes,
11 Eigen::Index startIdx = 0;
12 for (std::size_t kk = 0; kk < rowIdx; kk++) {
13 startIdx += rowBlockSizes[kk];
15 return matrix.const_cast_derived().middleRows(startIdx,
16 rowBlockSizes[rowIdx]);
19template <
typename Derived>
20auto blockVectorGetRow(
const Eigen::MatrixBase<Derived> &matrix,
21 const std::vector<Eigen::Index> &blockSizes,
22 std::size_t blockIdx) {
23 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived);
24 Eigen::Index startIdx = 0;
25 for (std::size_t kk = 0; kk < blockIdx; kk++) {
26 startIdx += blockSizes[kk];
28 return matrix.const_cast_derived().segment(startIdx, blockSizes[blockIdx]);
35template <
typename Scalar>
36struct ConstraintSetProductTpl : ConstraintSetTpl<Scalar> {
38 using Base = ConstraintSetTpl<Scalar>;
39 using ActiveType =
typename Base::ActiveType;
41 ConstraintSetProductTpl(
const std::vector<xyz::polymorphic<Base>> components,
42 const std::vector<Eigen::Index> &blockSizes)
43 : m_components(components), m_blockSizes(blockSizes) {
44 if (components.size() != blockSizes.size()) {
45 PROXSUITE_NLP_RUNTIME_ERROR(
"Number of components and corresponding "
46 "block sizes should be the same.");
50 ConstraintSetProductTpl(
const ConstraintSetProductTpl &) =
default;
51 ConstraintSetProductTpl &operator=(
const ConstraintSetProductTpl &) =
default;
52 ConstraintSetProductTpl(ConstraintSetProductTpl &&) =
default;
53 ConstraintSetProductTpl &operator=(ConstraintSetProductTpl &&) =
default;
55 Scalar
evaluate(
const ConstVectorRef &zproj)
const override {
57 for (std::size_t i = 0; i < m_components.size(); i++) {
58 auto zblock = blockVectorGetRow(zproj, m_blockSizes, i);
59 res += m_components[i]->evaluate(zblock);
64 void projection(
const ConstVectorRef &z, VectorRef zout)
const override {
65 for (std::size_t i = 0; i < m_components.size(); i++) {
66 ConstVectorRef inblock = blockVectorGetRow(z, m_blockSizes, i);
67 VectorRef outblock = blockVectorGetRow(zout, m_blockSizes, i);
68 m_components[i]->projection(inblock, outblock);
73 VectorRef zout)
const override {
74 for (std::size_t i = 0; i < m_components.size(); i++) {
75 ConstVectorRef inblock = blockVectorGetRow(z, m_blockSizes, i);
76 VectorRef outblock = blockVectorGetRow(zout, m_blockSizes, i);
77 m_components[i]->normalConeProjection(inblock, outblock);
82 MatrixRef Jout)
const override {
83 for (std::size_t i = 0; i < m_components.size(); i++) {
84 ConstVectorRef inblock = blockVectorGetRow(z, m_blockSizes, i);
85 MatrixRef outblock = blockMatrixGetRow(Jout, m_blockSizes, i);
86 m_components[i]->applyProjectionJacobian(inblock, outblock);
91 MatrixRef Jout)
const override {
92 for (std::size_t i = 0; i < m_components.size(); i++) {
93 ConstVectorRef inblock = blockVectorGetRow(z, m_blockSizes, i);
94 MatrixRef outblock = blockMatrixGetRow(Jout, m_blockSizes, i);
95 m_components[i]->applyNormalConeProjectionJacobian(inblock, outblock);
100 Eigen::Ref<ActiveType> out)
const override {
101 for (std::size_t i = 0; i < m_components.size(); i++) {
102 ConstVectorRef inblock = blockVectorGetRow(z, m_blockSizes, i);
103 decltype(out) outblock = blockVectorGetRow(out, m_blockSizes, i);
104 m_components[i]->computeActiveSet(inblock, outblock);
108 const std::vector<xyz::polymorphic<Base>> &components()
const {
111 const std::vector<Eigen::Index> &blockSizes()
const {
return m_blockSizes; }
114 std::vector<xyz::polymorphic<Base>> m_components;
115 std::vector<Eigen::Index> m_blockSizes;
118#ifdef PROXSUITE_NLP_ENABLE_TEMPLATE_INSTANTIATION
119extern template struct PROXSUITE_NLP_EXPLICIT_INSTANTIATION_DECLARATION_DLLAPI
#define PROXSUITE_NLP_DYNAMIC_TYPEDEFS(Scalar)
Cartesian product of multiple constraint sets. This class makes computing multipliers and Jacobian ma...
void computeActiveSet(const ConstVectorRef &z, Eigen::Ref< ActiveType > out) const override
void applyNormalConeProjectionJacobian(const ConstVectorRef &z, MatrixRef Jout) const override
Apply the jacobian of the projection on the normal cone.
void normalConeProjection(const ConstVectorRef &z, VectorRef zout) const override
Compute projection of z onto the normal cone to the set. The default implementation is just .
void applyProjectionJacobian(const ConstVectorRef &z, MatrixRef Jout) const override
Apply a jacobian of the projection/proximal operator to a matrix.
void projection(const ConstVectorRef &z, VectorRef zout) const override
Compute projection of variable z onto the constraint set.
Scalar evaluate(const ConstVectorRef &zproj) const override