// file: GenRandomGraph.h
// pg. 47-48, Algorithms in C++, Part 5, Robert Sedgewick
// Modified by Dawn Lawrie

#include <cstdlib>
#include <ctime>
#include "Graph.h"
template <class GraphType>
class GenRandomGraph {
public:
  static void seedRandom() {srand(time(0));}
  static void randomEdges(GraphType &graph, int edges);
  static void randomGraph(GraphType &graph, int edges);
  static void kNeighGraph(GraphType &graph, int edges, int k);
  static void euclidNeighGraph(GraphType &graph, double dist); // Currently undefined
  static void deBruijnGraph(GraphType &graph);
};


template <class GraphType>
void GenRandomGraph<GraphType>::randomEdges(GraphType &graph, int edges) {
  for (int i = 0; i < edges; i++) {
    int v = rand() % graph.V();
    int w = rand() % graph.V();
    graph.insert(Edge(v,w));
  }
}

template <class GraphType>
void GenRandomGraph<GraphType>::randomGraph(GraphType &graph, int edges) {
  int V = graph.V();
  double p = 2.0 * edges / (V * (V - 1));
  for (int i = 0 ; i < V; i++) 
    for (int j = 0; j < V; j++) 
      if (rand() < p * RAND_MAX)
	graph.insert(Edge(i,j));
}

template <class GraphType>
void GenRandomGraph<GraphType>::kNeighGraph(GraphType &graph, int edges, int k) {
  for (int i = 0; i < edges; i++) {
    int v = rand() % graph.V();
    int w = ((rand() % k) + v) % graph.V();
    graph.insert(Edge(v,w));
  }
}  


template <class GraphType>
void GenRandomGraph<GraphType>::deBruijnGraph(GraphType &graph) {
  int n = (int) (log(graph.V()) / log(2));
  int V = (int) pow(2, n);
  for (int i = 0; i < V; i++) {
    int v = ((2 * i)% V) ;
    int w = ((2 * i + 1)% V);
    graph.insert(Edge(v, w));
  }
}


