printing of env now happens in shutdown hook (EnvironmentShutdownHook.java)
[aco.git] / GraphTest.java
blob4a1ed5f39cecd672eb415e224e4ab79efc6632b4
1 import java.util.Vector;
2 import java.util.Iterator;
3 import si.ant.graph.*;
5 public class GraphTest {
7 public static void MatrixGraphTest() {
8 int n = 5;
9 int[][] graph = new int[n][n];
10 for (int i = 0; i < n; i++) {
11 for (int j = 0; j < n; j++) {
12 graph[i][j] = MatrixGraph.INFINITY;
16 graph[0][1] = 1;
17 graph[1][2] = 2;
18 graph[2][3] = 3;
19 graph[3][4] = 4;
21 MatrixGraph mg = new MatrixGraph(5, graph, graph, graph);
23 Vector<MatrixNode> nodes = mg.getNodes();
24 Vector<MatrixEdge> edges = mg.getEdges();
26 Iterator<MatrixNode> nodesit = nodes.iterator();
27 Iterator<MatrixEdge> edgesit = edges.iterator();
29 System.out.println("Nodes: ");
30 while (nodesit.hasNext())
31 System.out.println(nodesit.next().toString());
33 System.out.println("Edges: ");
34 while (edgesit.hasNext())
35 System.out.println(edgesit.next().toString());
37 System.out.println("nodes.get(2).getIndex(): " + nodes.get(2).getIndex());
38 System.out.println("true: " + nodes.get(2).isEqual(nodes.get(2)));
39 System.out.println("false: " + nodes.get(2).isEqual(nodes.get(3)));
40 System.out.println("3.0: " + edges.get(2).getDistance());
41 System.out.println("true: " + edges.get(2).isEqual(edges.get(2)));
42 System.out.println("false: " + edges.get(2).isEqual(edges.get(3)));
44 System.out.println("neighbours of " + nodes.get(3) + ":");
45 Vector<MatrixNode> neighbours = mg.getNeighbours(nodes.get(3));
46 Iterator<MatrixNode> neighboursit = neighbours.iterator();
48 while (neighboursit.hasNext())
49 System.out.println(neighboursit.next().toString());
52 public static void ListGraphTest() {
53 Vector<ListEdge> edgegraph = new Vector<ListEdge>(4);
54 ListNode node0 = new ListNode("nil");
55 ListNode node1 = new ListNode("one");
56 ListNode node2 = new ListNode("two");
57 ListNode node3 = new ListNode("three");
58 ListNode node4 = new ListNode("four");
59 edgegraph.add(new ListEdge(node0, node1, 0, 1, 0));
60 edgegraph.add(new ListEdge(node1, node2, 0, 2, 0));
61 edgegraph.add(new ListEdge(node2, node3, 0, 3, 0));
62 edgegraph.add(new ListEdge(node3, node4, 0, 4, 0));
64 ListGraph lg = new ListGraph(edgegraph);
66 Vector<ListNode> nodes = lg.getNodes();
67 Vector<ListEdge> edges = lg.getEdges();
69 Iterator<ListNode> nodesit = nodes.iterator();
70 Iterator<ListEdge> edgesit = edges.iterator();
72 System.out.println("Nodes: ");
73 while (nodesit.hasNext())
74 System.out.println(nodesit.next().toString());
76 System.out.println("Edges: ");
77 while (edgesit.hasNext())
78 System.out.println(edgesit.next().toString());
80 System.out.println("nodes.get(2).getID(): " + nodes.get(2).getID());
81 System.out.println("true: " + nodes.get(2).isEqual(nodes.get(2)));
82 System.out.println("false: " + nodes.get(2).isEqual(nodes.get(3)));
83 System.out.println("3.0: " + edges.get(2).getDistance());
84 System.out.println("true: " + edges.get(2).isEqual(edges.get(2)));
85 System.out.println("false: " + edges.get(2).isEqual(edges.get(3)));
87 System.out.println("neighbours of " + nodes.get(3) + ":");
88 Vector<ListNode> neighbours = lg.getNeighbours(nodes.get(3));
89 Iterator<ListNode> neighboursit = neighbours.iterator();
91 while (neighboursit.hasNext())
92 System.out.println(neighboursit.next().toString());
95 public static void main(String[] args) {
96 GraphTest.MatrixGraphTest();
97 System.out.println("==============");
98 GraphTest.ListGraphTest();