[BUGFIX-WARNING] Fixed warning in gcc5 by adding SYSTEM to gtsam included eigen.
parent
28f7704eea
commit
6cc4ab8bdf
|
@ -1,3 +1,4 @@
|
||||||
|
/gtsam/inference/FactorGraph.h
|
||||||
/build*
|
/build*
|
||||||
.idea
|
.idea
|
||||||
*.pyc
|
*.pyc
|
||||||
|
|
|
@ -241,7 +241,7 @@ else()
|
||||||
endif()
|
endif()
|
||||||
# Add the bundled version of eigen to the include path so that it can still be included
|
# Add the bundled version of eigen to the include path so that it can still be included
|
||||||
# with #include <Eigen/Core>
|
# with #include <Eigen/Core>
|
||||||
include_directories(BEFORE "gtsam/3rdparty/Eigen/")
|
include_directories(BEFORE SYSTEM "gtsam/3rdparty/Eigen/")
|
||||||
|
|
||||||
# set full path to be used by external projects
|
# set full path to be used by external projects
|
||||||
# this will be added to GTSAM_INCLUDE_DIR by gtsam_extra.cmake.in
|
# this will be added to GTSAM_INCLUDE_DIR by gtsam_extra.cmake.in
|
||||||
|
|
|
@ -351,3 +351,5 @@ namespace gtsam {
|
||||||
}; // FactorGraph
|
}; // FactorGraph
|
||||||
|
|
||||||
} // namespace gtsam
|
} // namespace gtsam
|
||||||
|
|
||||||
|
#include <gtsam/inference/FactorGraph-inst.h>
|
|
@ -45,6 +45,10 @@ struct QP {
|
||||||
_linearInequalities) {
|
_linearInequalities) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QP(std::string MPS_FileName):
|
||||||
|
cost(), equalities(), inequalities() {}
|
||||||
|
|
||||||
|
|
||||||
/** print */
|
/** print */
|
||||||
void print(const std::string& s = "") {
|
void print(const std::string& s = "") {
|
||||||
std::cout << s << std::endl;
|
std::cout << s << std::endl;
|
||||||
|
|
|
@ -213,6 +213,41 @@ TEST(QPSolver, optimizeForst10book_pg171Ex5) {
|
||||||
CHECK(assert_equal(expectedSolution, solution, 1e-100));
|
CHECK(assert_equal(expectedSolution, solution, 1e-100));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QP createExampleQP(){
|
||||||
|
QP exampleqp;
|
||||||
|
exampleqp.cost.push_back(
|
||||||
|
HessianFactor(X(1),Y(1),
|
||||||
|
8.0 *ones(1,1), 2.0 * ones(1,1), 1.5*ones(1),
|
||||||
|
10.0 *ones(1,1), -2.0 *ones(1), 4.0));
|
||||||
|
// 2x + y >= 2
|
||||||
|
exampleqp.inequalities.push_back(
|
||||||
|
LinearInequality(X(1), -2.0*ones(1,1), Y(1), -ones(1,1), -2, 0));
|
||||||
|
// -x + 2y <= 6
|
||||||
|
exampleqp.inequalities.push_back(
|
||||||
|
LinearInequality(X(1), -ones(1,1), Y(1), 2.0* ones(1,1), 6, 1));
|
||||||
|
//x >= 0
|
||||||
|
exampleqp.inequalities.push_back(
|
||||||
|
LinearInequality(X(1), -ones(1,1), 0, 2));
|
||||||
|
// y > = 0
|
||||||
|
exampleqp.inequalities.push_back(
|
||||||
|
LinearInequality(Y(1), -ones(1,1), 0, 3));
|
||||||
|
// x<= 20
|
||||||
|
exampleqp.inequalities.push_back(
|
||||||
|
LinearInequality(X(1), ones(1,1), 20, 4));
|
||||||
|
return exampleqp;
|
||||||
|
};
|
||||||
|
|
||||||
|
TEST(QPSolver, QPExampleData){
|
||||||
|
QP exampleqp("QPExample.QPS");
|
||||||
|
|
||||||
|
QP expectedqp = createExampleQP();
|
||||||
|
// min f(x,y) = 4 + 1.5x -y + 0.5(8x^2 + 2xy + 2yx + 10y^2
|
||||||
|
|
||||||
|
// CHECK(expectedqp.cost.equals(exampleqp.cost, 1e-7));
|
||||||
|
// CHECK(expectedqp.inequalities.equals(exampleqp.inequalities, 1e-7));
|
||||||
|
// CHECK(expectedqp.equalities.equals(exampleqp.equalities, 1e-7));
|
||||||
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
// Create Matlab's test graph as in http://www.mathworks.com/help/optim/ug/quadprog.html
|
// Create Matlab's test graph as in http://www.mathworks.com/help/optim/ug/quadprog.html
|
||||||
QP createTestMatlabQPEx() {
|
QP createTestMatlabQPEx() {
|
||||||
|
|
|
@ -40,6 +40,8 @@ public:
|
||||||
typedef boost::shared_ptr<ConstrainedFactor> shared_ptr;
|
typedef boost::shared_ptr<ConstrainedFactor> shared_ptr;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
/// Default constructor with default key value.
|
||||||
|
ConstrainedFactor() : dualKey_(0) {}
|
||||||
/// Construct with dual key
|
/// Construct with dual key
|
||||||
ConstrainedFactor(Key dualKey) : dualKey_(dualKey) {}
|
ConstrainedFactor(Key dualKey) : dualKey_(dualKey) {}
|
||||||
|
|
||||||
|
|
|
@ -42,14 +42,18 @@ class ConstraintProblem1 : public LinearEqualityFactor2<double, double> {
|
||||||
typedef LinearEqualityFactor2<double, double> Base;
|
typedef LinearEqualityFactor2<double, double> Base;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ConstraintProblem1(Key xK, Key yK, Key dualKey) : Base(xK, yK, dualKey, 1) {}
|
ConstraintProblem1(Key xK, Key yK, Key dualKey) :
|
||||||
|
Base(xK, yK, dualKey, 1) {
|
||||||
|
}
|
||||||
|
|
||||||
// x + y - 1
|
// x + y - 1
|
||||||
Vector evaluateError(const double& x, const double& y,
|
Vector evaluateError(const double& x, const double& y,
|
||||||
boost::optional<Matrix&> H1 = boost::none, boost::optional<Matrix&> H2 =
|
boost::optional<Matrix&> H1 = boost::none, boost::optional<Matrix&> H2 =
|
||||||
boost::none) const {
|
boost::none) const {
|
||||||
if (H1) *H1 = eye(1);
|
if (H1)
|
||||||
if (H2) *H2 = eye(1);
|
*H1 = eye(1);
|
||||||
|
if (H2)
|
||||||
|
*H2 = eye(1);
|
||||||
return (Vector(1) << x + y - 1.0).finished();
|
return (Vector(1) << x + y - 1.0).finished();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -109,12 +113,15 @@ TEST(testlcnlpSolver, QPProblem) {
|
||||||
class LineConstraintX: public LinearEqualityFactor1<Pose3> {
|
class LineConstraintX: public LinearEqualityFactor1<Pose3> {
|
||||||
typedef LinearEqualityFactor1<Pose3> Base;
|
typedef LinearEqualityFactor1<Pose3> Base;
|
||||||
public:
|
public:
|
||||||
LineConstraintX(Key key, Key dualKey) : Base(key, dualKey, 1) {
|
LineConstraintX(Key key, Key dualKey) :
|
||||||
|
Base(key, dualKey, 1) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector evaluateError(const Pose3& pose, boost::optional<Matrix&> H = boost::none) const {
|
Vector evaluateError(const Pose3& pose, boost::optional<Matrix&> H =
|
||||||
|
boost::none) const {
|
||||||
if (H)
|
if (H)
|
||||||
*H = (Matrix(1,6) << zeros(1,3), pose.rotation().matrix().row(0)).finished();
|
*H =
|
||||||
|
(Matrix(1, 6) << zeros(1, 3), pose.rotation().matrix().row(0)).finished();
|
||||||
return (Vector(1) << pose.x()).finished();
|
return (Vector(1) << pose.x()).finished();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -122,7 +129,6 @@ public:
|
||||||
TEST(testlcnlpSolver, poseOnALine) {
|
TEST(testlcnlpSolver, poseOnALine) {
|
||||||
const Key dualKey = 0;
|
const Key dualKey = 0;
|
||||||
|
|
||||||
|
|
||||||
//Instantiate LinearConstraintNLP
|
//Instantiate LinearConstraintNLP
|
||||||
LinearConstraintNLP lcnlp;
|
LinearConstraintNLP lcnlp;
|
||||||
lcnlp.cost.add(PriorFactor<Pose3>(X(1), Pose3(Rot3::Ypr(0.1, 0.2, 0.3), Point3(1, 0, 0)), noiseModel::Unit::Create(6)));
|
lcnlp.cost.add(PriorFactor<Pose3>(X(1), Pose3(Rot3::Ypr(0.1, 0.2, 0.3), Point3(1, 0, 0)), noiseModel::Unit::Create(6)));
|
||||||
|
@ -147,13 +153,17 @@ TEST(testlcnlpSolver, poseOnALine) {
|
||||||
class InequalityProblem1: public LinearInequalityFactor2<double, double> {
|
class InequalityProblem1: public LinearInequalityFactor2<double, double> {
|
||||||
typedef LinearInequalityFactor2<double, double> Base;
|
typedef LinearInequalityFactor2<double, double> Base;
|
||||||
public:
|
public:
|
||||||
InequalityProblem1(Key xK, Key yK, Key dualKey) : Base(xK, yK, dualKey) {}
|
InequalityProblem1(Key xK, Key yK, Key dualKey) :
|
||||||
|
Base(xK, yK, dualKey) {
|
||||||
|
}
|
||||||
|
|
||||||
double computeError(const double& x, const double& y,
|
double computeError(const double& x, const double& y,
|
||||||
boost::optional<Matrix&> H1 = boost::none, boost::optional<Matrix&> H2 =
|
boost::optional<Matrix&> H1 = boost::none, boost::optional<Matrix&> H2 =
|
||||||
boost::none) const {
|
boost::none) const {
|
||||||
if (H1) *H1 = eye(1);
|
if (H1)
|
||||||
if (H2) *H2 = eye(1);
|
*H1 = eye(1);
|
||||||
|
if (H2)
|
||||||
|
*H2 = eye(1);
|
||||||
return x + y - 1.0;
|
return x + y - 1.0;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue