Lodestar
An integrated real-time control package in C++
DirectedGraph.hpp
1 //
2 // Created by Hamza El-Kebir on 12/25/21.
3 //
4 
5 #ifndef LODESTAR_DIRECTEDGRAPH_HPP
6 #define LODESTAR_DIRECTEDGRAPH_HPP
7 
8 #include "Lodestar/GlobalConstants.hpp"
9 #include "Lodestar/blocks/BlockProto.hpp"
10 #include <vector>
11 #include <array>
12 #include "Eigen/Sparse"
13 
14 namespace ls {
15  namespace blocks {
16  namespace aux {
17  class DirectedGraph {
18  public:
19 
20  DirectedGraph() : adj_{LS_MAX_CONNECTIONS, LS_MAX_CONNECTIONS},
21  size_(LS_MAX_CONNECTIONS)
22  {}
23 
24  DirectedGraph(int n) : adj_{n, n}, size_(n)
25  {}
26 
27  DirectedGraph(const Eigen::SparseMatrix<int> &adj) : adj_(adj),
28  size_(adj.rows())
29  {}
30 
31  static DirectedGraph
32  fromBlocks(const ::std::vector<BlockProto *> &blocks);
33 
34  static DirectedGraph
35  fromBlocks(const ::std::vector<const BlockProto *> &blocks);
36 
37  template <int N>
38  static DirectedGraph
39  fromBlocks(const ::std::array<BlockProto *, N> &blocks);
40 
41  template <int N>
42  static DirectedGraph
43  fromBlocks(const ::std::array<const BlockProto *, N> &blocks);
44 
45  int &get(int src, int dst);
46 
47  int get(int src, int dst) const;
48 
49  bool hasConnection(int src, int dst) const;
50 
51  int getSize() const;
52 
53  bool resize(int n);
54 
55  void connect(int src, int dst, int conn = 1);
56 
57  const Eigen::SparseMatrix<int> &adj() const;
58 
59  protected:
60  Eigen::SparseMatrix<int> adj_;
61  int size_;
62  };
63  }
64  }
65 }
66 
67 
68 #endif //LODESTAR_DIRECTEDGRAPH_HPP
ls::blocks::aux::DirectedGraph
Definition: DirectedGraph.hpp:17
ls
Main Lodestar code.
Definition: BilinearTransformation.hpp:12