humoto
constraints_mixins.h
Go to the documentation of this file.
1 /**
2  @file
3  @author Alexander Sherikov
4  @copyright 2014-2017 INRIA. Licensed under the Apache License, Version 2.0.
5  (see @ref LICENSE or http://www.apache.org/licenses/LICENSE-2.0)
6 
7  @brief
8 */
9 
10 #pragma once
11 
12 namespace humoto
13 {
14  namespace constraints
15  {
16  /**
17  * @defgroup ConstraintsBounds Implementation of bounds
18  *
19  * @ingroup ConstraintsImplementation
20  *
21  * A set of mixins which implement bounds of constraints.
22  */
23 
24  /**
25  * @addtogroup ConstraintsBounds
26  * @{
27  */
28 
29  /**
30  * @brief Mixin representing vector 'b = 0' in an equality constraint.
31  *
32  * @tparam t_Base Base class: @ref humoto::constraints::ConstraintsBase or
33  * @ref humoto::TaskBase wrapped with other mixins.
34  */
35  template <class t_Base>
37  {
38  protected:
39  /**
40  * @brief Protected destructor: prevent destruction of the child
41  * classes through a base pointer.
42  */
45 
46 
47  /// @copydoc humoto::constraints::ContainerBase::resetBounds
48  void resetBounds ( const std::size_t number_of_constraints = 0,
49  const bool initialize_matrices = false)
50  {
51  // nothing to do
52  }
53 
54 
55  /// @copydoc humoto::constraints::ContainerBase::logBounds
57  const LogEntryName &parent = LogEntryName(),
58  const std::string &name = "constraints") const
59  {
60  // nothing to do
61  }
62 
63 
64  /**
65  * @brief Compute 'A^T * b' for general equality constaints and
66  * save or add the result to g.
67  *
68  * @param[in,out] g result
69  */
70  void getATb(Eigen::VectorXd &g) const
71  {
72  g.setZero(t_Base::getNumberOfVariables());
73  }
74 
75 
76  /// @copydoc getATb
77  void addATb(Eigen::VectorXd &g) const
78  {
79  // nothing to do
80  }
81 
82 
83  /**
84  * @brief Copy b
85  *
86  * @param[in,out] b
87  * @param[in] location
88  */
89  void copyEqualityBoundsTo( Eigen::VectorXd & b,
90  const Location & location) const
91  {
92  b.segment(location.offset_, location.length_).setZero();
93  }
94 
95 
96  public:
97  /// @copydoc humoto::constraints::ConstraintsBase::copyBoundsTo
98  void copyBoundsTo( Eigen::VectorXd & lb,
99  Eigen::VectorXd & ub,
100  const Location & location) const
101  {
102  lb.segment(location.offset_, location.length_).setZero();
103  ub.segment(location.offset_, location.length_).setZero();
104  }
105  };
106 
107 
108  /**
109  * @brief Mixin representing vector 'b' in an equality constraint.
110  *
111  * @tparam t_Base Base class: @ref humoto::constraints::ConstraintsBase or
112  * @ref humoto::TaskBase wrapped with other mixins.
113  */
114  template <class t_Base>
116  {
117  protected:
118  Eigen::VectorXd b_;
119 
120 
121  protected:
122  /**
123  * @brief Protected destructor: prevent destruction of the child
124  * classes through a base pointer.
125  */
128 
129 
130  /**
131  * @copydoc humoto::constraints::ContainerBase::resetBounds
132  * @note Initialization: b is filled with zeros
133  */
134  void resetBounds ( const std::size_t number_of_constraints = 0,
135  const bool initialize_matrices = false)
136  {
137  if (initialize_matrices)
138  {
139  b_.setZero(number_of_constraints);
140  }
141  else
142  {
143  b_.resize(number_of_constraints);
144  }
145  }
146 
147 
148  /// @copydoc humoto::constraints::ContainerBase::logBounds
150  const LogEntryName &parent = LogEntryName(),
151  const std::string &name = "constraints") const
152  {
153  logger.log(LogEntryName(parent).add(name).add("b"), b_);
154  }
155 
156 
157  /**
158  * @brief Copy b
159  *
160  * @param[in,out] b
161  * @param[in] location
162  */
163  void copyEqualityBoundsTo( Eigen::VectorXd & b,
164  const Location & location) const
165  {
166  b.segment(location.offset_, location.length_) = b_;
167  }
168 
169 
170  public:
171  /**
172  * @brief Get vector b from equalities: 'A*x = b' or 'x = b'.
173  *
174  * @return Vector b.
175  */
176  Eigen::VectorXd & getB()
177  {
178  return (b_);
179  }
180 
181 
182  /// @copydoc getB
183  const Eigen::VectorXd & getB() const
184  {
185  return (b_);
186  }
187 
188 
189  /// @copydoc humoto::constraints::ConstraintsBase::copyBoundsTo
190  void copyBoundsTo( Eigen::VectorXd & lb,
191  Eigen::VectorXd & ub,
192  const Location & location) const
193  {
194  lb.segment(location.offset_, location.length_) = b_;
195  ub.segment(location.offset_, location.length_) = b_;
196  }
197  };
198 
199 
200  /**
201  * @brief Mixin representing lower bound in an inequality constraint.
202  *
203  * @tparam t_Base Base class: @ref humoto::constraints::ConstraintsBase or
204  * @ref humoto::TaskBase wrapped with other mixins.
205  */
206  template <class t_Base>
208  {
209  protected:
210  Eigen::VectorXd lb_;
211 
212 
213  protected:
214  /**
215  * @brief Protected destructor: prevent destruction of the child
216  * classes through a base pointer.
217  */
220 
221 
222  /**
223  * @copydoc humoto::constraints::ContainerBase::resetBounds
224  * @note Initialization: lb is set to -humoto::g_infinity
225  */
226  void resetBounds (const std::size_t number_of_constraints, const bool initialize_matrices = false)
227  {
228  if (initialize_matrices)
229  {
230  lb_.setConstant(number_of_constraints, -humoto::g_infinity);
231  }
232  else
233  {
234  lb_.resize(number_of_constraints);
235  }
236  }
237 
238 
239  /// @copydoc humoto::constraints::ContainerBase::logBounds
241  const LogEntryName &parent = LogEntryName(),
242  const std::string &name = "constraints") const
243  {
244  logger.log(LogEntryName(parent).add(name).add("lb"), lb_);
245  }
246 
247 
248  public:
249  /**
250  * @brief Get lower bounds (lb/ub vectors from 'lb <= A*x <= ub').
251  *
252  * @return lower bounds.
253  */
254  Eigen::VectorXd & getLowerBounds()
255  {
256  return (lb_);
257  }
258 
259  /// @copydoc getLowerBounds
260  const Eigen::VectorXd & getLowerBounds() const
261  {
262  return (lb_);
263  }
264 
265 
266  /// @copydoc humoto::constraints::ConstraintsBase::copyBoundsTo
267  void copyBoundsTo( Eigen::VectorXd & lb,
268  Eigen::VectorXd & ub,
269  const Location & location) const
270  {
271  lb.segment(location.offset_, location.length_) = lb_;
272  ub.segment(location.offset_, location.length_).setConstant(humoto::g_infinity);
273  }
274  };
275 
276 
277 
278  /**
279  * @brief Mixin representing upper bound in an inequality constraint.
280  *
281  * @tparam t_Base Base class: @ref humoto::constraints::ConstraintsBase or
282  * @ref humoto::TaskBase wrapped with other mixins.
283  */
284  template <class t_Base>
286  {
287  protected:
288  Eigen::VectorXd ub_;
289 
290 
291  protected:
292  /**
293  * @brief Protected destructor: prevent destruction of the child
294  * classes through a base pointer.
295  */
298 
299 
300  /**
301  * @copydoc humoto::constraints::ContainerBase::resetBounds
302  * @note Initialization: ub is set to humoto::g_infinity
303  */
304  void resetBounds (const std::size_t number_of_constraints, const bool initialize_matrices = false)
305  {
306  if (initialize_matrices)
307  {
308  ub_.setConstant(number_of_constraints, humoto::g_infinity);
309  }
310  else
311  {
312  ub_.resize(number_of_constraints);
313  }
314  }
315 
316 
317  /// @copydoc humoto::constraints::ContainerBase::logBounds
319  const LogEntryName &parent = LogEntryName(),
320  const std::string &name = "constraints") const
321  {
322  logger.log(LogEntryName(parent).add(name).add("ub"), ub_);
323  }
324 
325 
326 
327  public:
328  /**
329  * @brief Get upper bounds (ub vectors from 'A*x <= ub').
330  *
331  * @return upper bounds.
332  */
333  Eigen::VectorXd & getUpperBounds()
334  {
335  return (ub_);
336  }
337 
338 
339  /// @copydoc getUpperBounds
340  const Eigen::VectorXd & getUpperBounds() const
341  {
342  return (ub_);
343  }
344 
345 
346  /// @copydoc humoto::constraints::ConstraintsBase::copyBoundsTo
347  void copyBoundsTo( Eigen::VectorXd & lb,
348  Eigen::VectorXd & ub,
349  const Location & location) const
350  {
351  lb.segment(location.offset_, location.length_).setConstant(-humoto::g_infinity);
352  ub.segment(location.offset_, location.length_) = ub_;
353  }
354  };
355 
356 
357 
358  /**
359  * @brief Mixin representing upper bound in an inequality constraint.
360  *
361  * @tparam t_Base Base class: @ref humoto::constraints::ConstraintsBase or
362  * @ref humoto::TaskBase wrapped with other mixins.
363  */
364  template <class t_Base>
365  class HUMOTO_LOCAL BoundsLUMixin : public BoundsLMixin< BoundsUMixin <t_Base> >
366  {
367  protected:
368  /**
369  * @brief Protected destructor: prevent destruction of the child
370  * classes through a base pointer.
371  */
374 
375 
376  /**
377  * @copydoc humoto::constraints::ContainerBase::resetBounds
378  * @note Initialization: lb is set to -humoto::g_infinity, ub is set to humoto::g_infinity
379  */
380  void resetBounds (const std::size_t number_of_constraints, const bool initialize_matrices = false)
381  {
382  BoundsLMixin< BoundsUMixin <t_Base> >::resetBounds(number_of_constraints, initialize_matrices);
383  BoundsUMixin <t_Base> ::resetBounds(number_of_constraints, initialize_matrices);
384  }
385 
386 
387  /// @copydoc humoto::constraints::ContainerBase::logBounds
389  const LogEntryName &parent = LogEntryName(),
390  const std::string &name = "constraints") const
391  {
392  LogEntryName subname = parent;
393  subname.add(name);
394  BoundsLMixin< BoundsUMixin <t_Base> >::logBounds(logger, subname, "");
395  BoundsUMixin <t_Base> ::logBounds(logger, subname, "");
396  }
397 
398 
399  public:
400  /// @copydoc humoto::constraints::ConstraintsBase::copyBoundsTo
401  void copyBoundsTo( Eigen::VectorXd & lb,
402  Eigen::VectorXd & ub,
403  const Location & location) const
404  {
405  lb.segment(location.offset_, location.length_) =
406  BoundsLMixin< BoundsUMixin <t_Base> >::getLowerBounds();
407  ub.segment(location.offset_, location.length_) =
409  }
410  };
411  /// @}
412 
413 
414  // ======================================================================================
415  // ======================================================================================
416  // ======================================================================================
417 
418  /**
419  * @defgroup ConstraintsBodies Implementation of bodies
420  *
421  * @ingroup ConstraintsImplementation
422  *
423  * A set of mixins which implement bodies of constraints.
424  */
425 
426  /**
427  * @addtogroup ConstraintsBodies
428  * @{
429  */
430 
431  /**
432  * @brief Mixin representing matrix 'A' in a general constraint.
433  *
434  * @tparam t_Base Base class: @ref humoto::constraints::ConstraintsBase or
435  * @ref humoto::TaskBase wrapped with other mixins.
436  */
437  template <class t_Base>
439  {
440  protected:
441  Eigen::MatrixXd A_;
442 
443 
444  protected:
445  /**
446  * @brief Protected destructor: prevent destruction of the child
447  * classes through a base pointer.
448  */
451 
452 
453  /**
454  * @brief Initialize A
455  *
456  * @param[in] number_of_constraints number of constraints
457  * @param[in] initialize_matrices initialize matrices using defaults
458  *
459  * Initialization:
460  * - A is filled with zeros
461  */
462  void resetBody (const std::size_t number_of_constraints, const bool initialize_matrices = false)
463  {
464  if (initialize_matrices)
465  {
466  A_.setZero(number_of_constraints, t_Base::getNumberOfVariables());
467  }
468  else
469  {
470  A_.resize(number_of_constraints, t_Base::getNumberOfVariables());
471  }
472  }
473 
474 
475  /// @copydoc humoto::constraints::ContainerBase::logBody
477  const LogEntryName &parent = LogEntryName(),
478  const std::string &name = "constraints") const
479  {
480  logger.log(LogEntryName(parent).add(name).add("A"), A_);
481  }
482 
483 
484 
485  /**
486  * @brief Compute 'A^T * A' for general equality constaints and
487  * save or add the result to H.
488  *
489  * @param[in,out] H left lower triangular part of the result.
490  *
491  * @attention Only the left lower triangular part of H is formed.
492  * Apply appropriate conversion with
493  * etools::convertLLTtoSymmetric() before using H.
494  */
495  void getATA(Eigen::MatrixXd &H) const
496  {
497  //H.noalias() = A_.transpose()*A_;
498  etools::getATA(H, A_);
499  }
500 
501 
502  /// @copydoc humoto::constraints::BodyAMixin::getATA
503  void addATA(Eigen::MatrixXd &H) const
504  {
505  //H.noalias() += A_.transpose()*A_;
506  etools::addATA(H, A_);
507  }
508 
509 
510  public:
511  // Access matrices
512  /**
513  * @brief Get matrix A from general constraints: 'A*x = b', 'lb <= A*x <= ub'.
514  *
515  * @return matrix A
516  */
517  Eigen::MatrixXd & getA()
518  {
519  return (A_);
520  }
521 
522  /// @copydoc getA
523  const Eigen::MatrixXd & getA() const
524  {
525  return (A_);
526  }
527 
528 
529  /// @copydoc humoto::constraints::ConstraintsBase::copyBodyTo
530  void copyBodyTo(Eigen::MatrixXd & A, const Location & location) const
531  {
532  HUMOTO_ASSERT( A_.cols() == A.cols(),
533  "Numbers of columns in constraint matrices do not match.");
534 
535  A.block(location.offset_, 0, location.length_, A_.cols()) = A_;
536  }
537 
538 
539  /// @copydoc humoto::constraints::ConstraintsBase::copyBodyTo
540  void copyNegativeBodyTo(Eigen::MatrixXd & A, const Location & location) const
541  {
542  HUMOTO_ASSERT( A_.cols() == A.cols(),
543  "Numbers of columns in constraint matrices do not match.");
544 
545  A.block(location.offset_, 0, location.length_, A_.cols()) = -A_;
546  }
547 
548 
549  /// @copydoc humoto::constraints::ConstraintsBase::getNumberOfConstraints
550  std::size_t getNumberOfConstraints() const
551  {
552  return (A_.rows());
553  }
554 
555 
556  /**
557  * @brief Compute A(i,:) * vector
558  *
559  * @param[in] i row index
560  * @param[in] vector vector
561  *
562  * @return result of multiplication
563  */
564  double getProduct( const std::size_t i,
565  const Eigen::VectorXd & vector) const
566  {
567  return(A_.row(i) * vector);
568  }
569  };
570 
571 
572 
573  /**
574  * @brief Mixin representing matrix 'A*S' in a general constraint.
575  *
576  * @tparam t_Base Base class: @ref humoto::constraints::ConstraintsBase or
577  * @ref humoto::TaskBase wrapped with other mixins.
578  */
579  template <class t_Base>
581  {
582  protected:
583  Eigen::MatrixXd A_;
584  std::ptrdiff_t offset_;
585 
586 
587  protected:
588  /**
589  * @brief Protected destructor: prevent destruction of the child
590  * classes through a base pointer.
591  */
594  {
595  offset_ = 0;
596  }
597 
598 
599  /**
600  * @brief Initialize A
601  *
602  * @param[in] number_of_constraints number of constraints
603  * @param[in] initialize_matrices initialize matrices using defaults
604  *
605  * Initialization:
606  * - A is filled with zeros
607  */
608  void resetBody (const std::size_t number_of_constraints, const bool initialize_matrices = false)
609  {
610  offset_ = 0;
611  if (initialize_matrices)
612  {
613  A_.setZero(number_of_constraints, t_Base::getNumberOfVariables());
614  }
615  else
616  {
617  A_.resize(number_of_constraints, t_Base::getNumberOfVariables());
618  }
619  }
620 
621 
622  /// @copydoc humoto::constraints::ContainerBase::logBody
624  const LogEntryName &parent = LogEntryName(),
625  const std::string &name = "constraints") const
626  {
627  logger.log(LogEntryName(parent).add(name).add("A"), A_);
628  logger.log(LogEntryName(parent).add(name).add("offset"), offset_);
629  }
630 
631 
632 
633  /// @copydoc humoto::constraints::BodyAMixin::getATA
634  void getATA(Eigen::MatrixXd &H) const
635  {
636  etools::getATA(H, A_, offset_, t_Base::getNumberOfVariables());
637  }
638 
639 
640  /// @copydoc humoto::constraints::BodyAMixin::getATA
641  void addATA(Eigen::MatrixXd &H) const
642  {
643  etools::addATA(H, A_, offset_);
644  }
645 
646 
647  public:
648  // Access matrices
649  /**
650  * @brief Get matrix A from general constraints: 'A*x = b', 'lb <= A*x <= ub'.
651  *
652  * @return matrix A
653  */
654  Eigen::MatrixXd & getA()
655  {
656  return (A_);
657  }
658 
659  /// @copydoc getA
660  const Eigen::MatrixXd & getA() const
661  {
662  return (A_);
663  }
664 
665 
666  /**
667  * @brief Get offset of body part in the constriaints.
668  *
669  * @return offset
670  */
671  std::ptrdiff_t getOffset() const
672  {
673  return (offset_);
674  }
675 
676 
677  /**
678  * @brief Set offset of body part in the constriaints.
679  *
680  * @param[in] offset
681  */
682  void setOffset(const std::ptrdiff_t offset)
683  {
684  offset_ = offset;
685  }
686 
687 
688  /// @copydoc humoto::constraints::ConstraintsBase::copyBodyTo
689  void copyBodyTo(Eigen::MatrixXd & A, const Location & location) const
690  {
691  HUMOTO_ASSERT( (t_Base::getNumberOfVariables() == static_cast<std::size_t>(A.cols()))
692  && (offset_ + A_.cols() <= A.cols()),
693  "Numbers of columns in constraint matrices do not match.");
694 
695  std::ptrdiff_t right_space_size = t_Base::getNumberOfVariables() - offset_ - A_.cols();
696 
697  A.middleRows(location.offset_, location.length_)
698  << Eigen::MatrixXd::Zero(location.length_, offset_),
699  A_,
700  Eigen::MatrixXd::Zero(location.length_, right_space_size);
701  }
702 
703 
704  /// @copydoc humoto::constraints::ConstraintsBase::copyBodyTo
705  void copyNegativeBodyTo(Eigen::MatrixXd & A, const Location & location) const
706  {
707  HUMOTO_ASSERT( (t_Base::getNumberOfVariables() == static_cast<std::size_t>(A.cols()))
708  && (offset_ + A_.cols() <= A.cols()),
709  "Numbers of columns in constraint matrices do not match.");
710 
711  std::ptrdiff_t right_space_size = t_Base::getNumberOfVariables() - offset_ - A_.cols();
712 
713  A.middleRows(location.offset_, location.length_)
714  << Eigen::MatrixXd::Zero(location.length_, offset_),
715  -A_,
716  Eigen::MatrixXd::Zero(location.length_, right_space_size);
717  }
718 
719 
720  /// @copydoc humoto::constraints::ConstraintsBase::getNumberOfConstraints
721  std::size_t getNumberOfConstraints() const
722  {
723  return (A_.rows());
724  }
725 
726 
727  /// @copydoc humoto::constraints::BodyAMixin::getProduct
728  double getProduct( const std::size_t i,
729  const Eigen::VectorXd & vector) const
730  {
731  return(A_.row(i) * vector.segment(offset_, A_.cols()));
732  }
733  };
734 
735 
736  /**
737  * @brief Mixin representing matrix of indices 'I' in a simple constraint.
738  *
739  * @tparam t_Base Base class: @ref humoto::constraints::ConstraintsBase or
740  * @ref humoto::TaskBase wrapped with other mixins.
741  */
742  template <class t_Base>
744  {
745  protected:
746  humoto::IndexVector I_; // vector of indices
747 
748 
749  protected:
750  /**
751  * @brief Protected destructor: prevent destruction of the child
752  * classes through a base pointer.
753  */
755 
756 
757  /**
758  * @brief Default constructor
759  */
761 
762 
763 
764 
765  /**
766  * @brief Initialize I and gains
767  *
768  * @param[in] number_of_constraints number of constraints
769  * @param[in] initialize_matrices initialize matrices using defaults
770  */
771  virtual void resetBody( const std::size_t number_of_constraints = 0,
772  const bool initialize_matrices = false)
773  {
774  I_.resize(number_of_constraints);
775  }
776 
777 
778 
779  /// @copydoc humoto::constraints::ContainerBase::logBody
781  const LogEntryName &parent = LogEntryName(),
782  const std::string &name = "constraints") const
783  {
784  logger.log(LogEntryName(parent).add(name).add("A"), I_);
785  }
786 
787 
788  /// @copydoc humoto::constraints::BodyAMixin::getATA
789  void getATA(Eigen::MatrixXd &H) const
790  {
791  //H.setZero(getNumberOfVariables(), getNumberOfVariables());
792  H.resize(getNumberOfVariables(), getNumberOfVariables());
793  H.triangularView<Eigen::Lower>().setZero();
794  addATA(H);
795  }
796 
797 
798  /// @copydoc humoto::constraints::BodyAMixin::getATA
799  void addATA(Eigen::MatrixXd &H) const
800  {
801  for (EigenIndex i = 0; i < I_.rows(); ++i)
802  {
803  H(I_[i], I_[i]) += 1;
804  }
805  }
806 
807 
808  public:
809  using t_Base::getNumberOfVariables;
810 
811 
812 
813  /// @copydoc humoto::constraints::ConstraintsBase::copyBodyTo
814  virtual void copyBodyTo(Eigen::MatrixXd & A, const Location & location) const
815  {
816  HUMOTO_ASSERT( static_cast<std::size_t>(A.cols()) == getNumberOfVariables(),
817  "Wrong number of variables.");
818  HUMOTO_ASSERT( static_cast<std::size_t>(I_.rows()) == location.length_,
819  "Wrong number of constraints.");
820 
821  A.block(location.offset_, 0, location.length_, getNumberOfVariables()).setZero();
822 
823  for (std::size_t i = 0; i < location.length_; ++i)
824  {
825  A(location.offset_ + i, I_[i]) = 1.0;
826  }
827  }
828 
829 
830  /// @copydoc humoto::constraints::ConstraintsBase::copyBodyTo
831  virtual void copyNegativeBodyTo(Eigen::MatrixXd & A, const Location & location) const
832  {
833  HUMOTO_ASSERT( static_cast<std::size_t>(A.cols()) == getNumberOfVariables(),
834  "Wrong number of variables.");
835  HUMOTO_ASSERT( static_cast<std::size_t>(I_.rows()) == location.length_,
836  "Wrong number of constraints.");
837 
838  A.block(location.offset_, 0, location.length_, getNumberOfVariables()).setZero();
839 
840  for (std::size_t i = 0; i < location.length_; ++i)
841  {
842  A(location.offset_ + i, I_[i]) = -1.0;
843  }
844  }
845 
846 
847  /**
848  * @brief Get indices
849  *
850  * @return indices
851  */
853  {
854  return (I_);
855  }
856 
857 
858  /// @copydoc getIndices
860  {
861  return (I_);
862  }
863 
864 
865  /// @copydoc humoto::constraints::ConstraintsBase::getNumberOfConstraints
866  std::size_t getNumberOfConstraints() const
867  {
868  return (I_.rows());
869  }
870 
871 
872  /// @copydoc humoto::constraints::BodyAMixin::getProduct
873  double getProduct( const std::size_t i,
874  const Eigen::VectorXd & vector) const
875  {
876  return(vector(I_(i)));
877  }
878  };
879 
880 
881 
882  /**
883  * @brief Mixin representing matrix of indices 'I' and matrix of gains 'G'
884  * in a simple constraint.
885  *
886  * @tparam t_Base Base class: @ref humoto::constraints::ConstraintsBase or
887  * @ref humoto::TaskBase wrapped with other mixins.
888  */
889  template <class t_Base>
890  class HUMOTO_LOCAL BodyGIMixin : public BodyIMixin<t_Base>
891  {
892  protected:
894  Eigen::VectorXd I_gains_;
895 
896 
897  protected:
898  /**
899  * @brief Protected destructor: prevent destruction of the child
900  * classes through a base pointer.
901  */
904 
905 
906  /**
907  * @brief Initialize I and gains
908  *
909  * @param[in] number_of_constraints number of constraints
910  * @param[in] initialize_matrices initialize matrices using defaults
911  */
912  void resetBody( const std::size_t number_of_constraints = 0,
913  const bool initialize_matrices = false)
914  {
915  BodyIMixin<t_Base>::resetBody(number_of_constraints, initialize_matrices);
916  I_gains_.setConstant(number_of_constraints, 1.0);
917  }
918 
919 
920 
921  /// @copydoc humoto::constraints::ContainerBase::logBody
923  const LogEntryName &parent = LogEntryName(),
924  const std::string &name = "constraints") const
925  {
926  LogEntryName subname = parent;
927  subname.add(name);
928  BodyIMixin<t_Base>::logBody(logger, subname, "");
929  logger.log(LogEntryName(subname).add("Agains"), I_gains_);
930  }
931 
932 
933 
934  /// @copydoc humoto::constraints::BodyAMixin::getATA
935  void getATA(Eigen::MatrixXd &H) const
936  {
937  //H.setZero(getNumberOfVariables(), getNumberOfVariables());
938  H.resize(getNumberOfVariables(), getNumberOfVariables());
939  H.triangularView<Eigen::Lower>().setZero();
940  addATA(H);
941  }
942 
943 
944  /// @copydoc humoto::constraints::BodyAMixin::getATA
945  void addATA(Eigen::MatrixXd &H) const
946  {
947  for (EigenIndex i = 0; i < I_.rows(); ++i)
948  {
949  H(I_[i], I_[i]) += I_gains_[i]*I_gains_[i];
950  }
951  }
952 
953 
954  public:
955  using t_Base::getNumberOfVariables;
956 
957 
958  /**
959  * @brief Get gains for each element in simple objective
960  *
961  * @return gains
962  */
963  Eigen::VectorXd & getIGains()
964  {
965  return (I_gains_);
966  }
967 
968  /// @copydoc getIGains
969  const Eigen::VectorXd& getIGains() const
970  {
971  return (I_gains_);
972  }
973 
974 
975  /// @copydoc humoto::constraints::ConstraintsBase::copyBodyTo
976  void copyBodyTo(Eigen::MatrixXd & A, const Location & location) const
977  {
978  HUMOTO_ASSERT( static_cast<std::size_t>(A.cols()) == getNumberOfVariables(),
979  "Wrong number of variables.");
980  HUMOTO_ASSERT( static_cast<std::size_t>(I_.rows()) == location.length_,
981  "Wrong number of constraints.");
982 
983  A.block(location.offset_, 0, location.length_, getNumberOfVariables()).setZero();
984 
985  for (std::size_t i = 0; i < location.length_; ++i)
986  {
987  A(location.offset_ + i, I_[i]) = I_gains_[i];
988  }
989  }
990 
991 
992  /// @copydoc humoto::constraints::ConstraintsBase::copyBodyTo
993  void copyNegativeBodyTo(Eigen::MatrixXd & A, const Location & location) const
994  {
995  HUMOTO_ASSERT( static_cast<std::size_t>(A.cols()) == getNumberOfVariables(),
996  "Wrong number of variables.");
997  HUMOTO_ASSERT( static_cast<std::size_t>(I_.rows()) == location.length_,
998  "Wrong number of constraints.");
999 
1000  A.block(location.offset_, 0, location.length_, getNumberOfVariables()).setZero();
1001 
1002  for (std::size_t i = 0; i < location.length_; ++i)
1003  {
1004  A(location.offset_ + i, I_[i]) = -I_gains_[i];
1005  }
1006  }
1007 
1008 
1009  /// @copydoc humoto::constraints::BodyAMixin::getProduct
1010  double getProduct( const std::size_t i,
1011  const Eigen::VectorXd & vector) const
1012  {
1013  return(I_gains_(i) * vector(I_(i)));
1014  }
1015  };
1016  /// @}
1017 
1018 
1019  // ======================================================================================
1020  // ======================================================================================
1021  // ======================================================================================
1022 
1023  /**
1024  * @defgroup ConstraintsActiveSetDetermination Determination of active set
1025  *
1026  * @ingroup ConstraintsImplementation
1027  *
1028  * A set of mixins which implement determination of active set based on
1029  * the solution.
1030  */
1031 
1032  /**
1033  * @addtogroup ConstraintsActiveSetDetermination
1034  * @{
1035  */
1036 
1037  /**
1038  * @brief This mixin provides functionality for determination of active
1039  * constraints.
1040  *
1041  * @tparam t_Base base class
1042  */
1043  template <class t_Base>
1045  {
1046  protected:
1047  /**
1048  * @brief Protected destructor: prevent destruction of the child
1049  * classes through a base pointer.
1050  */
1053 
1054  public:
1055  /// @copydoc humoto::constraints::ConstraintsBase::determineActiveSet
1057  const Location & location,
1058  const Solution & solution) const
1059  {
1060  HUMOTO_ASSERT( static_cast<std::size_t>(t_Base::getNumberOfConstraints()) == location.length_,
1061  std::string("Cannot determine active set: internal error."));
1062 
1063  for(std::size_t i = 0; i < location.length_; ++i)
1064  {
1065  if (t_Base::getLowerBounds()[i] > t_Base::getUpperBounds()[i])
1066  {
1067  active_set[location.offset_ + i] = ConstraintActivationType::UNDEFINED;
1068  }
1069  else
1070  {
1071  if (t_Base::getLowerBounds()[i] == t_Base::getUpperBounds()[i])
1072  {
1073  active_set[location.offset_ + i] = ConstraintActivationType::EQUALITY;
1074  }
1075  else
1076  {
1077  double product = t_Base::getProduct(i, solution.get_x());
1078 
1079  if (product <= t_Base::getLowerBounds()[i])
1080  {
1081  active_set[location.offset_ + i] = ConstraintActivationType::LOWER_BOUND;
1082  }
1083  else
1084  {
1085  if (product >= t_Base::getUpperBounds()[i])
1086  {
1087  active_set[location.offset_ + i] = ConstraintActivationType::UPPER_BOUND;
1088  }
1089  else
1090  {
1091  active_set[location.offset_ + i] = ConstraintActivationType::INACTIVE;
1092  }
1093  }
1094  }
1095  }
1096  }
1097  }
1098  };
1099 
1100 
1101  /// @copydoc ActiveSetDeterminationLUMixin
1102  template <class t_Base>
1104  {
1105  protected:
1106  /**
1107  * @brief Protected destructor: prevent destruction of the child
1108  * classes through a base pointer.
1109  */
1112 
1113  public:
1114  /// @copydoc humoto::constraints::ConstraintsBase::determineActiveSet
1116  const Location & location,
1117  const Solution & solution) const
1118  {
1119  HUMOTO_ASSERT( static_cast<std::size_t>(t_Base::getNumberOfConstraints()) == location.length_,
1120  std::string("Cannot determine active set: internal error."));
1121 
1122  for(std::size_t i = 0; i < location.length_; ++i)
1123  {
1124  if (t_Base::getProduct(i, solution.get_x()) <= t_Base::getLowerBounds()[i])
1125  {
1126  active_set[location.offset_ + i] = ConstraintActivationType::LOWER_BOUND;
1127  }
1128  else
1129  {
1130  active_set[location.offset_ + i] = ConstraintActivationType::INACTIVE;
1131  }
1132  }
1133  }
1134  };
1135 
1136 
1137  /// @copydoc ActiveSetDeterminationLUMixin
1138  template <class t_Base>
1140  {
1141  protected:
1142  /**
1143  * @brief Protected destructor: prevent destruction of the child
1144  * classes through a base pointer.
1145  */
1148 
1149  public:
1150  /// @copydoc humoto::constraints::ConstraintsBase::determineActiveSet
1152  const Location & location,
1153  const Solution & solution) const
1154  {
1155  HUMOTO_ASSERT( static_cast<std::size_t>(t_Base::getNumberOfConstraints()) == location.length_,
1156  std::string("Cannot determine active set: internal error."));
1157 
1158  for(std::size_t i = 0; i < location.length_; ++i)
1159  {
1160  if (t_Base::getProduct(i, solution.get_x()) >= t_Base::getUpperBounds()[i])
1161  {
1162  active_set[location.offset_ + i] = ConstraintActivationType::UPPER_BOUND;
1163  }
1164  else
1165  {
1166  active_set[location.offset_ + i] = ConstraintActivationType::INACTIVE;
1167  }
1168  }
1169  }
1170  };
1171 
1172 
1173  /// @copydoc ActiveSetDeterminationLUMixin
1174  template <class t_Base>
1176  {
1177  protected:
1178  /**
1179  * @brief Protected destructor: prevent destruction of the child
1180  * classes through a base pointer.
1181  */
1184 
1185  public:
1186  /// @copydoc humoto::constraints::ConstraintsBase::determineActiveSet
1188  const Location & location,
1189  const Solution & solution) const
1190  {
1191  active_set.set(location, ConstraintActivationType::EQUALITY);
1192  }
1193  };
1194  /// @}
1195 
1196 
1197  // ======================================================================================
1198  // ======================================================================================
1199  // ======================================================================================
1200 
1201  /**
1202  * @defgroup ConstraintsViolationsComputation Violations of constraints
1203  *
1204  * @ingroup ConstraintsImplementation
1205  *
1206  * A set of mixins which implement computation of violations of
1207  * constraints based on the solution.
1208  */
1209 
1210  /**
1211  * @addtogroup ConstraintsViolationsComputation
1212  * @{
1213  */
1214 
1215  /**
1216  * @brief This mixin provides functionality for compuation of violations of
1217  * the bounds.
1218  *
1219  * @tparam t_Base base class
1220  */
1221  template <class t_Base>
1223  {
1224  protected:
1225  /**
1226  * @brief Protected destructor: prevent destruction of the child
1227  * classes through a base pointer.
1228  */
1231 
1232  public:
1233  /// @copydoc humoto::constraints::ConstraintsBase::computeViolations
1235  const Location & location,
1236  const Solution & solution) const
1237  {
1238  HUMOTO_ASSERT( static_cast<std::size_t>(t_Base::getNumberOfConstraints()) == location.length_,
1239  std::string("Cannot determine active set: internal error."));
1240 
1241  for(std::size_t i = 0; i < location.length_; ++i)
1242  {
1243  double product = t_Base::getProduct(i, solution.get_x());
1244 
1245  violations.set( location.offset_ + i,
1246  product - t_Base::getLowerBounds()[i],
1247  product - t_Base::getUpperBounds()[i]);
1248  }
1249  }
1250  };
1251 
1252 
1253  /// @copydoc ViolationsComputationLUMixin
1254  template <class t_Base>
1256  {
1257  protected:
1258  /**
1259  * @brief Protected destructor: prevent destruction of the child
1260  * classes through a base pointer.
1261  */
1264 
1265  public:
1266  /// @copydoc humoto::constraints::ConstraintsBase::computeViolations
1268  const Location & location,
1269  const Solution & solution) const
1270  {
1271  HUMOTO_ASSERT( static_cast<std::size_t>(t_Base::getNumberOfConstraints()) == location.length_,
1272  std::string("Cannot determine active set: internal error."));
1273 
1274  for(std::size_t i = 0; i < location.length_; ++i)
1275  {
1276  double product = t_Base::getProduct(i, solution.get_x());
1277 
1278  violations.set( location.offset_ + i,
1279  product - t_Base::getLowerBounds()[i],
1280  0.0);
1281  }
1282  }
1283  };
1284 
1285 
1286  /// @copydoc ViolationsComputationLUMixin
1287  template <class t_Base>
1289  {
1290  protected:
1291  /**
1292  * @brief Protected destructor: prevent destruction of the child
1293  * classes through a base pointer.
1294  */
1297 
1298  public:
1299  /// @copydoc humoto::constraints::ConstraintsBase::computeViolations
1301  const Location & location,
1302  const Solution & solution) const
1303  {
1304  HUMOTO_ASSERT( static_cast<std::size_t>(t_Base::getNumberOfConstraints()) == location.length_,
1305  std::string("Cannot determine active set: internal error."));
1306 
1307  for(std::size_t i = 0; i < location.length_; ++i)
1308  {
1309  double product = t_Base::getProduct(i, solution.get_x());
1310 
1311  violations.set( location.offset_ + i,
1312  0.0,
1313  product - t_Base::getUpperBounds()[i]);
1314  }
1315  }
1316  };
1317 
1318 
1319  /// @copydoc ViolationsComputationLUMixin
1320  template <class t_Base>
1322  {
1323  protected:
1324  /**
1325  * @brief Protected destructor: prevent destruction of the child
1326  * classes through a base pointer.
1327  */
1330 
1331  public:
1332  /// @copydoc humoto::constraints::ConstraintsBase::computeViolations
1334  const Location & location,
1335  const Solution & solution) const
1336  {
1337  HUMOTO_ASSERT( static_cast<std::size_t>(t_Base::getNumberOfConstraints()) == location.length_,
1338  std::string("Cannot determine active set: internal error."));
1339 
1340  for(std::size_t i = 0; i < location.length_; ++i)
1341  {
1342  double product = t_Base::getProduct(i, solution.get_x());
1343 
1344  violations.set( location.offset_ + i,
1345  product - t_Base::getB()[i],
1346  product - t_Base::getB()[i]);
1347  }
1348  }
1349  };
1350 
1351 
1352  /// @copydoc ViolationsComputationLUMixin
1353  template <class t_Base>
1355  {
1356  protected:
1357  /**
1358  * @brief Protected destructor: prevent destruction of the child
1359  * classes through a base pointer.
1360  */
1363 
1364  public:
1365  /// @copydoc humoto::constraints::ConstraintsBase::computeViolations
1367  const Location & location,
1368  const Solution & solution) const
1369  {
1370  HUMOTO_ASSERT( static_cast<std::size_t>(t_Base::getNumberOfConstraints()) == location.length_,
1371  std::string("Cannot determine active set: internal error."));
1372 
1373  for(std::size_t i = 0; i < location.length_; ++i)
1374  {
1375  double product = t_Base::getProduct(i, solution.get_x());
1376 
1377  violations.set( location.offset_ + i,
1378  product,
1379  product);
1380  }
1381  }
1382  };
1383  /// @}
1384  }
1385 }
This mixin provides functionality for compuation of violations of the bounds.
~BoundsLMixin()
Protected destructor: prevent destruction of the child classes through a base pointer.
void copyNegativeBodyTo(Eigen::MatrixXd &A, const Location &location) const
Copy body to the given matrix.
void resetBounds(const std::size_t number_of_constraints, const bool initialize_matrices=false)
Reset bounds of constraints (b, lb, ub)
This mixin provides functionality for determination of active constraints.
void addATA(Eigen::MatrixXd &H) const
Compute &#39;A^T * A&#39; for general equality constaints and save or add the result to H.
const humoto::IndexVector & getIndices() const
Get indices.
virtual void resetBody(const std::size_t number_of_constraints=0, const bool initialize_matrices=false)
Initialize I and gains.
void computeViolations(ViolationsConstraints &violations, const Location &location, const Solution &solution) const
Compute violations given a solution vector.
~ViolationsComputationLMixin()
Protected destructor: prevent destruction of the child classes through a base pointer.
void copyBoundsTo(Eigen::VectorXd &lb, Eigen::VectorXd &ub, const Location &location) const
Copy bounds to given vectors.
Violations corresponding to Constraints class.
Definition: violations.h:17
Eigen::VectorXd & getB()
Get vector b from equalities: &#39;A*x = b&#39; or &#39;x = b&#39;.
This mixin provides functionality for determination of active constraints.
BodyIMixin()
Default constructor.
~ViolationsComputationLUMixin()
Protected destructor: prevent destruction of the child classes through a base pointer.
void logBounds(humoto::Logger &logger, const LogEntryName &parent=LogEntryName(), const std::string &name="constraints") const
Log bounds.
void logBounds(humoto::Logger &logger, const LogEntryName &parent=LogEntryName(), const std::string &name="constraints") const
Log bounds.
std::ptrdiff_t getOffset() const
Get offset of body part in the constriaints.
#define HUMOTO_LOCAL
Definition: export_import.h:26
void copyEqualityBoundsTo(Eigen::VectorXd &b, const Location &location) const
Copy b.
void resetBody(const std::size_t number_of_constraints, const bool initialize_matrices=false)
Initialize A.
void logBody(humoto::Logger &logger, const LogEntryName &parent=LogEntryName(), const std::string &name="constraints") const
Log body.
Constraint is an equality (always active)
Definition: active_set.h:35
void copyNegativeBodyTo(Eigen::MatrixXd &A, const Location &location) const
Copy body to the given matrix.
This mixin provides functionality for compuation of violations of the bounds.
void EIGENTOOLS_VISIBILITY_ATTRIBUTE addATA(Eigen::DenseBase< t_DerivedOutput > &result, const Eigen::DenseBase< t_DerivedInput > &A)
result += A^T * A
Definition: eigentools.h:262
void copyNegativeBodyTo(Eigen::MatrixXd &A, const Location &location) const
Copy body to the given matrix.
Mixin representing vector &#39;b = 0&#39; in an equality constraint.
const Eigen::VectorXd & getIGains() const
Get gains for each element in simple objective.
This mixin provides functionality for compuation of violations of the bounds.
double getProduct(const std::size_t i, const Eigen::VectorXd &vector) const
Compute A(i,:) * vector.
Mixin representing matrix of indices &#39;I&#39; and matrix of gains &#39;G&#39; in a simple constraint.
void set(const ConstraintActivationType::Type type)
Set type of all constraints.
Definition: active_set.h:104
void computeViolations(ViolationsConstraints &violations, const Location &location, const Solution &solution) const
Compute violations given a solution vector.
const double g_infinity
Infinity.
Definition: constants.h:24
Mixin representing matrix of indices &#39;I&#39; in a simple constraint.
std::size_t getNumberOfConstraints() const
Returns number of constraints in the task.
void logBounds(humoto::Logger &logger, const LogEntryName &parent=LogEntryName(), const std::string &name="constraints") const
Log bounds.
#define HUMOTO_GLOBAL_LOGGER_IF_DEFINED
Definition: logger.h:997
#define HUMOTO_ASSERT(condition, message)
void logBody(humoto::Logger &logger, const LogEntryName &parent=LogEntryName(), const std::string &name="constraints") const
Log body.
Mixin representing matrix &#39;A*S&#39; in a general constraint.
void resetBounds(const std::size_t number_of_constraints, const bool initialize_matrices=false)
Reset bounds of constraints (b, lb, ub)
humoto::IndexVector & getIndices()
Get indices.
~BodyGIMixin()
Protected destructor: prevent destruction of the child classes through a base pointer.
const Eigen::MatrixXd & getA() const
Get matrix A from general constraints: &#39;A*x = b&#39;, &#39;lb <= A*x <= ub&#39;.
void setOffset(const std::ptrdiff_t offset)
Set offset of body part in the constriaints.
Container of the solution.
Definition: solution.h:176
Active set corresponding to Constraints class.
Definition: active_set.h:43
This mixin provides functionality for compuation of violations of the bounds.
void logBounds(humoto::Logger &logger, const LogEntryName &parent=LogEntryName(), const std::string &name="constraints") const
Log bounds.
Represents log entry name.
Definition: logger.h:169
void set(const std::size_t constraint_index, const double lower_bound_diff=0.0, const double upper_bound_diff=0.0)
Set violation of a constraint.
Definition: violations.h:73
void resetBody(const std::size_t number_of_constraints, const bool initialize_matrices=false)
Initialize A.
EIGEN_DEFAULT_DENSE_INDEX_TYPE EigenIndex
Definition: utility.h:26
std::size_t length_
Definition: utility.h:150
const Eigen::MatrixXd & getA() const
Get matrix A from general constraints: &#39;A*x = b&#39;, &#39;lb <= A*x <= ub&#39;.
~BoundsB0Mixin()
Protected destructor: prevent destruction of the child classes through a base pointer.
void determineActiveSet(ActiveSetConstraints &active_set, const Location &location, const Solution &solution) const
Determine active set given a solution vector.
void logBounds(humoto::Logger &logger, const LogEntryName &parent=LogEntryName(), const std::string &name="constraints") const
Log bounds.
Eigen::MatrixXd & getA()
Get matrix A from general constraints: &#39;A*x = b&#39;, &#39;lb <= A*x <= ub&#39;.
void getATA(Eigen::MatrixXd &H) const
Compute &#39;A^T * A&#39; for general equality constaints and save or add the result to H.
void logBody(humoto::Logger &logger, const LogEntryName &parent=LogEntryName(), const std::string &name="constraints") const
Log body.
double getProduct(const std::size_t i, const Eigen::VectorXd &vector) const
Compute A(i,:) * vector.
Eigen::VectorXd & getUpperBounds()
Get upper bounds (ub vectors from &#39;A*x <= ub&#39;).
~BodyIMixin()
Protected destructor: prevent destruction of the child classes through a base pointer.
Eigen::Matrix< unsigned int, Eigen::Dynamic, 1 > IndexVector
Definition: utility.h:19
Eigen::MatrixXd & getA()
Get matrix A from general constraints: &#39;A*x = b&#39;, &#39;lb <= A*x <= ub&#39;.
void getATb(Eigen::VectorXd &g) const
Compute &#39;A^T * b&#39; for general equality constaints and save or add the result to g.
std::size_t getNumberOfConstraints() const
Returns number of constraints in the task.
const Eigen::VectorXd & getB() const
Get vector b from equalities: &#39;A*x = b&#39; or &#39;x = b&#39;.
~BoundsUMixin()
Protected destructor: prevent destruction of the child classes through a base pointer.
~ActiveSetDeterminationUMixin()
Protected destructor: prevent destruction of the child classes through a base pointer.
~ViolationsComputationB0Mixin()
Protected destructor: prevent destruction of the child classes through a base pointer.
void computeViolations(ViolationsConstraints &violations, const Location &location, const Solution &solution) const
Compute violations given a solution vector.
void resetBounds(const std::size_t number_of_constraints=0, const bool initialize_matrices=false)
Reset bounds of constraints (b, lb, ub)
std::size_t getNumberOfConstraints() const
Returns number of constraints in the task.
Eigen::VectorXd & getIGains()
Get gains for each element in simple objective.
Threaded logger: any data sent to this logger is wrapped in a message and pushed to a queue...
Definition: logger.h:555
void addATA(Eigen::MatrixXd &H) const
Compute &#39;A^T * A&#39; for general equality constaints and save or add the result to H.
~BodyASMixin()
Protected destructor: prevent destruction of the child classes through a base pointer.
void copyBoundsTo(Eigen::VectorXd &lb, Eigen::VectorXd &ub, const Location &location) const
Copy bounds to given vectors.
~BoundsBMixin()
Protected destructor: prevent destruction of the child classes through a base pointer.
~BodyAMixin()
Protected destructor: prevent destruction of the child classes through a base pointer.
void determineActiveSet(ActiveSetConstraints &active_set, const Location &location, const Solution &solution) const
Determine active set given a solution vector.
double getProduct(const std::size_t i, const Eigen::VectorXd &vector) const
Compute A(i,:) * vector.
Mixin representing upper bound in an inequality constraint.
Mixin representing vector &#39;b&#39; in an equality constraint.
void copyBodyTo(Eigen::MatrixXd &A, const Location &location) const
Copy body to the given matrix.
The root namespace of HuMoTo.
Definition: config.h:12
~ActiveSetDeterminationLUMixin()
Protected destructor: prevent destruction of the child classes through a base pointer.
const Eigen::VectorXd & get_x() const
Returns solution vector.
Definition: solution.h:337
void getATA(Eigen::MatrixXd &H) const
Compute &#39;A^T * A&#39; for general equality constaints and save or add the result to H.
void addATb(Eigen::VectorXd &g) const
Compute &#39;A^T * b&#39; for general equality constaints and save or add the result to g.
~ViolationsComputationBMixin()
Protected destructor: prevent destruction of the child classes through a base pointer.
const Eigen::VectorXd & getLowerBounds() const
Get lower bounds (lb/ub vectors from &#39;lb <= A*x <= ub&#39;).
void copyBoundsTo(Eigen::VectorXd &lb, Eigen::VectorXd &ub, const Location &location) const
Copy bounds to given vectors.
void determineActiveSet(ActiveSetConstraints &active_set, const Location &location, const Solution &solution) const
Determine active set given a solution vector.
void copyBodyTo(Eigen::MatrixXd &A, const Location &location) const
Copy body to the given matrix.
void getATA(Eigen::MatrixXd &H) const
Compute &#39;A^T * A&#39; for general equality constaints and save or add the result to H.
void resetBounds(const std::size_t number_of_constraints=0, const bool initialize_matrices=false)
Reset bounds of constraints (b, lb, ub)
Mixin representing upper bound in an inequality constraint.
This mixin provides functionality for determination of active constraints.
void resetBounds(const std::size_t number_of_constraints, const bool initialize_matrices=false)
Reset bounds of constraints (b, lb, ub)
void EIGENTOOLS_VISIBILITY_ATTRIBUTE getATA(Eigen::PlainObjectBase< t_DerivedOutput > &result, const Eigen::DenseBase< t_DerivedInput > &A)
result = A^T * A
Definition: eigentools.h:204
double getProduct(const std::size_t i, const Eigen::VectorXd &vector) const
Compute A(i,:) * vector.
This mixin provides functionality for determination of active constraints.
void computeViolations(ViolationsConstraints &violations, const Location &location, const Solution &solution) const
Compute violations given a solution vector.
This mixin provides functionality for compuation of violations of the bounds.
void determineActiveSet(ActiveSetConstraints &active_set, const Location &location, const Solution &solution) const
Determine active set given a solution vector.
void getATA(Eigen::MatrixXd &H) const
Compute &#39;A^T * A&#39; for general equality constaints and save or add the result to H.
~ViolationsComputationUMixin()
Protected destructor: prevent destruction of the child classes through a base pointer.
Mixin representing matrix &#39;A&#39; in a general constraint.
LogEntryName & add(const char *name)
extends entry name with a subname
Definition: logger.h:232
Location of a data chunk (offset + length).
Definition: utility.h:146
void addATA(Eigen::MatrixXd &H) const
Compute &#39;A^T * A&#39; for general equality constaints and save or add the result to H.
void computeViolations(ViolationsConstraints &violations, const Location &location, const Solution &solution) const
Compute violations given a solution vector.
virtual void copyBodyTo(Eigen::MatrixXd &A, const Location &location) const
Copy body to the given matrix.
~BoundsLUMixin()
Protected destructor: prevent destruction of the child classes through a base pointer.
Eigen::VectorXd & getLowerBounds()
Get lower bounds (lb/ub vectors from &#39;lb <= A*x <= ub&#39;).
void copyBoundsTo(Eigen::VectorXd &lb, Eigen::VectorXd &ub, const Location &location) const
Copy bounds to given vectors.
void copyBodyTo(Eigen::MatrixXd &A, const Location &location) const
Copy body to the given matrix.
void copyBoundsTo(Eigen::VectorXd &lb, Eigen::VectorXd &ub, const Location &location) const
Copy bounds to given vectors.
virtual void copyNegativeBodyTo(Eigen::MatrixXd &A, const Location &location) const
Copy body to the given matrix.
std::size_t offset_
Definition: utility.h:149
Mixin representing lower bound in an inequality constraint.
~ActiveSetDeterminationLMixin()
Protected destructor: prevent destruction of the child classes through a base pointer.
void logBody(humoto::Logger &logger, const LogEntryName &parent=LogEntryName(), const std::string &name="constraints") const
Log body.
void copyEqualityBoundsTo(Eigen::VectorXd &b, const Location &location) const
Copy b.
void addATA(Eigen::MatrixXd &H) const
Compute &#39;A^T * A&#39; for general equality constaints and save or add the result to H.
const Eigen::VectorXd & getUpperBounds() const
Get upper bounds (ub vectors from &#39;A*x <= ub&#39;).
void resetBody(const std::size_t number_of_constraints=0, const bool initialize_matrices=false)
Initialize I and gains.
~ActiveSetDeterminationBMixin()
Protected destructor: prevent destruction of the child classes through a base pointer.