25 #ifndef SRC_OPTIMIZATION_INCLUDE_CORBO_OPTIMIZATION_HYPER_GRAPH_VECTOR_VERTEX_H_ 26 #define SRC_OPTIMIZATION_INCLUDE_CORBO_OPTIMIZATION_HYPER_GRAPH_VECTOR_VERTEX_H_ 54 using Ptr = std::shared_ptr<VectorVertex>;
55 using UPtr = std::unique_ptr<VectorVertex>;
89 assert(values.size() == lb.size());
90 assert(values.size() == ub.size());
103 _values = Eigen::VectorXd::Zero(dim);
129 assert(values.size() == lb.size());
130 assert(values.size() == ub.size());
176 assert(idx <
_lb.size());
182 assert(idx <
_lb.size());
188 if (unfixed_only &&
_fixed)
196 if (unfixed_only &&
_fixed)
203 if (unfixed_only &&
_fixed)
279 using Ptr = std::shared_ptr<PartiallyFixedVectorVertex>;
280 using UPtr = std::unique_ptr<PartiallyFixedVectorVertex>;
286 :
VectorVertex(dimension),
_fixed(
Eigen::Array<bool, -1, 1>::Constant(dimension, false)), _num_unfixed(dimension)
322 _fixed.setConstant(dim,
false);
330 assert(values.size() == lb.size());
331 assert(values.size() == ub.size());
343 assert(values.size() == lb.size());
344 assert(values.size() == ub.size());
395 if (unfixed_only && _num_unfixed > 0)
411 if (unfixed_only && _num_unfixed > 0)
427 if (unfixed_only && _num_unfixed > 0)
450 #endif // SRC_OPTIMIZATION_INCLUDE_CORBO_OPTIMIZATION_HYPER_GRAPH_VECTOR_VERTEX_H_ bool hasFiniteLowerBound(int idx) const override
Check if finite lower bound for a single component is provided.
void plusUnfixed(const double *inc) override
Define the increment for the unfixed components of the vertex: x += inc with dim(inc)=getDimensionUnf...
Eigen::VectorXd & values()
Write-access to the underlying value vector.
int getNumberFiniteBounds(bool unfixed_only) const override
Get number of finite upper bounds (either upper or lower must be finite)
virtual void setDimension(int dim)
Change the dimension of the vertex (lower and upper bounds needs to be redefined) ...
bool isFixedComponent(int idx) const override
Check if individual components are fixed or unfixed.
int getNumberFiniteBounds(bool unfixed_only) const override
Get number of finite upper bounds (either upper or lower must be finite)
void setDimension(int dim) override
Change the dimension of the vertex (lower and upper bounds needs to be redefined) ...
A matrix or vector expression mapping an existing array of data.
bool hasFiniteLowerBounds() const override
Check if finite lower bounds are provided.
PartiallyFixedVectorVertex(int dimension, const Eigen::Ref< const Eigen::Array< bool, -1, 1 >> &fixed)
Construct and allocate memory for a given dimension.
bool hasFixedComponents() const override
Check if the vertex has fixed components.
Generic interface class for vertices.
bool hasFiniteUpperBounds() const override
Check if finite upper bounds are provided.
#define EIGEN_MAKE_ALIGNED_OPERATOR_NEW
static constexpr size_t size(Tuple< Args... > &)
Provides access to the number of elements in a tuple as a compile-time constant expression.
int getNumberFiniteLowerBounds(bool unfixed_only) const override
Get number of finite lower bounds.
void setFixed(bool fixed) override
Set complete vertex to fixed (and hence skip during optimization)
void setUpperBound(int idx, double ub) override
Define upper bound on a single component of the vertex (0 <= idx < getDimension()) ...
int getNumberFiniteUpperBounds(bool unfixed_only) const override
Get number of finite upper bounds.
int getDimensionUnfixed() const override
Return number of unfixed elements (unfixed elements are skipped as parameters in the Hessian and Jaco...
void setData(int idx, double data) override
Write data to to a specific component.
VectorVertex(const Eigen::Ref< const Eigen::VectorXd > &values, const Eigen::Ref< const Eigen::VectorXd > &lb, const Eigen::Ref< const Eigen::VectorXd > &ub, bool fixed=false)
Construct vertex with given values, lower and upper bounds.
void top() override
Restore the previously stored values of the backup stack WITHOUT removing them from the stack...
std::shared_ptr< VectorVertex > Ptr
VectorVertex(const Eigen::Ref< const Eigen::VectorXd > &values, bool fixed=false)
Construct vertex with given values.
Vector based vertex with support for partially fixed components.
const Eigen::VectorXd & lowerBound() const
Read-access to the underlying lower bound vector.
int getDimensionUnfixed() const override
Return number of unfixed elements (unfixed elements are skipped as parameters in the Hessian and Jaco...
std::vector< Eigen::VectorXd > _backup
void plusUnfixed(const double *inc) override
Define the increment for the unfixed components of the vertex: x += inc with dim(inc)=getDimensionUnf...
void setUpperBounds(const Eigen::Ref< const Eigen::VectorXd > &ub) override
Define upper bounds on the vertex values [getDimension() x 1].
constexpr const double CORBO_INF_DBL
Representation for infinity (double version)
void plus(int idx, double inc) override
Add value to a specific component of the vertex: x[idx] += inc.
void clear() override
Clear complete backup container.
int getDimension() const override
Return number of elements/values/components stored in this vertex.
bool isFixedComponent(int) const override
Check if individual components are fixed or unfixed.
A matrix or vector expression mapping an existing expression.
const double * getData() const override
Get read-only raw access to the values of the vertex.
const Eigen::Array< bool, -1, 1 > fixedArray() const
Read-only access to the underlying logical array for fixed components.
bool hasFiniteBounds() const override
Check if finite bounds (lower or upper) are provided.
bool hasFiniteUpperBound(int idx) const override
Check if finite upper bound for a single component is provided.
const Eigen::VectorXd & upperBound() const
Read-access to the underlying upper bound vector.
void pop() override
Restore the previously stored values of the backup stack and remove them from the stack...
const double * getUpperBounds() const override
Read-only raw access to upper bounds [getDimension() x 1].
PartiallyFixedVectorVertex(const Eigen::Ref< const Eigen::VectorXd > &values, const Eigen::Ref< const Eigen::Array< bool, -1, 1 >> &fixed)
Construct vertex with given values and fixed components.
VectorVertex(int dimension, bool fixed=false)
Construct and allocate memory for a given dimension.
void setLowerBounds(const Eigen::Ref< const Eigen::VectorXd > &lb) override
Define lower bounds on the vertex values [getDimension() x 1].
virtual void setFixed(bool fixed)
Set complete vertex to fixed (and hence skip during optimization)
void setFixed(const Eigen::Ref< const Eigen::Array< bool, -1, 1 >> &fixed)
Set logical array [dimension() x 1] in order to fix selected components.
void push() override
Store all values into a internal backup stack.
void discardTop() override
Delete the previously made backup from the stack without restoring it.
Vertex implementation that stores an Eigen::VectorXd (dynamic dimension)
const Eigen::VectorXd & values() const
Read-access to the underlying value vector.
double * getDataRaw() override
Get write access to the values of the vertex.
int getNumBackups() const override
Return the current size/number of backups of the backup stack.
const double * getLowerBounds() const override
Read-only raw access to lower bounds [getDimension() x 1].
PartiallyFixedVectorVertex(const Eigen::Ref< const Eigen::VectorXd > &values)
Construct vertex with given values.
bool hasFixedComponents() const override
Check if the vertex has fixed components.
PartiallyFixedVectorVertex(int dimension)
void plus(const double *inc) override
Define the increment for the vertex: x += inc with dim(inc)=getDimension().
int getNumberFiniteLowerBounds(bool unfixed_only) const override
Get number of finite lower bounds.
Eigen::Array< bool, -1, 1 > _fixed
void setFixed(int idx, bool fixed)
Set component with idx (0 <= idx < dimension()) to (un)fixed.
std::unique_ptr< VectorVertex > UPtr
PartiallyFixedVectorVertex(const Eigen::Ref< const Eigen::VectorXd > &values, const Eigen::Ref< const Eigen::VectorXd > &lb, const Eigen::Ref< const Eigen::VectorXd > &ub)
Construct vertex with given values, lower and upper bounds.
VectorVertex()=default
Default constructor.
void setLowerBound(int idx, double lb) override
Define lower bound on a single component of the vertex (0 <= idx < getDimension()) ...
int getNumberFiniteUpperBounds(bool unfixed_only) const override
Get number of finite upper bounds.