MCPcopy Create free account
hub / github.com/comaps/comaps / Save

Method Save

generator/road_penalty_generator.cpp:167–228  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

165}
166
167void RoadPenaltyCollector::Save()
168{
169 auto const fileName = GetFilename();
170 LOG(LINFO, ("Saving road penalty values to", fileName));
171 FileWriter writer(fileName);
172
173 // All vehicles use the same penalty types
174
175 // Group node penalties by way
176 struct NodePenaltyEntry
177 {
178 uint32_t nodeIdx = 0;
179 m2::PointU coord;
180 RoadPenalty::Type type = RoadPenalty::Type::None;
181 };
182
183 std::map<uint64_t, std::vector<NodePenaltyEntry>> penaltiesByWay;
184
185 m_roads.ForEachWayWithIndex([&](uint64_t wayID, std::vector<uint64_t> const & nodes, size_t idx)
186 {
187 std::vector<NodePenaltyEntry> wayNodePenalties;
188
189 for (uint32_t nodeIdx = 0; nodeIdx < nodes.size(); ++nodeIdx)
190 {
191 uint64_t const nodeID = nodes[nodeIdx];
192 auto const * barrierEntry = m_nodesWithType.Find(nodeID);
193 if (barrierEntry == nullptr)
194 continue;
195
196 NodePenaltyEntry entry;
197 entry.nodeIdx = nodeIdx;
198 entry.coord = barrierEntry->m_coord;
199 entry.type = barrierEntry->m_t;
200 wayNodePenalties.push_back(entry);
201 }
202
203 if (!wayNodePenalties.empty())
204 penaltiesByWay[wayID] = std::move(wayNodePenalties);
205 }, m_cache);
206
207 // Write node penalties grouped by way
208 uint64_t const wayCount = penaltiesByWay.size();
209 WriteToSink(writer, wayCount);
210 for (auto const & [wayID, entries] : penaltiesByWay)
211 {
212 WriteToSink(writer, wayID);
213 WriteToSink(writer, static_cast<uint32_t>(entries.size()));
214
215 for (auto const & entry : entries)
216 {
217 WriteToSink(writer, entry.nodeIdx);
218 WriteToSink(writer, entry.coord.x);
219 WriteToSink(writer, entry.coord.y);
220 WriteToSink(writer, kAllVehiclesMask);
221
222 // Store only penalty type (time derived from vehicle type when loading)
223 routing::Save(writer, entry.type);
224 }

Callers

nothing calls this directly

Calls 7

WriteToSinkFunction · 0.85
ForEachWayWithIndexMethod · 0.80
SaveFunction · 0.70
sizeMethod · 0.45
FindMethod · 0.45
push_backMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected