35 template <
class t_Base>
48 void resetBounds (
const std::size_t number_of_constraints = 0,
49 const bool initialize_matrices =
false)
58 const std::string &name =
"constraints")
const 70 void getATb(Eigen::VectorXd &g)
const 72 g.setZero(t_Base::getNumberOfVariables());
77 void addATb(Eigen::VectorXd &g)
const 114 template <
class t_Base>
135 const bool initialize_matrices =
false)
137 if (initialize_matrices)
139 b_.setZero(number_of_constraints);
143 b_.resize(number_of_constraints);
151 const std::string &name =
"constraints")
const 153 logger.log(
LogEntryName(parent).add(name).add(
"b"), b_);
183 const Eigen::VectorXd &
getB()
const 191 Eigen::VectorXd & ub,
206 template <
class t_Base>
226 void resetBounds (
const std::size_t number_of_constraints,
const bool initialize_matrices =
false)
228 if (initialize_matrices)
234 lb_.resize(number_of_constraints);
242 const std::string &name =
"constraints")
const 244 logger.log(
LogEntryName(parent).add(name).add(
"lb"), lb_);
268 Eigen::VectorXd & ub,
284 template <
class t_Base>
304 void resetBounds (
const std::size_t number_of_constraints,
const bool initialize_matrices =
false)
306 if (initialize_matrices)
312 ub_.resize(number_of_constraints);
320 const std::string &name =
"constraints")
const 322 logger.log(
LogEntryName(parent).add(name).add(
"ub"), ub_);
348 Eigen::VectorXd & ub,
364 template <
class t_Base>
380 void resetBounds (
const std::size_t number_of_constraints,
const bool initialize_matrices =
false)
390 const std::string &name =
"constraints")
const 402 Eigen::VectorXd & ub,
437 template <
class t_Base>
462 void resetBody (
const std::size_t number_of_constraints,
const bool initialize_matrices =
false)
464 if (initialize_matrices)
466 A_.setZero(number_of_constraints, t_Base::getNumberOfVariables());
470 A_.resize(number_of_constraints, t_Base::getNumberOfVariables());
478 const std::string &name =
"constraints")
const 480 logger.log(
LogEntryName(parent).add(name).add(
"A"), A_);
523 const Eigen::MatrixXd &
getA()
const 533 "Numbers of columns in constraint matrices do not match.");
543 "Numbers of columns in constraint matrices do not match.");
565 const Eigen::VectorXd & vector)
const 567 return(A_.row(i) * vector);
579 template <
class t_Base>
608 void resetBody (
const std::size_t number_of_constraints,
const bool initialize_matrices =
false)
611 if (initialize_matrices)
613 A_.setZero(number_of_constraints, t_Base::getNumberOfVariables());
617 A_.resize(number_of_constraints, t_Base::getNumberOfVariables());
625 const std::string &name =
"constraints")
const 627 logger.log(
LogEntryName(parent).add(name).add(
"A"), A_);
628 logger.log(
LogEntryName(parent).add(name).add(
"offset"), offset_);
660 const Eigen::MatrixXd &
getA()
const 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.");
695 std::ptrdiff_t right_space_size = t_Base::getNumberOfVariables() - offset_ - A_.cols();
698 << Eigen::MatrixXd::Zero(location.
length_, offset_),
700 Eigen::MatrixXd::Zero(location.
length_, right_space_size);
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.");
711 std::ptrdiff_t right_space_size = t_Base::getNumberOfVariables() - offset_ - A_.cols();
714 << Eigen::MatrixXd::Zero(location.
length_, offset_),
716 Eigen::MatrixXd::Zero(location.
length_, right_space_size);
729 const Eigen::VectorXd & vector)
const 731 return(A_.row(i) * vector.segment(offset_, A_.cols()));
742 template <
class t_Base>
771 virtual void resetBody(
const std::size_t number_of_constraints = 0,
772 const bool initialize_matrices =
false)
774 I_.resize(number_of_constraints);
782 const std::string &name =
"constraints")
const 784 logger.log(
LogEntryName(parent).add(name).add(
"A"), I_);
792 H.resize(getNumberOfVariables(), getNumberOfVariables());
793 H.triangularView<Eigen::Lower>().setZero();
803 H(I_[i], I_[i]) += 1;
809 using t_Base::getNumberOfVariables;
816 HUMOTO_ASSERT( static_cast<std::size_t>(A.cols()) == getNumberOfVariables(),
817 "Wrong number of variables.");
819 "Wrong number of constraints.");
821 A.block(location.
offset_, 0, location.
length_, getNumberOfVariables()).setZero();
823 for (std::size_t i = 0; i < location.
length_; ++i)
825 A(location.
offset_ + i, I_[i]) = 1.0;
833 HUMOTO_ASSERT( static_cast<std::size_t>(A.cols()) == getNumberOfVariables(),
834 "Wrong number of variables.");
836 "Wrong number of constraints.");
838 A.block(location.
offset_, 0, location.
length_, getNumberOfVariables()).setZero();
840 for (std::size_t i = 0; i < location.
length_; ++i)
842 A(location.
offset_ + i, I_[i]) = -1.0;
874 const Eigen::VectorXd & vector)
const 876 return(vector(I_(i)));
889 template <
class t_Base>
912 void resetBody(
const std::size_t number_of_constraints = 0,
913 const bool initialize_matrices =
false)
916 I_gains_.setConstant(number_of_constraints, 1.0);
924 const std::string &name =
"constraints")
const 929 logger.log(
LogEntryName(subname).add(
"Agains"), I_gains_);
938 H.resize(getNumberOfVariables(), getNumberOfVariables());
939 H.triangularView<Eigen::Lower>().setZero();
949 H(I_[i], I_[i]) += I_gains_[i]*I_gains_[i];
955 using t_Base::getNumberOfVariables;
978 HUMOTO_ASSERT( static_cast<std::size_t>(A.cols()) == getNumberOfVariables(),
979 "Wrong number of variables.");
981 "Wrong number of constraints.");
983 A.block(location.
offset_, 0, location.
length_, getNumberOfVariables()).setZero();
985 for (std::size_t i = 0; i < location.
length_; ++i)
987 A(location.
offset_ + i, I_[i]) = I_gains_[i];
995 HUMOTO_ASSERT( static_cast<std::size_t>(A.cols()) == getNumberOfVariables(),
996 "Wrong number of variables.");
998 "Wrong number of constraints.");
1000 A.block(location.
offset_, 0, location.
length_, getNumberOfVariables()).setZero();
1002 for (std::size_t i = 0; i < location.
length_; ++i)
1004 A(location.
offset_ + i, I_[i]) = -I_gains_[i];
1011 const Eigen::VectorXd & vector)
const 1013 return(I_gains_(i) * vector(I_(i)));
1043 template <
class t_Base>
1061 std::string(
"Cannot determine active set: internal error."));
1063 for(std::size_t i = 0; i < location.
length_; ++i)
1065 if (t_Base::getLowerBounds()[i] > t_Base::getUpperBounds()[i])
1071 if (t_Base::getLowerBounds()[i] == t_Base::getUpperBounds()[i])
1077 double product = t_Base::getProduct(i, solution.
get_x());
1079 if (product <= t_Base::getLowerBounds()[i])
1085 if (product >= t_Base::getUpperBounds()[i])
1102 template <
class t_Base>
1120 std::string(
"Cannot determine active set: internal error."));
1122 for(std::size_t i = 0; i < location.
length_; ++i)
1124 if (t_Base::getProduct(i, solution.
get_x()) <= t_Base::getLowerBounds()[i])
1138 template <
class t_Base>
1156 std::string(
"Cannot determine active set: internal error."));
1158 for(std::size_t i = 0; i < location.
length_; ++i)
1160 if (t_Base::getProduct(i, solution.
get_x()) >= t_Base::getUpperBounds()[i])
1174 template <
class t_Base>
1221 template <
class t_Base>
1239 std::string(
"Cannot determine active set: internal error."));
1241 for(std::size_t i = 0; i < location.
length_; ++i)
1243 double product = t_Base::getProduct(i, solution.
get_x());
1246 product - t_Base::getLowerBounds()[i],
1247 product - t_Base::getUpperBounds()[i]);
1254 template <
class t_Base>
1272 std::string(
"Cannot determine active set: internal error."));
1274 for(std::size_t i = 0; i < location.
length_; ++i)
1276 double product = t_Base::getProduct(i, solution.
get_x());
1279 product - t_Base::getLowerBounds()[i],
1287 template <
class t_Base>
1305 std::string(
"Cannot determine active set: internal error."));
1307 for(std::size_t i = 0; i < location.
length_; ++i)
1309 double product = t_Base::getProduct(i, solution.
get_x());
1313 product - t_Base::getUpperBounds()[i]);
1320 template <
class t_Base>
1338 std::string(
"Cannot determine active set: internal error."));
1340 for(std::size_t i = 0; i < location.
length_; ++i)
1342 double product = t_Base::getProduct(i, solution.
get_x());
1345 product - t_Base::getB()[i],
1346 product - t_Base::getB()[i]);
1353 template <
class t_Base>
1371 std::string(
"Cannot determine active set: internal error."));
1373 for(std::size_t i = 0; i < location.
length_; ++i)
1375 double product = t_Base::getProduct(i, solution.
get_x());
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 'A^T * A' 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.
Lower bound is activated.
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.
Eigen::VectorXd & getB()
Get vector b from equalities: 'A*x = b' or 'x = b'.
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.
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)
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 copyNegativeBodyTo(Eigen::MatrixXd &A, const Location &location) const
Copy body to the given matrix.
Mixin representing vector 'b = 0' 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 'I' and matrix of gains 'G' in a simple constraint.
void set(const ConstraintActivationType::Type type)
Set type of all constraints.
void computeViolations(ViolationsConstraints &violations, const Location &location, const Solution &solution) const
Compute violations given a solution vector.
const double g_infinity
Infinity.
Mixin representing matrix of indices 'I' 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
#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 'A*S' 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: 'A*x = b', 'lb <= A*x <= ub'.
void setOffset(const std::ptrdiff_t offset)
Set offset of body part in the constriaints.
Container of the solution.
Active set corresponding to Constraints class.
This mixin provides functionality for compuation of violations of the bounds.
ActiveSetDeterminationLMixin()
void logBounds(humoto::Logger &logger, const LogEntryName &parent=LogEntryName(), const std::string &name="constraints") const
Log bounds.
Represents log entry name.
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.
void resetBody(const std::size_t number_of_constraints, const bool initialize_matrices=false)
Initialize A.
ActiveSetDeterminationUMixin()
EIGEN_DEFAULT_DENSE_INDEX_TYPE EigenIndex
const Eigen::MatrixXd & getA() const
Get matrix A from general constraints: 'A*x = b', 'lb <= A*x <= ub'.
~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: 'A*x = b', 'lb <= A*x <= ub'.
void getATA(Eigen::MatrixXd &H) const
Compute 'A^T * A' 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 'A*x <= ub').
~BodyIMixin()
Protected destructor: prevent destruction of the child classes through a base pointer.
Eigen::Matrix< unsigned int, Eigen::Dynamic, 1 > IndexVector
Eigen::MatrixXd & getA()
Get matrix A from general constraints: 'A*x = b', 'lb <= A*x <= ub'.
void getATb(Eigen::VectorXd &g) const
Compute 'A^T * b' 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: 'A*x = b' or 'x = b'.
~BoundsUMixin()
Protected destructor: prevent destruction of the child classes through a base pointer.
ViolationsComputationB0Mixin()
~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...
void addATA(Eigen::MatrixXd &H) const
Compute 'A^T * A' 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.
ViolationsComputationLUMixin()
Mixin representing vector 'b' in an equality constraint.
void copyBodyTo(Eigen::MatrixXd &A, const Location &location) const
Copy body to the given matrix.
The root namespace of HuMoTo.
~ActiveSetDeterminationLUMixin()
Protected destructor: prevent destruction of the child classes through a base pointer.
const Eigen::VectorXd & get_x() const
Returns solution vector.
void getATA(Eigen::MatrixXd &H) const
Compute 'A^T * A' for general equality constaints and save or add the result to H.
void addATb(Eigen::VectorXd &g) const
Compute 'A^T * b' 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 'lb <= A*x <= ub').
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 'A^T * A' 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)
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 'A^T * A' 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 'A' in a general constraint.
LogEntryName & add(const char *name)
extends entry name with a subname
ViolationsComputationUMixin()
Location of a data chunk (offset + length).
void addATA(Eigen::MatrixXd &H) const
Compute 'A^T * A' 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 'lb <= A*x <= ub').
ViolationsComputationLMixin()
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.
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.
ActiveSetDeterminationLUMixin()
void addATA(Eigen::MatrixXd &H) const
Compute 'A^T * A' for general equality constaints and save or add the result to H.
Upper bound is activated.
const Eigen::VectorXd & getUpperBounds() const
Get upper bounds (ub vectors from 'A*x <= ub').
ActiveSetDeterminationBMixin()
void resetBody(const std::size_t number_of_constraints=0, const bool initialize_matrices=false)
Initialize I and gains.
ViolationsComputationBMixin()
~ActiveSetDeterminationBMixin()
Protected destructor: prevent destruction of the child classes through a base pointer.