Skip to content

Commit 64e4108

Browse files
committed
final version before the PR.
the commit include : - api closing with a key press on the console. - added (int)search_engine to inside config to determine what search engine the user want to select. (helper : getOneOrTwo). - deleted all profiling steps inside the search engine. - added a new search engine more lightweight to be more fast on sparse graph. (now their is search engine bidirectional / unidirectional). - added a new perf analyzer to determine whether the graph is more optimized for bidirectional engine or unidirectional. - separated the search engine in 3 files : 1 for the bidirectional SE (search_bidirectional.cpp) / 1 for the unidirectional SE (search_unidirectional.cpp) / 1 for for both of the engines (search.cpp).
1 parent 7f3187f commit 64e4108

File tree

11 files changed

+413
-349
lines changed

11 files changed

+413
-349
lines changed

src/api.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ int launchApiGateway(const graph& gdata, search_buffers& buffers, const config&
153153
return 1;
154154
}
155155

156-
console("success", "server is listening on port 80.");
156+
console("success", "server is listening on port 80. press any touch to close it.");
157157
logger("server is listening on port 80.");
158158

159159
while (true)
@@ -324,7 +324,12 @@ int launchApiGateway(const graph& gdata, search_buffers& buffers, const config&
324324

325325
path_result pres;
326326
if (success) {
327-
pres = findShortestPath(gdata, buffers, conf, start_val, end_val, used_weight);
327+
if(conf.search_engine == 1) {
328+
pres = findShortestPathUnidirectional(gdata, buffers, conf, start_val, end_val, used_weight);
329+
}
330+
else {
331+
pres = findShortestPathBidirectional(gdata, buffers, conf, start_val, end_val, used_weight);
332+
}
328333
if (pres.total_time < 0) {
329334
success = false;
330335
message_response = "NO PATH FOUND";

src/conf.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ static bool verifyConfFile(const config& conf)
161161
if (data.find("log") == data.end() || !isBoolString(data["log"])) return false;
162162
if (data.find("nb_alt") == data.end() || !isIntString(data["nb_alt"])) return false;
163163
if (data.find("weight") == data.end() || !isFloatString(data["weight"])) return false;
164+
if (data.find("search_engine") == data.end() || !isIntString(data["search_engine"])) return false;
164165
return true;
165166
}
166167

@@ -181,6 +182,7 @@ static void createConfFile(const config& conf)
181182
ofs << "weight=" << conf.weight << "\n";
182183
ofs << "personalized_weight=" << (conf.personalized_weight ? "true" : "false") << "\n";
183184
ofs << "log=" << (conf.log ? "true" : "false") << "\n";
185+
ofs << "search_engine=" << conf.search_engine << "\n";
184186
ofs.close();
185187
}
186188

@@ -204,6 +206,7 @@ static config loadConfFile(config conf)
204206
conf.personalized_weight = toBool(data["personalized_weight"]);
205207
}
206208
if (data.find("log") != data.end() && isBoolString(data["log"])) conf.log = toBool(data["log"]);
209+
if (data.find("search_engine") != data.end() && isIntString(data["search_engine"])) conf.search_engine = toInt(data["search_engine"]);
207210
return conf;
208211
}
209212

@@ -224,6 +227,7 @@ void loggerConf(config& conf)
224227
logger(" weight > " + std::to_string(conf.weight));
225228
logger(" personalized_weight > " + std::to_string(conf.personalized_weight));
226229
logger(" log > " + std::to_string(conf.log));
230+
logger(" search_engine > " + std::to_string(conf.search_engine));
227231
}
228232

229233
// ✅ function + comment verified.
@@ -329,14 +333,19 @@ config getConfiguration(config conf)
329333

330334
optimization_flags flags = checkGraphOptimization(conf.map_path);
331335
console("info","is obtimized for ALT: [" + (flags.alt_optimized ? GREEN + "Yes" + RESET : RED + "No" + RESET) + "] ");
336+
console("info", std::string("Search engine recommended: [ ") + (flags.search_engine_recommanded == 1 ? GREEN + "Unidirectional (avg: < 4 edges per node)" + RESET : "Unidirectional (avg: < 4 edges per node)")
337+
+ " / " + (flags.search_engine_recommanded == 2 ? GREEN + "Both can be used (avg: 4-5 edges per node) " + RESET : "Both can be used (avg: 4-5 edges per node) ")
338+
+ " / " + (flags.search_engine_recommanded == 3 ? GREEN + "Bidirectional (avg: > 5 edges per node)" + RESET : "Bidirectional (avg: > 5 edges per node)") + " ]");
332339

333340
std::cout << "\n ~ process\n" << std::flush;
334341

342+
conf.search_engine = getOneOrTwo("\n > what type of search engine do you want to use? ('1' for unidirectional - '2' for bidirectional): ");
343+
335344
bool use_alt = getYesNo("\n > do you want to use the ALT pre-processing method (1min ~ 10min)? (y/n): ");
336345
if (use_alt) {
337346
conf.use_alt = true;
338347
conf.nb_alt = getInteger("\n > how many landmarks do you want to use? (e.g., 10): ");
339-
std::cout << "\n";
348+
std::cout << "\n" << std::flush;
340349
bool backup_alt = getYesNo(" > do you want to backup this pre-process for future use? (this will consume time/storage) (y/n): ");
341350
conf.save_alt = backup_alt;
342351
}

