KJB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
bbb_association.h
Go to the documentation of this file.
1 /* =========================================================================== *
2  |
3  | Copyright (c) 1994-2011 by Kobus Barnard (author)
4  |
5  | Personal and educational use of this code is granted, provided that this
6  | header is kept intact, and that the authorship is not misrepresented, that
7  | its use is acknowledged in publications, and relevant papers are cited.
8  |
9  | For other use contact the author (kobus AT cs DOT arizona DOT edu).
10  |
11  | Please note that the code in this file has not necessarily been adequately
12  | tested. Naturally, there is no guarantee of performance, support, or fitness
13  | for any particular task. Nonetheless, I am interested in hearing about
14  | problems that you encounter.
15  |
16  | Author: Ernesto Brau
17  * =========================================================================== */
18 
19 /* $Id$ */
20 
21 #ifndef B3_ASSOCIATION_H
22 #define B3_ASSOCIATION_H
23 
24 #include <bbb_cpp/bbb_traj_set.h>
25 #include <string>
26 #include <vector>
27 #include <algorithm>
28 #include <iterator>
29 #include <boost/foreach.hpp>
30 
31 namespace kjb {
32 namespace bbb {
33 
39 struct Group
40 {
41 public:
42  Group(const std::string& role) : role_(role) {}
43 
44  void add(size_t j) { trajectories_.insert(j); }
45 
46  const Traj_set& trajectories() const { return trajectories_; }
47 
48  const std::string& role() const { return role_; }
49 
50 private:
51  std::string role_;
52  Traj_set trajectories_;
53 };
54 
61 {
62 public:
64  Association(const Traj_set& trajs) : trajs_(trajs) {}
65 
67  template<class SetIt, class StrIt>
68  void set(SetIt first_set, SetIt last_set, StrIt first_name);
69 
71  const Group& group(size_t k) const { return groups_[k]; }
72 
74  size_t num_groups() const { return groups_.size(); }
75 
76 private:
81  void check_consistent() const;
82 
83  Traj_set trajs_;
84  std::vector<Group> groups_;
85 };
86 
87 /* \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ */
88 
89 template<class SetIt, class StrIt>
90 void Association::set(SetIt first_set, SetIt last_set, StrIt first_name)
91 {
92  size_t K = std::distance(first_set, last_set);
93  groups_.reserve(K);
94 
95  for(; first_set != last_set; ++first_set, ++first_name)
96  {
97  groups_.push_back(Group(*first_name));
98  BOOST_FOREACH(size_t j, *first_set)
99  {
100  Traj_set::const_iterator j_p = trajs_.begin();
101  std::advance(j_p, j);
102  groups_.back().add(*j_p);
103  }
104  }
105 
106  check_consistent();
107 }
108 
109 }} // namespace kjb::bbb
110 
111 #endif /*B3_ASSOCIATION_H */
112 
void set(SetIt first_set, SetIt last_set, StrIt first_name)
Insert values for this association.
Definition: bbb_association.h:90
const Group & group(size_t k) const
Get the kth group of this association.
Definition: bbb_association.h:71
size_t num_groups() const
Get the number of groups in this association.
Definition: bbb_association.h:74
for k
Definition: APPgetLargeConnectedEdges.m:61
Group.
Definition: bbb_association.h:39
const std::string & role() const
Definition: bbb_association.h:48
Group(const std::string &role)
Definition: bbb_association.h:42
Association(const Traj_set &trajs)
Construct an associaiton of the given trajectories.
Definition: bbb_association.h:64
Definition: bbb_traj_set.h:37
void add(size_t j)
Definition: bbb_association.h:44
const_iterator begin() const
Iterator to first index.
Definition: bbb_traj_set.h:67
const Traj_set & trajectories() const
Definition: bbb_association.h:46
void insert(const SizeType &j)
Add trajectory to this association.
Definition: bbb_traj_set.h:57
Iset::const_iterator const_iterator
Definition: bbb_traj_set.h:43
Definition: bbb_association.h:60