Skip to content

Commit 4f697b4

Browse files
committed
network refactor: Removed agents from class
Refactored so that NetworkBase, UndirectedNetwork and DirectedNetwork are not templated on the agent type. The network also does not contain the agents.
1 parent ba51a0f commit 4f697b4

File tree

3 files changed

+13
-30
lines changed

3 files changed

+13
-30
lines changed

graph_lib/include/directed_network.hpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,20 @@ namespace Graph {
2020
Note: switch is equivalent to toggle + transpose, but much cheaper!
2121
*/
2222
template <typename AgentType, typename WeightType = double>
23-
class DirectedNetwork : public NetworkBase<AgentType, WeightType> {
23+
class DirectedNetwork : public NetworkBase<WeightType> {
2424
public:
2525
enum class EdgeDirection { Incoming, Outgoing };
2626

2727
using WeightT = WeightType;
28-
using AgentT = AgentType;
2928

3029
DirectedNetwork() = default;
3130

32-
DirectedNetwork(size_t n_agents) : NetworkBase<AgentT>(n_agents) {}
33-
34-
DirectedNetwork(std::vector<AgentT> agents) : NetworkBase<AgentT>(agents) {}
31+
DirectedNetwork(size_t n_agents) : NetworkBase<>(n_agents) {}
3532

3633
DirectedNetwork(std::vector<std::vector<size_t>> &&neighbour_list,
3734
std::vector<std::vector<WeightT>> &&weight_list,
3835
EdgeDirection direction)
39-
: NetworkBase<AgentT>(std::move(neighbour_list), std::move(weight_list)),
36+
: NetworkBase<>(std::move(neighbour_list), std::move(weight_list)),
4037
_direction(direction) {}
4138

4239
/*

graph_lib/include/network_base.hpp

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,10 @@ namespace Graph {
1414
/*
1515
An abstract base class for undirected and directed networks.
1616
*/
17-
template <typename AgentType, typename WeightType = double> class NetworkBase {
17+
template <typename WeightType = double> class NetworkBase {
1818
public:
1919
using WeightT = WeightType;
20-
using AgentT = AgentType;
21-
// @TODO: Make this private later
22-
std::vector<AgentT> agents{}; // List of agents of type AgentType
20+
2321
protected:
2422
std::vector<std::vector<size_t>>
2523
neighbour_list{}; // Neighbour list for the connections
@@ -30,31 +28,22 @@ template <typename AgentType, typename WeightType = double> class NetworkBase {
3028
NetworkBase() = default;
3129

3230
NetworkBase(size_t n_agents)
33-
: agents(std::vector<AgentT>(n_agents)),
34-
neighbour_list(
31+
: neighbour_list(
3532
std::vector<std::vector<size_t>>(n_agents, std::vector<size_t>{})),
3633
weight_list(std::vector<std::vector<WeightT>>(n_agents,
3734
std::vector<WeightT>{})) {
3835
}
3936

40-
NetworkBase(std::vector<AgentT> agents)
41-
: agents(agents), neighbour_list(std::vector<std::vector<size_t>>(
42-
agents.size(), std::vector<size_t>{})),
43-
weight_list(std::vector<std::vector<WeightT>>(agents.size(),
44-
std::vector<WeightT>{})) {
45-
}
46-
4737
NetworkBase(std::vector<std::vector<size_t>> &&neighbour_list,
4838
std::vector<std::vector<WeightT>> &&weight_list)
49-
: agents(std::vector<AgentT>(neighbour_list.size())),
50-
neighbour_list(neighbour_list), weight_list(weight_list) {}
39+
: neighbour_list(neighbour_list), weight_list(weight_list) {}
5140

5241
virtual ~NetworkBase() = default;
5342

5443
/*
5544
Gives the total number of nodes in the network
5645
*/
57-
[[nodiscard]] std::size_t n_agents() const { return agents.size(); }
46+
[[nodiscard]] std::size_t n_agents() const { return neighbour_list.size(); }
5847

5948
/*
6049
Gives the number of edges connected to agent_idx

graph_lib/include/undirected_network.hpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,19 @@ namespace Graph {
66
/*
77
A class that represents an undirected graph using adjacency lists.
88
*/
9-
template <typename AgentType, typename WeightType = double>
10-
class UndirectedNetwork : public NetworkBase<AgentType, WeightType> {
9+
template <typename WeightType = double>
10+
class UndirectedNetwork : public NetworkBase<WeightType> {
1111
public:
1212
using WeightT = WeightType;
13-
using AgentT = AgentType;
1413

1514
UndirectedNetwork() = default;
1615

17-
UndirectedNetwork(size_t n_agents) : NetworkBase<AgentT>(n_agents) {}
18-
19-
UndirectedNetwork(std::vector<AgentT> agents) : NetworkBase<AgentT>(agents) {}
16+
UndirectedNetwork(size_t n_agents) : NetworkBase<>(n_agents) {}
2017

2118
UndirectedNetwork(std::vector<std::vector<size_t>> &&neighbour_list,
2219
std::vector<std::vector<WeightT>> &&weight_list)
23-
: NetworkBase<AgentT>(std::move(neighbour_list), std::move(weight_list)) {
24-
}
20+
: Graph::NetworkBase<>(std::move(neighbour_list),
21+
std::move(weight_list)) {}
2522

2623
/*
2724
Gives the number of edges connected to agent_idx

0 commit comments

Comments
 (0)