src/decl.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ inline std::string GREEN = "\033[1;32m";
1414
inline std::string RESET = "\033[0m";
1515

1616
/*------------------------------------------------------------------------------------
17-
weight definition.
17+
structure definition.
1818
------------------------------------------------------------------------------------*/
1919

2020
/**
@@ -38,6 +38,8 @@ struct config
3838

3939
bool log = false;
4040

41+
int search_engine = 1;
42+
4143
config() = default;
4244
};
4345

@@ -74,6 +76,7 @@ struct graph
7476
struct optimization_flags
7577
{
7678
bool alt_optimized = false;
79+
int search_engine_recommanded = 1;
7780
};
7881

7982
/**
@@ -174,9 +177,12 @@ void clear();
174177
int getInteger(const std::string& prompt);
175178
double getPercentage(const std::string& prompt);
176179
bool getYesNo(const std::string& prompt);
180+
double getOneOrTwo(const std::string& prompt);
177181

178182
void initializeSearchBuffers(const graph& gdata, search_buffers& buffers);
179183

184+
std::vector<int> dijkstraSingleSource(const graph& gdata, int source, size_t node_count);
185+
180186
// log.cpp (Logging)
181187
bool initLogger(const std::string& log_file_path);
182188
void closeLogger();
@@ -212,9 +218,8 @@ bool loadAltData(graph& gdata, config& conf);
212218
void storePerf(const graph& g);
213219

214220
// search.cpp (Pathfinding)
215-
path_result findShortestPath(const graph& gdata, search_buffers& buffers, const config& conf, int start_node, int end_node, double weight);
216-
217-
std::vector<int> dijkstraSingleSource(const graph& gdata, int source, size_t node_count);
221+
path_result findShortestPathBidirectional(const graph& gdata, search_buffers& buffers, const config& conf, int start_node, int end_node, double weight);
222+
path_result findShortestPathUnidirectional(const graph& gdata, search_buffers& buffers, const config& conf, int start_node, int end_node, double weight);
218223

219224
// api.cpp (API management)
220225
int launchApiGateway(const graph& gdata, search_buffers& buffers, const config& conf);

src/helper.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,27 @@ double getPercentage(const std::string& prompt)
154154
return 1.0 + (static_cast<double>(percent) / 100.0);
155155
}
156156

157+
// ✅ function + comment verified.
158+
/**
159+
* @brief Prompts the user for a 1/2 response.
160+
*
161+
* Continuously asks until the user enters '1' or '2'.
162+
*
163+
* @param prompt The message displayed to the user.
164+
* @return '1' or '2'.
165+
*/
166+
double getOneOrTwo(const std::string& prompt)
167+
{
168+
int one_or_two;
169+
while (true) {
170+
one_or_two = getInteger(prompt);
171+
if (one_or_two != 1 || one_or_two != 2) {
172+
break;
173+
}
174+
console("error", "invalid input. please enter 1 or 2.");
175+
}
176+
return one_or_two;
177+
}
157178

158179

159180
// ✅ function + comment verified.

src/main.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
// ✅ file verified.
2+
/* comment in the code have been added with ChatGPT. */
23
#include "incl.h"
34
#include "decl.h"
45

6+
57
// ✅ function + comment verified.
68
/**
79
* @brief Prints the program's main menu with a dynamic step title.
@@ -120,7 +122,13 @@ int main()
120122

121123
storePerf(gdata);
122124

123-
launchApiGateway(gdata, buffers, conf);
125+
std::thread apiThread(launchApiGateway, std::ref(gdata), std::ref(buffers), std::ref(conf));
126+
apiThread.detach();
127+
128+
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
129+
std::cin.get();
124130

125131
closeLogger();
132+
133+
return 0;
126134
}

src/opti.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,18 @@ optimization_flags checkGraphOptimization(const std::string& map_path, double al
100100
density = edge_count / max_edges;
101101
}
102102

103+
double avg_edges_per_node = (node_count > 0) ? (2.0 * edge_count / node_count) : 0.0;
104+
103105
optimization_flags flags;
104106
flags.alt_optimized = (density < alt_density_threshold);
107+
if (avg_edges_per_node < 4) {
108+
flags.search_engine_recommanded = 1;
109+
}
110+
else if (avg_edges_per_node >= 4 && avg_edges_per_node <= 5) {
111+
flags.search_engine_recommanded = 2;
112+
}
113+
else if (avg_edges_per_node > 5) {
114+
flags.search_engine_recommanded = 3;
115+
}
105116
return flags;
106117
}

src/perf.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
*
2121
* Note: This file is independent of the main codebase and serves only for debugging.
2222
* It can be removed at any time without affecting core functionality.
23+
* Note: The differents estimations to get the System Memory and Process Memory on different platform was generated by AI.
2324
*/
2425

2526
#include "incl.h"

src/profiling.h

Lines changed: 0 additions & 74 deletions
This file was deleted.

0 commit comments

Comments
 (0)