[wpimath] Add Sleipnir (#6541)

This is useful for solving quadratic programs.
This commit is contained in:
Tyler Veness
2024-04-27 22:42:42 -07:00
committed by GitHub
parent 1e4a647918
commit fd363fdf5a
53 changed files with 9289 additions and 5 deletions

View File

@@ -0,0 +1,26 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include <gtest/gtest.h>
#include <sleipnir/optimization/OptimizationProblem.hpp>
TEST(SleipnirTest, Quartic) {
sleipnir::OptimizationProblem problem;
auto x = problem.DecisionVariable();
x.SetValue(20.0);
problem.Minimize(sleipnir::pow(x, 4));
problem.SubjectTo(x >= 1);
auto status = problem.Solve({.diagnostics = true});
EXPECT_EQ(status.costFunctionType, sleipnir::ExpressionType::kNonlinear);
EXPECT_EQ(status.equalityConstraintType, sleipnir::ExpressionType::kNone);
EXPECT_EQ(status.inequalityConstraintType, sleipnir::ExpressionType::kLinear);
EXPECT_EQ(status.exitCondition, sleipnir::SolverExitCondition::kSuccess);
EXPECT_NEAR(x.Value(), 1.0, 1e-6);
}