Advertisement
Guest User

sdugihbasgag

a guest
Dec 7th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. #include <string>
  2. #include <iostream>
  3. #include <fstream>
  4. #include "array_queue.hpp"
  5. #include "hash_graph.hpp"
  6. #include "dijkstra.hpp"
  7.  
  8.  
  9.  
  10. std::string get_node_in_graph(const ics::DistGraph& g, std::string prompt, bool allow_QUIT) {
  11. std::string node;
  12. for(;;) {
  13. node = ics::prompt_string(prompt + " (must be in graph" + (allow_QUIT ? " or QUIT" : "") + ")");
  14. if ( (allow_QUIT && node == "QUIT") || g.has_node(node) )
  15. break;
  16. }
  17. return node;
  18. }
  19.  
  20.  
  21. int main() {
  22. try {
  23. std::ifstream input_file;
  24. std::string fileName= ics::prompt_string("Enter graph file name");
  25. input_file.open(fileName);
  26. ics::DistGraph Graph;
  27. Graph.load(input_file, ";");
  28. std::cout << Graph;
  29. std::string startNode = get_node_in_graph(Graph, "Enter valid starting Node: ", false);
  30. ics::CostMap answer_map = ics::extended_dijkstra(Graph, startNode);
  31.  
  32. std::string endNode = "";
  33. while(endNode != "QUIT"){
  34. endNode = get_node_in_graph(Graph, "Enter valid end Node:", true);
  35. if(endNode != "QUIT") {
  36. std::cout << ics::recover_path(answer_map, endNode);
  37. }
  38. }
  39.  
  40.  
  41.  
  42. } catch (ics::IcsError& e) {
  43. std::cout << e.what() << std::endl;
  44. }
  45.  
  46. return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement