Skip to content

Commit

Permalink
Improve optimization interface
Browse files Browse the repository at this point in the history
  • Loading branch information
eastskykang authored and fdevinc committed Feb 15, 2024
1 parent 98ad589 commit 90e7e77
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions include/ungar/optimization/soft_sqp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,26 @@ class SoftSQPOptimizer {
return _cache.xp.head(nlpProblem.objective.IndependentVariableSize());
}

Autodiff::Function MakeSoftInequalityConstraintFunction(
const Concepts::NLPProblem auto& nlpProblem) const {
auto Zsoft = [&](const VectorXad& variables, VectorXad& Zsoft) -> void {
Zsoft.resize(1_idx);
Zsoft << SoftInequalityConstraint{0.0, _stiffness, _epsilon}.Evaluate<ad_scalar_t>(
-variables);
};

std::string softIneqModelName = Utils::ToSnakeCase(
"soft_sqp_soft_ineq_sz_"s +
std::to_string(nlpProblem.inequalityConstraints.DependentVariableSize()) + "_k_" +
std::to_string(_stiffness) + "_eps_" + std::to_string(_epsilon));
return Autodiff::MakeFunction({Zsoft,
nlpProblem.inequalityConstraints.DependentVariableSize(),
0_idx,
softIneqModelName,
EnabledDerivatives::ALL},
false);
}

private:
template <typename _XP> // clang-format off
requires std::same_as<typename _XP::Scalar, real_t>
Expand Down Expand Up @@ -203,26 +223,6 @@ class SoftSQPOptimizer {
}
}

Autodiff::Function MakeSoftInequalityConstraintFunction(
const Concepts::NLPProblem auto& nlpProblem) const {
auto Zsoft = [&](const VectorXad& variables, VectorXad& Zsoft) -> void {
Zsoft.resize(1_idx);
Zsoft << SoftInequalityConstraint{0.0, _stiffness, _epsilon}.Evaluate<ad_scalar_t>(
-variables);
};

std::string softIneqModelName = Utils::ToSnakeCase(
"soft_sqp_soft_ineq_sz_"s +
std::to_string(nlpProblem.inequalityConstraints.DependentVariableSize()) + "_k_" +
std::to_string(_stiffness) + "_eps_" + std::to_string(_epsilon));
return Autodiff::MakeFunction({Zsoft,
nlpProblem.inequalityConstraints.DependentVariableSize(),
0_idx,
softIneqModelName,
EnabledDerivatives::ALL},
false);
}

template <typename _XP> // clang-format off
requires std::same_as<typename _XP::Scalar, real_t>
real_t EvaluateSoftInequalityConstraints(const Concepts::NLPProblem auto& nlpProblem,
Expand Down

0 comments on commit 90e7e77

Please sign in to comment.