SECompartmentTransportGraph.hxx
1/* Distributed under the Apache License, Version 2.0.
2 See accompanying NOTICE file for details.*/
3
4template<COMPARTMENT_TRANSPORT_GRAPH_TEMPLATE>
5SECompartmentTransportGraph<COMPARTMENT_TRANSPORT_GRAPH_TYPES>::SECompartmentTransportGraph(const std::string& name, Logger* logger) : SECompartmentGraph<COMPARTMENT_GRAPH_TYPES>(name,logger)
6{
7
8}
9template<COMPARTMENT_TRANSPORT_GRAPH_TEMPLATE>
11{
12 Clear();
13}
14
15template<COMPARTMENT_TRANSPORT_GRAPH_TEMPLATE>
17{
19 for (auto& itr : m_TargetEdgeMap)
20 delete itr.second;
21 for (auto& itr : m_SourceEdgeMap)
22 delete itr.second;
23 m_Verticies.clear();
24 m_VertexIndicies.clear();
25 m_TargetEdgeMap.clear();
26 m_SourceEdgeMap.clear();
27}
28
29template<COMPARTMENT_TRANSPORT_GRAPH_TEMPLATE>
31{
32 for (auto& itr : m_TargetEdgeMap)
33 delete itr.second;
34 for (auto& itr : m_SourceEdgeMap)
35 delete itr.second;
36 m_TargetEdgeMap.clear();
37 m_SourceEdgeMap.clear();
38 // Cache what paths are connected to what nodes
39 for (CompartmentLinkType* link : this->m_CompartmentLinks)
40 {
41 CompartmentType* cSrc = &link->GetSourceCompartment();
42 CompartmentType* cTgt = &link->GetTargetCompartment();
43 // Source Edges
44 std::vector<GraphEdgeType*>* srcEdges = m_SourceEdgeMap[cSrc];
45 if (srcEdges == nullptr)
46 {
47 srcEdges = new std::vector<GraphEdgeType*>();
48 m_SourceEdgeMap[cSrc] = srcEdges;
49 }
50 srcEdges->push_back(link);
51 // Target Edges
52 std::vector<GraphEdgeType*>* tgtEdges = m_TargetEdgeMap[cTgt];
53 if (tgtEdges == nullptr)
54 {
55 tgtEdges = new std::vector<GraphEdgeType*>();
56 m_TargetEdgeMap[cTgt] = tgtEdges;
57 }
58 tgtEdges->push_back(link);
59 }
60 // Now push the compartments into graph lists for transport
61 int i = 0;
62 m_Verticies.clear();
63 m_VertexIndicies.clear();
64 for (CompartmentType* c : this->m_Compartments)
65 {
66 m_Verticies.push_back(c);
67 m_VertexIndicies[c] = i++;
68 }
69}
70
71template<COMPARTMENT_TRANSPORT_GRAPH_TEMPLATE>
73{
74 auto itr = m_VertexIndicies.find(&v);
75 if (itr == m_VertexIndicies.end())
76 {
77 this->Error("Vertex is not in Graph Index Map.");
78 return -1;
79 }
80 return itr->second;
81}
82template<COMPARTMENT_TRANSPORT_GRAPH_TEMPLATE>
84{
85 return m_Verticies;
86}
87template<COMPARTMENT_TRANSPORT_GRAPH_TEMPLATE>
88const std::vector<GraphEdgeType*>* SECompartmentTransportGraph<COMPARTMENT_TRANSPORT_GRAPH_TYPES>::GetSourceEdges(const GraphVertexType& v) const
89{
90 auto itr = m_SourceEdgeMap.find(&v);
91 if (itr == m_SourceEdgeMap.end())
92 return nullptr;
93 return itr->second;
94}
95template<COMPARTMENT_TRANSPORT_GRAPH_TEMPLATE>
96const std::vector<GraphEdgeType*>* SECompartmentTransportGraph<COMPARTMENT_TRANSPORT_GRAPH_TYPES>::GetTargetEdges(const GraphVertexType& v) const
97{
98 auto itr = m_TargetEdgeMap.find(&v);
99 if (itr == m_TargetEdgeMap.end())
100 return nullptr;
101 return itr->second;
102}
103
Definition: Logger.h:71
Definition: SECompartmentGraph.h:11
virtual void Clear()
void Clear() override
Definition: SECompartmentTransportGraph.cpp:19
const std::vector< GraphEdgeType * > * GetTargetEdges(const GraphVertexType &v) const override
Definition: SECompartmentTransportGraph.cpp:99
SECompartmentTransportGraph(const std::string &name, Logger *logger)
Definition: SECompartmentTransportGraph.cpp:8
int GetVertexIndex(const GraphVertexType &v) const override
Definition: SECompartmentTransportGraph.cpp:75
const std::vector< GraphEdgeType * > * GetSourceEdges(const GraphVertexType &v) const override
Definition: SECompartmentTransportGraph.cpp:91
virtual ~SECompartmentTransportGraph()
Definition: SECompartmentTransportGraph.cpp:13
virtual void StateChange()
Definition: SECompartmentTransportGraph.cpp:33
const std::vector< GraphVertexType * > & GetVerticies() const override
Definition: SECompartmentTransportGraph.cpp:86

Distributed under the Apache License, Version 2.0.

See accompanying NOTICE file for details.