Example #1
0
 // ====================================================================
 private void findMinSpan() {
   route.setText("");
   Iterator<BusEdge> it = grafen.minimumSpanningTree();
   if (it != null && it.hasNext()) {
     double totWeight = 0;
     int totNodes = 0; // only for easier testing
     karta.clearLayer(DrawGraph.Layer.OVERLAY);
     while (it.hasNext()) {
       BusEdge be = it.next();
       totNodes++;
       totWeight += be.getWeight();
       route.append(makeText2(be) + "\n");
       // draw the MST
       BusStop from = noderna.find(be.from);
       BusStop to = noderna.find(be.to);
       karta.drawLine(
           from.xpos, from.ypos, to.xpos, to.ypos, Color.red, 2.5, DrawGraph.Layer.OVERLAY);
     }
     karta.repaint();
     route.append("Antal: " + totNodes + " totalvikt: " + totWeight + "\n");
   } else from.setText("Det fanns ej någon lösning");
   to.setText("");
   from.setText("");
 } //  findMinSpan