From 3b897950a6de479ab810bb510ff4992faedbd2b3 Mon Sep 17 00:00:00 2001 From: Duy-Nguyen Ta Date: Wed, 15 Jun 2016 09:35:43 -0400 Subject: [PATCH 1/2] fix a crash due to problems with boost adaptors on rvalue (https://svn.boost.org/trac/boost/ticket/9578) --- gtsam_unstable/linear/QPSolver.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/gtsam_unstable/linear/QPSolver.cpp b/gtsam_unstable/linear/QPSolver.cpp index d5e3d028f..d4436d141 100644 --- a/gtsam_unstable/linear/QPSolver.cpp +++ b/gtsam_unstable/linear/QPSolver.cpp @@ -183,11 +183,11 @@ pair QPSolver::optimize( pair QPSolver::optimize() const { //Make an LP with any linear cost function. It doesn't matter for initialization. LP initProblem; - Key newKey = 0; // make an unrelated key for a random variable cost - for (Key key : qp_.cost.getKeyDimMap() | boost::adaptors::map_keys) - if (newKey < key) - newKey = key; - newKey++; + // make an unrelated key for a random variable cost: max key + 1 + std::array maxKeys = {*qp_.cost.keys().rbegin(), + *qp_.equalities.keys().rbegin(), + *qp_.inequalities.keys().rbegin()}; + Key newKey = *std::max_element(maxKeys.begin(), maxKeys.end()) + 1; initProblem.cost = LinearCost(newKey, Vector::Ones(1)); initProblem.equalities = qp_.equalities; initProblem.inequalities = qp_.inequalities; From 3c85e2d625b20c3b5080fd3023e083d890c7b053 Mon Sep 17 00:00:00 2001 From: Duy-Nguyen Ta Date: Wed, 15 Jun 2016 11:36:04 -0400 Subject: [PATCH 2/2] fix bad bugs when constrained graphs are empty --- gtsam_unstable/linear/QPSolver.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/gtsam_unstable/linear/QPSolver.cpp b/gtsam_unstable/linear/QPSolver.cpp index d4436d141..eb2f40e05 100644 --- a/gtsam_unstable/linear/QPSolver.cpp +++ b/gtsam_unstable/linear/QPSolver.cpp @@ -184,10 +184,12 @@ pair QPSolver::optimize() const { //Make an LP with any linear cost function. It doesn't matter for initialization. LP initProblem; // make an unrelated key for a random variable cost: max key + 1 - std::array maxKeys = {*qp_.cost.keys().rbegin(), - *qp_.equalities.keys().rbegin(), - *qp_.inequalities.keys().rbegin()}; - Key newKey = *std::max_element(maxKeys.begin(), maxKeys.end()) + 1; + Key newKey = *qp_.cost.keys().rbegin(); + if (!qp_.equalities.empty()) + newKey = std::max(newKey, *qp_.equalities.keys().rbegin()); + if (!qp_.inequalities.empty()) + newKey = std::max(newKey, *qp_.inequalities.keys().rbegin()); + ++newKey; initProblem.cost = LinearCost(newKey, Vector::Ones(1)); initProblem.equalities = qp_.equalities; initProblem.inequalities = qp_.inequalities;