34#ifdef AFBL_DEBUG_LEVEL_2
35#define AFBL_DEBUG_LEVEL_1
38#ifdef AFBL_DEBUG_LEVEL_1
39#define AFBL_DEBUG_LEVEL_0
50template<
class E,
class N,
class V>
66 AFBuilder(
int numberOfLevels,
const std::vector<E*>& edges,
bool unbuildIsWarning,
68 const std::shared_ptr<const FlippedLookupTable> flippedLookup =
nullptr,
69 const bool havePermissions =
false,
const bool haveRestrictions =
false,
74#ifdef AFBL_DEBUG_LEVEL_0
75 myArcFlagsFileName(
"arcflags.csv"),
78 for (
const E*
const edge : edges) {
82#ifdef AFBL_DEBUG_LEVEL_0
83 std::cout <<
"Building flipped edges (" << edges.size() <<
" edges) / nodes..." << std::endl;
85 for (
const E*
const edge : edges) {
91#ifdef AFBL_DEBUG_LEVEL_0
92 std::cout <<
"Flipped edges / nodes are ready." << std::endl;
96#ifdef AFBL_DEBUG_LEVEL_0
97 std::cout <<
"Instantiating arc flag build..." << std::endl;
100 flippedOperation, flippedLookup, havePermissions, haveRestrictions, toProhibit);
102#ifdef AFBL_DEBUG_LEVEL_0
103 std::cout <<
"Arc flag build is instantiated (but still uninitialized)." << std::endl;
125 std::vector<FlagInfo*>&
build(
SUMOTime msTime,
const V*
const vehicle);
135#ifdef AFBL_DEBUG_LEVEL_0
139 void loadFlagsFromCsv(
const std::string fileName);
143 void saveFlagsToCsv(
const std::string fileName);
148 bool fileExists(
const std::string& name) {
149 std::ifstream f(name.c_str());
167#ifdef AFBL_DEBUG_LEVEL_0
170 const std::string myArcFlagsFileName;
179template<
class E,
class N,
class V>
181 delete myArcFlagBuild;
182 delete myFlippedPartition;
183 for (
FlagInfo* flagInfo : myFlagInfos) {
188template<
class E,
class N,
class V>
190 for (
FlagInfo* flagInfo : myFlagInfos) {
196template<
class E,
class N,
class V>
201 assert(myFlippedPartition);
202 if (myFlippedPartition->isClean()) {
203 myFlippedPartition->init(vehicle);
204 myArcFlagBuild->setFlippedPartition(myFlippedPartition);
206 myFlippedPartition->reset(vehicle);
208 assert(myArcFlagBuild);
209#ifdef AFBL_DEBUG_LEVEL_0
210 bool fileExists = this->fileExists(myArcFlagsFileName);
211 if (fileExists && myAmClean) {
212 std::cout <<
"Loading arc flags from file " << myArcFlagsFileName << std::endl;
213 loadFlagsFromCsv(myArcFlagsFileName);
214 std::cout <<
"Arc flags loaded." << std::endl;
217 myArcFlagBuild->init(msTime, vehicle, myFlagInfos);
218#ifdef AFBL_DEBUG_LEVEL_0
221 delete myFlippedPartition;
222 myFlippedPartition =
nullptr;
224#ifdef AFBL_DEBUG_LEVEL_0
226 std::cout <<
"Saving arc flags..." << std::endl;
228 saveFlagsToCsv(myArcFlagsFileName);
229 std::cout <<
"Arc flags have been saved." << std::endl;
236#ifdef AFBL_DEBUG_LEVEL_0
237template<
class E,
class N,
class V>
239 std::ofstream csvFile(fileName);
240 for (FlagInfo* flagInfo : myFlagInfos) {
241 if ((flagInfo->arcFlags).empty()) {
243 std::fill_n(std::back_inserter(flagInfo->arcFlags),
244 myNumberOfArcFlags,
false);
246 for (
bool flag : flagInfo->arcFlags) {
249 csvFile << std::endl;
254template<
class E,
class N,
class V>
257 std::string fileNameCopy = fileName;
258 std::ifstream csvFile(fileNameCopy);
260 if (!csvFile.is_open()) {
261 result = fileNameCopy.insert(0,
"Could not open CSV file ");
262 throw std::runtime_error(result);
264 for (FlagInfo* flagInfo : myFlagInfos) {
265 (flagInfo->arcFlags).clear();
266 std::fill_n(std::back_inserter(flagInfo->arcFlags),
267 myNumberOfArcFlags,
false);
269 if (std::getline(csvFile, line)) {
273 std::stringstream stringStream(line);
274 std::string flagAsString(1,
'\0');
276 while (stringStream.read(&flagAsString[0], 1)) {
277 (flagInfo->arcFlags)[pos++] = (!flagAsString.compare(
"0") ? 0 : 1);
280 result = fileNameCopy.insert(0,
"CSV file ");
281 throw std::runtime_error(result.append(
" has not enough lines - wrong or corrupted file?"));
Builds the flags for (multi-level) arc flag routing (Hilger et al.) in its multi-level variant (also ...
Builds arc flags for shortest path search with the arc flag router.
std::vector< FlippedEdge< E, N, V > * > myFlippedEdges
The flipped (backward) edges.
AFBuilder(int numberOfLevels, const std::vector< E * > &edges, bool unbuildIsWarning, typename SUMOAbstractRouter< FlippedEdge< E, N, V >, V >::Operation flippedOperation, const std::shared_ptr< const FlippedLookupTable > flippedLookup=nullptr, const bool havePermissions=false, const bool haveRestrictions=false, const std::vector< FlippedEdge< E, N, V > * > *toProhibit=nullptr)
Constructor.
AFBuild< E, N, V > * getArcFlagBuild()
Returns the arc flag build.
int myNumberOfArcFlags
The number of arc flags per each edge.
AFInfo< E >::FlagInfo FlagInfo
std::vector< FlagInfo * > & build(SUMOTime msTime, const V *const vehicle)
Build the arc flag information for the arc flag router.
AbstractLookupTable< FlippedEdge< E, N, V >, V > FlippedLookupTable
std::vector< FlagInfo * > myFlagInfos
The flag informations.
AFBuild< E, N, V > * myArcFlagBuild
The arc flag build.
void reset()
Resets the builder.
const std::vector< E * > & getEdges()
Returns the edges.
int sHARCLevel2PartitionLevel(int sHARCLevel)
Converts a SHARC level number to a partition level number.
int myNumberOfLevels
The number of levels of the k-d tree partition of the network.
const std::vector< E * > & myEdges
The edges.
KDTreePartition< FlippedEdge< E, N, V >, FlippedNode< E, N, V >, V > * myFlippedPartition
The k-d tree partition of the backward graph with flipped edges.
static int sHARCLevel2PartitionLevel(int sHARCLevel, int numberOfPartitionLevels)
Converts a SHARC level number to a partition level number.
The edge type representing backward edges with flipped nodes.
the node type representing nodes used for backward search
Partitions the router's network wrt a k-d tree subdivision scheme.