61 freopen(edgeFile.c_str(),
"rt", stdin);
77 std::vector<std::string> vecToken;
83 if(vecToken.size() < 5)
84 fprintf(stderr,
"Error in %d edge\n", edge_count);
88 tempEdge.
id = atoi(vecToken[0].c_str());
89 tempEdge.
source = atoi(vecToken[1].c_str());
90 tempEdge.
target = atoi(vecToken[2].c_str());
91 tempEdge.
cost = atof(vecToken[3].c_str());
93 tempEdge.
s_x = atof(vecToken[5].c_str());
94 tempEdge.
s_y = atof(vecToken[6].c_str());
95 tempEdge.
t_x = atof(vecToken[7].c_str());
96 tempEdge.
t_y = atof(vecToken[8].c_str());
104 vecEdges.push_back(tempEdge);
112 edges[i] = vecEdges[i];
122 freopen(fileName.c_str(),
"wt", stdout);
129 printf(
"%d\t|%d\t|%.6lf\n", path[i].vertex_id, path[i].edge_id, path[i].cost);
139 void match(std::string fileName1, std::string fileName2, std::string outFile,
double ttime)
142 freopen(fileName1.c_str(),
"rt", stdin);
145 std::vector<int> nodeList1;
147 double totCost1, totCost2;
155 if(sscanf(
buff,
"%d |%d |%lf", &nid, &eid, &cost) != 3)
160 nodeList1.push_back(nid);
161 nodeList1.push_back(eid);
167 freopen(fileName2.c_str(),
"rt", stdin);
174 if(sscanf(
buff,
"%d |%d |%lf", &nid, &eid, &cost) != 3)
179 if(pos >= nodeList1.size() || nodeList1[pos] != nid)
184 if(pos >= nodeList1.size() || nodeList1[pos] != eid)
194 freopen(outFile.c_str(),
"a+", stdout);
195 printf(
"Case %d: ",
kase);
198 if(fabs(totCost1 - totCost2) <
EPS)
203 printf(
"Perfect Match!!!\n");
207 printf(
"Cost same, but path differs!!!\n");
212 printf(
"Cost differs, %s costs %lf and %s costs %lf\n", fileName1.c_str(), totCost1, fileName2.c_str(), totCost2);
214 printf(
"Query time: %lf sec\n\n", ttime);
225 std::string outFile =
"output.txt";
226 std::string inFile =
"input.txt";
229 FILE *fpout = fopen(outFile.c_str(),
"wt");
233 FILE *fpin = fopen(inFile.c_str(),
"rt");
237 while(fgets(
buff, 1000, fpin))
240 if(strlen(
buff) == 0)
249 std::vector<std::string> vecToken;
252 int totParam = vecToken.size();
259 std::string graphFile = vecToken[0];
262 int startNode = atoi(vecToken[1].c_str());
263 int endNode = atoi(vecToken[2].c_str());
266 std::string pathFile = vecToken[3];
267 int ind = pathFile.length() - 1;
268 while(pathFile[ind] < 32)
270 pathFile[ind] =
'\0';
289 std::string ansFile = vecToken[4];
290 ind = ansFile.length() - 1;
291 while(ansFile[ind] < 32)
297 match(pathFile, ansFile, outFile, cl / CLOCKS_PER_SEC);
302 fpout = fopen(outFile.c_str(),
"a+");
303 fprintf(fpout,
"Case %d: Path Written to file %s",
kase, pathFile.c_str());
304 fprintf(fpout,
"Query Time: %lf sec\n\n", cl / CLOCKS_PER_SEC);
bool parse(std::string strInput, std::string chDelim)
int bidir_astar(edge_astar_t *edges, size_t edge_count, int maxNode, int start_vertex, int end_vertex, path_element_t **path, size_t *path_count, char **err_msg)
void write_result(std::string fileName, int res)
std::vector< edge_astar_t > vecEdges
bool getTokens(StringVector &vecTokensRef)
void loadGraph(std::string edgeFile)
void match(std::string fileName1, std::string fileName2, std::string outFile, double ttime)