.. _program_listing_file_include_eiquadprog_eiquadprog-rt.hpp: Program Listing for File eiquadprog-rt.hpp ========================================== |exhale_lsh| :ref:`Return to documentation for file ` (``include/eiquadprog/eiquadprog-rt.hpp``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp // // Copyright (c) 2017 CNRS // // This file is part of eiquadprog. // // eiquadprog is free software: you can redistribute it and/or modify // it under the terms of the GNU Lesser General Public License as published by // the Free Software Foundation, either version 3 of the License, or //(at your option) any later version. // eiquadprog is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Lesser General Public License for more details. // You should have received a copy of the GNU Lesser General Public License // along with eiquadprog. If not, see . #ifndef __eiquadprog_rt_hpp__ #define __eiquadprog_rt_hpp__ #include #include "eiquadprog/eiquadprog-utils.hxx" #define OPTIMIZE_STEP_1_2 // compute s(x) = ci^T * x + ci0 #define OPTIMIZE_COMPUTE_D // use noalias #define OPTIMIZE_UPDATE_Z // use noalias #define OPTIMIZE_HESSIAN_INVERSE // use solveInPlace #define OPTIMIZE_UNCONSTR_MINIM // #define USE_WARM_START // #define PROFILE_EIQUADPROG // #define DEBUG_STREAM(msg) std::cout< struct RtMatrixX { typedef Eigen::Matrix d; }; template struct RtVectorX { typedef Eigen::Matrix d; typedef Eigen::Matrix i; }; namespace eiquadprog { namespace solvers { enum RtEiquadprog_status { RT_EIQUADPROG_OPTIMAL = 0, RT_EIQUADPROG_INFEASIBLE = 1, RT_EIQUADPROG_UNBOUNDED = 2, RT_EIQUADPROG_MAX_ITER_REACHED = 3, RT_EIQUADPROG_REDUNDANT_EQUALITIES = 4 }; template class RtEiquadprog { public: EIGEN_MAKE_ALIGNED_OPERATOR_NEW RtEiquadprog(); virtual ~RtEiquadprog(); int getMaxIter() const { return m_maxIter; } bool setMaxIter(int maxIter) { if (maxIter < 0) return false; m_maxIter = maxIter; return true; } int getActiveSetSize() const { return q; } int getIteratios() const { return iter; } double getObjValue() const { return f_value; } const typename RtVectorX::d& getLagrangeMultipliers() const { return u; } const typename RtVectorX::i& getActiveSet() const { return A; } RtEiquadprog_status solve_quadprog( const typename RtMatrixX::d& Hess, const typename RtVectorX::d& g0, const typename RtMatrixX::d& CE, const typename RtVectorX::d& ce0, const typename RtMatrixX::d& CI, const typename RtVectorX::d& ci0, typename RtVectorX::d& x); typename RtMatrixX::d m_J; // J * J' = Hessian bool is_inverse_provided_; private: int m_maxIter; double f_value; Eigen::LLT::d, Eigen::Lower> chol_; double solver_return_; typename RtMatrixX::d R; typename RtVectorX::d s; typename RtVectorX::d r; typename RtVectorX::d u; typename RtVectorX::d z; typename RtVectorX::d d; typename RtVectorX::d np; typename RtVectorX::i A; typename RtVectorX::i iai; typename RtVectorX::i iaexcl; typename RtVectorX::d x_old; // old value of x typename RtVectorX::d u_old; // old value of u typename RtVectorX::i A_old; // old value of A #ifdef OPTIMIZE_ADD_CONSTRAINT typename RtVectorX::d T1; // tmp vector #endif int q; int iter; template inline Scalar distance(Scalar a, Scalar b) { Scalar a1, b1, t; a1 = std::abs(a); b1 = std::abs(b); if (a1 > b1) { t = (b1 / a1); return a1 * std::sqrt(1.0 + t * t); } else if (b1 > a1) { t = (a1 / b1); return b1 * std::sqrt(1.0 + t * t); } return a1 * std::sqrt(2.0); } inline void compute_d(typename RtVectorX::d& d, const typename RtMatrixX::d& J, const typename RtVectorX::d& np) { #ifdef OPTIMIZE_COMPUTE_D d.noalias() = J.adjoint() * np; #else d = J.adjoint() * np; #endif } inline void update_z(typename RtVectorX::d& z, const typename RtMatrixX::d& J, const typename RtVectorX::d& d, int iq) { #ifdef OPTIMIZE_UPDATE_Z z.noalias() = J.rightCols(nVars - iq) * d.tail(nVars - iq); #else z = J.rightCols(J.cols() - iq) * d.tail(J.cols() - iq); #endif } inline void update_r(const typename RtMatrixX::d& R, typename RtVectorX::d& r, const typename RtVectorX::d& d, int iq) { r.head(iq) = d.head(iq); R.topLeftCorner(iq, iq) .template triangularView() .solveInPlace(r.head(iq)); } bool add_constraint(typename RtMatrixX::d& R, typename RtMatrixX::d& J, typename RtVectorX::d& d, int& iq, double& R_norm); void delete_constraint(typename RtMatrixX::d& R, typename RtMatrixX::d& J, typename RtVectorX::i& A, typename RtVectorX::d& u, int& iq, int l); }; } /* namespace solvers */ } /* namespace eiquadprog */ #include "eiquadprog/eiquadprog-rt.hxx" /* --- Details * -------------------------------------------------------------------- */ #endif /* __eiquadprog_rt_hpp__ */