-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpathsettester.java
62 lines (55 loc) · 2.41 KB
/
pathsettester.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
public class pathsettester {
public static void main( String args[] ) {
// Construct some points to work on.
Point p0 = new Point( 5, 1 );
Point p1 = new Point( 6, 1 );
Point p2 = new Point( 3, 1 );
Point p3 = new Point( 11, 1 );
Point pointArray[] = { p0, p1, p2, p3 };
PointSet pointSet = new PointSet( pointArray );
PathSet pathSet = new PathSet( pointSet );
System.out.println( "Before joining the closest path, the paths are:" );
for ( int i = 0; i < pathSet.getPaths().length; i++ ) {
System.out.printf( "(" );
for ( int j = 0; j < pathSet.getPaths()[i].indices.length; j++ ) {
System.out.printf( "%d, ", pathSet.getPaths()[i].indices[j] );
}
System.out.printf( ")\n" );
}
PathSet newPathSet = pathSet.joinClosestPair();
Path newPaths[] = newPathSet.getPaths();
System.out.println( "After joining the closest path, the resulting paths are:" );
for ( int i = 0; i < newPaths.length; i++ ) {
Path thisPath = newPaths[i];
System.out.printf( "(" );
for ( int j = 0; j < thisPath.indices.length; j++ ) {
System.out.printf( "%d, ", thisPath.indices[j] );
}
System.out.printf( " )\n" );
}
// Do it again...
newPathSet = newPathSet.joinClosestPair();
newPaths = newPathSet.getPaths();
System.out.println( "After joining the closest path, the resulting paths are:" );
for ( int i = 0; i < newPaths.length; i++ ) {
Path thisPath = newPaths[i];
System.out.printf( "(" );
for ( int j = 0; j < thisPath.indices.length; j++ ) {
System.out.printf( "%d, ", thisPath.indices[j] );
}
System.out.printf( " )\n" );
}
// Do it again...
newPathSet = newPathSet.joinClosestPair();
newPaths = newPathSet.getPaths();
System.out.println( "After joining the closest path, the resulting paths are:" );
for ( int i = 0; i < newPaths.length; i++ ) {
Path thisPath = newPaths[i];
System.out.printf( "(" );
for ( int j = 0; j < thisPath.indices.length; j++ ) {
System.out.printf( "%d, ", thisPath.indices[j] );
}
System.out.printf( " )\n" );
}
}
}