documentation files
[aco.git] / protoas / GraphTest.java
blobec52a89e4805942d93c21ad00183750fd5eecdeb
1 package protoas;
3 import java.util.Vector;
4 import java.util.Iterator;
5 import si.ant.graph.*;
7 public class GraphTest {
9 public static void MatrixGraphTest() {
10 int n = 5;
11 int[][] graph = new int[n][n];
12 for (int i = 0; i < n; i++) {
13 for (int j = 0; j < n; j++) {
14 graph[i][j] = MatrixGraph.INFINITY;
18 graph[0][1] = 1;
19 graph[1][2] = 2;
20 graph[2][3] = 3;
21 graph[3][4] = 4;
23 MatrixGraph mg = new MatrixGraph(5, graph, graph, graph);
25 Vector<MatrixNode> nodes = mg.getNodes();
26 Vector<MatrixEdge> edges = mg.getEdges();
28 Iterator<MatrixNode> nodesit = nodes.iterator();
29 Iterator<MatrixEdge> edgesit = edges.iterator();
31 System.out.println("Nodes: ");
32 while (nodesit.hasNext())
33 System.out.println(nodesit.next().toString());
35 System.out.println("Edges: ");
36 while (edgesit.hasNext())
37 System.out.println(edgesit.next().toString());
39 System.out.println("nodes.get(2).getIndex(): " + nodes.get(2).getIndex());
40 System.out.println("true: " + nodes.get(2).isEqual(nodes.get(2)));
41 System.out.println("false: " + nodes.get(2).isEqual(nodes.get(3)));
42 System.out.println("3.0: " + edges.get(2).getDistance());
43 System.out.println("true: " + edges.get(2).isEqual(edges.get(2)));
44 System.out.println("false: " + edges.get(2).isEqual(edges.get(3)));
46 System.out.println("neighbours of " + nodes.get(3) + ":");
47 Vector<MatrixNode> neighbours = mg.getNeighbours(nodes.get(3));
48 Iterator<MatrixNode> neighboursit = neighbours.iterator();
50 while (neighboursit.hasNext())
51 System.out.println(neighboursit.next().toString());
54 public static void ListGraphTest() {
55 Vector<ListEdge> edgegraph = new Vector<ListEdge>(4);
56 ListNode node0 = new ListNode("nil");
57 ListNode node1 = new ListNode("one");
58 ListNode node2 = new ListNode("two");
59 ListNode node3 = new ListNode("three");
60 ListNode node4 = new ListNode("four");
61 edgegraph.add(new ListEdge(node0, node1, 0, 1, 0));
62 edgegraph.add(new ListEdge(node1, node2, 0, 2, 0));
63 edgegraph.add(new ListEdge(node2, node3, 0, 3, 0));
64 edgegraph.add(new ListEdge(node3, node4, 0, 4, 0));
66 ListGraph lg = new ListGraph(edgegraph);
68 Vector<ListNode> nodes = lg.getNodes();
69 Vector<ListEdge> edges = lg.getEdges();
71 Iterator<ListNode> nodesit = nodes.iterator();
72 Iterator<ListEdge> edgesit = edges.iterator();
74 System.out.println("Nodes: ");
75 while (nodesit.hasNext())
76 System.out.println(nodesit.next().toString());
78 System.out.println("Edges: ");
79 while (edgesit.hasNext())
80 System.out.println(edgesit.next().toString());
82 System.out.println("nodes.get(2).getID(): " + nodes.get(2).getID());
83 System.out.println("true: " + nodes.get(2).isEqual(nodes.get(2)));
84 System.out.println("false: " + nodes.get(2).isEqual(nodes.get(3)));
85 System.out.println("3.0: " + edges.get(2).getDistance());
86 System.out.println("true: " + edges.get(2).isEqual(edges.get(2)));
87 System.out.println("false: " + edges.get(2).isEqual(edges.get(3)));
89 System.out.println("neighbours of " + nodes.get(3) + ":");
90 Vector<ListNode> neighbours = lg.getNeighbours(nodes.get(3));
91 Iterator<ListNode> neighboursit = neighbours.iterator();
93 while (neighboursit.hasNext())
94 System.out.println(neighboursit.next().toString());
97 public static void main(String[] args) {
98 GraphTest.MatrixGraphTest();
99 System.out.println("==============");
100 GraphTest.ListGraphTest();