SOLA
Loading...
Searching...
No Matches
directed_graph.h
1// Copyright 2023 The SOLA authors
2//
3// This file is part of DAISI.
4//
5// DAISI is free software: you can redistribute it and/or modify it under the terms of the GNU
6// General Public License as published by the Free Software Foundation; version 2.
7//
8// DAISI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
9// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
10// Public License for more details.
11//
12// You should have received a copy of the GNU General Public License along with DAISI. If not, see
13// <https://www.gnu.org/licenses/>.
14//
15// SPDX-License-Identifier: GPL-2.0-only
16
17#ifndef DAISI_DATASTRUCTURE_DIRECTED_GRAPH_H_
18#define DAISI_DATASTRUCTURE_DIRECTED_GRAPH_H_
19
20#include <optional>
21#include <unordered_map>
22#include <utility>
23#include <vector>
24
25namespace daisi::datastructure {
26
27template <typename Vertex, typename Edge> class DirectedGraph {
28public:
29 DirectedGraph() = default;
30 DirectedGraph(const DirectedGraph &other);
31
32 void addVertex(const Vertex &vertex);
33 void removeVertex(const Vertex &vertex);
34 bool hasVertex(const Vertex &vertex) const;
35
36 void addEdge(const Vertex &start, const Vertex &end, const Edge &edge);
37 void removeEdge(const Vertex &start, const Vertex &end);
38 bool hasEdge(const Vertex &start, const Vertex &end) const;
39
40 const std::vector<Vertex> &getVertices() const;
41 Edge &getEdge(const Vertex &start, const Vertex &end);
42
43 std::vector<std::pair<Vertex, Edge>> getOutgoingEdges(const Vertex &start) const;
44 std::vector<std::pair<Vertex, Edge>> getIncomingEdges(const Vertex &end) const;
45
46protected:
47 std::vector<Vertex> vertices_;
48 std::vector<std::vector<std::optional<Edge>>> adjacency_matrix_;
49};
50
51} // namespace daisi::datastructure
52
53#endif
Definition directed_graph.h:27