gtsam/gtsam_unstable/linear/QPSVisitor.h

121 lines
4.7 KiB
C
Raw Normal View History

2016-06-18 03:24:55 +08:00
/* ----------------------------------------------------------------------------
* GTSAM Copyright 2010, Georgia Tech Research Corporation,
* Atlanta, Georgia 30332-0415
* All Rights Reserved
* Authors: Frank Dellaert, et al. (see THANKS for the full author list)
* See LICENSE for the license information
* -------------------------------------------------------------------------- */
/**
2018-11-05 05:16:13 +08:00
* @file QPSVisitor.h
2016-06-18 03:24:55 +08:00
* @brief
* @author Ivan Dario Jimenez
* @date 3/5/16
*/
#pragma once
#include <gtsam_unstable/linear/QP.h>
2018-11-05 05:16:13 +08:00
#include <gtsam/inference/Symbol.h>
#include <gtsam/inference/Key.h>
2018-11-05 05:16:13 +08:00
#include <gtsam/base/Matrix.h>
#include <boost/fusion/include/vector.hpp>
#include <boost/fusion/sequence.hpp>
#include <unordered_map>
#include <string>
#include <vector>
namespace gtsam {
/**
2018-11-05 05:16:13 +08:00
* As the parser reads a file, it call functions in this visitor. This visitor in turn stores what the parser has read
* in a way that can be later used to build the full QP problem in the file.
*/
2018-11-05 05:16:13 +08:00
class QPSVisitor {
private:
typedef std::unordered_map<Key, Matrix11> coefficient_v;
typedef std::unordered_map<std::string, coefficient_v> constraint_v;
2018-11-05 05:16:13 +08:00
std::unordered_map<std::string, constraint_v*> row_to_constraint_v; // Maps QPS ROWS to Variable-Matrix pairs
constraint_v E; // Equalities
constraint_v IG;// Inequalities >=
constraint_v IL;// Inequalities <=
unsigned int numVariables;
std::unordered_map<std::string, double> b; // maps from constraint name to b value for Ax = b equality constraints
std::unordered_map<std::string, double> ranges; // Inequalities can be specified as ranges on a variable
std::unordered_map<Key, Vector1> g; // linear term of quadratic cost
std::unordered_map<std::string, Key> varname_to_key; // Variable QPS string name to key
std::unordered_map<Key, std::unordered_map<Key, Matrix11> > H; // H from hessian
double f; // Constant term of quadratic cost
std::string obj_name; // the objective function has a name in the QPS
std::string name_; // the quadratic program has a name in the QPS
std::unordered_map<Key, double> up; // Upper Bound constraints on variable where X < MAX
std::unordered_map<Key, double> lo; // Lower Bound constraints on variable where MIN < X
std::unordered_map<Key, double> fx; // Equalities specified as FX in BOUNDS part of QPS
std::vector<Key> Free; // Variables can be specified as Free (to which no constraints apply)
const bool debug = false;
public:
2018-11-05 05:16:13 +08:00
QPSVisitor() : numVariables(1) {
}
2016-03-08 23:34:31 +08:00
void setName(
boost::fusion::vector<std::vector<char>, std::vector<char>,
std::vector<char>> const & name);
2016-03-08 23:34:31 +08:00
void addColumn(
boost::fusion::vector<std::vector<char>, std::vector<char>,
std::vector<char>, std::vector<char>, std::vector<char>, double,
std::vector<char>> const & vars);
2016-03-08 23:34:31 +08:00
void addColumnDouble(
boost::fusion::vector<std::vector<char>, std::vector<char>,
std::vector<char>, std::vector<char>, double, std::vector<char>,
std::vector<char>, std::vector<char>, double> const & vars);
2016-03-08 23:34:31 +08:00
void addRHS(
boost::fusion::vector<std::vector<char>, std::vector<char>,
std::vector<char>, std::vector<char>, std::vector<char>, double,
std::vector<char>> const & vars);
2016-03-08 23:34:31 +08:00
void addRHSDouble(
boost::fusion::vector<std::vector<char>, std::vector<char>,
std::vector<char>, std::vector<char>, std::vector<char>, double,
std::vector<char>, std::vector<char>, std::vector<char>, double> const & vars);
void addRangeSingle(
boost::fusion::vector<std::vector<char>, std::vector<char>,
std::vector<char>, std::vector<char>, std::vector<char>, double,
std::vector<char>> const & vars);
void addRangeDouble(
boost::fusion::vector<std::vector<char>, std::vector<char>,
2016-03-08 23:34:31 +08:00
std::vector<char>, std::vector<char>, std::vector<char>, double,
std::vector<char>, std::vector<char>, std::vector<char>, double> const & vars);
2016-03-08 23:34:31 +08:00
void addRow(
boost::fusion::vector<std::vector<char>, char, std::vector<char>,
std::vector<char>, std::vector<char>> const & vars);
2016-03-08 23:34:31 +08:00
void addBound(
boost::fusion::vector<std::vector<char>, std::vector<char>,
std::vector<char>, std::vector<char>, std::vector<char>,
std::vector<char>, std::vector<char>, double> const & vars);
2016-03-08 23:34:31 +08:00
void addBoundFr(
boost::fusion::vector<std::vector<char>, std::vector<char>,
std::vector<char>, std::vector<char>, std::vector<char>,
std::vector<char>, std::vector<char>> const & vars);
2016-03-08 23:34:31 +08:00
void addQuadTerm(
boost::fusion::vector<std::vector<char>, std::vector<char>,
std::vector<char>, std::vector<char>, std::vector<char>, double,
std::vector<char>> const & vars);
QP makeQP();
}
;
}