Beispiel #1
0
/**
 * Kompilace: $ g++ -std=c++11 -Wall -pedantic main.cpp mygraph.cpp edge.cpp node.cpp dijkstra.cpp -o graph
 * ./graph [string] ... Spusti program, nacte ze souboru.
 * ./graph [string] [unsigned int] [unsigned int] ... Generuje graf do souboru,
 * druhy parametr je pocet uzlu a treti parametr pocet hran, ktere v prumeru
 * vedou z nejakeho uzlu.
 */
int main(int argc, char* const argv[]) {
    ios::sync_with_stdio(false);
    MyGraph * graph = new MyGraph();

    try {
        switch(argc) {
            case 2: {
                graph->load(argv[1]);

                //ofstream ofs;

                //ofs.open("dijkstra.out");
                //if(!ofs.is_open()) throw IOException();

                double ** matrix;
                CDijkstra dijkstra = CDijkstra(graph);
                clock_t begin = clock();
                //matrix = dijkstra.CalculateDistanceMatrix();
                clock_t end = clock();
                //printMatrix(ofs, matrix, graph->size());

                //ofs.close();

                double elapsed_secs = double(end - begin) / CLOCKS_PER_SEC;

                cout << "Dijkstra:\t" << elapsed_secs << " sec" << endl;

                //ofs.open("floydwarshall.out");
                //if(!ofs.is_open()) throw IOException();

                int blockSize = 36;
                while(graph->size() % blockSize != 0) ++blockSize;

                begin = clock();
                matrix = floydWarschall(graph, blockSize);
                end = clock();
                //printMatrix(ofs, matrix, graph->size());
                //ofs.close();
                elapsed_secs = double(end - begin) / CLOCKS_PER_SEC;

                cout << "FloydWarshall:\t" << elapsed_secs << " sec" << endl;

                /*double ** matrix;

                for(unsigned i = 1; i < 1080; ++i) {
                    if(1080 % i == 0)
                    {
                        clock_t begin = clock();
                        matrix = floydWarschall(graph, i);
                        clock_t end = clock();
                        cout << i << " " << double(end - begin) / CLOCKS_PER_SEC << endl;
                    }
                }*/

                break;
            }
            case 4: {
                unsigned int n, pocetHran;
                string arg = argv[2];
                arg += " ";
                arg += argv[3];
                arg += " ";
                stringstream ss(arg);
                ss >> n;
                ss >> pocetHran;
                if(ss.eof() || ss.fail()) throw IOException();
                graph->graphGen(n, pocetHran, argv[1]);
                break;
            }
            default: {
                throw IllegalArgumentException();
                break;
            }
        }
    }
    catch(IOException) {}
    catch(IllegalArgumentException) {}
    catch(...) {
        cerr << "Neco se podelalo." << endl;
    }

    delete graph;

    return 0;
}
Beispiel #2
0
/**
 * Kompilace: $ g++ -std=c++11 -Wall -pedantic main.cpp mygraph.cpp edge.cpp node.cpp dijkstra.cpp -o graph
 * ./graph [string] ... Spusti program, nacte ze souboru.
 * ./graph [string] [unsigned int] [unsigned int] ... Generuje graf do souboru,
 * druhy parametr je pocet uzlu a treti parametr pocet hran, ktere v prumeru
 * vedou z nejakeho uzlu.
 */
int main(int argc, char* const argv[]) {
    ios::sync_with_stdio(false);
    MyGraph * graph = new MyGraph();

    try {
        switch(argc) {
            case 2: {
                graph->load(argv[1]);

                ofstream ofs;

                //ofs.open("dijkstra.out");
                //if(!ofs.is_open()) throw IOException();
                
                double ** matrix;
                CDijkstra dijkstra = CDijkstra(graph);

                double time1 = omp_get_wtime();
                matrix = dijkstra.CalculateDistanceMatrix();
                double time2 = omp_get_wtime();

                //printMatrix(ofs, matrix, graph->size());
                //ofs.close();

                cout << "omptime: " << time2 - time1 << endl;
                //ofs.open("floydwarshall.out");
                //if(!ofs.is_open()) throw IOException();
                //begin = clock();
                //matrix = floydWarschall(graph);
                //end = clock();
                //printMatrix(ofs, matrix, graph->size());
                //ofs.close();
                //elapsed_secs = double(end - begin) / CLOCKS_PER_SEC;

                //cout << "FloydWarshall:\t" << elapsed_secs << " sec" << endl;

                break;
            }
            case 4: {
                unsigned int n, pocetHran;
                string arg = argv[2];
                arg += " ";
                arg += argv[3];
                arg += " ";
                stringstream ss(arg);
                ss >> n;
                ss >> pocetHran;
                if(ss.eof() || ss.fail()) throw IOException();
                graph->graphGen(n, pocetHran, argv[1]);
                break;
            }
            default: {
                throw IllegalArgumentException();
                break;
            }
        }
    }
    catch(IOException) {}
    catch(IllegalArgumentException) {}
    catch(...) {
        cerr << "Neco se podelalo." << endl;
    }

    delete graph;

    return 0;
}