コード例 #1
0
ファイル: Review.cpp プロジェクト: Antieight/MaxCompanySize
vector<Component> FindZeroIndegreeComponents(const DirectedGraph &graph) {
  vector<Component> components = FindWeaklyConnectedComponents(graph);
  vector<bool> top_component_flags(components.size(), true);
  vector<int> vertices_components(graph.size());
  for (int component_number = 0; 
       component_number < components.size(); ++component_number) {
    for (int vertex : components[component_number]) {
      vertices_components[vertex] = component_number;
    }
  }
  for (int vertex = 0; vertex < graph.size(); ++vertex) {
    for (int adj_vertex : graph.GetAdjacentVertices(vertex)) {
      if (vertices_components[vertex] != vertices_components[adj_vertex]) {
        top_component_flags[vertices_components[adj_vertex]] = false;
      }
    }
  }
  vector<Component> top_components;
  for (int component_number = 0; 
       component_number < components.size(); ++component_number) {
    if (top_component_flags[component_number]) {
      top_components.push_back(components[component_number]);
    }
  }
  return top_components;
}
コード例 #2
0
bool CircleFlowAlgorithm::reflow(DirectedGraph& g,const Rectangle<int>& area,
                                 ObjController& objController, float /*deltaTime*/)
{
    const int offsetX = area.getX();
    const int offsetY = area.getY();
    const int width = area.getWidth();
    const int height = area.getHeight();

    float interval = 2 * M_PI / (float) g.size();
    int cx = width/2;
    int cy = height/2;
//    float vl = cx - (2 * g->getNode(0)->r1) - 10;
    float vl = cx - 100;
    for (int a = 0; a < g.size(); ++a)
    {
        Point<int> nc = GraphUtils::rotateCoordinate(vl, 0, (float) a * interval);
        nc.x += offsetX;
        nc.y += offsetY;
        if(ObjectComponent* oc = objController.getObjectForId(g.getNode(a)->getLabel()))
        {
            Point<int> p(cx + nc.x*0.8, cy + nc.y*0.8);
            oc->setPosition(p, false);
        }
    }
    return false;
}
コード例 #3
0
ファイル: Review.cpp プロジェクト: Antieight/MaxCompanySize
int GetMaxCompanySize(const DirectedGraph &graph) {
  vector<Component> top_components = FindZeroIndegreeComponents(graph);
  int min_size = graph.size() + 2;
  for (const Component &top_component : top_components) {
    min_size = std::min(min_size, static_cast<int>(top_component.size()));
  }
  return graph.size() + 1 - min_size;
};
コード例 #4
0
ファイル: Review.cpp プロジェクト: Antieight/MaxCompanySize
DirectedGraph Transpose(const DirectedGraph &graph) {
  DirectedGraph tr_graph = DirectedGraph(graph.size());
  for (int vertex = 0; vertex < graph.size(); ++vertex) {
    for (int adj_vertex : graph.GetAdjacentVertices(vertex)) {
      tr_graph.AddEdge(Edge(adj_vertex, vertex));
    }
  }
  return tr_graph;
}
コード例 #5
0
ファイル: Review.cpp プロジェクト: Antieight/MaxCompanySize
vector<Component> FindWeaklyConnectedComponents(const DirectedGraph &graph) {
  const DirectedGraph tr_graph = Transpose(graph);
  vector<bool> visited(graph.size(), false);
  vector<int> order;
  Component current_component;
  vector<Component> components;
  for (int vertex = 0; vertex < graph.size(); ++vertex) {
    if (!visited[vertex])
      DepthFirstSearch(graph, order, visited, vertex);
    if (order.size() == graph.size())
      break;
  }
  visited.assign(graph.size(), false);
  for (auto it = order.rbegin(); it != order.rend(); ++it) {
    if (!visited[*it]) {
      DepthFirstSearch(tr_graph, current_component, visited, *it);
      components.push_back(current_component);
      current_component.clear();
    }
  }
  return components;
}