1
4
5 package geneticalgorithm;
6
7 import java.awt.Graphics;
8 import javax.swing.JPanel;
9
10
14 public class TourDisplay extends JPanel {
15 public static final int X_SIZE = 300;
16 public static final int Y_SIZE = 250;
17 public static final int RADIUS = 10;
18 private double [][] nodes;
19 private int [] tour;
20
21 public TourDisplay(double [][] n, int [] t) {
22 nodes = n;
23 tour = t;
24 }
25
26 public void paintComponent(Graphics g){
27 super.paintComponent(g);
28 for(int i = 0; i < nodes.length; i++) {
29 g.fillOval((int)(nodes[i][GeneticAlgorithm.X] * X_SIZE), (int)(nodes[i][1]* Y_SIZE), RADIUS, RADIUS);
30 }
31 int len = tour.length;
32 int start, dest;
33
34 for(int i = 0; i < len; i++) {
35 start = tour[i];
36 dest = tour[(i + 1) % len];
37 g.drawLine((int)(nodes[start][GeneticAlgorithm.X] * X_SIZE), (int)(nodes[start][GeneticAlgorithm.Y] * Y_SIZE), (int)(nodes[dest][GeneticAlgorithm.X] * X_SIZE), (int)(nodes[dest][GeneticAlgorithm.Y] * Y_SIZE));
38 }
39 }
40 }
41