25 #ifndef SRC_OPTIMIZATION_INCLUDE_CORBO_OPTIMIZATION_HYPER_GRAPH_GENERIC_EDGE_H_ 26 #define SRC_OPTIMIZATION_INCLUDE_CORBO_OPTIMIZATION_HYPER_GRAPH_GENERIC_EDGE_H_ 67 template <
class... VerticesT>
76 using ExtFunT = std::function<double(const VertexContainer&)>;
77 using ExtJacobT = std::function<void(const VertexContainer&, int, Eigen::Ref<Eigen::MatrixXd>,
const double*)>;
79 using Ptr = std::shared_ptr<EdgeGenericScalarFun>;
80 using UPtr = std::unique_ptr<EdgeGenericScalarFun>;
96 bool isLinear()
const override {
return false; }
149 template <
int D,
class... VerticesT>
156 using Ptr = std::shared_ptr<EdgeGenericVectorFun>;
157 using UPtr = std::unique_ptr<EdgeGenericVectorFun>;
164 using ExtFunT = std::function<void(const VertexContainer&, Eigen::Ref<ErrorVector>)>;
165 using ExtJacobT = std::function<void(const VertexContainer&, int, Eigen::Ref<Eigen::MatrixXd>,
const double*)>;
210 template <
class... VerticesT>
217 using Ptr = std::shared_ptr<MixedEdgeGenericVectorFun>;
218 using UPtr = std::unique_ptr<MixedEdgeGenericVectorFun>;
225 using ExtFunT = std::function<void(const VertexContainer&, Eigen::Ref<Eigen::VectorXd>)>;
230 const ExtFunT& eq_fun,
const ExtFunT& ineq_fun, VerticesT&... vertices)
232 _preqcompute_fun(precompute_fun),
284 bool _obj_lsq_form =
false;
294 template <
typename T,
void (T::*ComputeMethod)(
int, const Eigen::Ref<const Eigen::VectorXd>&, Eigen::Ref<Eigen::VectorXd>) const>
298 using Ptr = std::shared_ptr<UnaryVectorVertexEdge>;
301 :
Edge<
VectorVertex>(vertex), _dimension(dim), _k(k), _is_linear(is_linear), _is_lsq(is_lsq), _fun_obj(fun_obj)
308 bool isLinear()
const override {
return _is_linear; }
320 (_fun_obj.*ComputeMethod)(_k, vertex->
values(), values);
326 bool _is_linear =
false;
327 bool _is_lsq =
false;
332 template <
typename T,
void (T::*ComputeMethod)(
int,
double, Eigen::Ref<Eigen::VectorXd>) const>
336 using Ptr = std::shared_ptr<UnaryScalarVertexEdge>;
339 :
Edge<
ScalarVertex>(vertex), _dimension(dim), _k(k), _is_linear(is_linear), _is_lsq(is_lsq), _fun_obj(fun_obj)
346 bool isLinear()
const override {
return _is_linear; }
358 (_fun_obj.*ComputeMethod)(_k, vertex->
value(), values);
364 bool _is_linear =
false;
365 bool _is_lsq =
false;
370 template <
typename T,
void (T::*ComputeMethod)(
int, const Eigen::Ref<const Eigen::VectorXd>&, const Eigen::Ref<const Eigen::VectorXd>&,
371 Eigen::Ref<Eigen::VectorXd>) const>
375 using Ptr = std::shared_ptr<BinaryVectorVertexEdge>;
385 bool isLinear()
const override {
return _is_linear; }
398 (_fun_obj.*ComputeMethod)(_k, vertex1->
values(), vertex2->
values(), values);
404 bool _is_linear =
false;
405 bool _is_lsq =
false;
410 template <
typename T,
void (T::*ComputeMethod)(
int, const Eigen::Ref<const Eigen::VectorXd>&,
double, Eigen::Ref<Eigen::VectorXd>) const>
414 using Ptr = std::shared_ptr<BinaryVectorScalarVertexEdge>;
424 bool isLinear()
const override {
return _is_linear; }
437 (_fun_obj.*ComputeMethod)(_k, vertex1->
values(), vertex2->
value(), values);
443 bool _is_linear =
false;
444 bool _is_lsq =
false;
449 template <
typename T,
void (T::*ComputeMethod)(
int, const Eigen::Ref<const Eigen::VectorXd>&, const Eigen::Ref<const Eigen::VectorXd>&,
double,
450 Eigen::Ref<Eigen::VectorXd>) const>
454 using Ptr = std::shared_ptr<TernaryVectorScalarVertexEdge>;
457 bool is_linear,
bool is_lsq)
461 _is_linear(is_linear),
470 bool isLinear()
const override {
return _is_linear; }
484 (_fun_obj.*ComputeMethod)(_k, vec_vtx1->
values(), vec_vtx2->
values(), scalar_vtx->
value(), values);
490 bool _is_linear =
false;
491 bool _is_lsq =
false;
498 #endif // SRC_OPTIMIZATION_INCLUDE_CORBO_OPTIMIZATION_HYPER_GRAPH_GENERIC_EDGE_H_ void computeJacobian(int vtx_idx, Eigen::Ref< Eigen::MatrixXd > block_jacobian, const double *multiplier) override
Compute edge block jacobian for a given vertex.
bool providesJacobian() const override
Return true if a custom Jacobian is provided (e.g. computeJacobian() is overwritten) ...
int getDimension() const override
Get dimension of the edge (dimension of the cost-function/constraint value vector) ...
int getDimension() const override
Get dimension of the edge (dimension of the cost-function/constraint value vector) ...
std::unique_ptr< EdgeInterface > UPtr
bool isLinear() const override
Return true if the edge is linear (and hence its Hessian is always zero)
int getObjectiveDimension() const override
Construct generic vector function edge by passing the dimension D, the function object, a jacobian and all vertices.
void precompute() override
std::function< void(const VertexContainer &, int, Eigen::Ref< Eigen::MatrixXd >, const double *)> ExtJacobT
bool isLeastSquaresForm() const override
Defines if the edge is formulated as Least-Squares form.
bool providesJacobian() const override
Return true if a custom Jacobian is provided (e.g. computeJacobian() is overwritten) ...
ExtFunT _fun
Store the external function or functor.
EdgeGenericVectorFun(const ExtFunT &fun, const ExtJacobT &jacobian, bool lsq_form, VerticesT &... vertices)
Construct generic vector function edge by passing the dimension D, the function object, a jacobian and all vertices.
void computeObjectiveValues(Eigen::Ref< Eigen::VectorXd > obj_values) override
std::function< void(const VertexContainer &, Eigen::Ref< Eigen::VectorXd >)> ExtFunT
void setLinear(bool linear)
void setLinear(bool linear)
int getDimension() const override
Get dimension of the edge (dimension of the cost-function/constraint value vector) ...
void computeValues(Eigen::Ref< Eigen::VectorXd > values) override
Compute function values.
#define EIGEN_MAKE_ALIGNED_OPERATOR_NEW
bool isLinear() const override
Return true if the edge is linear (and hence its Hessian is always zero)
bool providesJacobian() const override
Return true if a custom Jacobian is provided (e.g. computeJacobian() is overwritten) ...
UnaryScalarVertexEdge(int dim, int k, const T &fun_obj, ScalarVertex &vertex, bool is_linear, bool is_lsq)
std::function< void(const VertexContainer &)> ExtPrecomputeT
BinaryVectorScalarVertexEdge(int dim, int k, const T &fun_obj, VectorVertex &vertex1, ScalarVertex &vertex2, bool is_linear, bool is_lsq)
std::shared_ptr< EdgeInterface > Ptr
std::function< double(const VertexContainer &)> ExtFunT
Vertex implementation for scalar values.
void computeValues(Eigen::Ref< Eigen::VectorXd > values) override
Compute function values.
BinaryVectorVertexEdge(int dim, int k, const T &fun_obj, VectorVertex &vertex1, VectorVertex &vertex2, bool is_linear, bool is_lsq)
std::function< void(const VertexContainer &, Eigen::Ref< ErrorVector >)> ExtFunT
ExtPrecomputeT _preqcompute_fun
void setObjectiveLsqForm(bool obj_lsq)
std::array< VertexInterface *, numVerticesCompileTime > VertexContainer
Typedef to represent the vertex container.
bool isLinear() const override
Return true if the edge is linear (and hence its Hessian is always zero)
bool isLeastSquaresForm() const override
Defines if the edge is formulated as Least-Squares form.
Generic edge for functions .
UnaryVectorVertexEdge(int dim, int k, const T &fun_obj, VectorVertex &vertex, bool is_linear=false, bool is_lsq=false)
bool isLeastSquaresForm() const override
Defines if the edge is formulated as Least-Squares form.
void computeValues(Eigen::Ref< Eigen::VectorXd > values) override
Compute function values.
void computeValues(Eigen::Ref< Eigen::VectorXd > values) override
Compute function values.
bool isLeastSquaresForm() const override
Defines if the edge is formulated as Least-Squares form.
ExtFunT _fun
Store the external function or functor.
bool providesJacobian() const override
Return true if a custom Jacobian is provided (e.g. computeJacobian() is overwritten) ...
int getInequalityDimension() const override
bool providesJacobian() const override
Return true if a custom Jacobian is provided (e.g. computeJacobian() is overwritten) ...
void computeValues(Eigen::Ref< Eigen::VectorXd > values) override
Compute function values.
void computeEqualityValues(Eigen::Ref< Eigen::VectorXd > eq_values) override
TernaryVectorScalarVertexEdge(int dim, int k, const T &fun_obj, VectorVertex &vec_vtx1, VectorVertex &vec_vtx2, ScalarVertex &scalar_vtx, bool is_linear, bool is_lsq)
bool isLeastSquaresForm() const override
Defines if the edge is formulated as Least-Squares form.
Generic edge for functions .
const double & value() const
Get underlying value.
bool isLinear() const override
Return true if the edge is linear (and hence its Hessian is always zero)
bool providesJacobian() const override
Return true if a custom Jacobian is provided (e.g. computeJacobian() is overwritten) ...
A matrix or vector expression mapping an existing expression.
ExtFunT _obj_fun
Store the external function or functor.
EdgeGenericScalarFun(const ExtFunT &fun, bool lsq_form, VerticesT &... vertices)
Construct generic scalar function edge by passing the function object and all vertices.
void computeValues(Eigen::Ref< Eigen::VectorXd > values) override
Compute function values.
int getDimension() const override
Get dimension of the edge (dimension of the cost-function/constraint value vector) ...
int getDimension() const override
Get dimension of the edge (dimension of the cost-function/constraint value vector) ...
bool isLeastSquaresForm() const override
Defines if the edge is formulated as Least-Squares form.
EdgeGenericScalarFun(const ExtFunT &fun, const ExtJacobT &jacobian, bool lsq_form, VerticesT &... vertices)
Construct generic scalar function edge by passing the function object, a jacobian, and all vertices.
bool isLinear() const override
Return true if the edge is linear (and hence its Hessian is always zero)
virtual void computeJacobian(int vtx_idx, Eigen::Ref< Eigen::MatrixXd > block_jacobian, const double *multipliers=nullptr)
Compute edge block jacobian for a given vertex.
int getDimension() const override
Get dimension of the edge (dimension of the cost-function/constraint value vector) ...
void setLinear(bool linear)
Templated base edge class that stores an arbitary number of value.
void computeValues(Eigen::Ref< Eigen::VectorXd > values) override
Compute function values.
void computeJacobian(int vtx_idx, Eigen::Ref< Eigen::MatrixXd > block_jacobian, const double *multiplier=nullptr) override
Compute edge block jacobian for a given vertex.
void computeInequalityValues(Eigen::Ref< Eigen::VectorXd > ineq_values) override
Vertex implementation that stores an Eigen::VectorXd (dynamic dimension)
int getEqualityDimension() const override
bool isObjectiveLeastSquaresForm() const override
bool providesJacobian() const override
Return true if a custom Jacobian is provided (e.g. computeJacobian() is overwritten) ...
const Eigen::VectorXd & values() const
Read-access to the underlying value vector.
const VertexContainer _vertices
Vertex container.
bool isLinear() const override
Return true if the edge is linear (and hence its Hessian is always zero)
The matrix class, also used for vectors and row-vectors.
EdgeGenericVectorFun(const ExtFunT &fun, bool lsq_form, VerticesT &... vertices)
Construct generic vector function edge by passing the dimension D, the function object and all vertic...
MixedEdgeGenericVectorFun(int obj_dim, int eq_dim, int ineq_dim, const ExtPrecomputeT &precompute_fun, const ExtFunT &obj_fun, const ExtFunT &eq_fun, const ExtFunT &ineq_fun, VerticesT &... vertices)
Construct generic vector function edge by passing the dimension D, the function object and all vertic...
bool isLinear() const override
Return true if the edge is linear (and hence its Hessian is always zero)
std::function< void(const VertexContainer &, int, Eigen::Ref< Eigen::MatrixXd >, const double *)> ExtJacobT
int getDimension() const override
Get dimension of the edge (dimension of the cost-function/constraint value vector) ...
bool isLeastSquaresForm() const override
Defines if the edge is formulated as Least-Squares form.