Bridges-C++  3.4.2
Bridges(C++ API)
GraphBenchmark.h
Go to the documentation of this file.
1 #ifndef GRAPH_BENCHMARK_H
2 #define GRAPH_BENCHMARK_H
3 
4 #include <GraphAdjList.h>
5 
6 namespace bridges {
7  namespace benchmark {
8  using namespace bridges::datastructure;
9 
16  protected:
17  double time_cap;
19  : time_cap (std::numeric_limits<double>::max())
20  {}
21 
23  std::tuple<long, long> generateWikidataMovieActor (int yearmin, int yearmax, GraphAdjList<std::string>& moviegraph) {
24  DataSource ds;
25  std::vector<MovieActorWikidata> v = ds.getWikidataActorMovie(yearmin, yearmax);
26  long edgeCount = 0;
27  long vertexCount = 0;
28 
29  //GraphAdjList<std::string, std::string> moviegraph;
30  for (auto ma : v) {
31 
32  //add the movie vertex
33  auto movievertex = moviegraph.getVertex(ma.getMovieURI());
34  if (movievertex == nullptr) {
35  moviegraph.addVertex(ma.getMovieURI(), ma.getMovieName());
36  movievertex = moviegraph.getVertex(ma.getMovieURI());
37  vertexCount++;
38  }
39 
40  //add the actor vertex
41  auto actorvertex = moviegraph.getVertex(ma.getActorURI());
42  if (actorvertex == nullptr) {
43  moviegraph.addVertex(ma.getActorURI(), ma.getActorName());
44  actorvertex = moviegraph.getVertex(ma.getActorURI());
45  vertexCount++;
46  }
47 
48  //add bidirectional edge
49  moviegraph.addEdge(ma.getMovieURI(), ma.getActorURI());
50  moviegraph.addEdge(ma.getActorURI(), ma.getMovieURI());
51  edgeCount += 2;
52  }
53 
54  return std::make_tuple(vertexCount, edgeCount);
55  }
56 
58  long maxdegree = -1;
59  std::string ret;
60 
61  for (auto k : gr.keySet()) {
62  long degree = 0;
63  for (auto e : gr.outgoingEdgeSetOf(k))
64  degree++;
65  if (degree > maxdegree) {
66  maxdegree = degree;
67  ret = k;
68  }
69  }
70 
71  return ret;
72  }
73 
74  template<typename GraphType>
75  long countVertices (const GraphType& gr) {
76  return gr.getVertices()->size();
77  }
78 
79  template<typename GraphType>
80  long countEdges(const GraphType& gr) {
81  long edges = 0;
82  for (auto k : gr.keySet())
83  for (auto e : gr.outgoingEdgeSetOf(k))
84  edges++;
85 
86  return edges;
87  }
88 
89 
90  public:
100  void setTimeCap(double cap_in_s) {
101  time_cap = cap_in_s;
102  }
103 
113  double getTimeCap() const {
114  return time_cap;
115  }
116 
117  };
118  }
119 }
120 
121 #endif
This class provides an API to various data sources used in BRIDGES.
Definition: DataSource.h:63
std::vector< MovieActorWikidata > getWikidataActorMovie(int yearbegin, int yearend)
This function returns the Movie and Actors playing in them between two years.
Definition: DataSource.h:1439
Base class for a variety of graph based benchmark.
Definition: GraphBenchmark.h:15
long countEdges(const GraphType &gr)
Definition: GraphBenchmark.h:80
double getTimeCap() const
Return time limit of a run.
Definition: GraphBenchmark.h:113
std::tuple< long, long > generateWikidataMovieActor(int yearmin, int yearmax, GraphAdjList< std::string > &moviegraph)
Definition: GraphBenchmark.h:23
void setTimeCap(double cap_in_s)
sets an upper bound to the time of a run.
Definition: GraphBenchmark.h:100
double time_cap
Definition: GraphBenchmark.h:17
GraphBenchmark()
Definition: GraphBenchmark.h:18
std::string highestDegreeVertex(GraphAdjList< std::string > &gr)
Definition: GraphBenchmark.h:57
long countVertices(const GraphType &gr)
Definition: GraphBenchmark.h:75
This class provides methods to represent adjacency list based graphs.
Definition: GraphAdjList.h:111
KeySet_helper keySet() const
Definition: GraphAdjList.h:817
void addVertex(const K &k, const E1 &e=E1())
Adds a vertex to the graph.
Definition: GraphAdjList.h:177
void addEdge(const K &src, const K &dest, const E2 &data=E2())
Definition: GraphAdjList.h:200
SLelement< Edge< K, E2 > >::SLelement_listhelper outgoingEdgeSetOf(K const &k)
This method is useful for iterating through a set of outgoing edges from a vertex.
Definition: GraphAdjList.h:826
const Element< E1 > * getVertex(const K &key) const
Return the vertex corresponding to a key.
Definition: GraphAdjList.h:408
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