Skip to content

Commit

Permalink
Regroup computations for initial x
Browse files Browse the repository at this point in the history
  • Loading branch information
aescande committed Jun 11, 2024
1 parent b59d348 commit f2bcd34
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
1 change: 1 addition & 0 deletions include/jrl-qp/GoldfarbIdnaniSolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class JRLQP_DLLAPI GoldfarbIdnaniSolver : public DualSolver
mutable internal::Workspace<> work_d_;
internal::Workspace<> work_J_;
internal::Workspace<> work_R_;
internal::Workspace<> work_tmp_;
Problem pb_;
};

Expand Down
16 changes: 7 additions & 9 deletions src/GoldfarbIdnaniSolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include <Eigen/Cholesky>
#include <Eigen/QR>
#include <jrl-qp/GoldfarbIdnaniSolver.h>
#include <jrl-qp/experimental/GoldfarbIdnaniSolver.h>
#include <jrl-qp/internal/ConstraintNormal.h>

namespace jrl::qp
Expand Down Expand Up @@ -62,10 +61,8 @@ internal::InitTermination GoldfarbIdnaniSolver::init_()
if(ret >= 0) return TerminationStatus::NON_POS_HESSIAN;

auto J = work_J_.asMatrix(nbVar_, nbVar_, nbVar_);
auto x = work_x_.asVector(nbVar_);

// J = L^-t
// x = -G^-1 * a
switch(options_.gFactorization_)
{
case GFactorization::NONE:
Expand All @@ -75,29 +72,29 @@ internal::InitTermination GoldfarbIdnaniSolver::init_()
auto L = pb_.G.template triangularView<Eigen::Lower>();
J.setIdentity();
L.transpose().solveInPlace(J);
x = L.solve(pb_.a);
L.transpose().solveInPlace(x); // possible [OPTIM]: J already contains L^-T
}
break;
case GFactorization::L_INV:
{
auto invL = pb_.G.template triangularView<Eigen::Lower>();
J = invL.transpose();
x = invL * pb_.a;
x = J.template triangularView<Eigen::Upper>() * x;
}
break;
case GFactorization::L_TINV:
{
auto invLT = pb_.G.template triangularView<Eigen::Upper>();
J = invLT;
x = invLT.transpose() * pb_.a;
x = invLT * x;
}
break;
default:
assert(false);
}

// x = -G^-1 * a
auto x = work_x_.asVector(nbVar_);
auto tmp = work_tmp_.asVector(nbVar_);
tmp.noalias() = J.template triangularView<Eigen::Upper>().transpose() * pb_.a;
x.noalias() = J.template triangularView<Eigen::Upper>() * tmp;
x = -x;
f_ = 0.5 * pb_.a.dot(x);

Expand Down Expand Up @@ -291,6 +288,7 @@ void GoldfarbIdnaniSolver::resize_(int nbVar, int /*nbCstr*/, bool /*useBounds*/
work_d_.resize(nbVar);
work_J_.resize(nbVar, nbVar);
work_R_.resize(nbVar, nbVar);
work_tmp_.resize(nbVar);
}
}

Expand Down

0 comments on commit f2bcd34

Please sign in to comment.