25 #ifndef SRC_OPTIMIZATION_INCLUDE_CORBO_OPTIMIZATION_HYPER_GRAPH_EDGE_INTERFACE_H_ 26 #define SRC_OPTIMIZATION_INCLUDE_CORBO_OPTIMIZATION_HYPER_GRAPH_EDGE_INTERFACE_H_ 35 class VertexInterface;
36 class VertexSetInterface;
37 class EdgeSetInterface;
59 using Ptr = std::shared_ptr<EdgeInterface>;
60 using UPtr = std::unique_ptr<EdgeInterface>;
91 return values.squaredNorm();
112 using Ptr = std::shared_ptr<BaseEdge>;
113 using UPtr = std::unique_ptr<BaseEdge>;
183 virtual void computeHessianInc(
int vtx_idx_i,
int vtx_idx_j,
Eigen::Ref<Eigen::MatrixXd> block_hessian_ij,
const double* multipliers =
nullptr,
184 double weight = 1.0);
191 reserveValuesCacheMemory(num_value_vectors);
192 reserveJacobiansCacheMemory(num_jacobians);
222 using Ptr = std::shared_ptr<BaseMixedEdge>;
223 using UPtr = std::unique_ptr<BaseMixedEdge>;
225 int getDimension()
const override {
return getObjectiveDimension() + getEqualityDimension() + getInequalityDimension(); }
227 virtual int getObjectiveDimension()
const = 0;
228 virtual int getEqualityDimension()
const = 0;
229 virtual int getInequalityDimension()
const = 0;
231 virtual bool isObjectiveLeastSquaresForm()
const = 0;
238 virtual void precompute() = 0;
246 computeObjectiveValues(values);
247 computeEqualityValues(values.segment(getObjectiveDimension(), getEqualityDimension()));
248 computeInequalityValues(values.tail(getInequalityDimension()));
253 Eigen::VectorXd values(getObjectiveDimension());
254 computeObjectiveValues(values);
260 Eigen::VectorXd values(getObjectiveDimension());
261 computeObjectiveValues(values);
262 return values.squaredNorm();
265 virtual void computeObjectiveJacobian(
int vtx_idx,
Eigen::Ref<Eigen::MatrixXd> block_jacobian,
const double* multipliers =
nullptr);
266 virtual void computeEqualityJacobian(
int vtx_idx,
Eigen::Ref<Eigen::MatrixXd> block_jacobian,
const double* multipliers =
nullptr);
267 virtual void computeInequalityJacobian(
int vtx_idx,
Eigen::Ref<Eigen::MatrixXd> block_jacobian,
const double* multipliers =
nullptr);
269 const double* eq_multipliers =
nullptr,
const double* ineq_multipliers =
nullptr);
272 const double* eq_multipliers =
nullptr,
const double* ineq_multipliers =
nullptr);
284 const double* multipliers_ineq =
nullptr,
double weight_obj = 1.0);
288 const double* multipliers_ineq =
nullptr);
300 const double* multipliers_ineq =
nullptr,
double weight_obj = 1.0);
304 const double* multipliers_ineq =
nullptr);
311 reserveValuesCacheMemory(num_value_vectors, num_value_vectors, num_value_vectors);
312 reserveJacobiansCacheMemory(num_jacobians, num_jacobians, num_jacobians);
316 _objective_cache.reserveMemoryValues(num_obj_values);
317 _equality_cache.reserveMemoryValues(num_eq_values);
318 _inequality_cache.reserveMemoryValues(num_ineq_values);
322 _objective_cache.reserveMemoryJacobians(num_obj_jacobians);
323 _equality_cache.reserveMemoryJacobians(num_eq_jacobians);
324 _inequality_cache.reserveMemoryJacobians(num_ineq_jacobians);
353 int _edge_idx_obj = 0;
354 int _edge_idx_eq = 0;
355 int _edge_idx_ineq = 0;
364 #endif // SRC_OPTIMIZATION_INCLUDE_CORBO_OPTIMIZATION_HYPER_GRAPH_EDGE_INTERFACE_H_ EdgeCache & getObjectiveCache()
virtual bool providesJacobian() const
Return true if a custom Jacobian is provided (e.g. computeJacobian() is overwritten) ...
virtual int getDimension() const =0
Get dimension of the edge (dimension of the cost-function/constraint value vector) ...
std::unique_ptr< EdgeInterface > UPtr
virtual bool providesHessian() const
Return true if a custom Hessian is provided (e.g. computeHessian() is overwritten) ...
const EdgeCache & getCache() const
int getEdgeIdx() const
Retrieve current edge index (warning, this value is determined within the related HyperGraph) ...
virtual int getNumVertices() const =0
Return number of attached vertices.
const EdgeCache & getInequalityCache() const
void computeValuesCached()
Call computeValues() and store result to previously allocated internal cache (call allocateInteralVal...
virtual bool isInequalityLinear() const
int getEdgeObjectiveIdx() const
Retrieve current edge index (warning, this value is determined within the related HyperGraph) ...
void computeSquaredNormOfValuesCached()
compute the specialied squared-norm method for computing the values (note only the first element in t...
Generic interface class for vertices.
std::shared_ptr< EdgeInterface > Ptr
const EdgeCache & getEqualityCache() const
virtual bool isLeastSquaresForm() const
Defines if the edge is formulated as Least-Squares form.
void computeValues(Eigen::Ref< Eigen::VectorXd > values) final
Compute function values.
void computeSquaredNormOfObjectiveValuesCached()
compute the specialied squared-norm method for computing the values (note only the first element in t...
void reserveCacheMemory(int num_value_vectors, int num_jacobians)
Abstract class representing a set of edges.
void reserveValuesCacheMemory(int num_value_vectors)
void computeInequalityValuesCached()
Call computeInequalityValues() and store result to the internal cache.
virtual ~EdgeInterface()
Virtual destructor.
int getEdgeEqualityIdx() const
void reserveValuesCacheMemory(int num_obj_values, int num_eq_values, int num_ineq_values)
int getDimension() const override
Get dimension of the edge (dimension of the cost-function/constraint value vector) ...
virtual void computeValues(Eigen::Ref< Eigen::VectorXd > values)=0
Compute function values.
virtual double computeSumOfObjectiveValues()
void reserveJacobiansCacheMemory(int num_obj_jacobians, int num_eq_jacobians, int num_ineq_jacobians)
virtual int verticesDimension() const =0
Return the combined dimension of all attached vertices (excluding fixed vertex components) ...
virtual bool isLinear() const
Return true if the edge is linear (and hence its Hessian is always zero)
EdgeCache _equality_cache
void computeObjectiveValuesCached()
Call computeObjectiveValues() and store result to the internal cache.
virtual VertexInterface * getVertexRaw(int idx)=0
Get access to vertex with index idx (0 <= idx < numVertices)
EdgeCache & getInequalityCache()
A matrix or vector expression mapping an existing expression.
int getNumFiniteVerticesUpperBounds() const
EdgeCache _inequality_cache
virtual bool isEqualityLinear() const
EdgeCache & getCache()
Retreive values computed previously via computeValuesCached()
virtual double computeSquaredNormOfValues()
virtual double computeSquaredNormOfObjectiveValues()
EdgeCache & getEqualityCache()
void reserveJacobiansCacheMemory(int num_jacobians)
int getNumFiniteVerticesLowerBounds() const
EdgeCache _objective_cache
int getEdgeInequalityIdx() const
void reserveCacheMemory(int num_value_vectors, int num_jacobians)
Generic interface class for edges.
virtual const VertexInterface * getVertex(int idx) const =0
virtual bool isObjectiveLinear() const
Return true if the edge is linear (and hence its Hessian is always zero)
void computeEqualityValuesCached()
Call computeEqualityValues() and store result to the internal cache.
virtual double computeSumOfValues()
const EdgeCache & getObjectiveCache() const