コード例 #1
0
 private Vertice getVerticeByInitialTime(List<Vertice> vertices, int time) {
   for (Vertice v : vertices) {
     if (v.getInitialTime() == time) {
       return v;
     }
   }
   return null;
 }
コード例 #2
0
  private void dfs() {
    init();
    this.tempo = 0;

    List<Vertice> vertices = grafo.getVertices();
    for (Vertice v : vertices) {
      if (v.getColor().equals(VerticeColor.WHITE)) {
        dfsVisit(v);
      }
    }
  }
コード例 #3
0
  public List<String> getConnectedComponents() {
    List<String> connectedComponents = new ArrayList<>();
    List<Vertice> vertices = grafo.getVertices();

    int currentTime = 1;
    Vertice initial = getVerticeByInitialTime(vertices, currentTime);
    while (initial != null) {
      connectedComponents.add(getConnectedComponent(vertices, initial));
      initial = getVerticeByInitialTime(vertices, (initial.getFinalTime() + 1));
    }

    return connectedComponents;
  }
コード例 #4
0
  private String getConnectedComponent(List<Vertice> vertices, Vertice initial) {
    String result = "";
    List<Vertice> listToDelete = new ArrayList<>();

    int finalTime = initial.getFinalTime();
    for (Vertice v : vertices) {
      if (v.getFinalTime() <= finalTime) {
        result += v.getRotulo() + ",";
        listToDelete.add(v);
      }
    }

    vertices.removeAll(listToDelete);
    return result;
  }
コード例 #5
0
  private void dfsVisit(Vertice u) {
    u.setColor(VerticeColor.GREY);
    this.tempo++;
    u.setInitialTime(this.tempo);
    if (u.getAdjacentes() != null) {
      for (Vertice adjacente : u.getAdjacentes()) {
        if (adjacente.getColor().equals(VerticeColor.WHITE)) {

          // TODO Verificar sobre vértices pais
          adjacente.setFather(u);
          dfsVisit(adjacente);
        }
      }
    }

    u.setColor(VerticeColor.BLACK);
    this.tempo++;
    u.setFinalTime(this.tempo);
    outVertices.add(u);
  }
コード例 #6
0
  public void printRoutingVector() {
    List<Vertice> vertices = grafo.getVertices();
    String rotulos = "";
    String fathers = "";
    String time = "";
    String temp = "";

    for (Vertice v : vertices) {
      if (v.getFather() != null) {
        temp = v.getFather().getRotulo();
      } else {
        temp = " ";
      }
      rotulos += v.getRotulo() + "   | ";
      fathers += temp + "   | ";
      time += String.valueOf(v.getInitialTime()) + "/" + String.valueOf(v.getFinalTime()) + " | ";
    }

    System.out.println(rotulos);
    System.out.println(fathers);
    System.out.println(time);
  }
コード例 #7
0
 private void init() {
   List<Vertice> vertices = grafo.getVertices();
   for (Vertice v : vertices) {
     v.setColor(VerticeColor.WHITE);
   }
 }