Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve optimization interface #13

Merged
merged 1 commit into from
Feb 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading