Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int main() {
- std::default_random_engine generator;
- std::normal_distribution<double> distribution(0, 100);
- for (int size = 2; size <= 14; ++size) {
- for (int test = 1; test <= 100; ++test) {
- std::cout << "size: " << size << std::endl << "test: " << test << std::endl;
- ArcGraph *Graph = new ArcGraph(size);
- std::vector<float> x;
- std::vector<float> y;
- for (int i = 0 ; i < size; ++i) { // генерируем координаты
- float x_coord = distribution(generator);
- float y_coord = distribution(generator);
- x.push_back(x_coord);
- y.push_back(y_coord);
- }
- for (int i = 0; i < size; ++i) {
- for (int k = i + 1; k < size; ++k) {
- float dist = sqrt((x[i] - x[k]) * (x[i] - x[k]) + (y[i] - y[k]) * (y[i] - y[k]));
- Graph->AddEdge(i, k, dist); // добавляем все ребра
- }
- }
- float the_shortest_route = Graph->TheShortestRoute(); // кратчайший путь (перебором)
- MinSpanningTree *MSTGraph = new MinSpanningTree(size);
- MSTGraph->BuildST(Graph);
- float short_route = MSTGraph->ShortestRoute();
- //assert(the_shortest_route <= short_route);
- //assert(short_route <= 2 * the_shortest_route);
- std::cout << std::fixed << std::setprecision(2) << "the shortest route length: " << the_shortest_route << std::endl;
- std::cout << std::fixed << std::setprecision(2) << "found route length: " << short_route << std::endl;
- std::cout << std::fixed << std::setprecision(2) << "ratio: " << short_route / the_shortest_route << std::endl;
- std::cout << std::endl;
- delete Graph;
- delete MSTGraph;
- }
- std::cout <<"-----------------------------------" << std::endl << std::endl;
- }
- std:: cout << "All tests were passed successfully" << std::endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement