Assignment.h
Go to the documentation of this file.
1 /* ----------------------------------------------------------------------------
2 
3  * GTSAM Copyright 2010, Georgia Tech Research Corporation,
4  * Atlanta, Georgia 30332-0415
5  * All Rights Reserved
6  * Authors: Frank Dellaert, et al. (see THANKS for the full author list)
7 
8  * See LICENSE for the license information
9 
10  * -------------------------------------------------------------------------- */
11 
19 #pragma once
20 
21 #include <iostream>
22 #include <vector>
23 #include <map>
24 
25 
26 namespace gtsam {
27 
33  template<class L>
34  class Assignment: public std::map<L, size_t> {
35  public:
36  void print(const std::string& s = "Assignment: ") const {
37  std::cout << s << ": ";
38  for(const typename Assignment::value_type& keyValue: *this)
39  std::cout << "(" << keyValue.first << ", " << keyValue.second << ")";
40  std::cout << std::endl;
41  }
42 
43  bool equals(const Assignment& other, double tol = 1e-9) const {
44  return (*this == other);
45  }
46  }; //Assignment
47 
48 
61  template<typename L>
62  std::vector<Assignment<L> > cartesianProduct(
63  const std::vector<std::pair<L, size_t> >& keys) {
64  std::vector<Assignment<L> > allPossValues;
66  typedef std::pair<L, size_t> DiscreteKey;
67  for(const DiscreteKey& key: keys)
68  values[key.first] = 0; //Initialize from 0
69  while (1) {
70  allPossValues.push_back(values);
71  size_t j = 0;
72  for (j = 0; j < keys.size(); j++) {
73  L idx = keys[j].first;
74  values[idx]++;
75  if (values[idx] < keys[j].second)
76  break;
77  //Wrap condition
78  values[idx] = 0;
79  }
80  if (j == keys.size())
81  break;
82  }
83  return allPossValues;
84  }
85 
86 } // namespace gtsam
std::vector< Assignment< L > > cartesianProduct(const std::vector< std::pair< L, size_t > > &keys)
Get Cartesian product consisting all possible configurations.
Definition: Assignment.h:62
bool equals(const Assignment &other, double tol=1e-9) const
Definition: Assignment.h:43
leaf::MyValues values
MatrixXd L
Definition: LLT_example.cpp:6
void print(const std::string &s="Assignment: ") const
Definition: Assignment.h:36
std::pair< Key, size_t > DiscreteKey
Definition: DiscreteKey.h:34
Array< double, 1, 3 > e(1./3., 0.5, 2.)
RealScalar s
traits
Definition: chartTesting.h:28
const G double tol
Definition: Group.h:83
const KeyVector keys
std::ptrdiff_t j


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:41:39