Simulateur Ferroviaire
Reconstruction et visualisation d'un réseau ferroviaire à partir de données GeoJSON — Win32 / WebView2 / Leaflet
Chargement...
Recherche...
Aucune correspondance
BlockSet.h
Aller à la documentation de ce fichier.
1
12#pragma once
13
14#include <array>
15#include <memory>
16#include <string>
17#include <unordered_map>
18#include <vector>
19
22
35{
36 size_t frontierNodeId = 0;
37 std::string neighbourId;
38};
39
48{
49 // =========================================================================
50 // Blocs — ownership exclusif
51 // =========================================================================
52
53 std::vector<std::unique_ptr<StraightBlock>> straights;
54 std::vector<std::unique_ptr<SwitchBlock>> switches;
55
56 // =========================================================================
57 // Index de lookup
58 // =========================================================================
59
64 std::unordered_map<size_t, std::vector<StraightBlock*>> straightsByNode;
65
67 std::unordered_map<size_t, SwitchBlock*> switchByNode;
68
74 std::unordered_map<size_t, StraightBlock*> straightByEndpointPair;
75
93 std::unordered_map<size_t, std::vector<StraightBlock*>> straightByDirectedPair;
94
95 // =========================================================================
96 // Endpoints — index parallèles aux vecteurs straights / switches
97 // =========================================================================
98
105 std::vector<std::pair<BlockEndpoint, BlockEndpoint>> straightEndpoints;
106
108 std::vector<std::array<BlockEndpoint, 3>> switchEndpoints;
109
110 // =========================================================================
111 // Utilitaires
112 // =========================================================================
113
114 void clear()
115 {
116 straights.clear(); straights.shrink_to_fit();
117 switches.clear(); switches.shrink_to_fit();
118 straightsByNode.clear();
119 switchByNode.clear();
122 straightEndpoints.clear();
123 switchEndpoints.clear();
124 }
125
126 [[nodiscard]] size_t totalCount() const
127 {
128 return straights.size() + switches.size();
129 }
130
140 {
141 straightsByNode.clear();
144
145 for (size_t i = 0; i < straights.size(); ++i)
146 {
147 if (i >= straightEndpoints.size()) break;
148 StraightBlock* st = straights[i].get();
149 const size_t nA = straightEndpoints[i].first.frontierNodeId;
150 const size_t nB = straightEndpoints[i].second.frontierNodeId;
151
152 // Saute les sous-blocs internes — pas de nœud frontière réel
153 if (nA == SIZE_MAX || nB == SIZE_MAX) continue;
154
155 straightsByNode[nA].push_back(st);
156 straightsByNode[nB].push_back(st);
157
158 const size_t a = std::min(nA, nB);
159 const size_t b = std::max(nA, nB);
160 straightByEndpointPair[(a + b) * (a + b + 1) / 2 + b] = st;
161
162 // Multi-valué : push_back pour conserver les deux entrées crossover
163 straightByDirectedPair[nA * 1'000'000ULL + nB].push_back(st);
164 straightByDirectedPair[nB * 1'000'000ULL + nA].push_back(st);
165 }
166 }
167};
Modèle de domaine d'un bloc de voie droite (Straight).
Modèle de domaine d'un aiguillage ferroviaire à 3 branches.
Definition StraightBlock.h:24
Extrémité d'un bloc — nœud frontière + ID du bloc voisin.
Definition BlockSet.h:35
std::string neighbourId
Definition BlockSet.h:37
size_t frontierNodeId
Definition BlockSet.h:36
Conteneur propriétaire des StraightBlock et SwitchBlock.
Definition BlockSet.h:48
size_t totalCount() const
Definition BlockSet.h:126
std::vector< std::pair< BlockEndpoint, BlockEndpoint > > straightEndpoints
Definition BlockSet.h:105
std::vector< std::unique_ptr< StraightBlock > > straights
Definition BlockSet.h:53
std::unordered_map< size_t, SwitchBlock * > switchByNode
Definition BlockSet.h:67
std::unordered_map< size_t, StraightBlock * > straightByEndpointPair
Definition BlockSet.h:74
std::vector< std::unique_ptr< SwitchBlock > > switches
Definition BlockSet.h:54
std::vector< std::array< BlockEndpoint, 3 > > switchEndpoints
Definition BlockSet.h:108
std::unordered_map< size_t, std::vector< StraightBlock * > > straightByDirectedPair
Definition BlockSet.h:93
void rebuildStraightIndex()
Reconstruit tous les index straight depuis straights et straightEndpoints (après absorption Phase7).
Definition BlockSet.h:139
std::unordered_map< size_t, std::vector< StraightBlock * > > straightsByNode
Definition BlockSet.h:64
void clear()
Definition BlockSet.h:114