bool BuildGraph(int i, int j, vector<vector<char>>& board, QuadGraph& g, bool& bFlip){ if (i < 0 || j < 0 || j >= board[0].size() || i >= board.size()){ bFlip = false; return false; } if (board[i][j] != 'O') return false; board[i][j] = '1'; QuadGraph gU(pair<int, int>(i - 1, j)); if (BuildGraph(i - 1, j, board, gU, bFlip)) g.AddSubNode(gU); QuadGraph gL(pair<int, int>(i, j - 1)); if (BuildGraph(i, j - 1, board, gL, bFlip)) g.AddSubNode(gL); QuadGraph gR(pair<int, int>(i, j + 1)); if (BuildGraph(i, j + 1, board, gR, bFlip)) g.AddSubNode(gR); QuadGraph gB(pair<int, int>(i + 1, j)); if (BuildGraph(i + 1, j, board, gB, bFlip)) g.AddSubNode(gB); board[i][j] = '2'; g.m_bFlip = bFlip; return true; }
///////////////////////////////////////////////////// // nsIStreamConverterService methods NS_IMETHODIMP nsStreamConverterService::CanConvert(const char* aFromType, const char* aToType, bool* _retval) { nsCOMPtr<nsIComponentRegistrar> reg; nsresult rv = NS_GetComponentRegistrar(getter_AddRefs(reg)); if (NS_FAILED(rv)) return rv; nsAutoCString contractID; contractID.AssignLiteral(NS_ISTREAMCONVERTER_KEY "?from="); contractID.Append(aFromType); contractID.AppendLiteral("&to="); contractID.Append(aToType); // See if we have a direct match rv = reg->IsContractIDRegistered(contractID.get(), _retval); if (NS_FAILED(rv)) return rv; if (*_retval) return NS_OK; // Otherwise try the graph. rv = BuildGraph(); if (NS_FAILED(rv)) return rv; nsTArray<nsCString> *converterChain = nullptr; rv = FindConverter(contractID.get(), &converterChain); *_retval = NS_SUCCEEDED(rv); delete converterChain; return NS_OK; }
void run_enron() { BuildGraph("/home/qicong/saedb/build/toolkit/influence/graph/graph_enron"); cout << "Generating Graph Data Done. " << endl; graph_type enron_graph; enron_graph.load_format("/home/qicong/saedb/build/toolkit/influence/graph/graph_enron"); cout <<"Loading Graph Done."<<endl; cout<<"num of vertexes :"<<enron_graph.num_local_vertices()<<endl; cout<<"Process Start..."<<endl; //Cal degree saedb::IEngine<degree> *engine_degree = new saedb::EngineDelegate<degree>(enron_graph); engine_degree->signalAll(); engine_degree->start(); delete engine_degree; cout<<"Process done"<<endl; Output(); }
void MinimumSpanningTree::Init(Game& game) { BuildCamera(game); BuildGraph(game); game.EnableEventWaiting(true); }
/*两种遍历算法的简单使用*/ int main(void){ LGraph Graph; Graph = BuildGraph(); for(int i=0;i<MaxVertexNum;i++){ Printed[i] = false; } for(int S=0;S<Graph->Nv;S++){ if(!Printed[S]){ for(int i=0;i<MaxVertexNum*MaxVertexNum;i++){ Visited[i] = false; } putchar('{'); DFS(Graph,S); printf(" }\n"); } } for(int i=0;i<MaxVertexNum;i++){ Printed[i] = false; } for(int S=0;S<Graph->Nv;S++){ if(!Printed[S]){ for(int i=0;i<MaxVertexNum*MaxVertexNum;i++){ Visited[i] = false; } putchar('{'); BFS(Graph,S); printf(" }\n"); } } return 0; }
DeformationGraph::DeformationGraph(DeformableMesh3d& _dmesh, int _nodenum, int _relatenum, int _samplescale, double _deletearearate, double _wrot, double _wreg, double _wcon, double _wlen) : dmesh(_dmesh), nodenum(_nodenum), relatenum(_relatenum), samplescale(_samplescale), deletearearate(_deletearearate), wrot(_wrot), wreg(_wreg), wcon(_wcon), wlen(_wlen) { BuildGraph(); }
/********************************************** * Build Obj graph for learning * **********************************************/ Expression BuildObjGraph(const Doc& doc, ComputationGraph& cg, LatentSeq latseq, LatentSeq obsseq){ Expression obj = BuildGraph(doc, cg, latseq, obsseq, "OBJ"); return obj; }
int main() { BuildGraph(); for (int i = 0; i < N; ++i) { if (discovered[i] == -1) Dfs(i); } return 0; }
void MinimumSpanningTree::Update(Game& game) { IInput& input = game.GetInput(); if (input.KeyPress(KEY_ENTER)) { BuildGraph(game); } else if (input.KeyPress(KEY_SPACE)) { m_bEnableMST = !m_bEnableMST; m_pGraph->EnableMST(m_bEnableMST); } }
void solve_rec(vector<vector<char>>& board) { vector<QuadGraph> vGraphs; for (int i = 0; i < board.size(); ++i){ for (int j = 0; j < board[0].size(); ++j){ if (board[i][j] == 'O'){ QuadGraph g(pair<int, int>(i, j)); bool bFlip = true; BuildGraph(i, j, board, g, bFlip); vGraphs.push_back(g); } } } for (int i = 0; i < vGraphs.size(); ++i){ processOneGraph(vGraphs[i], board); } }
void CentralitySampling:: PreCompute(const vector<pair<int, int> > &es, int num_samples){ BuildGraph(es); centrality_map = vector<double>(V, 0); temp_on_DAG = vector<bool>(V, 0); temp_distance = vector<vector<int> > (2, vector<int>(V, -1)); temp_num_paths = vector<vector<double> > (2, vector<double>(V, 0)); for (int k = 0; k < num_samples; k++){ int source = rand() % V; int target = rand() % V; // Step1. Compute vertices on shortest paths DAG between a source and a target. vector<int> DAG_vertices = ComputeDAG(source, target); // Step2. for (int v : DAG_vertices){ temp_distance [Forward][v] = temp_distance [Backward][v] = -1; temp_num_paths[Forward][v] = temp_num_paths[Backward][v] = 0; temp_on_DAG[v] = true; } if (DAG_vertices.empty()){ // There are no paths from source to sink. continue; } BreadthFirstSearchOnDAG(source, Forward); BreadthFirstSearchOnDAG(target, Backward); // Step3. for (int v : DAG_vertices){ if (v != source && v != target) { double num = temp_num_paths[Forward][v] * temp_num_paths[Backward][v]; double tot = temp_num_paths[Forward][target]; assert(tot > 0); centrality_map[v] += num / tot * V / num_samples * V ; } temp_on_DAG[v] = false; temp_distance [0][v] = temp_distance [1][v] = -1; temp_num_paths[0][v] = temp_num_paths[1][v] = 0; } } }
static void UpdateGraph() { // TODO: update sort and sweep. for moving sprites. static int frameTimer = 0; TIMER_DEF(BuildGraph); TIMER_DEF(TSort); TIMER_DEF(StateSort); TIMER_START(BuildGraph); Graph* graph = BuildGraph(s_screenSprite); TIMER_STOP(BuildGraph, frameTimer); TIMER_START(TSort); graph->TSort(s_nodeVecVec); TIMER_STOP(TSort, frameTimer); TIMER_START(StateSort); if (s_useStateSort) TextureStateSort(s_nodeVecVec, s_spriteVec); else NoStateSort(s_nodeVecVec, s_spriteVec); delete graph; TIMER_STOP(StateSort, frameTimer); TIMER_REPORT(BuildGraph, frameTimer); TIMER_REPORT(TSort, frameTimer); TIMER_REPORT(StateSort, frameTimer); frameTimer++; // Clean up s_nodeVecVec! NodeVecVec::iterator vecVecIter = s_nodeVecVec.begin(); NodeVecVec::iterator vecVecEnd = s_nodeVecVec.end(); for (; vecVecIter != vecVecEnd; ++vecVecIter) delete (*vecVecIter); s_nodeVecVec.clear(); }
void CSSGraph::RemoveShortVertices ( int nmin_hx, int nmin_sd ) { PPCSSVertex V; int i,n; n = 0; for (i=0;i<nVertices;i++) if (Vertex[i]) { if (((Vertex[i]->type==V_HELIX) && (Vertex[i]->nres>nmin_hx)) || ((Vertex[i]->type==V_STRAND) && (Vertex[i]->nres>nmin_sd))) n++; } if (n<nVertices) { if (n>0) { V = new PCSSVertex[n]; n = 0; for (i=0;i<nVertices;i++) if (Vertex[i]) { if (((Vertex[i]->type==V_HELIX) && (Vertex[i]->nres>nmin_hx)) || ((Vertex[i]->type==V_STRAND) && (Vertex[i]->nres>nmin_sd))) V[n++] = Vertex[i]; else delete Vertex[i]; } for (i=nVertices;i<nVAlloc;i++) if (Vertex[i]) delete Vertex[i]; delete[] Vertex; Vertex = V; nVertices = n; nVAlloc = 0; } else if (Vertex) { for (i=0;i<nVAlloc;i++) if (Vertex[i]) delete Vertex[i]; delete[] Vertex; Vertex = NULL; nVertices = 0; nVAlloc = 0; } } BuildGraph(); }
NS_IMETHODIMP nsStreamConverterService::AsyncConvertData(const char *aFromType, const char *aToType, nsIStreamListener *aListener, nsISupports *aContext, nsIStreamListener **_retval) { if (!aFromType || !aToType || !aListener || !_retval) return NS_ERROR_NULL_POINTER; nsresult rv; // first determine whether we can even handle this conversion // build a CONTRACTID nsAutoCString contractID; contractID.AssignLiteral(NS_ISTREAMCONVERTER_KEY "?from="); contractID.Append(aFromType); contractID.AppendLiteral("&to="); contractID.Append(aToType); const char *cContractID = contractID.get(); nsCOMPtr<nsIStreamConverter> listener(do_CreateInstance(cContractID, &rv)); if (NS_FAILED(rv)) { // couldn't go direct, let's try walking the graph of converters. rv = BuildGraph(); if (NS_FAILED(rv)) return rv; nsTArray<nsCString> *converterChain = nullptr; rv = FindConverter(cContractID, &converterChain); if (NS_FAILED(rv)) { // can't make this conversion. // XXX should have a more descriptive error code. return NS_ERROR_FAILURE; } // aListener is the listener that wants the final, converted, data. // we initialize finalListener w/ aListener so it gets put at the // tail end of the chain, which in the loop below, means the *first* // converter created. nsCOMPtr<nsIStreamListener> finalListener = aListener; // convert the stream using each edge of the graph as a step. // this is our stream conversion traversal. int32_t edgeCount = int32_t(converterChain->Length()); NS_ASSERTION(edgeCount > 0, "findConverter should have failed"); for (int i = 0; i < edgeCount; i++) { const char *lContractID = converterChain->ElementAt(i).get(); // create the converter for this from/to pair nsCOMPtr<nsIStreamConverter> converter(do_CreateInstance(lContractID)); NS_ASSERTION(converter, "graph construction problem, built a contractid that wasn't registered"); nsAutoCString fromStr, toStr; rv = ParseFromTo(lContractID, fromStr, toStr); if (NS_FAILED(rv)) { delete converterChain; return rv; } // connect the converter w/ the listener that should get the converted data. rv = converter->AsyncConvertData(fromStr.get(), toStr.get(), finalListener, aContext); if (NS_FAILED(rv)) { delete converterChain; return rv; } nsCOMPtr<nsIStreamListener> chainListener(do_QueryInterface(converter, &rv)); if (NS_FAILED(rv)) { delete converterChain; return rv; } // the last iteration of this loop will result in finalListener // pointing to the converter that "starts" the conversion chain. // this converter's "from" type is the original "from" type. Prior // to the last iteration, finalListener will continuously be wedged // into the next listener in the chain, then be updated. finalListener = chainListener; } delete converterChain; // return the first listener in the chain. *_retval = finalListener; NS_ADDREF(*_retval); } else { // we're going direct. *_retval = listener; NS_ADDREF(*_retval); rv = listener->AsyncConvertData(aFromType, aToType, aListener, aContext); } return rv; }
NS_IMETHODIMP nsStreamConverterService::Convert(nsIInputStream *aFromStream, const char *aFromType, const char *aToType, nsISupports *aContext, nsIInputStream **_retval) { if (!aFromStream || !aFromType || !aToType || !_retval) return NS_ERROR_NULL_POINTER; nsresult rv; // first determine whether we can even handle this conversion // build a CONTRACTID nsAutoCString contractID; contractID.AssignLiteral(NS_ISTREAMCONVERTER_KEY "?from="); contractID.Append(aFromType); contractID.AppendLiteral("&to="); contractID.Append(aToType); const char *cContractID = contractID.get(); nsCOMPtr<nsIStreamConverter> converter(do_CreateInstance(cContractID, &rv)); if (NS_FAILED(rv)) { // couldn't go direct, let's try walking the graph of converters. rv = BuildGraph(); if (NS_FAILED(rv)) return rv; nsTArray<nsCString> *converterChain = nullptr; rv = FindConverter(cContractID, &converterChain); if (NS_FAILED(rv)) { // can't make this conversion. // XXX should have a more descriptive error code. return NS_ERROR_FAILURE; } int32_t edgeCount = int32_t(converterChain->Length()); NS_ASSERTION(edgeCount > 0, "findConverter should have failed"); // convert the stream using each edge of the graph as a step. // this is our stream conversion traversal. nsCOMPtr<nsIInputStream> dataToConvert = aFromStream; nsCOMPtr<nsIInputStream> convertedData; for (int32_t i = edgeCount-1; i >= 0; i--) { const char *lContractID = converterChain->ElementAt(i).get(); converter = do_CreateInstance(lContractID, &rv); if (NS_FAILED(rv)) { delete converterChain; return rv; } nsAutoCString fromStr, toStr; rv = ParseFromTo(lContractID, fromStr, toStr); if (NS_FAILED(rv)) { delete converterChain; return rv; } rv = converter->Convert(dataToConvert, fromStr.get(), toStr.get(), aContext, getter_AddRefs(convertedData)); dataToConvert = convertedData; if (NS_FAILED(rv)) { delete converterChain; return rv; } } delete converterChain; *_retval = convertedData; NS_ADDREF(*_retval); } else { // we're going direct. rv = converter->Convert(aFromStream, aFromType, aToType, aContext, _retval); } return rv; }
Molecule(const std::string& formula, const std::string& baseElements = "CON" ) :_formula(formula),_baseElements(baseElements) { BuildGraph(); }