Exemple #1
0
  public void drawMe(Graphics g) {
    g.setColor(Color.blue);

    g.fillOval(x, y, 10, 10);
    g.drawString(identS, x, y);

    Iterator<Edge> it = edges.iterator();
    while (it.hasNext()) {
      Edge f = it.next();
      f.drawMe(g, Color.green);
    }
  }
Exemple #2
0
  public Path finishCircuit(int dispair, Vertex home, Graphics g) {
    visited = true;

    Path bestPath = new Path();
    bestPath.cost = 100000000;

    if (dispair == 0) // Last being visited
    {
      Iterator<Edge> it = edges.iterator();
      Boolean match = false;

      // Looks through all this vertex's edges and find the one that goes home
      while (!match && it.hasNext()) {
        Edge f = it.next();

        if (f.fromVertex.ident == home.ident) {
          Path p = new Path();
          bestPath = p;
          bestPath.add(f);
          match = true;
        }
      }
    } else {
      Iterator<Edge> it = edges.iterator();

      // Finds all possible paths through nodes not visited
      while (it.hasNext()) {
        Edge e = it.next();
        Vertex c = e.fromVertex;

        if (!c.visited) {
          e.drawMe(g, Color.black); // Draws edge
          Path p = c.finishCircuit(dispair - 1, home, g);
          p.add(e);
          e.drawMe(g, Color.green); // Un-draws edge

          if (p.cost < bestPath.cost) // Sets bestPath
          {
            bestPath = p;
          }
        }
      }
    }

    visited = false;
    return bestPath;
  }