コード例 #1
0
   bool FindWinner(Graph &G, EDGECOLOR color){
     //adds nodes to adj_list of every edge in graph
     for (int i = 0; i < G.GetSize(); i++) {
       for (int j = 0; j < G.GetSize(); j++) {
         G.matrix[i][j].build_adj(i,j,G);
       }
     }

     //start looking for path
     for (int j = 0; j < G.GetSize(); j++) {
       if(color == P1){
         bool iftrue = look_for_path(G,color,G.matrix[0][j],G.GetSize(),j);
         if(iftrue == true){
           return true;
         }
       }
       if(color == P2){
         bool iftrue = look_for_path(G,color,G.matrix[j][0],G.GetSize(),j);
         if(iftrue == true){
           return true;
         }
       }
     }
     return false;
   }
コード例 #2
0
 //Finds every edge that the current edge is connected to.
 void edge::build_adj(int x, int y, Graph &G){
   for(int j = -1; j <= 1; j++){
     for(int i = -1; i <= 1; i++){
        if(x+i < 0 || x+i >= G.GetSize()){
          continue;
        }
        if(y+j < 0 || y+j >= G.GetSize()){
          continue;
        }
        if(i == 0 && j == 0){
          continue;
        }
        if(i == -1 && j == -1){
          continue;
        }
        if(i == 1 && j== 1){
          continue;
        }
        edge_ref tmp;
        tmp.x = x+i;
        tmp.y = y+j;
        adj_list.push_back(tmp);
      }
    }
  }
コード例 #3
0
  TarjanSCC(const Graph &graph) : graph(graph) {
    v_index = vector<int>(graph.GetSize(), UNDEFINED);
    lowlink = vector<int>(graph.GetSize(), UNDEFINED);
    onstack = vector<bool>(graph.GetSize(), false);

    index = 0;
    S.clear();

    // cout << "BEGIN SCC" << endl;
    for (int v = 0; v < v_index.size(); v++) {
      if (v_index[v] == UNDEFINED)
        StrongConnect(v);
    }
    // cout << "END SCC (we survived recursion)" << endl;

    reverse(result.begin(), result.end());
  }
コード例 #4
0
  DpSolver(const DFA &dfa, const Graph &graph, unsigned novelty_mask) : dfa(dfa), graph(graph), novelty_mask(novelty_mask) {
    statii = {(size_t) graph.GetSize(), Status::MakeInvalid(dfa)};
    statii.at(graph.GetStartNode()) = MakeInitialStatus();

    scc_by_node = vector<int>(graph.GetSize(), 0);

    auto sccs = StronglyConnectedComponents(graph);
    int i = 0;
    for (const auto &scc : sccs) {
      for (int node : scc)
        scc_by_node[node] = i;
      i++;
    }

    // cout << scc_by_node << endl;

    //cout << sccs << endl;
    // for (auto scc : sccs) {
    //   ShowNodes(scc);
    // }

    for (const auto &scc : sccs) {
      UpdateSCC(scc);
      for (int node : scc) {
        for (int cmd = 0; cmd < 6; cmd++) {
          int node2 = graph.tr[node][cmd];
          if (node2 == Graph::COLLISION)
            continue;

          if (scc_by_node.at(node2) > scc_by_node.at(node)) {
            //cout << node << " -> " << node2 << endl;
            statii[node2].Merge(statii[node].Translate(cmd, dfa));
            //
          }
        }
      }
    }

    // for (const auto &scc : sccs) {
    //   cout << "---" << endl;
    //   for (int node : scc) {
    //     cout << node << " " << statii[node].score << " " << ChainToVector(statii[node].best) << endl;
    //   }
    // }
  }