void SmallWriteBuildImpl::add(const NGWrapper &w) { // If the graph is poisoned (i.e. we can't build a SmallWrite version), // we don't even try. if (poisoned) { return; } if (w.som || w.min_length || isVacuous(w)) { /* cannot support in smwr */ poisoned = true; return; } DEBUG_PRINTF("w=%p\n", &w); // make a copy of the graph so that we can modify it for our purposes unique_ptr<NGHolder> h = cloneHolder(w); reduceGraph(*h, SOM_NONE, w.utf8, cc); // If the earliest match location is outside the small write region, // then we don't need to build a SmallWrite version. // However, we don't poison this case either, since it is simply a case, // where we know the resulting graph won't match. if (findMinWidth(*h) > depth(cc.grey.smallWriteLargestBuffer)) { return; } // Now we can actually build the McClellan DFA assert(h->kind == NFA_OUTFIX); auto r = buildMcClellan(*h, &rm, cc.grey); // If we couldn't build a McClellan DFA for this portion, we won't be able // build a smwr which represents the pattern set if (!r) { DEBUG_PRINTF("failed to determinise\n"); poisoned = true; return; } prune_overlong(*r, cc.grey.smallWriteLargestBuffer); if (rdfa) { // do a merge of the new dfa with the existing dfa auto merged = mergeTwoDfas(rdfa.get(), r.get(), DFA_MERGE_MAX_STATES, &rm, cc.grey); if (!merged) { DEBUG_PRINTF("merge failed\n"); poisoned = true; return; } DEBUG_PRINTF("merge succeeded, built %p\n", merged.get()); rdfa = move(merged); } else { rdfa = move(r); } }
int main() { Graph initial, reduced; initial = buildGraph(); Tarjan(initial); reduced = reduceGraph(initial, translation); printSccGraph(reduced, n_scc); freeGraph(reduced); freeTarjan(); return 0; }
int main(int argc, char* argv[]) { if (argc != 4) die(1); printf("going to get graph\n"); myGraph* graph = getGraph(argv[1]); printf("got graph\n"); int v1, v2 = -1; sscanf(argv[2], "%d", &v1); sscanf(argv[3], "%d", &v2); // check that we were given an actual edge if (!isEdge(graph, v1, v2)) die(1); checkWts(graph); int lastNNZ = -1; while(graph->nnz > 2) // note each edge is counted twice (forwards/backwards) { printf("graph->nnz: %d\n", graph->nnz); reduceGraph(&graph, v1, v2); if (lastNNZ == graph->nnz) { fprintf(stderr, "ERROR: reduceGraph failed to do anything!\n"); exit(2); } lastNNZ = graph->nnz; } printf("The effective resistence is: %lf\n", graph->wts[v1][0]); // assume all other edges gone, so it has to be first listing! freeGraph(graph); return 0; }