MorphoGraphX  2.0-1-227
VVGraph.hpp
Go to the documentation of this file.
1 //
2 // This file is part of MorphoGraphX - http://www.MorphoGraphX.org
3 // Copyright (C) 2012-2015 Richard S. Smith and collaborators.
4 //
5 // If you use MorphoGraphX in your work, please cite:
6 // http://dx.doi.org/10.7554/eLife.05864
7 //
8 // MorphoGraphX is free software, and is licensed under under the terms of the
9 // GNU General (GPL) Public License version 2.0, http://www.gnu.org/licenses.
10 //
11 #ifndef VV_GRAPH_HPP
12 #define VV_GRAPH_HPP
13 
20 #include <Config.hpp>
21 
22 #include <CircIterator.hpp>
23 #include <Edge.hpp>
24 #include <Forall.hpp>
25 #include <MemberIterator.hpp>
26 #include <Tie.hpp>
27 #include <UnorderedMap.hpp>
28 #include <Vertex.hpp>
29 
30 #include <algorithm>
31 #include <iostream>
32 #include <iterator>
33 #include <list>
34 #include <memory>
35 #include <utility>
36 #include <vector>
37 
38 namespace std
39 {
40  //using namespace tr1;
41 }
42 
43 namespace mgx
44 {
51  // This was used by the forall macro, now used only for VV
52  namespace ForAll
53  {
55  {
56  virtual ~BaseForwardIter() {}
57  };
58 
59  template <typename iterator> struct ForwardIter : public BaseForwardIter
60  {
61  typedef typename std::iterator_traits<iterator>::value_type value_type;
62  typedef typename std::iterator_traits<iterator>::reference reference;
63 
64  ForwardIter(const iterator& fst, const iterator& lst) : it(fst), end(lst), brk(0) {}
65 
66  const reference value() const
67  {
68  ++brk;
69  return *it;
70  }
71  bool is_end() const { return (it == end) || brk; }
72  mutable iterator it;
73  iterator end;
74  mutable int brk;
75  };
76 
77  template <typename Pair, typename iterator>
78  inline ForwardIter<iterator> forwardIter(const Pair& range, const iterator*)
79  {
80  return ForwardIter<iterator>(range.first, range.second);
81  }
82 
83  template <typename iterator>
84  inline const ForwardIter<iterator>* castForwardIter(const BaseForwardIter* base, const iterator*)
85  {
86  return static_cast<const ForwardIter<iterator>*>(base);
87  }
88 
89  template <typename T> inline T* pointer(const T&)
90  {
91  return 0;
92  }
93 
94  template <typename Container>
95  std::pair<typename Container::iterator, typename Container::iterator> make_range(Container& cont)
96  {
97  return std::make_pair(cont.begin(), cont.end());
98  }
99 
100  template <typename Container>
101  std::pair<typename Container::const_iterator,
102  typename Container::const_iterator> make_range(const Container& cont)
103  {
104  return std::make_pair(cont.begin(), cont.end());
105  }
106 
107  template <typename Iterator> std::pair<Iterator, Iterator>
108  make_range(const std::pair<Iterator, Iterator>& cont)
109  {
110  return cont;
111  }
112 
113  template <typename Container>
114  std::pair<typename Container::reverse_iterator, typename Container::reverse_iterator>
115  make_reverse_range(Container& cont)
116  {
117  return std::make_pair(cont.rbegin(), cont.rend());
118  }
119 
120  template <typename Container>
121  std::pair<typename Container::const_reverse_iterator, typename Container::const_reverse_iterator>
122  make_reverse_range(const Container& cont)
123  {
124  return std::make_pair(cont.rbegin(), cont.rend());
125  }
126 
127  template <typename Iterator>
128  std::pair<std::reverse_iterator<Iterator>, std::reverse_iterator<Iterator> >
129  make_reverse_range(const std::pair<Iterator, Iterator>& cont)
130  {
131  typedef std::reverse_iterator<Iterator> reverse_it;
132  return make_pair(reverse_it(cont.second), reverse_it(cont.first));
133  }
134  }
135 
143  {
144  return *this;
145  }
146  };
147 
161  template <typename VertexContent, typename EdgeContent = _EmptyEdgeContent>
162  class VVGraph
163  {
164  public:
166 
167 
180 
185 
191  VVGraph() : modified(false) {}
192 
196  VVGraph(const VVGraph& copy);
197 
202  {
203  if(neighborhood.size() > 0) {
204  typename neighborhood_t::iterator it;
205  for(it = neighborhood.begin(); it != neighborhood.end(); ++it) {
206  delete *it;
207  *it = 0;
208  }
209  }
210  }
211 
217  template <typename Iterator> VVGraph(Iterator begin, Iterator end, bool checkUnique = true)
218  {
219  insert(begin, end, checkUnique);
220  }
221 
227  template <typename Container> VVGraph(const Container& c, bool checkUnique = true)
228  {
229  insert(ForAll::make_range(c), checkUnique);
230  }
231 
232  protected:
233  struct single_neighborhood_t;
234 
238  struct neighbor_t : public EdgeContent {
242  //RSS typedef std::list<neighbor_t> edge_list_t;
243  // swaped list for vector, does not seem to make much difference performance-wise, i
244  // and should be smaller
245  typedef std::vector<neighbor_t> edge_list_t;
246 
250  neighbor_t(const vertex_t& tgt, const EdgeContent& e) : EdgeContent(e), target(tgt) {}
251 
252  neighbor_t(const neighbor_t& copy) : EdgeContent(copy), target(copy.target) {}
253 
254  void clear_edge()
255  {
256  static_cast<EdgeContent&>(*this) = EdgeContent();
257  }
258 
260 
262  {
263  target = copy.target;
264  static_cast<EdgeContent&>(*this) = static_cast<const EdgeContent&>(copy);
265  return *this;
266  }
267 
274 
281  bool operator==(const neighbor_t& other) const
282  {
283  return (target == other.target)
284  && (static_cast<const EdgeContent&>(*this) == static_cast<const EdgeContent&>(other));
285  }
286  };
287 
292 
297  {
298 
300 
302 
307 
309  {
310  return *this;
311  }
312 
318  bool operator==(const single_neighborhood_t& other) const
319  {
320  return edges == other.edges;
321  }
322  };
323 
324  public:
326  {
327  NeighborhoodPair(const vertex_t& v) : vertex(v) {}
328 
331 
333  {
334  NeighborhoodPair* np = new NeighborhoodPair(*this);
335  return np;
336  }
337 
340  };
341 
345  typedef std::vector<NeighborhoodPair*> neighborhood_t;
346 
350  typedef std::unordered_map<vertex_t, NeighborhoodPair*> lookup_t;
351 
355  typedef typename neighborhood_t::value_type neighborhood_value_type;
356 
360  typedef typename neighborhood_t::size_type size_type;
361 
363 
364 
367  typedef SelectMemberPointerIterator<typename neighborhood_t::iterator,
372  typedef SelectMemberPointerIterator<typename neighborhood_t::const_iterator,
377  typedef SelectMemberIterator<typename edge_list_t::iterator, vertex_t,
384  typedef std::pair<neighbor_iterator, neighbor_iterator> neighbor_iterator_pair;
385 
391 
395  typedef std::pair<circ_neighbor_iterator, circ_neighbor_iterator> circ_neighbor_iterator_pair;
396 
400  typedef SelectMemberIterator<typename edge_list_t::const_iterator,
408  typedef std::pair<const_neighbor_iterator, const_neighbor_iterator>
410 
416 
420  typedef std::pair<const_circ_neighbor_iterator, const_circ_neighbor_iterator>
422 
424 
426 
427 
443  size_type erase(const vertex_t& v);
444 
457  bool insert(const vertex_t& v, bool checkUnique = true);
458 
460 
462 
463 
476  const vertex_t& any() const;
477 
507  const vertex_t& operator[](size_type idx) const;
508 
522  bool contains(const vertex_t& v) const;
523 
541  const vertex_t& reference(vertex_t v) const
542  {
543  const NeighborhoodPair* found = this->findVertex(v);
544  if(found)
545  return found->vertex;
546  return vertex_t::null; // vertex_t(0);
547  }
548 
552  size_type size() const
553  {
554  return neighborhood.size();
555  }
556 
560  bool empty() const
561  {
562  return neighborhood.empty();
563  }
564 
568  bool isModified() const
569  {
570  return modified;
571  }
572 
576  void setModified(bool _modified)
577  {
578  modified = _modified;
579  }
580 
581 
583 
585 
586 
606  const vertex_t& anyIn(const vertex_t& v) const;
607 
624  size_type valence(const vertex_t& v) const;
625 
647  bool empty(const vertex_t& v) const;
648 
668  const vertex_t& nextTo(const vertex_t& v, const vertex_t& neighbor, unsigned int n = 1) const;
669 
689  const vertex_t& prevTo(const vertex_t& v, const vertex_t& ref, unsigned int n = 1) const;
690 
717  edge_t edge(const vertex_t& src, const vertex_t& tgt);
718 
747  const_edge_t edge(const vertex_t& src, const vertex_t& tgt) const;
748 
783 
799 
815 
829  const vertex_t& source(const edge_t& edge) const
830  {
831  const NeighborhoodPair* found = this->findVertex(vertex_t(edge.source()));
832  if(found)
833  return found->vertex;
834  return vertex_t::null; // vertex_t(0);
835  }
836 
850  const vertex_t& target(const edge_t& edge) const
851  {
852  const NeighborhoodPair* found = this->findVertex(vertex_t(edge.target()));
853  if(found)
854  return found->vertex;
855  return vertex_t::null; // vertex_t(0);
856  }
857 
859 
861 
862 
884  size_type eraseEdge(const vertex_t& src, const vertex_t& tgt);
885 
917  edge_t replace(const vertex_t& v, const vertex_t& neighbor, const vertex_t& new_neighbor);
918 
945  edge_t spliceAfter(const vertex_t& v, const vertex_t& neighbor, const vertex_t& new_neighbor);
946 
973  edge_t spliceBefore(const vertex_t& v, const vertex_t& neighbor, const vertex_t& new_neighbor);
974 
993  edge_t insertEdge(const vertex_t& src, const vertex_t& tgt);
994 
1015  bool eraseAllEdges(const vertex_t& v);
1016 
1034  bool clear(const vertex_t& v);
1035 
1042  bool uniqueTri(const vertex_t& v, const vertex_t& n, const vertex_t& m) const;
1043 
1050  bool uniqueLine(const vertex_t& v, const vertex_t& n) const;
1052 
1054 
1055 
1058  VVGraph& operator=(const VVGraph& other);
1059 
1063  VVGraph& reverse();
1064 
1068  void swap(VVGraph& other);
1069 
1079  bool operator==(const VVGraph& other) const;
1080 
1084  void clear();
1085 
1102  void eraseAllEdges();
1103 
1119  template <typename VertexContainer> VVGraph subgraph(const VertexContainer& vertexes) const;
1121 
1123 
1124 
1128  void erase(iterator pos);
1129 
1134 
1139 
1143  template <typename Iterator>
1144  void insert(Iterator first, Iterator last, bool checkUnique = true);
1145 
1149  template <typename Iterator>
1150  void insert(const std::pair<Iterator, Iterator>& range, bool checkUnique = true);
1151 
1156  return neighborhood.begin();
1157  }
1162  return neighborhood.end();
1163  }
1164 
1169  return neighborhood.begin();
1170  }
1175  return neighborhood.end();
1176  }
1177 
1181  size_type count(const vertex_t& v) const;
1182 
1192  neighbor_iterator findIn(const vertex_t& v, const vertex_t& n);
1202  const_neighbor_iterator findIn(const vertex_t& v, const vertex_t& n) const;
1203 
1209  void eraseAllEdges(iterator it);
1210 
1214  void clear(iterator it);
1215 
1219  void reserve(size_type s) {
1220  neighborhood.reserve(s);
1221  }
1222 
1224 
1225  protected:
1226  void eraseAllEdges(NeighborhoodPair* it);
1233  template <class Neighborhood, class Iterator> struct search_result_t
1234  {
1241 
1245  search_result_t(Iterator i, Neighborhood* n, bool ok = true)
1246  : found(ok) , it(i), neighborhood(n) {}
1247 
1252  : found(copy.found), it(copy.it), neighborhood(copy.neighborhood) {}
1253 
1257  operator bool()
1258  {
1259  return found;
1260  }
1261 
1265  bool found;
1269  Iterator it;
1273  Neighborhood* neighborhood;
1274  };
1275 
1279  typedef typename edge_list_t::iterator int_neighbor_iterator;
1283  typedef typename edge_list_t::const_iterator int_const_neighbor_iterator;
1284 
1288  typedef search_result_t<single_neighborhood_t, int_neighbor_iterator> neighbor_found_t;
1292  typedef search_result_t<const single_neighborhood_t, int_const_neighbor_iterator>
1294 
1298  NeighborhoodPair* findVertex(const vertex_t& v);
1299 
1303  const NeighborhoodPair* findVertex(const vertex_t& v) const;
1304 
1308  typename neighborhood_t::iterator findIterator(const NeighborhoodPair* np);
1309  typename neighborhood_t::const_iterator findIterator(const NeighborhoodPair* np) const;
1310 
1325  neighbor_found_t findInVertex(const vertex_t& v, const vertex_t& neighbor);
1326 
1330  const_neighbor_found_t findInVertex(const vertex_t& v, const vertex_t& neighbor) const;
1331 
1336 
1341 
1345  bool modified;
1346  };
1347 
1348  // Clear the VVGraph
1349  template <typename VertexContent, typename EdgeContent>
1351  {
1352  if(neighborhood.size() == 0)
1353  return;
1354  typename neighborhood_t::iterator it;
1355  for(it = neighborhood.begin(); it != neighborhood.end(); ++it) {
1356  delete *it;
1357  *it = 0;
1358  }
1359  neighborhood.clear();
1360  lookup.clear();
1361  modified = true;
1362  }
1363 
1364  // Erase vertex at iterator, RSS can we check it is valid?
1365  template <typename VertexContent, typename EdgeContent>
1367  {
1368  eraseAllEdges(it);
1369  lookup.erase(*it);
1370  delete *it.base();
1371  *it.base() = neighborhood.back();
1372  neighborhood.pop_back();
1373  modified = true;
1374  }
1375 
1376  // Erase a vertex, return 1 is successful
1377  template <typename VertexContent, typename EdgeContent>
1380  {
1381  if(eraseAllEdges(v)) {
1382  NeighborhoodPair* np = lookup[v];
1383  lookup.erase(v);
1384  typename neighborhood_t::iterator it = this->findIterator(np);
1385  delete np;
1386  *it = neighborhood.back();
1387  neighborhood.pop_back();
1388  modified = true;
1389  return 1;
1390  }
1391  return 0;
1392  }
1393 
1394  // Erase all edges of a vertex
1395  template <typename VertexContent, typename EdgeContent>
1397  {
1398  if(neighborhood.size() == 0)
1399  return;
1400  for(typename neighborhood_t::iterator it = neighborhood.begin(); it != neighborhood.end(); ++it)
1401  it->single_neighborhood.edges.clear();
1402  modified = true;
1403  }
1404 
1405  // Erase all edges of a vertex, return true if sucessful
1406  template <typename VertexContent, typename EdgeContent>
1408  {
1409  NeighborhoodPair* it_found = this->findVertex(v);
1410  if(it_found) {
1411  eraseAllEdges(it_found);
1412  return true;
1413  }
1414  return false;
1415  }
1416 
1417  // Erase all edges of a neighborhood pair
1418  template <typename VertexContent, typename EdgeContent>
1420  {
1421  const vertex_t& v = np->vertex;
1422 
1423  NeighborhoodPair* it_found = this->findVertex(v);
1424  edge_list_t& lst = it_found->single_neighborhood.edges;
1425  for(typename edge_list_t::iterator it = lst.begin(); it != lst.end(); ++it)
1426  eraseEdge(it->target, v);
1427 
1428  np->single_neighborhood.edges.clear();
1429  modified = true;
1430  }
1431 
1432  // Erase alls edges of a vertex at iterator
1433  template <typename VertexContent, typename EdgeContent>
1435  {
1436  eraseAllEdges(*it_found.base());
1437  }
1438 
1439  // Clear a vertex, erase all edges
1440  template <typename VertexContent, typename EdgeContent>
1442  {
1443  typename neighborhood_t::iterator it_found = this->findVertex(v);
1444  if(it_found != neighborhood.end()) {
1445  clear(it_found);
1446  return true;
1447  }
1448  return false;
1449  }
1450 
1451  // Clear a vertex?
1452  template <typename VertexContent, typename EdgeContent>
1454  {
1455  const vertex_t& v = *it;
1456  it.base()->single_neighborhood.edges.clear();
1457  modified = true;
1458  }
1459 
1460  // Return 1 if vertex exists
1461  template <typename VertexContent, typename EdgeContent>
1464  {
1465  return lookup.count(v);
1466  }
1467 
1468  // Inset a vertex in the graph and return an iterator to it
1469  template <typename VertexContent, typename EdgeContent>
1471  {
1472  typename lookup_t::iterator it_found = lookup.end();
1473  if(checkUnique)
1474  it_found = lookup.find(v);
1475  if(!checkUnique or it_found == lookup.end()) {
1476  NeighborhoodPair* np = new NeighborhoodPair(v);
1477  neighborhood.push_back(np);
1478  lookup[v] = np;
1479  iterator it = neighborhood.end();
1480  --it;
1481  modified = true;
1482  return true;
1483  }
1484  return false;
1485  }
1486 
1487  // Insert a range of vertices into the graph
1488  template <typename VertexContent, typename EdgeContent>
1489  template <typename Iterator>
1490  void VVGraph<VertexContent, EdgeContent>::insert(const std::pair<Iterator, Iterator>& range, bool checkUnique)
1491  {
1492  insert(range.first, range.second, checkUnique);
1493  }
1494 
1495  // Insert a range of vertices into the graph
1496  template <typename VertexContent, typename EdgeContent>
1497  template <typename Iterator>
1498  void VVGraph<VertexContent, EdgeContent>::insert(Iterator first, Iterator last, bool checkUnique)
1499  {
1500  if(checkUnique) {
1501  for(Iterator it = first; it != last; ++it)
1502  insert(*it);
1503  } else {
1504  for(Iterator it = first; it != last; ++it) {
1505  NeighborhoodPair* np = new NeighborhoodPair(*it);
1506  neighborhood.push_back(np);
1507  lookup[*it] = np;
1508  }
1509  }
1510  modified = true;
1511  }
1512 
1513  // Return any vertex in the graph
1514  template <typename VertexContent, typename EdgeContent>
1517  {
1518  if(neighborhood.empty())
1519  return vertex_t::null;
1520  return *begin();
1521  }
1522 
1523  // Return vertex at []
1524  template <typename VertexContent, typename EdgeContent>
1527  {
1528  typename neighborhood_t::const_iterator it = neighborhood.begin();
1529  std::advance(it, idx);
1530  return (*it)->vertex;
1531  }
1532 
1533  // Return any neighbor
1534  template <typename VertexContent, typename EdgeContent>
1537  {
1538  if(v.isNull())
1539  return vertex_t::null; // vertex_t(0);
1540  const NeighborhoodPair* it_found = this->findVertex(v);
1541  if(not it_found || it_found->single_neighborhood.edges.empty())
1542  return vertex_t::null; // vertex_t(0);
1543  const edge_list_t& lst = it_found->single_neighborhood.edges;
1544  return lst.front().target;
1545  }
1546 
1547  // Return the valence
1548  template <typename VertexContent, typename EdgeContent>
1551  {
1552  if(v.isNull())
1553  return 0;
1554  const NeighborhoodPair* it_found = this->findVertex(v);
1555  if(not it_found)
1556  return 0;
1557  return it_found->single_neighborhood.edges.size();
1558  }
1559 
1560  // Is graph empty
1561  template <typename VertexContent, typename EdgeContent>
1563  {
1564  if(v.isNull())
1565  return true;
1566  const NeighborhoodPair* it_found = this->findVertex(v);
1567  if(not it_found)
1568  return true;
1569  return it_found->single_neighborhood.edges.empty();
1570  }
1571 
1572  // Find a vertex
1573  template <typename VertexContent, typename EdgeContent>
1576  {
1577  return std::find(neighborhood.begin(), neighborhood.end(), np);
1578  }
1579 
1580  // Find a vertex
1581  template <typename VertexContent, typename EdgeContent>
1583  VVGraph<VertexContent, EdgeContent>::findIterator(const NeighborhoodPair* np) const
1584  {
1585  return std::find(neighborhood.begin(), neighborhood.end(), np);
1586  }
1587 
1588  // Find a vertex
1589  template <typename VertexContent, typename EdgeContent>
1592  {
1593  typename lookup_t::const_iterator it_found = lookup.find(v);
1594  if(it_found != lookup.end())
1595  return it_found->second;
1596  return 0;
1597  }
1598 
1599  // Find a vertex
1600  template <typename VertexContent, typename EdgeContent>
1603  {
1604  typename lookup_t::const_iterator it_found = lookup.find(v);
1605  if(it_found != lookup.end())
1606  return it_found->second;
1607  return 0;
1608  }
1609 
1610  // Find a vertex in a neighborhood
1611  template <typename VertexContent, typename EdgeContent>
1614  {
1615  if(v.isNull() || n.isNull() || v == n)
1616  return neighbor_found_t();
1617  NeighborhoodPair* it_found = this->findVertex(v);
1618  if(not it_found)
1619  return neighbor_found_t();
1620  edge_list_t& lst = it_found->single_neighborhood.edges;
1621  single_neighborhood_t* neighborhood = &it_found->single_neighborhood;
1622  for(typename edge_list_t::iterator it = lst.begin(); it != lst.end(); ++it) {
1623  if(it->target == n) {
1624  return neighbor_found_t(it, neighborhood);
1625  }
1626  }
1627  return neighbor_found_t(lst.end(), neighborhood, false);
1628  }
1629 
1630  // Find a vertex in a neighborhood
1631  template <typename VertexContent, typename EdgeContent>
1634  {
1635  if(v.isNull() || n.isNull() || v == n)
1636  return const_neighbor_found_t();
1637  const NeighborhoodPair* it_found = this->findVertex(v);
1638  if(not it_found)
1639  return const_neighbor_found_t();
1640  const edge_list_t& lst = it_found->single_neighborhood.edges;
1641  const single_neighborhood_t* neighborhood = &it_found->single_neighborhood;
1642  for(typename edge_list_t::const_iterator it = lst.begin(); it != lst.end(); ++it) {
1643  if(it->target == n) {
1644  return const_neighbor_found_t(it, neighborhood);
1645  }
1646  }
1647  return const_neighbor_found_t(lst.end(), neighborhood, false);
1648  }
1649 
1650  // Find a vertex in a neighborhood
1651  template <typename VertexContent, typename EdgeContent>
1654  {
1655  neighbor_found_t found = this->findInVertex(v, n);
1656  if(found.neighborhood)
1657  return neighbor_iterator(found.it);
1658  return neighbor_iterator();
1659  }
1660 
1661  // Find a vertex in a neighborhood
1662  template <typename VertexContent, typename EdgeContent>
1665  {
1666  const_neighbor_found_t found = this->findInVertex(v, n);
1667  if(found.neighborhood)
1668  return const_neighbor_iterator(found.it);
1669  return const_neighbor_iterator(found.it);
1670  }
1671 
1672  // Erase an edge
1673  template <typename VertexContent, typename EdgeContent>
1676  {
1677  return eraseEdge(v, *pos);
1678  }
1679 
1680  // Erase an edge
1681  template <typename VertexContent, typename EdgeContent>
1684  {
1685  return eraseEdge(v, pos.base());
1686  }
1687 
1688  // Erase an edge
1689  template <typename VertexContent, typename EdgeContent>
1692  {
1693  neighbor_found_t found = this->findInVertex(v, n);
1694  if(!found)
1695  return 0;
1696  found.neighborhood->edges.erase(found.it);
1697  modified = true;
1698  return 1;
1699  }
1700 
1701  // See if graph contains a vertex
1702  template <typename VertexContent, typename EdgeContent>
1704  {
1705  return this->findVertex(v);
1706  }
1707 
1708  // Replace a vertex in a neighborhood with another
1709  template <typename VertexContent, typename EdgeContent>
1712  const vertex_t& new_neighbor)
1713  {
1714  if(new_neighbor.isNull() or (v == new_neighbor) or (neighbor == new_neighbor))
1715  return edge_t();
1716  neighbor_found_t found = this->findInVertex(v, neighbor);
1717  if(!found)
1718  return edge_t();
1719  //NeighborhoodPair* n_found = this->findVertex(neighbor);
1720 
1721  found.it->target = new_neighbor;
1722  found.it->clear_edge();
1723  modified = true;
1724  return edge_t(v.id(), new_neighbor.id(), &*found.it);
1725  }
1726 
1727  // Get next vertex in a neighborhood
1728  template <typename VertexContent, typename EdgeContent>
1730  VVGraph<VertexContent, EdgeContent>::nextTo(const vertex_t &v, const vertex_t &ref, unsigned int n) const
1731  {
1732  const_neighbor_found_t found = this->findInVertex(v, ref);
1733  if(!found)
1734  return vertex_t::null; // vertex_t(0);
1735  typename edge_list_t::const_iterator it = found.it;
1736  const edge_list_t& lst = found.neighborhood->edges;
1737  for(unsigned int i = 0; i < n; ++i) {
1738  ++it;
1739  if(it == lst.end())
1740  it = lst.begin();
1741  }
1742  return it->target;
1743  }
1744 
1745  // Get previous vertex in a neighborhood
1746  template <typename VertexContent, typename EdgeContent>
1748  VVGraph<VertexContent, EdgeContent>::prevTo(const vertex_t &v, const vertex_t &ref, unsigned int n) const
1749  {
1750  const_neighbor_found_t found = this->findInVertex(v, ref);
1751  if(!found)
1752  return vertex_t::null; // vertex_t(0);
1753  typename edge_list_t::const_iterator it = found.it;
1754  const edge_list_t& lst = found.neighborhood->edges;
1755  for(unsigned int i = 0; i < n; ++i) {
1756  if(it == lst.begin())
1757  it = lst.end();
1758  --it;
1759  }
1760  return it->target;
1761  }
1762 
1763  // Get an edge
1764  template <typename VertexContent, typename EdgeContent>
1767  {
1768  neighbor_found_t found = this->findInVertex(src, tgt);
1769  if(!found)
1770  return edge_t();
1771  return edge_t(src.id(), tgt.id(), &*found.it);
1772  }
1773 
1774  // Get an edge
1775  template <typename VertexContent, typename EdgeContent>
1778  {
1779  const_neighbor_found_t found = this->findInVertex(src, tgt);
1780  if(!found)
1781  return const_edge_t();
1782  return const_edge_t(src.id(), tgt.id(), &*found.it);
1783  }
1784 
1785  // Insert a vertex in a neighborhood after another
1786  template <typename VertexContent, typename EdgeContent>
1789  const vertex_t& new_neighbor)
1790  {
1791  if(new_neighbor.isNull() || v == new_neighbor)
1792  return edge_t();
1793  neighbor_found_t found = this->findInVertex(v, neighbor);
1794  if(!found)
1795  return edge_t();
1796  ++found.it;
1797  typename edge_list_t::iterator new_edge_it
1798  = found.neighborhood->edges.insert(found.it, neighbor_t(new_neighbor, EdgeContent()));
1799  modified = true;
1800  return edge_t(v.id(), new_neighbor.id(), &*new_edge_it);
1801  }
1802 
1803  // Insert a vertex in a neighborhood before another
1804  template <typename VertexContent, typename EdgeContent>
1807  const vertex_t& new_neighbor)
1808  {
1809  if(new_neighbor.isNull() || v == new_neighbor)
1810  return edge_t();
1811  neighbor_found_t found = this->findInVertex(v, neighbor);
1812  if(!found)
1813  return edge_t();
1814  typename edge_list_t::iterator new_edge_it
1815  = found.neighborhood->edges.insert(found.it, neighbor_t(new_neighbor, EdgeContent()));
1816  modified = true;
1817  return edge_t(v.id(), new_neighbor.id(), &*new_edge_it);
1818  }
1819 
1820  // Insert an edge
1821  template <typename VertexContent, typename EdgeContent>
1824  {
1825  if(v.isNull() || new_neighbor.isNull() || v == new_neighbor)
1826  return edge_t();
1827  NeighborhoodPair* it_found = this->findVertex(v);
1828  if(not it_found)
1829  return edge_t();
1830  edge_list_t& lst = it_found->single_neighborhood.edges;
1831  //RSS change from list to vec
1832  //RSS lst.push_front(neighbor_t(new_neighbor, EdgeContent()));
1833  //RSS typename edge_list_t::iterator it = lst.begin();
1834  lst.push_back(neighbor_t(new_neighbor, EdgeContent()));
1835  modified = true;
1836  return edge_t(v.id(), new_neighbor.id(), &lst.back());
1837  }
1838 
1839  // Return the neighborhood
1840  template <typename VertexContent, typename EdgeContent>
1843  {
1845  if(v.isNull())
1846  return result;
1847  const NeighborhoodPair* it_found = this->findVertex(v);
1848  if(not it_found)
1849  return result;
1850  const edge_list_t& lst = it_found->single_neighborhood.edges;
1851  result.first = const_neighbor_iterator(lst.begin());
1852  result.second = const_neighbor_iterator(lst.end());
1853  return result;
1854  }
1855 
1856  // Return the neighborhood
1857  template <typename VertexContent, typename EdgeContent>
1860  {
1861  neighbor_iterator_pair result;
1862  if(v.isNull())
1863  return result;
1864  NeighborhoodPair* it_found = this->findVertex(v);
1865  if(not it_found)
1866  return result;
1867  edge_list_t& lst = it_found->single_neighborhood.edges;
1868  result.first = neighbor_iterator(lst.begin());
1869  result.second = neighbor_iterator(lst.end());
1870  return result;
1871  }
1872 
1873  // Return the neighborhood starting at n
1874  template <typename VertexContent, typename EdgeContent>
1877  {
1879  if(v.isNull())
1880  return result;
1881  const_neighbor_found_t found = this->findInVertex(v, n);
1882  if(!found)
1883  return result;
1884  const edge_list_t& lst = found.neighborhood->edges;
1885  result.first = const_circ_neighbor_iterator(lst.begin(), lst.end(), found.it);
1886  result.second = const_circ_neighbor_iterator(lst.begin(), lst.end());
1887  return result;
1888  }
1889 
1890  // Return the neighborhood starting at n
1891  template <typename VertexContent, typename EdgeContent>
1894  {
1896  if(v.isNull())
1897  return result;
1898  neighbor_found_t found = this->findInVertex(v, n);
1899  if(!found)
1900  return result;
1901  edge_list_t& lst = found.neighborhood->edges;
1902  result.first = circ_neighbor_iterator(lst.begin(), lst.end(), found.it);
1903  result.second = circ_neighbor_iterator(lst.begin(), lst.end());
1904  return result;
1905  }
1906 
1907  // Get a subgraph of the graph
1908  template <typename VertexContent, typename EdgeContent>
1909  template <typename VertexContainer>
1911  VVGraph<VertexContent, EdgeContent>::subgraph(const VertexContainer& verts) const
1912  {
1913  typename VertexContainer::const_iterator it;
1914  VVGraph result;
1915  // First, insert the vertexes in the result graph
1916  for(it = verts.begin(); it != verts.end(); ++it) {
1917  result.insert(*it);
1918  }
1919  const NeighborhoodPair* it_orign;
1920  typename neighborhood_t::iterator it_n;
1921  //RSS typename edge_list_t::const_reverse_iterator it_sn;
1922  typename edge_list_t::const_iterator it_sn;
1923  // Then, creates the in and out edges
1924  for(it_n = result.neighborhood.begin(); it_n != result.neighborhood.end(); ++it_n) {
1925  const vertex_t& v = (*it_n)->vertex;
1926  // For each vertex, find out which edges to add
1927  it_orign = this->findVertex(v);
1928  const edge_list_t& orig_lst = it_orign->single_neighborhood.edges;
1929  edge_list_t& lst = (*it_n)->single_neighborhood.edges;
1930  //RSS change from list to vec
1931  // Going backward because it is easier to retrieve the iterator ...
1932  //RSS for(it_sn = orig_lst.rbegin(); it_sn != orig_lst.rend(); ++it_sn) {
1933  for(it_sn = orig_lst.begin(); it_sn != orig_lst.end(); ++it_sn) {
1934  // For each existing edge from the vertex, keep only the ones whose
1935  // target are on the subgraph
1936  if(result.contains(it_sn->target)) {
1937  // Insert the outgoing edge
1938  // RSSlst.push_front(neighbor_t(it_sn->target, *it_sn));
1939  lst.push_back(neighbor_t(it_sn->target, *it_sn));
1940  }
1941  }
1942  }
1943  return result;
1944  }
1945 
1946  // Copy constructor
1947  template <typename VertexContent, typename EdgeContent>
1949  {
1950  *this = copy;
1951  }
1952 
1953  // Operator ==
1954  template <typename VertexContent, typename EdgeContent>
1956  {
1957  if(neighborhood.size() != other.neighborhood.size())
1958  return false;
1959  for(typename neighborhood_t::const_iterator it = neighborhood.begin(); it != neighborhood.end(); ++it) {
1960  const vertex_t& v1 = it->vertex;
1961  typename lookup_t::const_iterator it_found = other.lookup.find(v1);
1962  if(it_found == other.lookup.end())
1963  return false;
1964  if(it->single_neighborhood.edges.empty()) {
1965  if(!it_found->single_neighborhood.single_neighborhood.edges.empty())
1966  return false;
1967  } else {
1968  const edge_list_t& lst = it->single_neighborhood.edges;
1969  const edge_list_t& olst = it_found->second->single_neighborhood.edges;
1970  if(lst.size() != olst.size())
1971  return false;
1972  const vertex_t& v2 = lst.begin()->target;
1973  bool found = false;
1974  for(typename edge_list_t::const_iterator it_olst = olst.begin(); it_olst != olst.end(); ++it_olst) {
1975  if(it_olst->target == v2) {
1976  found = true;
1977  for(typename edge_list_t::const_iterator it_lst = lst.begin(); it_lst != lst.end(); ++it_lst) {
1978  if(it_lst->target != it_olst->target)
1979  return false;
1980  ++it_olst;
1981  if(it_olst == olst.end())
1982  it_olst = olst.begin();
1983  }
1984  break;
1985  }
1986  }
1987  if(!found)
1988  return false;
1989  }
1990  }
1991  return true;
1992  }
1993 
1994  // Return graph in reverse
1995  template <typename VertexContent, typename EdgeContent>
1997  {
1998  typename neighborhood_t::iterator it;
1999  for(it = neighborhood.begin(); it != neighborhood.end(); ++it) {
2000  std::reverse((*it)->single_neighborhood.edges.begin(), (*it)->single_neighborhood.edges.end());
2001  }
2002  return *this;
2003  }
2004 
2005  // Operator =
2006  template <typename VertexContent, typename EdgeContent>
2008  {
2009  typename neighborhood_t::const_iterator it_o;
2010  typename neighborhood_t::iterator it;
2011  for(it = neighborhood.begin(); it != neighborhood.end(); ++it) {
2012  delete *it;
2013  *it = 0;
2014  }
2015  neighborhood.clear();
2016  lookup.clear();
2017  it = neighborhood.end();
2018  for(it_o = other.neighborhood.begin(); it_o != other.neighborhood.end(); ++it_o) {
2019  NeighborhoodPair* np = (*it_o)->copy();
2020  neighborhood.push_back(np);
2021  lookup[(*it_o)->vertex] = np;
2022  }
2023  return *this;
2024  }
2025 
2026  // Swap
2027  template <typename VertexContent, typename EdgeContent>
2029  {
2030  neighborhood.swap(other.neighborhood);
2031  lookup.swap(other.lookup);
2032  }
2033 
2034  // Test for unique triangle, only use with triangle meshes
2035  template <typename VertexContent, typename EdgeContent>
2037  {
2038  if(v <= n or v <= m or n == m or !edge(v, n) or !edge(v, m) or !edge(n, m))
2039  return false;
2040  else
2041  return true;
2042  }
2043 
2044  // Test for unique line, only use with graphs that always have edges in both directions
2045  template <typename VertexContent, typename EdgeContent>
2047  {
2048  if(v <= n or !edge(v, n))
2049  return false;
2050  else
2051  return true;
2052  }
2053 }
2054 
2055 #endif
mgx::VVGraph::edge_t
Edge< EdgeContent > edge_t
Weak pointer on an edge.
Definition: VVGraph.hpp:174
mgx::VVGraph::lookup
lookup_t lookup
Hash map to optimise look-up.
Definition: VVGraph.hpp:1340
mgx::VVGraph::valence
size_type valence(const vertex_t &v) const
Returns the number of neighbors of v.
Definition: VVGraph.hpp:1550
mgx::VVGraph::const_neighbor_found_t
search_result_t< const single_neighborhood_t, int_const_neighbor_iterator > const_neighbor_found_t
Constant result of a search in the neighborhood.
Definition: VVGraph.hpp:1293
mgx::VVGraph::neighbor_iterator_pair
std::pair< neighbor_iterator, neighbor_iterator > neighbor_iterator_pair
Range of the neighbors of a vertex.
Definition: VVGraph.hpp:384
mgx::ForAll::ForwardIter::ForwardIter
ForwardIter(const iterator &fst, const iterator &lst)
Definition: VVGraph.hpp:64
mgx::_EmptyEdgeContent
Definition: VVGraph.hpp:141
mgx::VVGraph::begin
const_iterator begin() const
Returns an iterator on the beginning of the set of vertexes of the graph.
Definition: VVGraph.hpp:1168
mgx::CircIterator::base
ForwardIterator base() const
Definition: CircIterator.hpp:83
Tie.hpp
mgx::VVGraph::search_result_t::found
bool found
True if the search was completely successful.
Definition: VVGraph.hpp:1265
mgx::Edge::target
identity_t target() const
Returns the identifier of the target of the edge.
Definition: Edge.hpp:178
mgx::VVGraph::findIterator
neighborhood_t::iterator findIterator(const NeighborhoodPair *np)
Find the iterator for a given neighborhood pair.
Definition: VVGraph.hpp:1575
mgx::ForAll::forwardIter
ForwardIter< iterator > forwardIter(const Pair &range, const iterator *)
Definition: VVGraph.hpp:78
mgx::Edge::source
identity_t source() const
Returns the identifier of the source of the edge.
Definition: Edge.hpp:169
mgx::VVGraph::contains
bool contains(const vertex_t &v) const
Test if v is in the graph.
Definition: VVGraph.hpp:1703
mgx::VVGraph::modified
bool modified
If true, the vertex list has been modified.
Definition: VVGraph.hpp:1345
mgx::VVGraph::NeighborhoodPair::vertex
vertex_t vertex
Definition: VVGraph.hpp:338
mgx::VVGraph::int_const_neighbor_iterator
edge_list_t::const_iterator int_const_neighbor_iterator
Constant iterator on the outgoing edges.
Definition: VVGraph.hpp:1283
mgx::VVGraph::neighbor_iterator
SelectMemberIterator< typename edge_list_t::iterator, vertex_t, &neighbor_t::target > neighbor_iterator
Iterator on the neighbors of a vertex.
Definition: VVGraph.hpp:378
mgx::VVGraph::const_neighbor_iterator
SelectMemberIterator< typename edge_list_t::const_iterator, const vertex_t, &neighbor_t::target > const_neighbor_iterator
Constant iterator on the neighbors of a vertex.
Definition: VVGraph.hpp:402
mgx::VVGraph::insert
bool insert(const vertex_t &v, bool checkUnique=true)
Insert a new vertex in the graph.
Definition: VVGraph.hpp:1470
mgx::VVGraph::value_type
vertex_t value_type
Type of the value of the graph as standard container.
Definition: VVGraph.hpp:184
mgx::VVGraph::search_result_t::search_result_t
search_result_t(Iterator i, Neighborhood *n, bool ok=true)
Successful constructor.
Definition: VVGraph.hpp:1245
mgx::VVGraph::prevTo
const vertex_t & prevTo(const vertex_t &v, const vertex_t &ref, unsigned int n=1) const
Returns the nth vertex before ref in the neighborhood of v.
Definition: VVGraph.hpp:1748
mgx::Edge
Definition: Edge.hpp:42
mgx::_EmptyEdgeContent::operator=
_EmptyEdgeContent & operator=(const _EmptyEdgeContent &)
Definition: VVGraph.hpp:142
n
#define n
Definition: Eigenvalues.hpp:36
mgx::VVGraph::end
iterator end()
Returns an iterator on the end of the set of vertexes of the graph.
Definition: VVGraph.hpp:1161
mgx::VVGraph::source
const vertex_t & source(const edge_t &edge) const
Return the source vertex of the edge.
Definition: VVGraph.hpp:829
mgx::VVGraph::uniqueTri
bool uniqueTri(const vertex_t &v, const vertex_t &n, const vertex_t &m) const
Test for unique triangle.
Definition: VVGraph.hpp:2036
mgx::VVGraph::size_type
neighborhood_t::size_type size_type
Type of a size.
Definition: VVGraph.hpp:360
mgx::VVGraph::reverse
VVGraph & reverse()
Reverse the order of all the neighbors.
Definition: VVGraph.hpp:1996
mgx::VVGraph::const_circ_neighbor_iterator_pair
std::pair< const_circ_neighbor_iterator, const_circ_neighbor_iterator > const_circ_neighbor_iterator_pair
Range of circular iterators.
Definition: VVGraph.hpp:421
mgx::ForAll::BaseForwardIter
Definition: VVGraph.hpp:54
mgx::ForAll::ForwardIter::it
iterator it
Definition: VVGraph.hpp:72
mgx::VVGraph::neighbor_t::neighbor_t
neighbor_t(const vertex_t &tgt, const EdgeContent &e)
Constructor.
Definition: VVGraph.hpp:250
mgx::VVGraph::search_result_t::it
Iterator it
Iterator pointing in the edge list.
Definition: VVGraph.hpp:1269
mgx::VVGraph::lookup_t
std::unordered_map< vertex_t, NeighborhoodPair * > lookup_t
Type of the fast-search map.
Definition: VVGraph.hpp:350
mgx::VVGraph::begin
iterator begin()
Returns an iterator on the beginning of the set of vertexes of the graph.
Definition: VVGraph.hpp:1155
mgx::VVGraph::NeighborhoodPair::single_neighborhood
single_neighborhood_t single_neighborhood
Definition: VVGraph.hpp:339
mgx::BaseIterator::base
base_iterator base() const
Direct access to the base iterator.
Definition: MemberIterator.hpp:182
mgx::insert
const VVGraph< VertexContent, EdgeContent >::vertex_t & insert(const typename VVGraph< VertexContent, EdgeContent >::vertex_t &a, const typename VVGraph< VertexContent, EdgeContent >::vertex_t &b, VVGraph< VertexContent, EdgeContent > &S)
Definition: Insert.hpp:102
CircIterator.hpp
mgx::VVGraph::findIn
neighbor_iterator findIn(const vertex_t &v, const vertex_t &n)
Find the vertex n in the neighborhood of v.
Definition: VVGraph.hpp:1653
MemberIterator.hpp
mgx::VVGraph::neighbor_t::edge_list_t
std::vector< neighbor_t > edge_list_t
Type of the list of outgoing neighbors.
Definition: VVGraph.hpp:245
mgx::ForAll::pointer
T * pointer(const T &)
Definition: VVGraph.hpp:89
mgx::VVGraph::reserve
void reserve(size_type s)
Reserve space for more vertices.
Definition: VVGraph.hpp:1219
mgx::VVGraph::single_neighborhood_t
Type of the neighborhood of a vertex.
Definition: VVGraph.hpp:296
mgx::VVGraph::NeighborhoodPair::NeighborhoodPair
NeighborhoodPair(const NeighborhoodPair &copy)
Definition: VVGraph.hpp:329
mgx::VVGraph::single_neighborhood_t::single_neighborhood_t
single_neighborhood_t(const single_neighborhood_t &copy)
Definition: VVGraph.hpp:301
mgx::VVGraph::neighbor_t::clear_edge
void clear_edge()
Definition: VVGraph.hpp:254
mgx::Vertex::isNull
bool isNull() const
Test if a vertex is a null vertex.
Definition: Vertex.hpp:235
mgx::ForAll::ForwardIter::brk
int brk
Definition: VVGraph.hpp:74
mgx::VVGraph::VVGraph
VVGraph(const Container &c, bool checkUnique=true)
Construct from an existing list of vertices.
Definition: VVGraph.hpp:227
mgx::VVGraph::neighborhood
neighborhood_t neighborhood
Main data structure containing everything.
Definition: VVGraph.hpp:1335
mgx
Distributed matrix library.
Definition: Assert.hpp:26
Vertex.hpp
mgx::VVGraph::replace
edge_t replace(const vertex_t &v, const vertex_t &neighbor, const vertex_t &new_neighbor)
Replace a vertex by another in a neighborhood.
Definition: VVGraph.hpp:1711
mgx::VVGraph::search_result_t::neighborhood
Neighborhood * neighborhood
Neighborhood containing the element.
Definition: VVGraph.hpp:1273
mgx::ForAll::castForwardIter
const ForwardIter< iterator > * castForwardIter(const BaseForwardIter *base, const iterator *)
Definition: VVGraph.hpp:84
mgx::SelectMemberIterator
Iterate over a container of structure, dereferencing only a member of it.
Definition: MemberIterator.hpp:229
mgx::SelectMemberPointerIterator
Definition: MemberIterator.hpp:317
mgx::VVGraph::nextTo
const vertex_t & nextTo(const vertex_t &v, const vertex_t &neighbor, unsigned int n=1) const
Returns the nth vertex after neighbor in the neighborhood of v.
Definition: VVGraph.hpp:1730
mgx::VVGraph::single_neighborhood_t::edges
edge_list_t edges
List of the outgoing edges.
Definition: VVGraph.hpp:306
mgx::VVGraph::search_result_t::search_result_t
search_result_t(const search_result_t &copy)
Copy constructor.
Definition: VVGraph.hpp:1251
mgx::Vertex::null
static Vertex null
Definition: Vertex.hpp:258
mgx::VVGraph::const_neighbor_iterator_pair
std::pair< const_neighbor_iterator, const_neighbor_iterator > const_neighbor_iterator_pair
Constant range of the neighbors of a vertex.
Definition: VVGraph.hpp:409
mgx::VVGraph::insertEdge
edge_t insertEdge(const vertex_t &src, const vertex_t &tgt)
Insert a new edge in the graph, without ordering.
Definition: VVGraph.hpp:1823
mgx::VVGraph::NeighborhoodPair::copy
NeighborhoodPair * copy() const
Definition: VVGraph.hpp:332
mgx::VVGraph::neighbors
const_neighbor_iterator_pair neighbors(const vertex_t &v) const
Return the constant range of neighbors of v.
Definition: VVGraph.hpp:1842
mgx::VVGraph::search_result_t
Type of the result of the search for a vertex in a neighborhood.
Definition: VVGraph.hpp:1233
mgx::VVGraph::operator==
bool operator==(const VVGraph &other) const
Test equality for the graphs.
Definition: VVGraph.hpp:1955
mgx::VVGraph::single_neighborhood_t::single_neighborhood_t
single_neighborhood_t()
Definition: VVGraph.hpp:299
mgx::VVGraph::circ_neighbor_iterator_pair
std::pair< circ_neighbor_iterator, circ_neighbor_iterator > circ_neighbor_iterator_pair
Range of circular iterators.
Definition: VVGraph.hpp:395
mgx::VVGraph::single_neighborhood_t::operator=
single_neighborhood_t & operator=(const single_neighborhood_t &other)
Definition: VVGraph.hpp:308
mgx::VVGraph::clear
void clear()
Clear the graph.
Definition: VVGraph.hpp:1350
mgx::ForAll::BaseForwardIter::~BaseForwardIter
virtual ~BaseForwardIter()
Definition: VVGraph.hpp:56
mgx::VVGraph::NeighborhoodPair::NeighborhoodPair
NeighborhoodPair(const vertex_t &v)
Definition: VVGraph.hpp:327
mgx::VVGraph::isModified
bool isModified() const
Test if vertex list has been modified.
Definition: VVGraph.hpp:568
mgx::VVGraph::VVGraph
VVGraph(Iterator begin, Iterator end, bool checkUnique=true)
Construct from an existing list of vertices.
Definition: VVGraph.hpp:217
mgx::VVGraph::size
size_type size() const
Return the number of vertexes on the graph.
Definition: VVGraph.hpp:552
mgx::VVGraph::findVertex
NeighborhoodPair * findVertex(const vertex_t &v)
Find a vertex in the graph and returns the iterator on it.
Definition: VVGraph.hpp:1591
mgx::VVGraph::NeighborhoodPair
Definition: VVGraph.hpp:325
mgx::ForAll::ForwardIter::value
const reference value() const
Definition: VVGraph.hpp:66
mgx::ForAll::make_range
std::pair< typename Container::iterator, typename Container::iterator > make_range(Container &cont)
Definition: VVGraph.hpp:95
mgx::VVGraph::operator=
VVGraph & operator=(const VVGraph &other)
Copy the graph into another graph.
Definition: VVGraph.hpp:2007
mgx::VVGraph::edge
edge_t edge(const vertex_t &src, const vertex_t &tgt)
Returns the edge from src to tgt.
Definition: VVGraph.hpp:1766
mgx::ForAll::ForwardIter::end
iterator end
Definition: VVGraph.hpp:73
mgx::VVGraph::neighbor_found_t
search_result_t< single_neighborhood_t, int_neighbor_iterator > neighbor_found_t
Result of a search in the neighborhood.
Definition: VVGraph.hpp:1288
mgx::VVGraph::uniqueLine
bool uniqueLine(const vertex_t &v, const vertex_t &n) const
Test for unique line.
Definition: VVGraph.hpp:2046
mgx::VVGraph::target
const vertex_t & target(const edge_t &edge) const
Return the target vertex of the edge.
Definition: VVGraph.hpp:850
mgx::Vertex::id
identity_t id() const
Return the identifier of a vertex.
Definition: Vertex.hpp:242
mgx::ForAll::ForwardIter::value_type
std::iterator_traits< iterator >::value_type value_type
Definition: VVGraph.hpp:61
mgx::ForAll::ForwardIter::reference
std::iterator_traits< iterator >::reference reference
Definition: VVGraph.hpp:62
mgx::VVGraph::neighbor_t::target
vertex_t target
Target of the edge.
Definition: VVGraph.hpp:273
mgx::VVGraph::search_result_t::search_result_t
search_result_t()
Default constructor.
Definition: VVGraph.hpp:1240
mgx::VVGraph::iterator
SelectMemberPointerIterator< typename neighborhood_t::iterator, const vertex_t, &NeighborhoodPair::vertex > iterator
Iterator on the vertexes.
Definition: VVGraph.hpp:368
mgx::VVGraph::neighbor_t::operator==
bool operator==(const neighbor_t &other) const
Equality of two neighbors/edge.
Definition: VVGraph.hpp:281
mgx::VVGraph::single_neighborhood_t::operator==
bool operator==(const single_neighborhood_t &other) const
Equality of two neighborhood.
Definition: VVGraph.hpp:318
mgx::VVGraph::findInVertex
neighbor_found_t findInVertex(const vertex_t &v, const vertex_t &neighbor)
Find a vertex neighbor in the neighborhood of v.
Definition: VVGraph.hpp:1613
mgx::ForAll::ForwardIter::is_end
bool is_end() const
Definition: VVGraph.hpp:71
mgx::VVGraph::any
const vertex_t & any() const
Return a vertex from the graph.
Definition: VVGraph.hpp:1516
mgx::VVGraph::subgraph
VVGraph subgraph(const VertexContainer &vertexes) const
Extract the subgraph containing the vertexes.
Edge.hpp
mgx::VVGraph::edge_list_t
neighbor_t::edge_list_t edge_list_t
Type of the list of outgoing neighbors.
Definition: VVGraph.hpp:291
mgx::VVGraph::reference
const vertex_t & reference(vertex_t v) const
Get a reference on the vertex in the graph.
Definition: VVGraph.hpp:541
mgx::VVGraph::swap
void swap(VVGraph &other)
Swap the content of both graphs.
Definition: VVGraph.hpp:2028
mgx::VVGraph::int_neighbor_iterator
edge_list_t::iterator int_neighbor_iterator
Iterator on the outgoing edges.
Definition: VVGraph.hpp:1279
mgx::VVGraph::neighbor_t::neighbor_t
neighbor_t(const neighbor_t &copy)
Definition: VVGraph.hpp:252
mgx::VVGraph::anyIn
const vertex_t & anyIn(const vertex_t &v) const
Return a vertex in the neighborhood of v.
Definition: VVGraph.hpp:1536
mgx::VVGraph::VVGraph
VVGraph()
Default constructor.
Definition: VVGraph.hpp:191
mgx::edge
vvGraph::edge_t edge
Type of an edge.
Definition: Misc.hpp:53
mgx::VVGraph::count
size_type count(const vertex_t &v) const
Count the number of vertexes v in the graph (can be 0 or 1 only)
Definition: VVGraph.hpp:1463
mgx::VVGraph::~VVGraph
~VVGraph()
Destructor.
Definition: VVGraph.hpp:201
mgx::ForAll::make_reverse_range
std::pair< typename Container::reverse_iterator, typename Container::reverse_iterator > make_reverse_range(Container &cont)
Definition: VVGraph.hpp:115
mgx::VVGraph::spliceAfter
edge_t spliceAfter(const vertex_t &v, const vertex_t &neighbor, const vertex_t &new_neighbor)
Insert neighbor in the neighborhood of v after reference.
Definition: VVGraph.hpp:1788
mgx::VVGraph::circ_neighbor_iterator
CircIterator< neighbor_iterator > circ_neighbor_iterator
Iterator used to iterate over the neighbors, but specifying the starting point.
Definition: VVGraph.hpp:390
mgx::ForAll::ForwardIter
Definition: VVGraph.hpp:59
mgx::VVGraph
Definition: VVGraph.hpp:162
mgx::VVGraph::spliceBefore
edge_t spliceBefore(const vertex_t &v, const vertex_t &neighbor, const vertex_t &new_neighbor)
Insert neighbor in the neighborhood of v before reference.
Definition: VVGraph.hpp:1806
mgx::VVGraph::eraseAllEdges
void eraseAllEdges()
Clear all the edges in the graph.
Definition: VVGraph.hpp:1396
mgx::VVGraph::empty
bool empty() const
Test if there is any vertex in the graph.
Definition: VVGraph.hpp:560
mgx::CircIterator
Definition: CircIterator.hpp:24
mgx::VVGraph::operator[]
const vertex_t & operator[](size_type idx) const
Return the element of index idx.
Definition: VVGraph.hpp:1526
mgx::VVGraph::erase
size_type erase(const vertex_t &v)
Remove a vertex from the graph.
Definition: VVGraph.hpp:1379
mgx::VVGraph::const_iterator
SelectMemberPointerIterator< typename neighborhood_t::const_iterator, const vertex_t, &NeighborhoodPair::vertex > const_iterator
Constant iterator on the vertexes.
Definition: VVGraph.hpp:373
mgx::VVGraph::neighborhood_t
std::vector< NeighborhoodPair * > neighborhood_t
Type of the list of vertexes, together with the neighborhood.
Definition: VVGraph.hpp:345
mgx::VVGraph::vertex_t
Vertex< VertexContent > vertex_t
Smart pointer on a vertex.
Definition: VVGraph.hpp:170
mgx::VVGraph::const_edge_t
Edge< const EdgeContent > const_edge_t
Weak pointer on a constant edge.
Definition: VVGraph.hpp:178
mgx::VVGraph::clear
bool clear(const vertex_t &v)
Clear the outgoing edges of a vertex.
Definition: VVGraph.hpp:1441
mgx::VVGraph::neighborhood_value_type
neighborhood_t::value_type neighborhood_value_type
Shortcut for the value_type of the neighborhood.
Definition: VVGraph.hpp:355
mgx::VVGraph::setModified
void setModified(bool _modified)
Set modified status.
Definition: VVGraph.hpp:576
Forall.hpp
mgx::VVGraph::neighbor_t::~neighbor_t
~neighbor_t()
Definition: VVGraph.hpp:259
mgx::VVGraph::neighbor_t
Structure maintaining the data for a single neighbor.
Definition: VVGraph.hpp:238
mgx::VVGraph::eraseEdge
size_type eraseEdge(const vertex_t &src, const vertex_t &tgt)
Erase the edge from src to tgt.
Definition: VVGraph.hpp:1691
mgx::VVGraph::const_circ_neighbor_iterator
CircIterator< const_neighbor_iterator > const_circ_neighbor_iterator
Iterator used to iterate over the neighbors, but spcifying the starting point.
Definition: VVGraph.hpp:415
mgx::Vertex
Definition: Vertex.hpp:58
mgx::VVGraph::neighbor_t::operator=
neighbor_t & operator=(const neighbor_t &copy)
Definition: VVGraph.hpp:261
UnorderedMap.hpp
mgx::VVGraph::end
const_iterator end() const
Returns an iterator on the end of the set of vertexes of the graph.
Definition: VVGraph.hpp:1174