diff --git a/CMakeLists.txt b/CMakeLists.txt index 19d94c5..5444133 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required (VERSION 2.6) project (PROJECT_GRAPH_BROWSER) -set (CXX_FLAGS "-std=c++14") +set (CXX_FLAGS "-std=c++14 -ggdb") add_definitions(${CXX_FLAGS}) set (CMAKE_CXX_COMPILER "/usr/bin/g++-5.1.0") diff --git a/main.cpp b/main.cpp index 1762812..fbaf417 100644 --- a/main.cpp +++ b/main.cpp @@ -1,10 +1,60 @@ #include #include +#include +#include + +// https://stackoverflow.com/questions/440133/how-do-i-create-a-random-alpha-numeric-string-in-c +std::string GenerateRandomString(size_t length) +{ + auto GenerateRandomChar = []() -> char + { + const char charset[] = + "0123456789" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyz"; + const size_t max_index = (sizeof(charset) - 1); + return charset[ rand() % max_index ]; + }; + std::string str(length,0); + std::generate_n( str.begin(), length, GenerateRandomChar ); + return str; +} + +std::vector GenerateRandomStrings(size_t number_of_strings, + size_t min_length, + size_t max_length) +{ + std::vector v; + v.resize(number_of_strings); + for (int i = 0; i < number_of_strings; ++i) { + const size_t l = min_length + rand()%(max_length - min_length); + v[i] = GenerateRandomString(l); + } + + return v; +} + +Graph GenerateRandomGraph(size_t number_of_vertices, + size_t number_of_edges, + size_t vertex_text_min_length, + size_t vertex_text_max_length) +{ + Graph graph; + const std::vector v = GenerateRandomStrings(number_of_vertices, + vertex_text_min_length, + vertex_text_max_length); + for (int i = 0; i < number_of_edges; ++i) + graph.addEdge(v[rand()%number_of_vertices], v[rand()%number_of_vertices]); + + return graph; +} int main(int argc, char* argv[]) { - Graph g{ "one", "two", "three" }; + const Graph g = GenerateRandomGraph(10, 200, 5, 20); + + return EXIT_SUCCESS; } \ No newline at end of file