48 std::vector<BaseEdge::Ptr> cost_terms, eq_terms, ineq_terms;
49 for (
int k = 0; k <
n - 1; ++k)
51 VectorVertex& x_next = (k <
n - 2) ?
_x_seq[k + 1] :
_xf;
58 nlp_fun.getNonIntegralStageFunctionEdges(k,
_x_seq[k],
_u_seq[k],
_dt, u_prev, dt_prev, cost_terms, eq_terms, ineq_terms);
59 for (
BaseEdge::Ptr& edge : cost_terms) edges.addObjectiveEdge(edge);
61 for (
BaseEdge::Ptr& edge : ineq_terms) edges.addInequalityEdge(edge);
63 if (nlp_fun.stage_cost && nlp_fun.stage_cost->hasIntegralTerms(k))
68 std::make_shared<TrapezoidalIntegralCostEdge>(
_x_seq[k],
_u_seq[k], x_next,
_dt, nlp_fun.stage_cost, k);
69 edges.addObjectiveEdge(edge);
74 edges.addObjectiveEdge(edge);
80 if (nlp_fun.stage_equalities && nlp_fun.stage_equalities->hasIntegralTerms(k))
85 dynamics,
_x_seq[k],
_u_seq[k], x_next,
_dt, nlp_fun.stage_equalities, k);
86 edge->setFiniteDifferencesCollocationMethod(
_fd_eval);
87 edges.addEqualityEdge(edge);
92 edges.addEqualityEdge(edge);
96 sys_edge->setFiniteDifferencesCollocationMethod(
_fd_eval);
97 edges.addEqualityEdge(sys_edge);
106 edge->setFiniteDifferencesCollocationMethod(
_fd_eval);
107 edges.addEqualityEdge(edge);
110 if (nlp_fun.stage_inequalities && nlp_fun.stage_inequalities->hasIntegralTerms(k))
115 std::make_shared<TrapezoidalIntegralInequalityEdge>(
_x_seq[k],
_u_seq[k], x_next,
_dt, nlp_fun.stage_inequalities, k);
116 edges.addInequalityEdge(edge);
121 edges.addInequalityEdge(edge);
133 if (cost_edge) edges.addObjectiveEdge(cost_edge);
139 if (nlp_fun.final_stage_constraints->isEqualityConstraint())
140 edges.addEqualityEdge(constr_edge);
142 edges.addInequalityEdge(constr_edge);
150 nlp_fun.getFinalControlDeviationEdges(
n,
_u_ref,
_u_seq.back(),
_dt, cost_terms, eq_terms, ineq_terms);
151 for (
BaseEdge::Ptr& edge : cost_terms) edges.addObjectiveEdge(edge);
152 for (
BaseEdge::Ptr& edge : eq_terms) edges.addEqualityEdge(edge);
153 for (
BaseEdge::Ptr& edge : ineq_terms) edges.addInequalityEdge(edge);
156 #ifdef MESSAGE_SUPPORT
157 void FiniteDifferencesGrid::fromMessage(
const messages::FiniteDifferencesGrid& message, std::stringstream* issues)
159 if (message.n() < 2 && issues) *issues <<
"FiniteDifferencesGrid: Number of states must be greater than or equal 2.\n";
160 if (message.dt() <= 0 && issues) *issues <<
"FiniteDifferencesGrid: Dt must be greater than 0.0.\n";
166 switch (message.cost_integration_rule())
168 case messages::FiniteDifferencesGrid::CostIntegrationRule::FiniteDifferencesGrid_CostIntegrationRule_LeftSum:
173 case messages::FiniteDifferencesGrid::CostIntegrationRule::FiniteDifferencesGrid_CostIntegrationRule_TrapezoidalRule:
187 util::get_oneof_field_type(message.fd_collocation(),
"fd_collocation", type,
false);
192 fd_eval->fromMessage(message.fd_collocation(), issues);
197 if (issues) *issues <<
"FiniteDifferencesGrid: unknown finite differences collocation method specified.\n";
202 void FiniteDifferencesGrid::toMessage(messages::FiniteDifferencesGrid& message)
const
215 message.set_cost_integration_rule(
216 messages::FiniteDifferencesGrid::CostIntegrationRule::FiniteDifferencesGrid_CostIntegrationRule_LeftSum);
221 message.set_cost_integration_rule(
222 messages::FiniteDifferencesGrid::CostIntegrationRule::FiniteDifferencesGrid_CostIntegrationRule_TrapezoidalRule);