int main(int argc, char* argv[]) { size_t cliques; Graph g; bool stat = false; boost::property_map<Graph, boost::vertex_name_t>::type v_name = get(boost::vertex_name, g); boost::property_map<Graph, boost::edge_name_t>::type e_name = get(boost::edge_name, g); clique_printer<std::ostream> vis(std::cout, v_name, e_name); if(argc==2) { if(fs::extension(argv[1])==".dot") stat = readGraphFromFile(argv[1],g, 1); else if(fs::extension(argv[1])==".xml") stat = readGraphFromFile(argv[1],g, 0); else { std::cout<<"File type not supported!"<<std::endl; return -1; } if(stat) boost::bron_kerbosch_all_cliques(g, vis); else { std::cout<<"File does not exists!"<<std::endl; return -1; } } else { std::cout<<"Missing path to graph file!"<<std::endl; return -1; } std::cout<<"MCS created and saved to disk!"<<std::endl; return 0; }
int main(int argc, char* argv[]) { Graph g1,g2,gProd; readGraphFromFile(argv[1],g1, 1); readGraphFromFile(argv[2],g2, 1); if(!modProductGraph(g1,g2,gProd)){ std::cout <<"Error, stopping program!"<<std::endl; return -1; } saveGraphToFile("modularProd.dot",gProd,1); std::cout<<"Modular product computed and saved to disk!"<<std::endl; return 0; }
int main(int argc, char* argv[]) { Graph g1,lg1; readGraphFromFile(argv[1],g1, 1); if(!lineGraph(g1,lg1)){ std::cout <<"Error, stopping program!"<<std::endl; return -1; } saveGraphToFile(std::string("lg_")+argv[1],lg1,1); std::cout <<"Line graph created and saved to disk!"<<std::endl; return 0; }
void PlannerPRM::initialize(Sampler* sampler_, const RoboCompCommonBehavior::ParameterList ¶ms) { sampler = sampler_; //////////////////////// /// Initialize RRTplaner //////////////////////// plannerRRT.initialize(sampler); //////////////////////// /// Check if graph already exists //////////////////////// if( QFile(graphFileName).exists()) { qDebug() << __FUNCTION__ << "Graph file exits. Loading"; readGraphFromFile(graphFileName); } else { try { nPointsInGraph = std::stoi(params.at("PlannerGraphPoints").value); nNeighboursInGraph = std::stoi(params.at("PlannerGraphNeighbours").value); maxDistToSearchmm = std::stof(params.at("PlannerGraphMaxDistanceToSearch").value); robotRadiusmm = std::stof(params.at("RobotRadius").value); } catch(...) { qFatal("Planner-Initialize. Aborting. Some Planner graph parameters not found in config file"); } qDebug() << __FUNCTION__ << "No graph file found. Creating with " << nPointsInGraph << "nodes and " << nNeighboursInGraph << "neighboors"; QList<QVec> pointList = sampler->sampleFreeSpaceR2(nPointsInGraph); if( pointList.size() < nNeighboursInGraph ) qFatal("Planner-Initialize. Aborting. Could not find enough free points to build de graph"); qDebug() << __FUNCTION__ << "Creating with " << nPointsInGraph << "nodes and " << nNeighboursInGraph << "neighboors"; constructGraph(pointList, nNeighboursInGraph, maxDistToSearchmm, robotRadiusmm); ///GET From IM ---------------------------------- qDebug() << __FUNCTION__ << "Graph constructed with " << pointList.size() << "points"; writeGraphToFile(graphFileName); } graphDirtyBit = true; }
/** * Main function. Reads graph, reapeats randomized contraction algorithm a * few times and prints the result. * @param argc Command line arguments no. * @param argv Command line arguments. * @return Success/error code. (0 is a success, anything else is error). */ int main(int argc, char** argv) { printf("------ Begin Graph Min Cuts ------\n"); int i, minCutsCount = 1000000, numberOfCuts; Graph graph; Node *node1, *node2; clock_t start, end; char error[128]; /* read graph */ if (argc == 1) { err("Err. The input file must be given as an argument.\n"); } if (!readGraphFromFile(&graph, argv[1], error)) { err(error); } /* print read graph */ //printf("The read graph is: "); //printGraph(graph); //printf("\n"); /* compute min cuts */ start = clock(); for (i = 0; i < graph.n * 50; i++) { numberOfCuts = randomizedContraction(graph); if (numberOfCuts < minCutsCount) { minCutsCount = numberOfCuts; } } end = clock(); /* free memory */ freeGraph(&graph); /* print result */ printf("Min cuts count is: %d\n", minCutsCount); printf("Elapsed: %f seconds to compute the min cuts count.\n", (double) (end - start) / CLOCKS_PER_SEC); printf("------- End Graph Min Cuts -------\n"); return EXIT_SUCCESS; }
/* main * graph is read from a given file as parameter */ int main(int argc, char *argv[]) { if(argc < 2) { print_usage_and_exit(); } int option = 0; int greedyIterations = 10; char fileName[255]; bool isFileNameSet = false; int iterationsCount = 1; bool printTime = false; bool printEFTEC = false; bool printMinimumCr = false; bool lessVerbose = false; bool distributedTime = false; while ((option = getopt(argc, argv,"f:i:temn:ld")) != -1) { switch (option) { case 'f' : strcpy(fileName, optarg); isFileNameSet = true; break; case 'i' : iterationsCount = atoi(optarg); break; case 't' : printTime = true; break; case 'e' : printEFTEC = true; break; case 'm' : printMinimumCr = true; break; case 'n' : greedyIterations = atoi(optarg); break; case 'l': lessVerbose = true; break; case 'd': distributedTime = true; break; default: print_usage_and_exit(); } } if (!isFileNameSet) { print_usage_and_exit(); } int edgesCount, vertexCount, edgesFailedToEmbedCount; int minCr = 9999999, sumCr = 0; int ** edgesList = readGraphFromFile(fileName, &edgesCount, &vertexCount); if(edgesList == NULL) { std::cout << "reading from file failed" << std::endl; exit(1); } int ** edgesFailedToEmbedList = (int**)malloc(edgesCount * sizeof(int*)); for(int i = 0; i < edgesCount; i++) { edgesFailedToEmbedList[i] = (int*)malloc(2 * sizeof(int)); } std::vector<std::pair<int, int> > * edgesSucceedToEmbed = new std::vector<std::pair<int, int> >; clock_t begin, end, cbegin = 0, cend = 0, ebegin = 0, eend = 0; double time_spent; int minEFTEC = 0; begin = clock(); //MAIN BODY for(int i = 0; i < iterationsCount; i++) { ebegin = clock(); edgesFailedToEmbedCount = getEFTEC(edgesList, edgesCount, edgesFailedToEmbedList, edgesSucceedToEmbed, greedyIterations); eend = clock(); cbegin = clock(); int cr = getCrossingNumber(edgesSucceedToEmbed, edgesCount, edgesFailedToEmbedList, edgesFailedToEmbedCount, vertexCount); cend = clock(); if(cr < minCr) { minCr = cr; minEFTEC = edgesFailedToEmbedCount; } sumCr += cr; } //END MAIN BODY end = clock(); time_spent = (double)(end - begin) / CLOCKS_PER_SEC; if(lessVerbose) { std::cout << minCr << std::endl; } else { if(distributedTime) { std::cout << "time spent on EFTEC search - " << (double)(eend - ebegin) / CLOCKS_PER_SEC << std::endl; std::cout << "time spent on crossings search - " << (double)(cend - cbegin) / CLOCKS_PER_SEC << std::endl; } if(printTime) { std::cout << "time spent - " << time_spent << std::endl; } if(printEFTEC) { std::cout << "EFTEC - " << minEFTEC << std::endl; } if(printMinimumCr) { std::cout << "minimum crossing number - " << minCr << std::endl; } std::cout << "average crossing number - " << (float)sumCr / iterationsCount << std::endl; } delete edgesSucceedToEmbed; freeEdgesList(edgesList, edgesCount); freeEdgesList(edgesFailedToEmbedList, edgesCount); return 0; }