Merge branch 'long-map' into baritone-testing
This commit is contained in:
@@ -5,7 +5,9 @@ import com.github.btrekkie.connectivity.ConnVertex;
|
||||
import com.github.leijurv.EulerTourForest;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
@@ -13,6 +15,9 @@ import static org.junit.Assert.*;
|
||||
* behavior more predictable. That way, there are consistent test results, and test failures are easier to debug.
|
||||
*/
|
||||
public class ConnGraphTest {
|
||||
private static long toLong(int x, int y) {
|
||||
return (long) x & 0xffffffffL | ((long) y & 0xffffffffL) << 32;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPerformanceOnRepeatedConnectionAndDisconnection() {
|
||||
@@ -26,10 +31,10 @@ public class ConnGraphTest {
|
||||
long setup = System.currentTimeMillis();
|
||||
ConnGraph graph = new ConnGraph((a, b) -> (Integer) a + (Integer) b);
|
||||
int SZ = 1000;
|
||||
ConnVertex[] vertices = new ConnVertex[SZ * SZ];
|
||||
for (int i = 0; i < vertices.length; i++) {
|
||||
vertices[i] = new ConnVertex();
|
||||
graph.setVertexAugmentation(vertices[i], 1);
|
||||
for (int x = 0; x < SZ; x++) {
|
||||
for (int y = 0; y < SZ; y++) {
|
||||
graph.setVertexAugmentation(toLong(x, y), 1); // much faster to do this earlier idk
|
||||
}
|
||||
}
|
||||
for (int x = 0; x < SZ; x++) {
|
||||
if (x % 100 == 0) {
|
||||
@@ -37,15 +42,15 @@ public class ConnGraphTest {
|
||||
}
|
||||
for (int y = 0; y < SZ; y++) {
|
||||
if (y != SZ - 1 && y != SZ / 2) { // leave graph disconnected in the center - two big areas with no connection
|
||||
graph.addEdge(vertices[x * SZ + y], vertices[x * SZ + y + 1]);
|
||||
graph.addEdge(toLong(x, y), toLong(x, y + 1));
|
||||
}
|
||||
if (x != SZ - 1) {
|
||||
graph.addEdge(vertices[x * SZ + y], vertices[(x + 1) * SZ + y]);
|
||||
graph.addEdge(toLong(x, y), toLong(x + 1, y));
|
||||
}
|
||||
}
|
||||
}
|
||||
System.out.println("Setup took " + (System.currentTimeMillis() - setup));
|
||||
System.out.println("Part size " + graph.getComponentAugmentation(vertices[0]));
|
||||
System.out.println("Part size " + graph.getComponentAugmentation(0));
|
||||
|
||||
/*
|
||||
// previous test for cutting in half
|
||||
@@ -64,11 +69,11 @@ public class ConnGraphTest {
|
||||
long start = System.currentTimeMillis();
|
||||
int x = SZ / 2;
|
||||
int y = SZ / 2;
|
||||
graph.addEdge(vertices[x * SZ + y], vertices[x * SZ + y + 1]);
|
||||
graph.addEdge(toLong(x, y), toLong(x, y + 1));
|
||||
long afterAdd = System.currentTimeMillis();
|
||||
System.out.println("Connected size " + graph.getComponentAugmentation(vertices[0]));
|
||||
graph.removeEdge(vertices[x * SZ + y], vertices[x * SZ + y + 1]);
|
||||
System.out.println("Disconnected size " + graph.getComponentAugmentation(vertices[0]));
|
||||
System.out.println("Connected size " + graph.getComponentAugmentation(0));
|
||||
graph.removeEdge(toLong(x, y), toLong(x, y + 1));
|
||||
System.out.println("Disconnected size " + graph.getComponentAugmentation(0));
|
||||
System.out.println("Took " + (System.currentTimeMillis() - afterAdd) + " to remove and " + (afterAdd - start) + " to add");
|
||||
}
|
||||
|
||||
@@ -80,34 +85,34 @@ public class ConnGraphTest {
|
||||
long start = System.currentTimeMillis();
|
||||
int y = SZ / 2;
|
||||
for (int x = 0; x < SZ; x++) {
|
||||
graph.addEdge(vertices[x * SZ + y], vertices[x * SZ + y + 1]);
|
||||
graph.addEdge(toLong(x, y), toLong(x, y + 1));
|
||||
}
|
||||
long afterAdd = System.currentTimeMillis();
|
||||
System.out.println("Connected size " + graph.getComponentAugmentation(vertices[0]));
|
||||
System.out.println("Connected size " + graph.getComponentAugmentation(0));
|
||||
for (int x = 0; x < SZ; x++) {
|
||||
graph.removeEdge(vertices[x * SZ + y], vertices[x * SZ + y + 1]);
|
||||
graph.removeEdge(toLong(x, y), toLong(x, y + 1));
|
||||
}
|
||||
System.out.println("Disconnected size " + graph.getComponentAugmentation(vertices[0]));
|
||||
System.out.println("Disconnected size " + graph.getComponentAugmentation(0));
|
||||
System.out.println("Took " + (System.currentTimeMillis() - afterAdd) + " to remove and " + (afterAdd - start) + " to add");
|
||||
}
|
||||
|
||||
// entire column
|
||||
System.out.println("Part size " + graph.getComponentAugmentation(vertices[0]));
|
||||
System.out.println("Part size " + graph.getComponentAugmentation(0));
|
||||
{
|
||||
int y = SZ / 2;
|
||||
for (int x = 0; x < SZ; x++) {
|
||||
graph.addEdge(vertices[x * SZ + y], vertices[x * SZ + y + 1]);
|
||||
graph.addEdge(toLong(x, y), toLong(x, y + 1));
|
||||
}
|
||||
}
|
||||
System.out.println("Part size " + graph.getComponentAugmentation(vertices[0]));
|
||||
System.out.println("Part size " + graph.getComponentAugmentation(0));
|
||||
long col = System.currentTimeMillis();
|
||||
{
|
||||
int x = SZ / 2;
|
||||
for (int y = 0; y < SZ; y++) {
|
||||
graph.removeEdge(vertices[x * SZ + y], vertices[(x + 1) * SZ + y]);
|
||||
graph.removeEdge(toLong(x, y), toLong(x + 1, y));
|
||||
}
|
||||
}
|
||||
System.out.println("Part size " + graph.getComponentAugmentation(vertices[0]));
|
||||
System.out.println("Part size " + graph.getComponentAugmentation(0));
|
||||
System.out.println("Column took " + (System.currentTimeMillis() - col));
|
||||
}
|
||||
}
|
||||
@@ -162,7 +167,7 @@ public class ConnGraphTest {
|
||||
assertFalse(graph.connected(vertex1, vertex8));
|
||||
assertFalse(graph.connected(vertex6, vertex9));
|
||||
|
||||
Set<ConnVertex> expectedAdjVertices = new HashSet<ConnVertex>();
|
||||
/*Set<ConnVertex> expectedAdjVertices = new HashSet<ConnVertex>();
|
||||
expectedAdjVertices.add(vertex2);
|
||||
expectedAdjVertices.add(vertex3);
|
||||
expectedAdjVertices.add(vertex4);
|
||||
@@ -172,7 +177,7 @@ public class ConnGraphTest {
|
||||
expectedAdjVertices.add(vertex7);
|
||||
assertEquals(expectedAdjVertices, new HashSet<ConnVertex>(graph.adjacentVertices(vertex6)));
|
||||
assertEquals(Collections.singleton(vertex8), new HashSet<ConnVertex>(graph.adjacentVertices(vertex9)));
|
||||
assertEquals(Collections.emptySet(), new HashSet<ConnVertex>(graph.adjacentVertices(new ConnVertex(random))));
|
||||
assertEquals(Collections.emptySet(), new HashSet<ConnVertex>(graph.adjacentVertices(new ConnVertex(random))));*/
|
||||
graph.optimize();
|
||||
|
||||
List<ConnVertex> vertices = new ArrayList<ConnVertex>(1000);
|
||||
@@ -1091,8 +1096,8 @@ public class ConnGraphTest {
|
||||
assertTrue(graph.connected(vertex4, vertex5));
|
||||
assertFalse(graph.connected(vertex1, vertex4));
|
||||
|
||||
assertEquals(Collections.singleton(vertex3), new HashSet<ConnVertex>(graph.adjacentVertices(vertex2)));
|
||||
assertTrue(graph.adjacentVertices(vertex1).isEmpty());
|
||||
assertTrue(graph.adjacentVertices(vertex6).isEmpty());
|
||||
//assertEquals(Collections.singleton(vertex3), new HashSet<ConnVertex>(graph.adjacentVertices(vertex2)));
|
||||
//assertTrue(graph.adjacentVertices(vertex1).isEmpty());
|
||||
//assertTrue(graph.adjacentVertices(vertex6).isEmpty());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user