Bridges-C++  3.4.4
Bridges(C++ API)
ShortestPathBenchmark.h
Go to the documentation of this file.
1 #ifndef SHORTESTPATH_BENCHMARK_H
2 #define SHORTESTPATH_BENCHMARK_H
3 
4 #include <LineChart.h>
5 #include <limits>
6 #include <vector>
7 #include <chrono>
8 #include <stdlib.h>
9 #include <iostream>
10 #include <GraphBenchmark.h>
11 
12 namespace bridges {
13  namespace benchmark {
14  using namespace bridges::datastructure;
43  private:
44  LineChart& plot;
45  DataSource ds;
46 
47  int getCenter(const OSMData& osm_data, const GraphAdjList<int, OSMVertex, double>& graph,
48  double latc, double lonc) {
49  //
50  auto distfunction = [ = ](const OSMVertex & v) -> double {
51  return (v.getLatitude() - latc) * (v.getLatitude() - latc) + (v.getLongitude() - lonc) * (v.getLongitude() - lonc);
52  };
53 
54  int minindex = 0;
55  double dist = distfunction(graph.getVertex(minindex)->getValue());
56 
57  for (int i = 1; i < graph.getVertices()->size(); ++i) {
58  double locdist = distfunction(graph.getVertex(i)->getValue());
59  if (locdist < dist) {
60  minindex = i;
61  dist = locdist;
62  }
63  }
64 
65  return minindex;
66  }
67 
68  public:
70  : plot (p) {
71  p.setXLabel("Number of Edges");
72  p.setYLabel("Runtime (in s)");
73 
74  }
75 
82  void run(std::string algoName,
83  void (*spalgo)(const GraphAdjList<int, OSMVertex, double>& gr,
84  int source,
85  std::unordered_map<int, double>& distance,
86  std::unordered_map<int, int>& parent)) {
87  std::vector<double> time;
88  std::vector<double> vtxCounts;
89  std::vector<double> edgeCounts;
90 
91  // double reflat = 39.9713; //Columbus, OH
92  // double reflong = -82.99;
93 
94  double reflat = 40.74; //New York City, NC
95  double reflong = -73.98;
96 
97  for (double radius = 0.02; radius < 0.15; radius += 0.02) {
98  std::cerr << "*" << std::flush;
99  //std::tie(vertexCount, edgeCount)= generateWikidataMovieActor(year, 2019, graph);
100 
101  OSMData osm_data = ds.getOSMData(reflat - radius, reflong - radius,
102  reflat + radius, reflong + radius);
104  osm_data.getGraph (&graph);
105 
106  long vertexCount = countVertices(graph);
107  long edgeCount = countEdges(graph);
108 
109  int root = getCenter(osm_data, graph, reflat, reflong);
110 
111  std::unordered_map<int, double> level;
112  std::unordered_map<int, int> parent;
113 
114  std::chrono::time_point<std::chrono::system_clock> start = std::chrono::system_clock::now();
115 
116  spalgo(graph, root, level, parent);
117 
118  std::chrono::time_point<std::chrono::system_clock> end = std::chrono::system_clock::now();
119 
120  std::chrono::duration<double> elapsed_seconds = end - start;
121 
122  time.push_back ((double)elapsed_seconds.count() );
123  vtxCounts.push_back ( (double)vertexCount );
124  edgeCounts.push_back ( (double)edgeCount );
125 
126  if (elapsed_seconds.count() > time_cap) {
127  break;
128  }
129  }
130  plot.setXData(algoName, edgeCounts);
131  plot.setYData(algoName, time);
132  std::cerr << "\n" << std::flush;
133  }
134  };
135  }
136 }
137 
138 #endif
This class provides an API to various data sources used in BRIDGES.
Definition: DataSource.h:62
OSMData getOSMData(double lat_min, double long_min, double lat_max, double long_max, string level="default")
Get OpenStreetMap data given a bounding rectangle of lat/long values.
Definition: DataSource.h:829
Base class for a variety of graph based benchmark.
Definition: GraphBenchmark.h:15
Benchmarks Shortest Path algorithms.
Definition: ShortestPathBenchmark.h:42
void run(std::string algoName, void(*spalgo)(const GraphAdjList< int, OSMVertex, double > &gr, int source, std::unordered_map< int, double > &distance, std::unordered_map< int, int > &parent))
benchmark one implementation
Definition: ShortestPathBenchmark.h:82
ShortestPathBenchmark(LineChart &p)
Definition: ShortestPathBenchmark.h:69
Class that hold Open Street Map Data.
Definition: OSMData.h:38
void getGraph(GraphAdjList< int, OSMVertex, double > *gr) const
Definition: OSMData.h:146
Class that hold Open Street Map vertices.
Definition: OSMVertex.h:33
E const & getValue() const
Gets the object held in the generic object E.
Definition: Element.h:207
This class provides methods to represent adjacency list based graphs.
Definition: GraphAdjList.h:110
const Element< E1 > * getVertex(const K &key) const
Return the vertex corresponding to a key.
Definition: GraphAdjList.h:405
unordered_map< K, Element< E1 > * > * getVertices()
Return the graph nodes.
Definition: GraphAdjList.h:388
Show series of data or functions using a line chart.
Definition: LineChart.h:43
void setYData(string series, vector< double > ydata)
Changes the Y data for a series.
Definition: LineChart.h:234
void setXData(string series, vector< double > xdata)
Changes the X data for a series.
Definition: LineChart.h:214
Definition: Array.h:9
these methods convert byte arrays in to base64 codes and are used in BRIDGES to represent the color a...
Definition: alltypes.h:4