41 std::vector<BaseEdge::Ptr> cost_terms, eq_terms, ineq_terms;
45 for (
int k = 0; k <
n - 1; ++k)
63 nlp_fun.getNonIntegralStageFunctionEdges(k,
_x_seq[k],
_u_seq[block_idx],
_dt, u_prev, dt_prev, cost_terms, eq_terms, ineq_terms);
64 for (
BaseEdge::Ptr& edge : cost_terms) edges.addObjectiveEdge(edge);
65 for (
BaseEdge::Ptr& edge : eq_terms) edges.addEqualityEdge(edge);
66 for (
BaseEdge::Ptr& edge : ineq_terms) edges.addInequalityEdge(edge);
68 if (nlp_fun.stage_cost && nlp_fun.stage_cost->hasIntegralTerms(k))
73 std::make_shared<TrapezoidalIntegralCostEdge>(
_x_seq[k],
_u_seq[block_idx], x_next,
_dt, nlp_fun.stage_cost, k);
74 edges.addObjectiveEdge(edge);
79 edges.addObjectiveEdge(edge);
85 if (nlp_fun.stage_equalities && nlp_fun.stage_equalities->hasIntegralTerms(k))
90 dynamics,
_x_seq[k],
_u_seq[block_idx], x_next,
_dt, nlp_fun.stage_equalities, k);
91 edge->setFiniteDifferencesCollocationMethod(
_fd_eval);
92 edges.addEqualityEdge(edge);
97 edges.addEqualityEdge(edge);
101 sys_edge->setFiniteDifferencesCollocationMethod(
_fd_eval);
102 edges.addEqualityEdge(sys_edge);
111 edge->setFiniteDifferencesCollocationMethod(
_fd_eval);
112 edges.addEqualityEdge(edge);
115 if (nlp_fun.stage_inequalities && nlp_fun.stage_inequalities->hasIntegralTerms(k))
120 std::make_shared<TrapezoidalIntegralInequalityEdge>(
_x_seq[k],
_u_seq[block_idx], x_next,
_dt, nlp_fun.stage_inequalities, k);
121 edges.addInequalityEdge(edge);
126 std::make_shared<LeftSumInequalityEdge>(
_x_seq[k],
_u_seq[block_idx],
_dt, nlp_fun.stage_inequalities, k);
127 edges.addInequalityEdge(edge);
139 if (cost_edge) edges.addObjectiveEdge(cost_edge);
145 if (nlp_fun.final_stage_constraints->isEqualityConstraint())
146 edges.addEqualityEdge(constr_edge);
148 edges.addInequalityEdge(constr_edge);
156 nlp_fun.getFinalControlDeviationEdges(
n,
_u_ref,
_u_seq.back(),
_dt, cost_terms, eq_terms, ineq_terms);
157 for (
BaseEdge::Ptr& edge : cost_terms) edges.addObjectiveEdge(edge);
158 for (
BaseEdge::Ptr& edge : eq_terms) edges.addEqualityEdge(edge);
159 for (
BaseEdge::Ptr& edge : ineq_terms) edges.addInequalityEdge(edge);
162 #ifdef MESSAGE_SUPPORT
163 void FiniteDifferencesGridMoveBlocking::fromMessage(
const messages::FiniteDifferencesGridMoveBlocking& message, std::stringstream* issues)
165 if (message.n() < 2 && issues) *issues <<
"FiniteDifferencesGridMoveBlocking: Number of states must be greater than or equal 2.\n";
166 if (message.dt() <= 0 && issues) *issues <<
"FiniteDifferencesGridMoveBlocking: Dt must be greater than 0.0.\n";
173 switch (message.cost_integration_rule())
175 case messages::FiniteDifferencesGridMoveBlocking::CostIntegrationRule::FiniteDifferencesGridMoveBlocking_CostIntegrationRule_LeftSum:
180 case messages::FiniteDifferencesGridMoveBlocking::CostIntegrationRule::FiniteDifferencesGridMoveBlocking_CostIntegrationRule_TrapezoidalRule:
187 PRINT_ERROR_NAMED(
"FiniteDifferencesGridMoveBlocking: Selected cost integration rule not implemented");
194 util::get_oneof_field_type(message.fd_collocation(),
"fd_collocation", type,
false);
199 fd_eval->fromMessage(message.fd_collocation(), issues);
204 if (issues) *issues <<
"FiniteDifferencesGridMoveBlocking: unknown finite differences collocation method specified.\n";
209 if (message.b_size() >
getNRef() - 1 && issues)
211 *issues <<
"FiniteDifferencesGridMoveBlocking: Cannot have more blocking indices than controls.\n";
217 void FiniteDifferencesGridMoveBlocking::toMessage(messages::FiniteDifferencesGridMoveBlocking& message)
const
231 message.set_cost_integration_rule(
232 messages::FiniteDifferencesGridMoveBlocking::CostIntegrationRule::FiniteDifferencesGridMoveBlocking_CostIntegrationRule_LeftSum);
237 message.set_cost_integration_rule(messages::FiniteDifferencesGridMoveBlocking::CostIntegrationRule::
238 FiniteDifferencesGridMoveBlocking_CostIntegrationRule_TrapezoidalRule);
243 PRINT_ERROR_NAMED(
"FiniteDifferencesGridMoveBlocking: Selected cost integration rule not implemented");