void fill_up_edge_vector( Square& rec, std::vector<Edge>& edgeVector, std::uniform_int_distribution<>& dis, std::mt19937_64& gen, const double RMAT_a, const double RMAT_b, const double RMAT_c, const bool allowEdgeToSelf, const bool allowDuplicateEdges, const bool directedGraph ) { std::vector<unsigned long long> throwAwayEdgesIndices; // Indices for those edges that must be eliminated due to duplicates and/or having same destination and source index. edgeVector.reserve(rec.getnEdges()); generate_edges( std::ref(rec), std::ref(edgeVector), RMAT_a, RMAT_b, RMAT_c, directedGraph, allowEdgeToSelf, std::ref(dis), std::ref(gen), std::ref(throwAwayEdgesIndices) ); if( !allowDuplicateEdges ) { do{ // Resize the throw away edges vector for a fresh begin. throwAwayEdgesIndices.resize(0); std::sort( edgeVector.begin(), edgeVector.end() ); // Detection of Invalid edges. for( unsigned long long edgeIdx = 0; edgeIdx < (edgeVector.size()-1); ++edgeIdx ) if( edgeVector.at(edgeIdx) == edgeVector.at(edgeIdx+1) ) throwAwayEdgesIndices.push_back(edgeIdx); // Add instead of eliminated and check until generate enough. if( !throwAwayEdgesIndices.empty() ) generate_edges( std::ref(rec), std::ref(edgeVector), RMAT_a, RMAT_b, RMAT_c, directedGraph, allowEdgeToSelf, std::ref(dis), std::ref(gen), std::ref(throwAwayEdgesIndices) ); } while( !throwAwayEdgesIndices.empty() ); } }
void CGameGraphBuilder::build_graph (const float &start, const float &amount) { Progress (start); Msg ("Building graph"); CTimer timer; timer.Start (); m_graph_engine = xr_new<CGraphEngine>(level_graph().header().vertex_count()); Progress (start + 0.000000f*amount + amount*0.067204f); // Msg ("BG : %f",timer.GetElapsed_sec()); generate_edges (start + 0.067204f*amount, amount*0.922647f); // Msg ("BG : %f",timer.GetElapsed_sec()); xr_delete (m_graph_engine); Progress (start + 0.989851f*amount + amount*0.002150f); // Msg ("BG : %f",timer.GetElapsed_sec()); connectivity_check (start + 0.992001f*amount, amount*0.000030f); // Msg ("BG : %f",timer.GetElapsed_sec()); optimize_graph (start + 0.992031f*amount, amount*0.000454f); // Msg ("BG : %f",timer.GetElapsed_sec()); save_graph (start + 0.992485f*amount, amount*0.007515f); // Msg ("BG : %f",timer.GetElapsed_sec()); Progress (start + amount); }
void CGameGraphBuilder::generate_edges (const float &start, const float &amount) { Progress (start); Msg ("Generating edges"); graph_type::const_vertex_iterator I = graph().vertices().begin(); graph_type::const_vertex_iterator E = graph().vertices().end(); for ( ; I != E; ++I) { fill_neighbours ((*I).second->vertex_id()); generate_edges ((*I).second->vertex_id()); } Msg ("%d edges built",graph().edge_count()); Progress (start + amount); }