4 #define SOLVER_VERBOSE 0 6 # define IF_SOLVER_VERBOSE(x) x 8 # define IF_SOLVER_VERBOSE(x) ((void)0); 45 static const std::string info =
"";
61 return _A.topRows(
_m);
71 return VectorXd::Zero(
_m);
76 return _A.bottomRows(
_p);
86 return VectorXd::Zero(
_p);
91 return VectorXd::Constant(
_p, 1e10);
109 updateObjectiveEquations();
110 updateEqualityEquations();
111 updateInequalityEquations();
116 std::cout <<
"obj" << std::endl;
117 std::cout << _C << std::endl << std::endl;
118 std::cout << _d << std::endl << std::endl;
120 std::cout <<
"cstr" << std::endl;
121 std::cout << _A << std::endl << std::endl;
122 std::cout << _b << std::endl << std::endl;
124 std::cout <<
"bnd" << std::endl;
125 std::cout << _xl << std::endl << std::endl;
126 std::cout << _xu << std::endl << std::endl;
134 info = _solver->
solve(_C, _d, _A, _b, static_cast<int>(
_m), x, _xl, _xu);
143 void QLDSolver::resize()
149 int mp =
static_cast<int>(
_m+
_ps);
151 _buffer.
resize(_n*(_n+mp+3)+mp);
163 _xl.setConstant(-_infinity);
164 _xu.setConstant(+_infinity);
168 void QLDSolver::updateEqualityEquations()
174 int dim = cstr->getDimension();
177 Eigen::Block<MatrixMap> _A_block = _A.block(m, 0, dim,
n());
178 Eigen::DenseBase<VectorMap>::SegmentReturnType _b_segment = _b.segment(m, dim);
186 void QLDSolver::updateInequalityEquations()
188 int p =
static_cast<int>(
_m);
192 int dim = cstr->getDimension();
198 Eigen::Block<Eigen::Map<Eigen::MatrixXd> > _A_block = _A.block(p, 0, dim,
n());
199 Eigen::VectorBlock<Eigen::Map<Eigen::Matrix<double, Eigen::Dynamic, 1> > > _b_segment = _b.segment(p, dim);
207 void QLDSolver::updateObjectiveEquations()
217 void QLDSolver::updateBounds()
219 for (
size_t i=0; i<
_bounds.size(); ++i)
222 const std::vector<int>& mapping =
findMapping(cstr->getVariable());
229 void QLDSolver::translateReturnInfo(
eReturnInfo& ocraInfo,
int qldInfo)
241 throw std::runtime_error(
"[QLDSolver::translateReturnInfo] invalid info number.");
245 #undef SOLVER_VERBOSE 246 #undef IF_SOLVER_VERBOSE 383 MatrixXd A1(1,1); A1 << 1;
384 VectorXd b1(1); b1 << -3;
388 MatrixXd A2(1,2); A2 << 3,1 ;
389 VectorXd b2(1); b2 << 0;
393 MatrixXd A3(2,2); A3 << 2,1,-0.5,1 ;
394 VectorXd b3(2); b3 << 0, 1;
407 std::cout <<
"sol = " << std::endl << solver.
solve().
solution << std::endl << std::endl;
413 VectorXd lz(1); lz << 1;
414 VectorXd uz(1); uz << 2;
417 std::cout <<
"sol = " << std::endl << solver.
solve().
solution << std::endl << std::endl;
421 VectorXd ut(2); ut << -4,-1;
426 QuadraticFunction objFunc2(t, Matrix2d::Identity(), Vector2d::Constant(2.71828),0);
429 std::cout <<
"sol = " << std::endl << solver.
solve().
solution << std::endl << std::endl;
434 std::cout <<
"sol = " << std::endl << solver.
solve().
solution << std::endl << std::endl;
const Variable & getVariable() const
void setTolerance(double epsilon)
void addCompressed2d(const MatrixBase< Derived1 > &in, MatrixBase< Derived2 > const &_out, const std::vector< int > &mapping, double scale, bool reverseMapping)
std::vector< LinearConstraint * > _equalityConstraints
void removeConstraint(LinearConstraint &constraint)
int solve(Map< MatrixXd > &C, const Map< VectorXd > &d, const Map< MatrixXd > &A, const Map< VectorXd > &b, int me, Map< VectorXd > &x, const Map< VectorXd > &xl, const Map< VectorXd > &xu, bool factorizedC=false)
OptimizationResult _result
const OptimizationResult & solve()
void addBounds(BoundConstraint &constraint)
const std::vector< int > & findMapping(Variable &var)
const std::string & getMoreInfo() const
Optimization-based Robot Controller namespace. a library of classes to write and solve optimization p...
Map< MatrixXd > MatrixMap
Declaration file of the QLDSolver class.
void addConstraint(LinearConstraint &constraint)
double getTolerance(void) const
void convert(const LinearConstraint &cstr, const std::vector< int > &mapping, eConstraintOutput type, MatrixBase< Derived > &A, VectorBase1 &b, VectorBase2 &l, double infinity=0.)
const VectorXd & getqi(int index=0) const
void addCompressedByRow(const MatrixBase< Derived1 > &in, MatrixBase< Derived2 > const &_out, const std::vector< int > &mapping, double scale, bool reverseMapping)
const MatrixXd & getPi(int index=0) const
Map< VectorXd > VectorMap
std::vector< LinearConstraint * > _inequalityConstraints
const OptimizationResult & getLastResult() const
void addObjective(QuadraticObjective &obj)
void intersectBounds(const DiagonalLinearConstraint &bounds, const std::vector< int > &mapping, VectorBase1 &bl, VectorBase2 &bu)
std::vector< DiagonalLinearConstraint * > _bounds
std::vector< QuadraticObjective * > _objectives
A concatenation of base variables and other composite variables.
double getEps(void) const
#define ocra_assert(ocra_expression)
Implements a basic variable.
#define IF_SOLVER_VERBOSE(x)
ptr_type allocate(size_t n)