diff --git a/Style Guide.txt b/Style Guide.txt index 2dbb405c..ea478410 100644 --- a/Style Guide.txt +++ b/Style Guide.txt @@ -63,7 +63,7 @@ Testing: -Map Arrays - CellTypeMap: +Map Arrays - LocationTypeMap: In arrays that represent maps, dimensions will be ordered as follows: arr[x][y][z]... So that arr.length is equal to the x length (the width) of the represented map. @@ -75,4 +75,4 @@ Map Arrays - CellTypeMap: Example of a standard for i for j iteration: for (int xIndex = 0; xIndex < xAxis_length; xIndex++) for (int yIndex = 0; yIndex < yAxis_length; yIndex++) - CellTypeMap[xIndex][yIndex] + LocationTypeMap[xIndex][yIndex] diff --git a/src/main/java/BasicCBS/Instances/InstanceBuilders/I_InstanceBuilder.java b/src/main/java/BasicCBS/Instances/InstanceBuilders/I_InstanceBuilder.java index 7436e79a..df3ccffa 100644 --- a/src/main/java/BasicCBS/Instances/InstanceBuilders/I_InstanceBuilder.java +++ b/src/main/java/BasicCBS/Instances/InstanceBuilders/I_InstanceBuilder.java @@ -3,7 +3,7 @@ import BasicCBS.Instances.InstanceProperties; import BasicCBS.Instances.MAPF_Instance; import Environment.IO_Package.Reader; -import BasicCBS.Instances.Maps.Enum_MapCellType; +import BasicCBS.Instances.Maps.Enum_MapLocationType; import BasicCBS.Instances.Maps.GraphMap; import BasicCBS.Instances.Maps.MapDimensions; import BasicCBS.Instances.Maps.MapFactory; @@ -69,25 +69,25 @@ static String[] buildMapAsStringArray(Reader reader, MapDimensions mapDimensions * @param mapAsStrings - Map from file, rows are yAxis * @param mapSeparator - Regex value to split map values. by default is "". * @param mapDimensions - A {@link MapDimensions}, must be valid. - * @param cellTypeHashMap - HashMap for converting Character to {@link Enum_MapCellType} + * @param locationTypeHashMap - HashMap for converting Character to {@link Enum_MapLocationType} * @param obstacle - Value is a {@link BasicCBS.Instances.InstanceProperties.ObstacleWrapper} indicates obstacle in the map. * @return A GraphMap */ - static GraphMap buildGraphMap(String[] mapAsStrings, String mapSeparator, MapDimensions mapDimensions, HashMap cellTypeHashMap, InstanceProperties.ObstacleWrapper obstacle) { + static GraphMap buildGraphMap(String[] mapAsStrings, String mapSeparator, MapDimensions mapDimensions, HashMap locationTypeHashMap, InstanceProperties.ObstacleWrapper obstacle) { switch ( mapDimensions.numOfDimensions ){ case 2: Character[][] mapAsCharacters_2d = build2D_CharacterMap(mapAsStrings,mapDimensions,mapSeparator); - Enum_MapCellType[][] mapAsCellType_2D = build_2D_cellTypeMap(mapAsCharacters_2d, cellTypeHashMap, mapDimensions.mapOrientation, obstacle); - if( mapAsCellType_2D == null){ + Enum_MapLocationType[][] mapAsLocationType_2D = build_2D_locationTypeMap(mapAsCharacters_2d, locationTypeHashMap, mapDimensions.mapOrientation, obstacle); + if( mapAsLocationType_2D == null){ return null; // Error while building the map } - return MapFactory.newSimple4Connected2D_GraphMap(mapAsCellType_2D); + return MapFactory.newSimple4Connected2D_GraphMap(mapAsLocationType_2D); case 3: Character[][][] mapAsCharacters_3d = new Character[][][]{}; - Enum_MapCellType[][][] mapAsCellType_3D = build_3D_cellTypeMap(mapAsCharacters_3d, cellTypeHashMap, obstacle); + Enum_MapLocationType[][][] mapAsLocationType_3D = build_3D_locationTypeMap(mapAsCharacters_3d, locationTypeHashMap, obstacle); return null; // niceToHave - change to newSimple 4Connected 3D_GraphMap if exists in MapFactory } @@ -100,7 +100,7 @@ static GraphMap buildGraphMap(String[] mapAsStrings, String mapSeparator, MapDim * @param mapAsStrings Map lines as string array * @param mapDimensions Holds the dimensions sizes and orientation * @param mapSeparator Indicates how to split the map lines - * @return Character 2d array of map cells + * @return Character 2d array of map locations */ static Character[][] build2D_CharacterMap(String[] mapAsStrings, MapDimensions mapDimensions, String mapSeparator){ @@ -128,15 +128,15 @@ static Character[][] build2D_CharacterMap(String[] mapAsStrings, MapDimensions m /** - * Builds {@link Enum_MapCellType} array by converting chars. + * Builds {@link Enum_MapLocationType} array by converting chars. * Also checks that obstacles in map are valid * @param mapAsCharacters The map as Character array - * @param cellTypeHashMap Mapping from char to {@link Enum_MapCellType} + * @param locationTypeHashMap Mapping from char to {@link Enum_MapLocationType} * @param mapOrientation Holds the dimensions sizes and orientation * @param obstacle A {@link BasicCBS.Instances.InstanceProperties.ObstacleWrapper} from {@link InstanceProperties} - * @return An obstacle valid array of {@link Enum_MapCellType} + * @return An obstacle valid array of {@link Enum_MapLocationType} */ - static Enum_MapCellType[][] build_2D_cellTypeMap(Character[][] mapAsCharacters , HashMap cellTypeHashMap, MapDimensions.Enum_mapOrientation mapOrientation, InstanceProperties.ObstacleWrapper obstacle) { + static Enum_MapLocationType[][] build_2D_locationTypeMap(Character[][] mapAsCharacters , HashMap locationTypeHashMap, MapDimensions.Enum_mapOrientation mapOrientation, InstanceProperties.ObstacleWrapper obstacle) { if(mapAsCharacters == null){ return null; } @@ -148,7 +148,7 @@ static Enum_MapCellType[][] build_2D_cellTypeMap(Character[][] mapAsCharacters , int numOfNonObstacles = 0; // init array - Enum_MapCellType[][] cellTypeMap = new Enum_MapCellType[xAxis_length][yAxis_length]; + Enum_MapLocationType[][] locationTypeMap = new Enum_MapLocationType[xAxis_length][yAxis_length]; for (int xIndex = 0; xIndex < xAxis_length; xIndex++) { for (int yIndex = 0; yIndex < yAxis_length; yIndex++) { @@ -156,14 +156,14 @@ static Enum_MapCellType[][] build_2D_cellTypeMap(Character[][] mapAsCharacters , Character character = null; character = mapAsCharacters[xIndex][yIndex]; - Enum_MapCellType cellType = cellTypeHashMap.get(character); + Enum_MapLocationType locationType = locationTypeHashMap.get(character); - if ( cellType.equals(Enum_MapCellType.WALL)){ + if ( locationType.equals(Enum_MapLocationType.WALL)){ actualNumOfObstacles++; // add one wall to counter }else{ numOfNonObstacles++; // add one to non obstacle counter } - cellTypeMap[xIndex][yIndex] = cellType; + locationTypeMap[xIndex][yIndex] = locationType; } } @@ -178,10 +178,10 @@ static Enum_MapCellType[][] build_2D_cellTypeMap(Character[][] mapAsCharacters , int obstaclePercentage = (int) Math.ceil( ((double) actualNumOfObstacles / (double) boardSize) * 100 ); obstacle.setWithPercentage(obstaclePercentage); - return cellTypeMap; + return locationTypeMap; } - static Enum_MapCellType[][][] build_3D_cellTypeMap(Character[][][] mapAsCharacters, HashMap cellTypeHashMap, InstanceProperties.ObstacleWrapper obstacle) { + static Enum_MapLocationType[][][] build_3D_locationTypeMap(Character[][][] mapAsCharacters, HashMap locationTypeHashMap, InstanceProperties.ObstacleWrapper obstacle) { // niceToHave - no need to implement for now return null; } diff --git a/src/main/java/BasicCBS/Instances/InstanceBuilders/InstanceBuilder_BGU.java b/src/main/java/BasicCBS/Instances/InstanceBuilders/InstanceBuilder_BGU.java index bbfe323d..3a6a3616 100644 --- a/src/main/java/BasicCBS/Instances/InstanceBuilders/InstanceBuilder_BGU.java +++ b/src/main/java/BasicCBS/Instances/InstanceBuilders/InstanceBuilder_BGU.java @@ -35,13 +35,13 @@ public class InstanceBuilder_BGU implements I_InstanceBuilder { private final int INDEX_AGENT_TARGET_YVALUE = 2; - /* =Cell Types= */ + /* =Location Types= */ private final char EMPTY = '.'; private final char WALL = '@'; - private HashMap cellTypeHashMap = new HashMap<>(){{ - put(EMPTY,Enum_MapCellType.EMPTY); - put(WALL,Enum_MapCellType.WALL); + private HashMap locationTypeHashMap = new HashMap<>(){{ + put(EMPTY, Enum_MapLocationType.EMPTY); + put(WALL, Enum_MapLocationType.WALL); }}; @@ -94,7 +94,7 @@ private MAPF_Instance getInstance(String instanceName, InstanceManager.InstanceP String[] mapAsStrings = I_InstanceBuilder.buildMapAsStringArray(reader, mapDimensionsFromFile); // build map - graphMap = I_InstanceBuilder.buildGraphMap(mapAsStrings, this.SEPARATOR_MAP, mapDimensionsFromFile, this.cellTypeHashMap, instanceProperties.obstacles); + graphMap = I_InstanceBuilder.buildGraphMap(mapAsStrings, this.SEPARATOR_MAP, mapDimensionsFromFile, this.locationTypeHashMap, instanceProperties.obstacles); break; // end case diff --git a/src/main/java/BasicCBS/Instances/InstanceBuilders/InstanceBuilder_MovingAI.java b/src/main/java/BasicCBS/Instances/InstanceBuilders/InstanceBuilder_MovingAI.java index 4f4a89c6..3ce8bb44 100644 --- a/src/main/java/BasicCBS/Instances/InstanceBuilders/InstanceBuilder_MovingAI.java +++ b/src/main/java/BasicCBS/Instances/InstanceBuilders/InstanceBuilder_MovingAI.java @@ -54,16 +54,16 @@ public class InstanceBuilder_MovingAI implements I_InstanceBuilder { private final ArrayList instanceList = new ArrayList<>(); - /* =Cell Types= */ + /* =Location Types= */ private final char EMPTY = '.'; private final char WALL = '@'; private final char TREE = 'T'; - /* Mapping from char to Cell type */ - private HashMap cellTypeHashMap = new HashMap(){{ - put(EMPTY,Enum_MapCellType.EMPTY); - put(WALL,Enum_MapCellType.WALL); - put(TREE,Enum_MapCellType.TREE); + /* Mapping from char to Location type */ + private HashMap locationTypeHashMap = new HashMap(){{ + put(EMPTY, Enum_MapLocationType.EMPTY); + put(WALL, Enum_MapLocationType.WALL); + put(TREE, Enum_MapLocationType.TREE); }}; private final Priorities priorities; @@ -244,7 +244,7 @@ private GraphMap getMap( InstanceManager.InstancePath instancePath, InstanceProp String[] mapAsStrings = I_InstanceBuilder.buildMapAsStringArray(reader, dimensionsFromFile); // build map - graphMap = I_InstanceBuilder.buildGraphMap(mapAsStrings, this.SEPARATOR_MAP, dimensionsFromFile, this.cellTypeHashMap, instanceProperties.obstacles); + graphMap = I_InstanceBuilder.buildGraphMap(mapAsStrings, this.SEPARATOR_MAP, dimensionsFromFile, this.locationTypeHashMap, instanceProperties.obstacles); break; } nextLine = reader.getNextLine(); diff --git a/src/main/java/BasicCBS/Instances/InstanceProperties.java b/src/main/java/BasicCBS/Instances/InstanceProperties.java index b53e5878..6c198a63 100644 --- a/src/main/java/BasicCBS/Instances/InstanceProperties.java +++ b/src/main/java/BasicCBS/Instances/InstanceProperties.java @@ -44,7 +44,7 @@ public class ObstacleWrapper { /* Rate for the report: {@link #reportRate} is the map's rate, it will be updated from - {@link I_InstanceBuilder#build_2D_cellTypeMap(Character[][], HashMap, MapDimensions.Enum_mapOrientation, ObstacleWrapper)} + {@link I_InstanceBuilder#build_2D_locationTypeMap(Character[][], HashMap, MapDimensions.Enum_mapOrientation, ObstacleWrapper)} */ private double reportRate = DEFAULT_OBSTACLE_RATE; // this we be updated from diff --git a/src/main/java/BasicCBS/Instances/Maps/Enum_MapCellType.java b/src/main/java/BasicCBS/Instances/Maps/Enum_MapCellType.java deleted file mode 100644 index 888f52dc..00000000 --- a/src/main/java/BasicCBS/Instances/Maps/Enum_MapCellType.java +++ /dev/null @@ -1,14 +0,0 @@ -package BasicCBS.Instances.Maps; - -/** - * Represents the type of a {@link I_Location cell}. - * The type could determine whether or not an agent can traverse or occupy a cell. - * - * The basic implementation has EMPTY to denote passable cells, and WALL to denote impassable cells. Other types my be - * added to represent more complex domains. - */ -public enum Enum_MapCellType { - EMPTY, - TREE, - WALL -} diff --git a/src/main/java/BasicCBS/Instances/Maps/Enum_MapLocationType.java b/src/main/java/BasicCBS/Instances/Maps/Enum_MapLocationType.java new file mode 100644 index 00000000..fc98d793 --- /dev/null +++ b/src/main/java/BasicCBS/Instances/Maps/Enum_MapLocationType.java @@ -0,0 +1,23 @@ +package BasicCBS.Instances.Maps; + +/** + * Represents the type of {@link I_Location location}. + * The type could determine whether an agent can traverse or occupy a location. + * + * The basic implementation has EMPTY to denote traversable location, and WALL to denote impassable locations. Other + * types may be added to represent more complex domains. + */ +public enum Enum_MapLocationType { + /** + * Standard empty, traversable, location. + */ + EMPTY, + /** + * Traversable by some agents but impassable for other (undefined). + */ + TREE, + /** + * Impassable location. + */ + WALL +} diff --git a/src/main/java/BasicCBS/Instances/Maps/GraphMap.java b/src/main/java/BasicCBS/Instances/Maps/GraphMap.java index 51682619..5daddcff 100644 --- a/src/main/java/BasicCBS/Instances/Maps/GraphMap.java +++ b/src/main/java/BasicCBS/Instances/Maps/GraphMap.java @@ -15,14 +15,14 @@ */ public class GraphMap implements I_ExplicitMap { - private HashMap allGraphCells; + private HashMap allGraphLocations; /** * Initialization in {@link MapFactory}. - * @param allGraphVertices a {@link HashMap} containing all cells in the graph. + * @param allGraphVertices a {@link HashMap} containing all locations in the graph. */ GraphMap(HashMap allGraphVertices) { - this.allGraphCells = allGraphVertices; + this.allGraphLocations = allGraphVertices; } /** @@ -31,13 +31,13 @@ public class GraphMap implements I_ExplicitMap { * @return the {@link GraphMapVertex} for the given {@link I_Coordinate}. */ @Override - public GraphMapVertex getMapCell(I_Coordinate coordinate) { - return allGraphCells.get(coordinate); + public GraphMapVertex getMapLocation(I_Coordinate coordinate) { + return allGraphLocations.get(coordinate); } @Override public boolean isValidCoordinate(I_Coordinate coordinate) { - return this.allGraphCells.containsKey(coordinate); + return this.allGraphLocations.containsKey(coordinate); } @Override @@ -46,13 +46,13 @@ public I_Map getSubmapWithout(Collection mapLocations) { HashMap vertexMappings = new HashMap<>(); // populate with stub vertices (copies), except for vertices that we want to remove - for (Map.Entry pair : this.allGraphCells.entrySet()) { + for (Map.Entry pair : this.allGraphLocations.entrySet()) { if(!mapLocations.contains(pair.getValue())){ - vertexMappings.put(pair.getKey(), new GraphMapVertex(pair.getValue().cellType, pair.getKey())); + vertexMappings.put(pair.getKey(), new GraphMapVertex(pair.getValue().locationType, pair.getKey())); } } // now iterate over original vertices and copy over their neighbors, except for neighbors that were removed. - for (Map.Entry pair : this.allGraphCells.entrySet()) { + for (Map.Entry pair : this.allGraphLocations.entrySet()) { I_Coordinate coor = pair.getKey(); GraphMapVertex originalVertex = pair.getValue(); if(!mapLocations.contains(originalVertex)){ @@ -70,8 +70,8 @@ public I_Map getSubmapWithout(Collection mapLocations) { return new GraphMap(vertexMappings); } - public int getNumMapCells(){ - return allGraphCells.size(); + public int getNumMapLocations(){ + return allGraphLocations.size(); } @@ -80,6 +80,6 @@ public int getNumMapCells(){ */ @Override public Collection getAllLocations() { - return new ArrayList<>(this.allGraphCells.values()); + return new ArrayList<>(this.allGraphLocations.values()); } } diff --git a/src/main/java/BasicCBS/Instances/Maps/GraphMapVertex.java b/src/main/java/BasicCBS/Instances/Maps/GraphMapVertex.java index d5944c46..20c7c047 100644 --- a/src/main/java/BasicCBS/Instances/Maps/GraphMapVertex.java +++ b/src/main/java/BasicCBS/Instances/Maps/GraphMapVertex.java @@ -8,7 +8,7 @@ import java.util.List; /** - * A single cell(/vertex) in a {@link GraphMap}. Represents a unique location in the graph. + * A single location(/vertex) in a {@link GraphMap}. Represents a unique location in the graph. * Immutable beyond first initialization (First with a constructor, and then with {@link #setNeighbors(GraphMapVertex[])}. */ public class GraphMapVertex implements I_Location { @@ -20,9 +20,9 @@ public class GraphMapVertex implements I_Location { private final int UniqueID = IDCounter++; /** - * The type of the cell. The type could determine whether or not an agent can traverse or occupy a cell. + * The type of the location. The type could determine whether or not an agent can traverse or occupy a location. */ - public final Enum_MapCellType cellType; + public final Enum_MapLocationType locationType; public List outgoingEdges; private List incomingEdges = new ArrayList<>(); /** @@ -38,17 +38,17 @@ public class GraphMapVertex implements I_Location { public final I_Coordinate coordinate; - GraphMapVertex(Enum_MapCellType cellType, I_Coordinate coordinate) { - this.cellType = cellType; + GraphMapVertex(Enum_MapLocationType locationType, I_Coordinate coordinate) { + this.locationType = locationType; this.coordinate = coordinate; this.outgoingEdges = null; } /** - * Sets the cell's neighbors. All cells in the array should logically be non null. + * Sets the location's neighbors. All locations in the array should logically be non null. * Used during graph construction. Only the first call to this method on an instance affects the instance. * Also sets this as a reverse edge on each of the neighbors. - * @param outgoingEdges the cell's neighbors. + * @param outgoingEdges the location's neighbors. * @throws NullPointerException if an element is null or the given array is null. */ void setNeighbors(GraphMapVertex[] outgoingEdges) { @@ -58,11 +58,11 @@ void setNeighbors(GraphMapVertex[] outgoingEdges) { } /** - * Sets the cell's neighbors. All cells in the array should logically be non null. + * Sets the location's neighbors. All locations in the array should logically be non null. * Used during graph construction. Only the first call to this method on an instance affects the instance. * Also sets this as a reverse edge on each of the neighbors. * Also sets weights for the edges to the neighbors. - * @param outgoingEdges the cell's neighbors. must be indexed uniformly with edgeWeights. + * @param outgoingEdges the location's neighbors. must be indexed uniformly with edgeWeights. * @param edgeWeights weights of the connections to the neighbors. must be indexed uniformly with neighbors. * @throws NullPointerException if an element is null or the given array is null. */ @@ -82,17 +82,17 @@ void setNeighbors(GraphMapVertex[] outgoingEdges, Integer[] edgeWeights) { } /** - * Returns the type of the cell. - * @return the type of the cell. + * Returns the type of the location. + * @return the type of the location. */ @Override - public Enum_MapCellType getType() { - return cellType; + public Enum_MapLocationType getType() { + return locationType; } /** - * returns the cell's coordinate. - * @return the cell's coordinate. + * returns the location's coordinate. + * @return the location's coordinate. */ @Override public I_Coordinate getCoordinate() { @@ -100,10 +100,10 @@ public I_Coordinate getCoordinate() { } /** - * Returns an UnmodifiableList of this cell's neighbors. + * Returns an UnmodifiableList of this location's neighbors. * The amount of neighbors varies by map and connectivity. * Runs in O(1). - * @return an UnmodifiableList of this cell's neighbors. + * @return an UnmodifiableList of this location's neighbors. */ @Override public List outgoingEdges() { @@ -124,11 +124,11 @@ public List incomingEdges() { } /** - * Returns an UnmodifiableList of the weights of this cell's edges. + * Returns an UnmodifiableList of the weights of this location's edges. * The amount of neighbors varies by map and connectivity. * Runs in O(1). * Indexed uniformly with the list of neighbors returned by {@link #outgoingEdges()}. - * @return an UnmodifiableList of the weights of this cell's edges. + * @return an UnmodifiableList of the weights of this location's edges. */ @Override public List getOutgoingEdgesWeights() { @@ -157,7 +157,7 @@ public boolean isNeighbor(I_Location other) { @Override public String toString() { - return "GraphMapCell{" + + return "GraphMapLocation{" + "coordinate=" + coordinate + '}'; } diff --git a/src/main/java/BasicCBS/Instances/Maps/I_Location.java b/src/main/java/BasicCBS/Instances/Maps/I_Location.java index 4e80f4cc..9a09b702 100644 --- a/src/main/java/BasicCBS/Instances/Maps/I_Location.java +++ b/src/main/java/BasicCBS/Instances/Maps/I_Location.java @@ -7,10 +7,10 @@ public interface I_Location { /** - * Returns the type of the cell. - * @return the type of the cell. + * Returns the type of the location. + * @return the type of the location. */ - Enum_MapCellType getType(); + Enum_MapLocationType getType(); /** * Returns an array that contains references to locations directly reachable from this. Should not include this. @@ -27,22 +27,22 @@ public interface I_Location { List incomingEdges(); /** - * returns the cell's coordinate. - * @return the cell's coordinate. + * returns the location's coordinate. + * @return the location's coordinate. */ I_Coordinate getCoordinate(); /** - * Get weights of the connections to this cell's neighbors. + * Get weights of the connections to this location's neighbors. * Should be uniformly indexed with the return value of {@link #outgoingEdges()}. - * @return weights of the connections to this cell's neighbors. + * @return weights of the connections to this location's neighbors. */ List getOutgoingEdgesWeights(); /** - * Get weights of the connections from this cell's neighbors. + * Get weights of the connections from this location's neighbors. * Should be uniformly indexed with the return value of {@link #incomingEdges()}. - * @return weights of the connections from this cell's neighbors. + * @return weights of the connections from this location's neighbors. */ List getIncomingEdgesWeights(); diff --git a/src/main/java/BasicCBS/Instances/Maps/I_Map.java b/src/main/java/BasicCBS/Instances/Maps/I_Map.java index 855766d9..b6852607 100644 --- a/src/main/java/BasicCBS/Instances/Maps/I_Map.java +++ b/src/main/java/BasicCBS/Instances/Maps/I_Map.java @@ -8,11 +8,11 @@ public interface I_Map { /** /** - * Returns the {@link I_Location map cell} for the given {@link I_Coordinate}. - * @param i_coordinate the {@link I_Coordinate} of the {@link I_Location map cell}. - * @return the {@link I_Location map cell} for the given {@link I_Coordinate}. + * Returns the {@link I_Location map location} for the given {@link I_Coordinate}. + * @param i_coordinate the {@link I_Coordinate} of the {@link I_Location map location}. + * @return the {@link I_Location map location} for the given {@link I_Coordinate}. */ - I_Location getMapCell(I_Coordinate i_coordinate); + I_Location getMapLocation(I_Coordinate i_coordinate); /** * @param i_coordinate the {@link I_Coordinate} to check. diff --git a/src/main/java/BasicCBS/Instances/Maps/MapFactory.java b/src/main/java/BasicCBS/Instances/Maps/MapFactory.java index ef295bf3..c7fca38d 100644 --- a/src/main/java/BasicCBS/Instances/Maps/MapFactory.java +++ b/src/main/java/BasicCBS/Instances/Maps/MapFactory.java @@ -15,63 +15,97 @@ public class MapFactory { /** * Generates a new 4-connected {@link GraphMap} from a square, 2D grid. * - * Simple - Only 2 {@link Enum_MapCellType cell types} exist, {@link Enum_MapCellType#EMPTY} and - * {@link Enum_MapCellType#WALL}. {@link Enum_MapCellType#EMPTY} cells are passable, and can only connect to other - * {@link Enum_MapCellType#EMPTY} cells. {@link Enum_MapCellType#WALL} cells are impassable, and can not connect to - * any other cell, so they will not be generated. - * @param rectangle_2D_Map A rectangle grid representing a map, containing only {@link Enum_MapCellType#EMPTY} and - * {@link Enum_MapCellType#WALL}. The length of its first dimension should correspond to the + * Simple - Only 2 {@link Enum_MapLocationType location types} exist, {@link Enum_MapLocationType#EMPTY} and + * {@link Enum_MapLocationType#WALL}. {@link Enum_MapLocationType#EMPTY} locations are passable, and can only connect to other + * {@link Enum_MapLocationType#EMPTY} locations. {@link Enum_MapLocationType#WALL} locations are impassable, and can not connect to + * any other location, so they will not be generated. + * @param rectangle_2D_Map A rectangle grid representing a map, containing only {@link Enum_MapLocationType#EMPTY} and + * {@link Enum_MapLocationType#WALL}. The length of its first dimension should correspond to the * original map's x dimension. * @return a new 4-connected {@link GraphMap}. */ - public static GraphMap newSimple4Connected2D_GraphMap(Enum_MapCellType[][] rectangle_2D_Map){ + public static GraphMap newSimple4Connected2D_GraphMap(Enum_MapLocationType[][] rectangle_2D_Map){ int xAxis_length = rectangle_2D_Map.length; int yAxis_length = rectangle_2D_Map[0].length; - GraphMapVertex[][] cells = new GraphMapVertex[xAxis_length][yAxis_length]; //rectangle map - //generate all cells + GraphMapVertex[][] locations = new GraphMapVertex[xAxis_length][yAxis_length]; //rectangle map + //generate all locations for (int xIndex = 0; xIndex < xAxis_length; xIndex++) { for (int yIndex = 0; yIndex < yAxis_length; yIndex++) { - if(rectangle_2D_Map[xIndex][yIndex] == Enum_MapCellType.EMPTY){ - cells[xIndex][yIndex] = new GraphMapVertex(rectangle_2D_Map[xIndex][yIndex], new Coordinate_2D(xIndex, yIndex)); + if(rectangle_2D_Map[xIndex][yIndex] == Enum_MapLocationType.EMPTY){ + locations[xIndex][yIndex] = new GraphMapVertex(rectangle_2D_Map[xIndex][yIndex], new Coordinate_2D(xIndex, yIndex)); } } } - HashMap allCells = new HashMap<>(); //to be used for GraphMap constructor - //connect cells to their neighbors (4-connected) + HashMap allLocations = new HashMap<>(); //to be used for GraphMap constructor + //connect locations to their neighbors (4-connected) ArrayList neighbors = new ArrayList<>(4); for (int xIndex = 0; xIndex < xAxis_length; xIndex++) { for (int yIndex = 0; yIndex < yAxis_length; yIndex++) { - GraphMapVertex currentCell = cells[xIndex][yIndex]; - if(cells[xIndex][yIndex] != null){ + GraphMapVertex currentLocation = locations[xIndex][yIndex]; + if(locations[xIndex][yIndex] != null){ neighbors.clear(); //look for WEST neighbor - if(xIndex-1 >= 0 && cells[xIndex-1][yIndex] != null){neighbors.add(cells[xIndex-1][yIndex]);} + if(xIndex-1 >= 0 && locations[xIndex-1][yIndex] != null){neighbors.add(locations[xIndex-1][yIndex]);} //look for EAST neighbor - if(xIndex+1 < xAxis_length && cells[xIndex+1][yIndex] != null){neighbors.add(cells[xIndex+1][yIndex]);} + if(xIndex+1 < xAxis_length && locations[xIndex+1][yIndex] != null){neighbors.add(locations[xIndex+1][yIndex]);} //look for NORTH neighbor - if(yIndex-1 >= 0 && cells[xIndex][yIndex-1] != null){neighbors.add(cells[xIndex][yIndex-1]);} + if(yIndex-1 >= 0 && locations[xIndex][yIndex-1] != null){neighbors.add(locations[xIndex][yIndex-1]);} //look for SOUTH neighbor - if(yIndex+1 < yAxis_length && cells[xIndex][yIndex+1] != null){neighbors.add(cells[xIndex][yIndex+1]);} - // set cell neighbors - currentCell.setNeighbors(neighbors.toArray(new GraphMapVertex[0])); - // add to allCells - allCells.put(currentCell.coordinate, currentCell); + if(yIndex+1 < yAxis_length && locations[xIndex][yIndex+1] != null){neighbors.add(locations[xIndex][yIndex+1]);} + // set location neighbors + currentLocation.setNeighbors(neighbors.toArray(new GraphMapVertex[0])); + // add to allLocations + allLocations.put(currentLocation.coordinate, currentLocation); } } } - return new GraphMap(allCells); + return new GraphMap(allLocations); } /* nicetohave - 8 connected 2D map - public static GraphMap newSimple8Connected2D_GraphMap(Enum_MapCellType[][] map_2D){ + public static GraphMap newSimple8Connected2D_GraphMap(Enum_MapLocationType[][] map_2D){ return null; } */ /* nicetohave - 3D map - public static GraphMap newSimple6Connected3D_GraphMap(Enum_MapCellType[][] map_2D){ + public static GraphMap newSimple6Connected3D_GraphMap(Enum_MapLocationType[][] map_2D){ return null; } */ + /** + * Create a {@link GraphMap} with any arbitrary shape or dimensionality. + * @param coordinatesAdjacencyLists maps from every vertex to a list of (directed) edges coming out of it. + * @param coordinatesEdgeWeights maps from every vertex to a list of edges weights of its edges. + * @param coordinatesLocationTypes maps from every vertex to its location type. + * @return a {@link GraphMap}. + */ + public static GraphMap newArbitraryGraphMap(Map> coordinatesAdjacencyLists, + Map> coordinatesEdgeWeights, + Map coordinatesLocationTypes){ + HashMap allLocations = new HashMap<>(coordinatesAdjacencyLists.size()); + + for (I_Coordinate coordinateCurrentVertex: coordinatesAdjacencyLists.keySet()){ + allLocations.putIfAbsent(coordinateCurrentVertex, + new GraphMapVertex(coordinatesLocationTypes != null ? coordinatesLocationTypes.get(coordinateCurrentVertex) : Enum_MapLocationType.EMPTY, coordinateCurrentVertex)); + GraphMapVertex currentVertex = allLocations.get(coordinateCurrentVertex); + + List coordinateNeighbors = coordinatesAdjacencyLists.get(coordinateCurrentVertex); + List edgeWeights = coordinatesEdgeWeights.get(coordinateCurrentVertex); + + GraphMapVertex[] neighbors = new GraphMapVertex[coordinateNeighbors.size()]; + for (int i = 0; i < neighbors.length; i++) { + I_Coordinate neighborCoordinate = coordinateNeighbors.get(i); + allLocations.putIfAbsent(neighborCoordinate, + new GraphMapVertex(coordinatesLocationTypes != null ? coordinatesLocationTypes.get(coordinateCurrentVertex) : Enum_MapLocationType.EMPTY, neighborCoordinate)); + neighbors[i] = allLocations.get(neighborCoordinate); + } + + currentVertex.setNeighbors(neighbors, edgeWeights.toArray(Integer[]::new)); + } + + return new GraphMap(allLocations); + } + } diff --git a/src/main/java/BasicCBS/Solvers/AStar/CachingDistanceTableHeuristic.java b/src/main/java/BasicCBS/Solvers/AStar/CachingDistanceTableHeuristic.java index bf993579..9840c32f 100644 --- a/src/main/java/BasicCBS/Solvers/AStar/CachingDistanceTableHeuristic.java +++ b/src/main/java/BasicCBS/Solvers/AStar/CachingDistanceTableHeuristic.java @@ -41,7 +41,7 @@ public void setCurrentMap(I_ExplicitMap map){ @Override public float getH(SingleAgentAStar_Solver.AStarState state) { DistanceTableAStarHeuristic dt = this.distanceTables.get(this.currentMap); - I_Location target = this.currentMap.getMapCell(state.getMove().agent.target); + I_Location target = this.currentMap.getMapLocation(state.getMove().agent.target); if (dt.getDistanceDictionaries().containsKey(target)){ return dt.getH(state); } diff --git a/src/main/java/BasicCBS/Solvers/AStar/DistanceTableAStarHeuristic.java b/src/main/java/BasicCBS/Solvers/AStar/DistanceTableAStarHeuristic.java index d1d2340d..a35216e2 100644 --- a/src/main/java/BasicCBS/Solvers/AStar/DistanceTableAStarHeuristic.java +++ b/src/main/java/BasicCBS/Solvers/AStar/DistanceTableAStarHeuristic.java @@ -53,7 +53,7 @@ public DistanceTableAStarHeuristic(I_ExplicitMap map) { } public void addAgentToHeuristic(Agent agent) { - addTargetToHeuristic(map.getMapCell(agent.target)); + addTargetToHeuristic(map.getMapLocation(agent.target)); } public void addTargetToHeuristic(I_Location target) { @@ -75,13 +75,13 @@ public void addTargetToHeuristic(I_Location target) { while (!(queue.isEmpty())) { I_Location i_location = queue.remove(0); - //if a graphMapCell didn't get a distance yet + //if a graphMapLocation didn't get a distance yet if (!(this.distanceDictionaries.get(target).containsKey(i_location))) { this.distanceDictionaries.get(target).put(i_location, distance); // traversing edges in reverse back from current vertex - List neighborsCell = i_location.incomingEdges(); - queue.addAll(neighborsCell); + List neighborsLocation = i_location.incomingEdges(); + queue.addAll(neighborsLocation); } count--; @@ -99,7 +99,7 @@ public float getH(SingleAgentAStar_Solver.AStarState state) { } public Integer getHToTargetFromLocation(I_Coordinate target, I_Location currLocation) { - Map relevantDictionary = this.distanceDictionaries.get(map.getMapCell(target)); + Map relevantDictionary = this.distanceDictionaries.get(map.getMapLocation(target)); return relevantDictionary.get(currLocation); } diff --git a/src/main/java/BasicCBS/Solvers/AStar/SingleAgentAStar_Solver.java b/src/main/java/BasicCBS/Solvers/AStar/SingleAgentAStar_Solver.java index e7804265..df024350 100644 --- a/src/main/java/BasicCBS/Solvers/AStar/SingleAgentAStar_Solver.java +++ b/src/main/java/BasicCBS/Solvers/AStar/SingleAgentAStar_Solver.java @@ -3,6 +3,7 @@ import BasicCBS.Instances.Agent; import BasicCBS.Instances.MAPF_Instance; import BasicCBS.Instances.Maps.Coordinates.I_Coordinate; +import BasicCBS.Instances.Maps.Enum_MapLocationType; import BasicCBS.Instances.Maps.I_Map; import BasicCBS.Instances.Maps.I_Location; import BasicCBS.Solvers.ConstraintsAndConflicts.ConflictManagement.I_ConflictAvoidanceTable; @@ -166,7 +167,7 @@ protected Solution solveAStar() { * Initialises {@link #openList OPEN}. * * OPEN is not initialised with a single root state as is common. This is because states in this solver represent - * {@link Move moves} (classically - operators) rather than {@link I_Location map cells} (classically - states). + * {@link Move moves} (classically - operators) rather than {@link I_Location map locations} (classically - states). * Instead, OPEN is initialised with all possible moves from the starting position. * @return true if OPEN was successfully initialised, else false. */ @@ -182,13 +183,13 @@ protected boolean initOpen() { } else { // the existing plan is empty (no existing plan) - I_Location sourceCell = map.getMapCell(this.sourceCoor); - // can move to neighboring locations or stay put - List neighborCellsIncludingCurrent = new ArrayList<>(sourceCell.outgoingEdges()); - neighborCellsIncludingCurrent.add(sourceCell); + I_Location sourceLocation = map.getMapLocation(this.sourceCoor); + // can move to neighboring locations or stay, unless this is an ice location, in which case can only move + List neighborLocationsIncludingCurrent = new ArrayList<>(sourceLocation.outgoingEdges()); + neighborLocationsIncludingCurrent.add(sourceLocation); - for (I_Location destination: neighborCellsIncludingCurrent) { - Move possibleMove = new Move(agent, problemStartTime + 1, sourceCell, destination); + for (I_Location destination: neighborLocationsIncludingCurrent) { + Move possibleMove = new Move(agent, problemStartTime + 1, sourceLocation, destination); if (constraints.accepts(possibleMove)) { //move not prohibited by existing constraint AStarState rootState = new AStarState(possibleMove, null, 1, 0); openList.add(rootState); @@ -299,11 +300,11 @@ private float calcH() { public void expand() { expandedNodes++; - // can move to neighboring cells or stay put - List neighborCellsIncludingCurrent = new ArrayList<>(this.move.currLocation.outgoingEdges()); - neighborCellsIncludingCurrent.add(this.move.currLocation); + // can move to neighboring locations or stay put + List neighborLocationsIncludingCurrent = new ArrayList<>(this.move.currLocation.outgoingEdges()); + neighborLocationsIncludingCurrent.add(this.move.currLocation); - for (I_Location destination: neighborCellsIncludingCurrent){ + for (I_Location destination: neighborLocationsIncludingCurrent){ Move possibleMove = new Move(this.move.agent, this.move.timeNow+1, this.move.currLocation, destination); // forbidden from performing stay moves after the time of last constraint. this makes A* complete even // when there are goal constraints (infinite) diff --git a/src/main/java/BasicCBS/Solvers/ConstraintsAndConflicts/CorridorConflict.java b/src/main/java/BasicCBS/Solvers/ConstraintsAndConflicts/CorridorConflict.java index 443827a1..2a65a422 100644 --- a/src/main/java/BasicCBS/Solvers/ConstraintsAndConflicts/CorridorConflict.java +++ b/src/main/java/BasicCBS/Solvers/ConstraintsAndConflicts/CorridorConflict.java @@ -101,7 +101,7 @@ protected int getBypassCase(int agentMinTimeWithBypass) { */ private int getMinTimeToCorridorFartherSideBypass(Agent agent, I_Location fartherSide, MAPF_Instance trimmedInstance) { // must make sure that it is reachable first. if unreachable, state-time A Star will not halt. - if(!reachableFrom(fartherSide, trimmedInstance.map.getMapCell(agent.source))){ + if(!reachableFrom(fartherSide, trimmedInstance.map.getMapLocation(agent.source))){ return Integer.MAX_VALUE; } else{ diff --git a/src/main/java/BasicCBS/Solvers/ICTS/HighLevel/ICTS_Solver.java b/src/main/java/BasicCBS/Solvers/ICTS/HighLevel/ICTS_Solver.java index 03a239e2..6c0346a6 100644 --- a/src/main/java/BasicCBS/Solvers/ICTS/HighLevel/ICTS_Solver.java +++ b/src/main/java/BasicCBS/Solvers/ICTS/HighLevel/ICTS_Solver.java @@ -260,11 +260,11 @@ protected void getHeuristic(MAPF_Instance instance) { } protected I_Location getSource(Agent agent){ - return instance.map.getMapCell(agent.source); + return instance.map.getMapLocation(agent.source); } protected I_Location getTarget(Agent agent){ - return instance.map.getMapCell(agent.target); + return instance.map.getMapLocation(agent.target); } private ICT_Node pollFromOpen() { diff --git a/src/main/java/BasicCBS/Solvers/ICTS/MDDs/MDDSearchNode.java b/src/main/java/BasicCBS/Solvers/ICTS/MDDs/MDDSearchNode.java index 238181d9..4aae9fb5 100644 --- a/src/main/java/BasicCBS/Solvers/ICTS/MDDs/MDDSearchNode.java +++ b/src/main/java/BasicCBS/Solvers/ICTS/MDDs/MDDSearchNode.java @@ -86,11 +86,11 @@ public void addParents(List parents) { } public List getNeighborLocations(){ - // can move to neighboring cells or stay put + // can move to neighboring locations or stay put I_Location currLocation = this.location; - List neighborCellsIncludingCurrent = new ArrayList<>(currLocation.outgoingEdges()); - neighborCellsIncludingCurrent.add(currLocation); //staying in the same location is possible - return neighborCellsIncludingCurrent; + List neighborLocationsIncludingCurrent = new ArrayList<>(currLocation.outgoingEdges()); + neighborLocationsIncludingCurrent.add(currLocation); //staying in the same location is possible + return neighborLocationsIncludingCurrent; } @Override diff --git a/src/main/java/BasicCBS/Solvers/Solution.java b/src/main/java/BasicCBS/Solvers/Solution.java index 8144a74a..2dd88d27 100644 --- a/src/main/java/BasicCBS/Solvers/Solution.java +++ b/src/main/java/BasicCBS/Solvers/Solution.java @@ -99,8 +99,8 @@ public boolean solves(MAPF_Instance instance){ continue; } // check start and end at source and target - if (!plan.moveAt(plan.getFirstMoveTime()).prevLocation.equals(instance.map.getMapCell(plan.agent.source)) /*start at source*/ - || !plan.moveAt(plan.getEndTime()).currLocation.equals(instance.map.getMapCell(plan.agent.target))) /*end at target*/ + if (!plan.moveAt(plan.getFirstMoveTime()).prevLocation.equals(instance.map.getMapLocation(plan.agent.source)) /*start at source*/ + || !plan.moveAt(plan.getEndTime()).currLocation.equals(instance.map.getMapLocation(plan.agent.target))) /*end at target*/ { return false; } diff --git a/src/main/java/Environment/Metrics/InstanceReport.java b/src/main/java/Environment/Metrics/InstanceReport.java index 7439bcbd..a9b41d5b 100644 --- a/src/main/java/Environment/Metrics/InstanceReport.java +++ b/src/main/java/Environment/Metrics/InstanceReport.java @@ -11,7 +11,7 @@ */ public class InstanceReport { - //max cell size of excel, plus room for wrapping with "" plus some safety + //max location size of excel, plus room for wrapping with "" plus some safety private static final int MAX_STRING_SIZE = 32767 - 12; public static final String EXTENSION_STRING = " - Extended "; diff --git a/src/test/java/BasicCBS/Instances/I_InstanceBuilderTest.java b/src/test/java/BasicCBS/Instances/I_InstanceBuilderTest.java index a3784d16..dffd631c 100644 --- a/src/test/java/BasicCBS/Instances/I_InstanceBuilderTest.java +++ b/src/test/java/BasicCBS/Instances/I_InstanceBuilderTest.java @@ -1,7 +1,7 @@ package BasicCBS.Instances; import BasicCBS.Instances.InstanceBuilders.I_InstanceBuilder; -import BasicCBS.Instances.Maps.Enum_MapCellType; +import BasicCBS.Instances.Maps.Enum_MapLocationType; import BasicCBS.Instances.Maps.MapDimensions; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; @@ -12,13 +12,13 @@ public class I_InstanceBuilderTest { - /* =Cell Types= */ + /* =Location Types= */ private final char EMPTY = '.'; private final char WALL = '@'; - private HashMap cellTypeHashMap = new HashMap<>(){{ - put(EMPTY,Enum_MapCellType.EMPTY); - put(WALL,Enum_MapCellType.WALL); + private HashMap locationTypeHashMap = new HashMap<>(){{ + put(EMPTY, Enum_MapLocationType.EMPTY); + put(WALL, Enum_MapLocationType.WALL); }}; /* =Expected value= */ @@ -63,14 +63,14 @@ public void build2D_CharacterMap_Instance_8_15_5(){ @Test - public void testObstacleCalculation_build_2D_cellTypeMap(){ + public void testObstacleCalculation_build_2D_locationTypeMap(){ InstanceProperties properties = new InstanceProperties(); InstanceProperties.ObstacleWrapper obstacle = properties.obstacles; obstacle.setMinRate(0.15); obstacle.setMaxRate(0.15); - I_InstanceBuilder.build_2D_cellTypeMap( this.charMap_Instance_8_15_5, this.cellTypeHashMap, MapDimensions.Enum_mapOrientation.Y_HORIZONTAL_X_VERTICAL, obstacle); + I_InstanceBuilder.build_2D_locationTypeMap( this.charMap_Instance_8_15_5, this.locationTypeHashMap, MapDimensions.Enum_mapOrientation.Y_HORIZONTAL_X_VERTICAL, obstacle); assertEquals( 15, obstacle.getReportPercentage()); diff --git a/src/test/java/BasicCBS/Instances/InstanceBuilder_BGUTest.java b/src/test/java/BasicCBS/Instances/InstanceBuilder_BGUTest.java index 31d013a4..eae44498 100644 --- a/src/test/java/BasicCBS/Instances/InstanceBuilder_BGUTest.java +++ b/src/test/java/BasicCBS/Instances/InstanceBuilder_BGUTest.java @@ -15,32 +15,32 @@ public class InstanceBuilder_BGUTest { private InstanceBuilder_BGU instanceBuilderBgu = new InstanceBuilder_BGU(); - private final Enum_MapCellType e = Enum_MapCellType.EMPTY; - private final Enum_MapCellType w = Enum_MapCellType.WALL; + private final Enum_MapLocationType e = Enum_MapLocationType.EMPTY; + private final Enum_MapLocationType w = Enum_MapLocationType.WALL; /* Check that map is valid */ - private boolean checkAllMapCells(Enum_MapCellType[][] expectedCellTypeMap, I_Map actualMap){ + private boolean checkAllMapLocations(Enum_MapLocationType[][] expectedLocationTypeMap, I_Map actualMap){ - for (int xAxis_value = 0; xAxis_value < expectedCellTypeMap.length; xAxis_value++) { - for (int yAxis_value = 0; yAxis_value < expectedCellTypeMap[0].length; yAxis_value++) { + for (int xAxis_value = 0; xAxis_value < expectedLocationTypeMap.length; xAxis_value++) { + for (int yAxis_value = 0; yAxis_value < expectedLocationTypeMap[0].length; yAxis_value++) { // Create coordinate I_Coordinate coordinate = new Coordinate_2D(xAxis_value, yAxis_value); - // Get the relevant mapCell - I_Location actualMapCell = actualMap.getMapCell(coordinate); + // Get the relevant mapLocation + I_Location actualMapLocation = actualMap.getMapLocation(coordinate); // Check that wall doesnt exists in actualMap - if( actualMapCell == null && expectedCellTypeMap[xAxis_value][yAxis_value] == w){ continue; } + if( actualMapLocation == null && expectedLocationTypeMap[xAxis_value][yAxis_value] == w){ continue; } - // check that actualMapCell is the same as the expectedCellTypeMap[xAxis_value][yAxis_value] - if( actualMapCell != null && actualMapCell.getType() == expectedCellTypeMap[xAxis_value][yAxis_value]){ continue; } + // check that actualMapLocation is the same as the expectedLocationTypeMap[xAxis_value][yAxis_value] + if( actualMapLocation != null && actualMapLocation.getType() == expectedLocationTypeMap[xAxis_value][yAxis_value]){ continue; } assertFalse(true); return false; // Invalid value } } - return true; // All cells are valid + return true; // All locations are valid } @@ -76,14 +76,14 @@ public void prepareInstances_Instance_16_0_7() { int yAxis_length = 16; int xAxis_length = 16; - /* =Create expected cellType Map= */ - Enum_MapCellType[][] expectedCellTypeMap = new Enum_MapCellType[xAxis_length][yAxis_length]; + /* =Create expected locationType Map= */ + Enum_MapLocationType[][] expectedLocationTypeMap = new Enum_MapLocationType[xAxis_length][yAxis_length]; for (int xIndex = 0; xIndex < xAxis_length; xIndex++) { for (int yIndex = 0; yIndex < yAxis_length; yIndex++) { - Enum_MapCellType cellType = Enum_MapCellType.EMPTY; - expectedCellTypeMap[xIndex][yIndex] = cellType; + Enum_MapLocationType locationType = Enum_MapLocationType.EMPTY; + expectedLocationTypeMap[xIndex][yIndex] = locationType; } } @@ -107,7 +107,7 @@ public void prepareInstances_Instance_16_0_7() { /* = Check map = */ I_Map actualMap = mapf_instance.map; - assertTrue(checkAllMapCells(expectedCellTypeMap,actualMap)); + assertTrue(checkAllMapLocations(expectedLocationTypeMap,actualMap)); } @@ -184,7 +184,7 @@ public void prepareInstances_Instance_8_15_5() { - /* =Create expected cellType Map= */ + /* =Create expected locationType Map= */ /* Note: Map from file ........ @@ -197,7 +197,7 @@ public void prepareInstances_Instance_8_15_5() { @..@@... */ - Enum_MapCellType[][] expectedCellTypeMap = new Enum_MapCellType[][]{ + Enum_MapLocationType[][] expectedLocationTypeMap = new Enum_MapLocationType[][]{ {e,e,e,e,e,e,e,e}, {e,e,e,e,e,e,e,e}, {e,e,e,w,e,e,e,e}, @@ -230,7 +230,7 @@ public void prepareInstances_Instance_8_15_5() { /* = Check map = */ I_Map actualMap = mapf_instance.map; - assertTrue(checkAllMapCells(expectedCellTypeMap,actualMap)); + assertTrue(checkAllMapLocations(expectedLocationTypeMap,actualMap)); } diff --git a/src/test/java/BasicCBS/Maps/MapFactoryTest.java b/src/test/java/BasicCBS/Maps/MapFactoryTest.java index 3bbc7c51..aabe10e8 100644 --- a/src/test/java/BasicCBS/Maps/MapFactoryTest.java +++ b/src/test/java/BasicCBS/Maps/MapFactoryTest.java @@ -13,8 +13,8 @@ class MapFactoryTest { - private final Enum_MapCellType e = Enum_MapCellType.EMPTY; - private final Enum_MapCellType w = Enum_MapCellType.WALL; + private final Enum_MapLocationType e = Enum_MapLocationType.EMPTY; + private final Enum_MapLocationType w = Enum_MapLocationType.WALL; @BeforeEach void setUp() { @@ -23,7 +23,7 @@ void setUp() { /* = Tests on Sample 2D Maps = */ - private Enum_MapCellType[][] map_2D_1Cell_middle = { + private Enum_MapLocationType[][] map_2D_1Location_middle = { {w, w, w, w, w, w}, {w, e, w, w, w, w}, {w, w, w, w, w, w}, @@ -32,13 +32,13 @@ void setUp() { {w, w, w, w, w, w}, }; @Test - void test_newSimple4Connected2D_GraphMap_map_2D_1Cell_middle(){ - GraphMap map = MapFactory.newSimple4Connected2D_GraphMap(map_2D_1Cell_middle); + void test_newSimple4Connected2D_GraphMap_map_2D_1Location_middle(){ + GraphMap map = MapFactory.newSimple4Connected2D_GraphMap(map_2D_1Location_middle); checkGraphMapProperties(map,1, new Coordinate_2D[]{asCoordinate2D(1,1)} ); } - private Enum_MapCellType[][] map_2D_1Cell_fringe = { + private Enum_MapLocationType[][] map_2D_1Location_fringe = { {w, w, w, w, w, w}, {e, w, w, w, w, w}, {w, w, w, w, w, w}, @@ -47,12 +47,12 @@ void test_newSimple4Connected2D_GraphMap_map_2D_1Cell_middle(){ {w, w, w, w, w, w}, }; @Test - void test_newSimple4Connected2D_GraphMap_map_2D_1Cell_fringe(){ - GraphMap map = MapFactory.newSimple4Connected2D_GraphMap(map_2D_1Cell_fringe); + void test_newSimple4Connected2D_GraphMap_map_2D_1Location_fringe(){ + GraphMap map = MapFactory.newSimple4Connected2D_GraphMap(map_2D_1Location_fringe); checkGraphMapProperties(map,1, new Coordinate_2D[]{asCoordinate2D(1,0)} ); } - private Enum_MapCellType[][] map_2D_2Cells_middle = { + private Enum_MapLocationType[][] map_2D_2Locations_middle = { {w, w, w, w, w, w}, {w, w, w, e, e, w}, {w, w, w, w, w, w}, @@ -61,14 +61,14 @@ void test_newSimple4Connected2D_GraphMap_map_2D_1Cell_fringe(){ {w, w, w, w, w, w}, }; @Test - void test_newSimple4Connected2D_GraphMap_map_2D_2Cells_middle(){ - GraphMap map = MapFactory.newSimple4Connected2D_GraphMap(map_2D_2Cells_middle); + void test_newSimple4Connected2D_GraphMap_map_2D_2Locations_middle(){ + GraphMap map = MapFactory.newSimple4Connected2D_GraphMap(map_2D_2Locations_middle); checkGraphMapProperties(map,2, new Coordinate_2D[]{asCoordinate2D(1,3), asCoordinate2D(1,4)} ); assertAreNeighbors(map, asCoordinate2D(1,3), asCoordinate2D(1,4)); } - private Enum_MapCellType[][] map_2D_2Cells_fringe = { + private Enum_MapLocationType[][] map_2D_2Locations_fringe = { {w, w, w, w, e, w}, {w, w, w, w, e, w}, {w, w, w, w, w, w}, @@ -77,14 +77,14 @@ void test_newSimple4Connected2D_GraphMap_map_2D_2Cells_middle(){ {w, w, w, w, w, w}, }; @Test - void test_newSimple4Connected2D_GraphMap_map_2D_2Cells_fringe(){ - GraphMap map = MapFactory.newSimple4Connected2D_GraphMap(map_2D_2Cells_fringe); + void test_newSimple4Connected2D_GraphMap_map_2D_2Locations_fringe(){ + GraphMap map = MapFactory.newSimple4Connected2D_GraphMap(map_2D_2Locations_fringe); checkGraphMapProperties(map,2, new Coordinate_2D[]{asCoordinate2D(0,4), asCoordinate2D(1,4)} ); assertAreNeighbors(map, asCoordinate2D(0,4), asCoordinate2D(1,4)); } - private Enum_MapCellType[][] map_2D_2Cells_diagonal = { + private Enum_MapLocationType[][] map_2D_2Locations_diagonal = { {w, w, w, w, w, w}, {w, w, w, w, w, w}, {w, w, w, w, w, w}, @@ -93,15 +93,15 @@ void test_newSimple4Connected2D_GraphMap_map_2D_2Cells_fringe(){ {w, w, w, w, w, w}, }; @Test - void test_newSimple4Connected2D_GraphMap_map_2D_2Cells_diagonal(){ - GraphMap map = MapFactory.newSimple4Connected2D_GraphMap(map_2D_2Cells_diagonal); + void test_newSimple4Connected2D_GraphMap_map_2D_2Locations_diagonal(){ + GraphMap map = MapFactory.newSimple4Connected2D_GraphMap(map_2D_2Locations_diagonal); checkGraphMapProperties(map,2, new Coordinate_2D[]{asCoordinate2D(3,2), asCoordinate2D(4,3)} ); assertNotNeighbors(map, asCoordinate2D(3,2), asCoordinate2D(4,3)); } - private Enum_MapCellType[][] map_2D_3Cells_line = { + private Enum_MapLocationType[][] map_2D_3Locations_line = { {w, w, w, e, w, w}, {w, w, w, e, w, w}, {w, w, w, e, w, w}, @@ -110,8 +110,8 @@ void test_newSimple4Connected2D_GraphMap_map_2D_2Cells_diagonal(){ {w, w, w, w, w, w}, }; @Test - void test_newSimple4Connected2D_GraphMap_map_2D_3Cells_line(){ - GraphMap map = MapFactory.newSimple4Connected2D_GraphMap(map_2D_3Cells_line); + void test_newSimple4Connected2D_GraphMap_map_2D_3Locations_line(){ + GraphMap map = MapFactory.newSimple4Connected2D_GraphMap(map_2D_3Locations_line); checkGraphMapProperties(map,3, new Coordinate_2D[]{asCoordinate2D(0, 3), asCoordinate2D(1,3), asCoordinate2D(2,3)} ); @@ -121,7 +121,7 @@ void test_newSimple4Connected2D_GraphMap_map_2D_3Cells_line(){ assertNotNeighbors(map, asCoordinate2D(0, 3), asCoordinate2D(2,3)); } - private Enum_MapCellType[][] map_2D_4cells_clump = { + private Enum_MapLocationType[][] map_2D_4locations_clump = { {w, w, w, w, w, w}, {w, w, w, e, e, w}, {w, w, w, e, e, w}, @@ -130,8 +130,8 @@ void test_newSimple4Connected2D_GraphMap_map_2D_3Cells_line(){ {w, w, w, w, w, w}, }; @Test - void test_newSimple4Connected2D_GraphMap_map_2D_4cells_clump(){ - GraphMap map = MapFactory.newSimple4Connected2D_GraphMap(map_2D_4cells_clump); + void test_newSimple4Connected2D_GraphMap_map_2D_4locations_clump(){ + GraphMap map = MapFactory.newSimple4Connected2D_GraphMap(map_2D_4locations_clump); checkGraphMapProperties(map,4, new Coordinate_2D[]{asCoordinate2D(1, 3), asCoordinate2D(2, 3), asCoordinate2D(1,4), asCoordinate2D(2,4)} ); @@ -141,7 +141,7 @@ void test_newSimple4Connected2D_GraphMap_map_2D_4cells_clump(){ assertAreNeighbors(map, asCoordinate2D(1,4), asCoordinate2D(1,3)); } - private Enum_MapCellType[][] map_2D_circle = { + private Enum_MapLocationType[][] map_2D_circle = { {w, w, w, w, w, w}, {w, w, e, e, e, w}, {w, w, e, w, e, w}, @@ -169,7 +169,7 @@ void test_newSimple4Connected2D_GraphMap_map_2D_circle(){ assertNotNeighbors(map, asCoordinate2D(2,2), asCoordinate2D(2,4)); } - private Enum_MapCellType[][] map_2D_corners = { + private Enum_MapLocationType[][] map_2D_corners = { {e, w, w, w, w, e}, {w, w, w, w, w, w}, {w, w, w, w, w, w}, @@ -184,7 +184,7 @@ void test_newSimple4Connected2D_GraphMap_map_2D_corners(){ asCoordinate2D(5,0), asCoordinate2D(0,5), asCoordinate2D(5,5)} ); } - private Enum_MapCellType[][] map_2D_disjointGroups = { + private Enum_MapLocationType[][] map_2D_disjointGroups = { {w, w, w, w, w, w}, {w, w, w, w, e, w}, {w, w, w, w, w, w}, @@ -218,7 +218,7 @@ void test_newSimple4Connected2D_GraphMap_map_2D_disjointGroups(){ assertNotNeighbors(map, asCoordinate2D(1,4), asCoordinate2D(5,5)); } - private Enum_MapCellType[][] map_2D_empty = { + private Enum_MapLocationType[][] map_2D_empty = { {e, e, e, e, e, e}, {e, e, e, e, e, e}, {e, e, e, e, e, e}, @@ -241,7 +241,7 @@ void test_newSimple4Connected2D_GraphMap_map_2D_empty(){ assertAreNeighbors(map, asCoordinate2D(2,1), asCoordinate2D(3,1)); } - private Enum_MapCellType[][] map_2D_allWalls = { + private Enum_MapLocationType[][] map_2D_allWalls = { {w, w, w, w, w, w}, {w, w, w, w, w, w}, {w, w, w, w, w, w}, @@ -258,8 +258,8 @@ void test_newSimple4Connected2D_GraphMap_map_2D_allWalls(){ /* = Utility functions = */ - static void checkGraphMapProperties(GraphMap map, int numCells, Coordinate_2D[] containsCoordinates){ - assertEquals(numCells, map.getNumMapCells()); + static void checkGraphMapProperties(GraphMap map, int numLocations, Coordinate_2D[] containsCoordinates){ + assertEquals(numLocations, map.getNumMapLocations()); for (Coordinate_2D coor: containsCoordinates){ assertTrue(map.isValidCoordinate(coor)); @@ -267,15 +267,15 @@ static void checkGraphMapProperties(GraphMap map, int numCells, Coordinate_2D[] } static void assertAreNeighbors(I_Map map, I_Coordinate coor1, I_Coordinate coor2){ - I_Location cell1 = map.getMapCell(coor1); - I_Location cell2 = map.getMapCell(coor2); - assertTrue(cell1.isNeighbor(cell2) && cell2.isNeighbor(cell1)); + I_Location location1 = map.getMapLocation(coor1); + I_Location location2 = map.getMapLocation(coor2); + assertTrue(location1.isNeighbor(location2) && location2.isNeighbor(location1)); } static void assertNotNeighbors(I_Map map, I_Coordinate coor1, I_Coordinate coor2){ - I_Location cell1 = map.getMapCell(coor1); - I_Location cell2 = map.getMapCell(coor2); - assertFalse(cell1.isNeighbor(cell2) && cell2.isNeighbor(cell1)); + I_Location location1 = map.getMapLocation(coor1); + I_Location location2 = map.getMapLocation(coor2); + assertFalse(location1.isNeighbor(location2) && location2.isNeighbor(location1)); } static Coordinate_2D asCoordinate2D(int iIndex, int jIndex){ diff --git a/src/test/java/BasicCBS/Solvers/AStar/DistanceTableAStarHeuristicTest.java b/src/test/java/BasicCBS/Solvers/AStar/DistanceTableAStarHeuristicTest.java index 7c0fa580..3f793201 100644 --- a/src/test/java/BasicCBS/Solvers/AStar/DistanceTableAStarHeuristicTest.java +++ b/src/test/java/BasicCBS/Solvers/AStar/DistanceTableAStarHeuristicTest.java @@ -14,9 +14,9 @@ public class DistanceTableAStarHeuristicTest { - final Enum_MapCellType e = Enum_MapCellType.EMPTY; - final Enum_MapCellType w = Enum_MapCellType.WALL; - Enum_MapCellType[][] map_2D_H = { + final Enum_MapLocationType e = Enum_MapLocationType.EMPTY; + final Enum_MapLocationType w = Enum_MapLocationType.WALL; + Enum_MapLocationType[][] map_2D_H = { { e, w, w, e}, { e, e, e, e}, { e, w, w, e}, @@ -33,25 +33,25 @@ private boolean equalsAllAgentMap(Map> expe for (Map.Entry> agentMapEntry: expectedValues.entrySet()){ I_Location target = agentMapEntry.getKey(); - Map expectedCellMap = expectedValues.get(target); - Map actualCellMap = actualValues.get(target); + Map expectedLocationMap = expectedValues.get(target); + Map actualLocationMap = actualValues.get(target); - if (! this.equalsAllCellMap(expectedCellMap,actualCellMap)){ + if (! this.equalsAllLocationMap(expectedLocationMap,actualLocationMap)){ return false; } } return true; } - private boolean equalsAllCellMap(Map expectedCellMap, Map actualCellMap) { - if( expectedCellMap.size() != actualCellMap.size() ){ + private boolean equalsAllLocationMap(Map expectedLocationMap, Map actualLocationMap) { + if( expectedLocationMap.size() != actualLocationMap.size() ){ return false; } - for (Map.Entry MapCellEntry: expectedCellMap.entrySet()){ + for (Map.Entry MapLocationEntry: expectedLocationMap.entrySet()){ - I_Location mapCell = MapCellEntry.getKey(); - int expectedDistance = expectedCellMap.get(mapCell); - int actualDistance = actualCellMap.get(mapCell); + I_Location mapLocation = MapLocationEntry.getKey(); + int expectedDistance = expectedLocationMap.get(mapLocation); + int actualDistance = actualLocationMap.get(mapLocation); if ( expectedDistance != actualDistance){ return false; @@ -68,8 +68,8 @@ public void test(){ Coordinate_2D[][] array=new Coordinate_2D[3][4]; for(int i=0;i> expected = new HashMap<>(); Map insideMap = new HashMap<>(); Map insideMap2 = new HashMap<>(); - insideMap.put(map.getMapCell(new Coordinate_2D(1,3)),1); - insideMap.put(map.getMapCell(new Coordinate_2D(2,3)),2); - insideMap.put(map.getMapCell(new Coordinate_2D(1,2)),2); - insideMap.put(map.getMapCell(new Coordinate_2D(1,1)),3); - insideMap.put(map.getMapCell(new Coordinate_2D(1,0)),4); - insideMap.put(map.getMapCell(new Coordinate_2D(0,0)),5); - insideMap.put(map.getMapCell(new Coordinate_2D(2,0)),5); - insideMap.put(map.getMapCell(new Coordinate_2D(0,3)),0); - - insideMap2.put(map.getMapCell(new Coordinate_2D(1,3)),1); - insideMap2.put(map.getMapCell(new Coordinate_2D(0,3)),2); - insideMap2.put(map.getMapCell(new Coordinate_2D(1,2)),2); - insideMap2.put(map.getMapCell(new Coordinate_2D(1,1)),3); - insideMap2.put(map.getMapCell(new Coordinate_2D(1,0)),4); - insideMap2.put(map.getMapCell(new Coordinate_2D(0,0)),5); - insideMap2.put(map.getMapCell(new Coordinate_2D(2,0)),5); - insideMap2.put(map.getMapCell(new Coordinate_2D(2,3)),0); - - expected.put(map.getMapCell(agent_1.target), insideMap); - expected.put(map.getMapCell(agent_2.target), insideMap2); + insideMap.put(map.getMapLocation(new Coordinate_2D(1,3)),1); + insideMap.put(map.getMapLocation(new Coordinate_2D(2,3)),2); + insideMap.put(map.getMapLocation(new Coordinate_2D(1,2)),2); + insideMap.put(map.getMapLocation(new Coordinate_2D(1,1)),3); + insideMap.put(map.getMapLocation(new Coordinate_2D(1,0)),4); + insideMap.put(map.getMapLocation(new Coordinate_2D(0,0)),5); + insideMap.put(map.getMapLocation(new Coordinate_2D(2,0)),5); + insideMap.put(map.getMapLocation(new Coordinate_2D(0,3)),0); + + insideMap2.put(map.getMapLocation(new Coordinate_2D(1,3)),1); + insideMap2.put(map.getMapLocation(new Coordinate_2D(0,3)),2); + insideMap2.put(map.getMapLocation(new Coordinate_2D(1,2)),2); + insideMap2.put(map.getMapLocation(new Coordinate_2D(1,1)),3); + insideMap2.put(map.getMapLocation(new Coordinate_2D(1,0)),4); + insideMap2.put(map.getMapLocation(new Coordinate_2D(0,0)),5); + insideMap2.put(map.getMapLocation(new Coordinate_2D(2,0)),5); + insideMap2.put(map.getMapLocation(new Coordinate_2D(2,3)),0); + + expected.put(map.getMapLocation(agent_1.target), insideMap); + expected.put(map.getMapLocation(agent_2.target), insideMap2); /* = Test actual values = */ DistanceTableAStarHeuristic distanceTableAStarHeuristic = new DistanceTableAStarHeuristic(list, map); diff --git a/src/test/java/BasicCBS/Solvers/AStar/SingleAgentAStar_SolverTest.java b/src/test/java/BasicCBS/Solvers/AStar/SingleAgentAStar_SolverTest.java index 64e254a8..888ad6a6 100644 --- a/src/test/java/BasicCBS/Solvers/AStar/SingleAgentAStar_SolverTest.java +++ b/src/test/java/BasicCBS/Solvers/AStar/SingleAgentAStar_SolverTest.java @@ -22,9 +22,9 @@ class SingleAgentAStar_SolverTest { - private final Enum_MapCellType e = Enum_MapCellType.EMPTY; - private final Enum_MapCellType w = Enum_MapCellType.WALL; - private Enum_MapCellType[][] map_2D_circle = { + private final Enum_MapLocationType e = Enum_MapLocationType.EMPTY; + private final Enum_MapLocationType w = Enum_MapLocationType.WALL; + private Enum_MapLocationType[][] map_2D_circle = { {w, w, w, w, w, w}, {w, w, e, e, e, w}, {w, w, e, w, e, w}, @@ -34,7 +34,7 @@ class SingleAgentAStar_SolverTest { }; private I_Map mapCircle = MapFactory.newSimple4Connected2D_GraphMap(map_2D_circle); - Enum_MapCellType[][] map_2D_empty = { + Enum_MapLocationType[][] map_2D_empty = { {e, e, e, e, e, e}, {e, e, e, e, e, e}, {e, e, e, e, e, e}, @@ -44,7 +44,7 @@ class SingleAgentAStar_SolverTest { }; private I_Map mapEmpty = MapFactory.newSimple4Connected2D_GraphMap(map_2D_empty); - Enum_MapCellType[][] map_2D_withPocket = { + Enum_MapLocationType[][] map_2D_withPocket = { {e, w, e, w, e, w}, {e, w, e, e, e, e}, {w, w, e, w, w, e}, @@ -71,22 +71,22 @@ class SingleAgentAStar_SolverTest { private I_Coordinate coor04 = new Coordinate_2D(0,4); private I_Coordinate coor00 = new Coordinate_2D(0,0); - private I_Location cell12Circle = mapCircle.getMapCell(coor12); - private I_Location cell13Circle = mapCircle.getMapCell(coor13); - private I_Location cell14Circle = mapCircle.getMapCell(coor14); - private I_Location cell22Circle = mapCircle.getMapCell(coor22); - private I_Location cell24Circle = mapCircle.getMapCell(coor24); - private I_Location cell32Circle = mapCircle.getMapCell(coor32); - private I_Location cell33Circle = mapCircle.getMapCell(coor33); - private I_Location cell34Circle = mapCircle.getMapCell(coor34); + private I_Location location12Circle = mapCircle.getMapLocation(coor12); + private I_Location location13Circle = mapCircle.getMapLocation(coor13); + private I_Location location14Circle = mapCircle.getMapLocation(coor14); + private I_Location location22Circle = mapCircle.getMapLocation(coor22); + private I_Location location24Circle = mapCircle.getMapLocation(coor24); + private I_Location location32Circle = mapCircle.getMapLocation(coor32); + private I_Location location33Circle = mapCircle.getMapLocation(coor33); + private I_Location location34Circle = mapCircle.getMapLocation(coor34); - private I_Location cell11 = mapCircle.getMapCell(coor11); - private I_Location cell43 = mapCircle.getMapCell(coor43); - private I_Location cell53 = mapCircle.getMapCell(coor53); - private I_Location cell05 = mapCircle.getMapCell(coor05); + private I_Location location11 = mapCircle.getMapLocation(coor11); + private I_Location location43 = mapCircle.getMapLocation(coor43); + private I_Location location53 = mapCircle.getMapLocation(coor53); + private I_Location location05 = mapCircle.getMapLocation(coor05); - private I_Location cell04 = mapCircle.getMapCell(coor04); - private I_Location cell00 = mapCircle.getMapCell(coor00); + private I_Location location04 = mapCircle.getMapLocation(coor04); + private I_Location location00 = mapCircle.getMapLocation(coor00); private Agent agent33to12 = new Agent(0, coor33, coor12); private Agent agent12to33 = new Agent(1, coor12, coor33); @@ -119,8 +119,8 @@ void oneMoveSolution() { Map plans = new HashMap<>(); SingleAgentPlan plan = new SingleAgentPlan(testInstance.agents.get(0)); - I_Location cell = testInstance.map.getMapCell(new Coordinate_2D(4,5)); - plan.addMove(new Move(testInstance.agents.get(0), 1, cell, cell)); + I_Location location = testInstance.map.getMapLocation(new Coordinate_2D(4,5)); + plan.addMove(new Move(testInstance.agents.get(0), 1, location, location)); plans.put(testInstance.agents.get(0), plan); Solution expected = new Solution(plans); @@ -135,9 +135,9 @@ void circleOptimality1(){ Solution solved = aStar.solve(testInstance, new RunParameters()); SingleAgentPlan plan = new SingleAgentPlan(agent); - plan.addMove(new Move(agent, 1, cell33Circle, cell32Circle)); - plan.addMove(new Move(agent, 2, cell32Circle, cell22Circle)); - plan.addMove(new Move(agent, 3, cell22Circle, cell12Circle)); + plan.addMove(new Move(agent, 1, location33Circle, location32Circle)); + plan.addMove(new Move(agent, 2, location32Circle, location22Circle)); + plan.addMove(new Move(agent, 3, location22Circle, location12Circle)); Solution expected = new Solution(); expected.putPlan(plan); @@ -152,7 +152,7 @@ void circleOptimalityWaitingBecauseOfConstraint1(){ Agent agent = testInstance.agents.get(0); //constraint - Constraint vertexConstraint = new Constraint(null, 1, null, cell32Circle); + Constraint vertexConstraint = new Constraint(null, 1, null, location32Circle); ConstraintSet constraints = new ConstraintSet(); constraints.add(vertexConstraint); RunParameters parameters = new RunParameters(constraints); @@ -160,10 +160,10 @@ void circleOptimalityWaitingBecauseOfConstraint1(){ Solution solved = aStar.solve(testInstance, parameters); SingleAgentPlan plan = new SingleAgentPlan(agent); - plan.addMove(new Move(agent, 1, cell33Circle, cell33Circle)); - plan.addMove(new Move(agent, 2, cell33Circle, cell32Circle)); - plan.addMove(new Move(agent, 3, cell32Circle, cell22Circle)); - plan.addMove(new Move(agent, 4, cell22Circle, cell12Circle)); + plan.addMove(new Move(agent, 1, location33Circle, location33Circle)); + plan.addMove(new Move(agent, 2, location33Circle, location32Circle)); + plan.addMove(new Move(agent, 3, location32Circle, location22Circle)); + plan.addMove(new Move(agent, 4, location22Circle, location12Circle)); Solution expected = new Solution(); expected.putPlan(plan); @@ -178,7 +178,7 @@ void circleOptimalityWaitingBecauseOfConstraint2(){ Agent agent = testInstance.agents.get(0); //constraint - Constraint vertexConstraint = new Constraint(agent, 1, null, cell32Circle); + Constraint vertexConstraint = new Constraint(agent, 1, null, location32Circle); ConstraintSet constraints = new ConstraintSet(); constraints.add(vertexConstraint); RunParameters parameters = new RunParameters(constraints); @@ -186,10 +186,10 @@ void circleOptimalityWaitingBecauseOfConstraint2(){ Solution solved = aStar.solve(testInstance, parameters); SingleAgentPlan plan = new SingleAgentPlan(agent); - plan.addMove(new Move(agent, 1, cell33Circle, cell33Circle)); - plan.addMove(new Move(agent, 2, cell33Circle, cell32Circle)); - plan.addMove(new Move(agent, 3, cell32Circle, cell22Circle)); - plan.addMove(new Move(agent, 4, cell22Circle, cell12Circle)); + plan.addMove(new Move(agent, 1, location33Circle, location33Circle)); + plan.addMove(new Move(agent, 2, location33Circle, location32Circle)); + plan.addMove(new Move(agent, 3, location32Circle, location22Circle)); + plan.addMove(new Move(agent, 4, location22Circle, location12Circle)); Solution expected = new Solution(); expected.putPlan(plan); @@ -203,7 +203,7 @@ void circleOptimalityWaitingBecauseOfConstraint3(){ Agent agent = testInstance.agents.get(0); //constraint - Constraint swappingConstraint = new Constraint(agent, 1, cell33Circle, cell32Circle); + Constraint swappingConstraint = new Constraint(agent, 1, location33Circle, location32Circle); ConstraintSet constraints = new ConstraintSet(); constraints.add(swappingConstraint); RunParameters parameters = new RunParameters(constraints); @@ -211,10 +211,10 @@ void circleOptimalityWaitingBecauseOfConstraint3(){ Solution solved = aStar.solve(testInstance, parameters); SingleAgentPlan plan = new SingleAgentPlan(agent); - plan.addMove(new Move(agent, 1, cell33Circle, cell33Circle)); - plan.addMove(new Move(agent, 2, cell33Circle, cell32Circle)); - plan.addMove(new Move(agent, 3, cell32Circle, cell22Circle)); - plan.addMove(new Move(agent, 4, cell22Circle, cell12Circle)); + plan.addMove(new Move(agent, 1, location33Circle, location33Circle)); + plan.addMove(new Move(agent, 2, location33Circle, location32Circle)); + plan.addMove(new Move(agent, 3, location32Circle, location22Circle)); + plan.addMove(new Move(agent, 4, location22Circle, location12Circle)); Solution expected = new Solution(); expected.putPlan(plan); @@ -228,9 +228,9 @@ void circleOptimalityOtherDirectionBecauseOfConstraints(){ Agent agent = testInstance.agents.get(0); //constraint - Constraint swappingConstraint1 = new Constraint(null, 1, cell33Circle, cell32Circle); - Constraint swappingConstraint2 = new Constraint(null, 2, cell33Circle, cell32Circle); - Constraint swappingConstraint3 = new Constraint(null, 3, cell33Circle, cell32Circle); + Constraint swappingConstraint1 = new Constraint(null, 1, location33Circle, location32Circle); + Constraint swappingConstraint2 = new Constraint(null, 2, location33Circle, location32Circle); + Constraint swappingConstraint3 = new Constraint(null, 3, location33Circle, location32Circle); ConstraintSet constraints = new ConstraintSet(); constraints.add(swappingConstraint1); constraints.add(swappingConstraint2); @@ -240,11 +240,11 @@ void circleOptimalityOtherDirectionBecauseOfConstraints(){ Solution solved = aStar.solve(testInstance, parameters); SingleAgentPlan plan = new SingleAgentPlan(agent); - plan.addMove(new Move(agent, 1, cell33Circle, cell34Circle)); - plan.addMove(new Move(agent, 2, cell34Circle, cell24Circle)); - plan.addMove(new Move(agent, 3, cell24Circle, cell14Circle)); - plan.addMove(new Move(agent, 4, cell14Circle, cell13Circle)); - plan.addMove(new Move(agent, 5, cell13Circle, cell12Circle)); + plan.addMove(new Move(agent, 1, location33Circle, location34Circle)); + plan.addMove(new Move(agent, 2, location34Circle, location24Circle)); + plan.addMove(new Move(agent, 3, location24Circle, location14Circle)); + plan.addMove(new Move(agent, 4, location14Circle, location13Circle)); + plan.addMove(new Move(agent, 5, location13Circle, location12Circle)); Solution expected = new Solution(); expected.putPlan(plan); @@ -261,9 +261,9 @@ void circleOptimalityNorthwestToSoutheast(){ Solution solved = aStar.solve(testInstance, new RunParameters()); SingleAgentPlan plan = new SingleAgentPlan(agent); - plan.addMove(new Move(agent, 1, cell12Circle, cell22Circle)); - plan.addMove(new Move(agent, 2, cell22Circle, cell32Circle)); - plan.addMove(new Move(agent, 3, cell32Circle, cell33Circle)); + plan.addMove(new Move(agent, 1, location12Circle, location22Circle)); + plan.addMove(new Move(agent, 2, location22Circle, location32Circle)); + plan.addMove(new Move(agent, 3, location32Circle, location33Circle)); Solution expected = new Solution(); expected.putPlan(plan); @@ -301,7 +301,7 @@ void unsolvableShouldTimeout(){ void accountsForConstraintAfterReachingGoal() { MAPF_Instance testInstance = instanceEmpty1; Agent agent = testInstance.agents.get(0); - Constraint constraintAtTimeAfterReachingGoal = new Constraint(agent,9, null, instanceEmpty1.map.getMapCell(coor05)); + Constraint constraintAtTimeAfterReachingGoal = new Constraint(agent,9, null, instanceEmpty1.map.getMapLocation(coor05)); ConstraintSet constraints = new ConstraintSet(); constraints.add(constraintAtTimeAfterReachingGoal); RunParameters runParameters = new RunParameters(constraints); @@ -316,9 +316,9 @@ void accountsForConstraintAfterReachingGoal() { void accountsForMultipleConstraintsAfterReachingGoal() { MAPF_Instance testInstance = instanceEmpty1; Agent agent = testInstance.agents.get(0); - Constraint constraintAtTimeAfterReachingGoal1 = new Constraint(agent,9, null, instanceEmpty1.map.getMapCell(coor05)); - Constraint constraintAtTimeAfterReachingGoal2 = new Constraint(agent,13, null, instanceEmpty1.map.getMapCell(coor05)); - Constraint constraintAtTimeAfterReachingGoal3 = new Constraint(agent,14, null, instanceEmpty1.map.getMapCell(coor05)); + Constraint constraintAtTimeAfterReachingGoal1 = new Constraint(agent,9, null, instanceEmpty1.map.getMapLocation(coor05)); + Constraint constraintAtTimeAfterReachingGoal2 = new Constraint(agent,13, null, instanceEmpty1.map.getMapLocation(coor05)); + Constraint constraintAtTimeAfterReachingGoal3 = new Constraint(agent,14, null, instanceEmpty1.map.getMapLocation(coor05)); ConstraintSet constraints = new ConstraintSet(); constraints.add(constraintAtTimeAfterReachingGoal1); constraints.add(constraintAtTimeAfterReachingGoal2); @@ -338,7 +338,7 @@ void accountsForMultipleConstraintsAfterReachingGoal2() { MAPF_Instance testInstance = instanceCircle2; Agent agent = testInstance.agents.get(0); - Constraint constraintAtTimeAfterReachingGoal1 = new Constraint(agent,5, null, cell33Circle); + Constraint constraintAtTimeAfterReachingGoal1 = new Constraint(agent,5, null, location33Circle); ConstraintSet constraints = new ConstraintSet(); constraints.add(constraintAtTimeAfterReachingGoal1); RunParameters runParameters = new RunParameters(constraints); @@ -346,22 +346,22 @@ void accountsForMultipleConstraintsAfterReachingGoal2() { Solution solved = aStar.solve(testInstance, runParameters); SingleAgentPlan plan1 = new SingleAgentPlan(agent); - plan1.addMove(new Move(agent, 1, cell12Circle, cell22Circle)); - plan1.addMove(new Move(agent, 2, cell22Circle, cell32Circle)); - plan1.addMove(new Move(agent, 3, cell32Circle, cell33Circle)); - plan1.addMove(new Move(agent, 4, cell33Circle, cell33Circle)); - plan1.addMove(new Move(agent, 5, cell33Circle, cell32Circle)); - plan1.addMove(new Move(agent, 6, cell32Circle, cell33Circle)); + plan1.addMove(new Move(agent, 1, location12Circle, location22Circle)); + plan1.addMove(new Move(agent, 2, location22Circle, location32Circle)); + plan1.addMove(new Move(agent, 3, location32Circle, location33Circle)); + plan1.addMove(new Move(agent, 4, location33Circle, location33Circle)); + plan1.addMove(new Move(agent, 5, location33Circle, location32Circle)); + plan1.addMove(new Move(agent, 6, location32Circle, location33Circle)); Solution expected1 = new Solution(); expected1.putPlan(plan1); SingleAgentPlan plan2 = new SingleAgentPlan(agent); - plan2.addMove(new Move(agent, 1, cell12Circle, cell22Circle)); - plan2.addMove(new Move(agent, 2, cell22Circle, cell32Circle)); - plan2.addMove(new Move(agent, 3, cell32Circle, cell33Circle)); - plan2.addMove(new Move(agent, 4, cell33Circle, cell33Circle)); - plan2.addMove(new Move(agent, 5, cell33Circle, cell34Circle)); - plan2.addMove(new Move(agent, 6, cell34Circle, cell33Circle)); + plan2.addMove(new Move(agent, 1, location12Circle, location22Circle)); + plan2.addMove(new Move(agent, 2, location22Circle, location32Circle)); + plan2.addMove(new Move(agent, 3, location32Circle, location33Circle)); + plan2.addMove(new Move(agent, 4, location33Circle, location33Circle)); + plan2.addMove(new Move(agent, 5, location33Circle, location34Circle)); + plan2.addMove(new Move(agent, 6, location34Circle, location33Circle)); Solution expected2 = new Solution(); expected2.putPlan(plan2); @@ -377,8 +377,8 @@ void continuingFromExistingPlan() { Agent agent = testInstance.agents.get(0); SingleAgentPlan existingPlan = new SingleAgentPlan(agent); - existingPlan.addMove(new Move(agent, 1, cell33Circle, cell34Circle)); - existingPlan.addMove(new Move(agent, 2, cell34Circle, cell24Circle)); + existingPlan.addMove(new Move(agent, 1, location33Circle, location34Circle)); + existingPlan.addMove(new Move(agent, 2, location34Circle, location24Circle)); Solution existingSolution = new Solution(); existingSolution.putPlan(existingPlan); @@ -386,11 +386,11 @@ void continuingFromExistingPlan() { Solution solved = aStar.solve(testInstance, new RunParameters(existingSolution)); SingleAgentPlan plan = new SingleAgentPlan(agent); - plan.addMove(new Move(agent, 1, cell33Circle, cell34Circle)); - plan.addMove(new Move(agent, 2, cell34Circle, cell24Circle)); - plan.addMove(new Move(agent, 3, cell24Circle, cell14Circle)); - plan.addMove(new Move(agent, 4, cell14Circle, cell13Circle)); - plan.addMove(new Move(agent, 5, cell13Circle, cell12Circle)); + plan.addMove(new Move(agent, 1, location33Circle, location34Circle)); + plan.addMove(new Move(agent, 2, location34Circle, location24Circle)); + plan.addMove(new Move(agent, 3, location24Circle, location14Circle)); + plan.addMove(new Move(agent, 4, location14Circle, location13Circle)); + plan.addMove(new Move(agent, 5, location13Circle, location12Circle)); Solution expected = new Solution(); expected.putPlan(plan); diff --git a/src/test/java/BasicCBS/Solvers/CBS/CBS_SolverTest.java b/src/test/java/BasicCBS/Solvers/CBS/CBS_SolverTest.java index f6a8e564..078fba95 100644 --- a/src/test/java/BasicCBS/Solvers/CBS/CBS_SolverTest.java +++ b/src/test/java/BasicCBS/Solvers/CBS/CBS_SolverTest.java @@ -30,9 +30,9 @@ class CBS_SolverTest { - private final Enum_MapCellType e = Enum_MapCellType.EMPTY; - private final Enum_MapCellType w = Enum_MapCellType.WALL; - private Enum_MapCellType[][] map_2D_circle = { + private final Enum_MapLocationType e = Enum_MapLocationType.EMPTY; + private final Enum_MapLocationType w = Enum_MapLocationType.WALL; + private Enum_MapLocationType[][] map_2D_circle = { {w, w, w, w, w, w}, {w, w, e, e, e, w}, {w, w, e, w, e, w}, @@ -42,7 +42,7 @@ class CBS_SolverTest { }; private I_Map mapCircle = MapFactory.newSimple4Connected2D_GraphMap(map_2D_circle); - Enum_MapCellType[][] map_2D_empty = { + Enum_MapLocationType[][] map_2D_empty = { {e, e, e, e, e, e}, {e, e, e, e, e, e}, {e, e, e, e, e, e}, @@ -52,7 +52,7 @@ class CBS_SolverTest { }; private I_Map mapEmpty = MapFactory.newSimple4Connected2D_GraphMap(map_2D_empty); - Enum_MapCellType[][] map_2D_withPocket = { + Enum_MapLocationType[][] map_2D_withPocket = { {e, w, e, w, e, w}, {e, w, e, e, e, e}, {w, w, e, w, w, e}, @@ -62,7 +62,7 @@ class CBS_SolverTest { }; private I_Map mapWithPocket = MapFactory.newSimple4Connected2D_GraphMap(map_2D_withPocket); - Enum_MapCellType[][] map_2D_smallMaze = { + Enum_MapLocationType[][] map_2D_smallMaze = { {e, e, e, w, e, w}, {e, w, e, e, e, e}, {e, w, e, w, w, e}, @@ -178,8 +178,8 @@ void unsolvableBecauseConstraintsShouldReturnNull1() { MAPF_Instance testInstance = instanceSmallMaze; InstanceReport instanceReport = S_Metrics.newInstanceReport(); ConstraintSet constraintSet = new ConstraintSet(); - constraintSet.add(new Constraint(agent04to00, 1, testInstance.map.getMapCell(coor04))); - constraintSet.add(new Constraint(agent04to00, 1, testInstance.map.getMapCell(coor14))); + constraintSet.add(new Constraint(agent04to00, 1, testInstance.map.getMapLocation(coor04))); + constraintSet.add(new Constraint(agent04to00, 1, testInstance.map.getMapLocation(coor14))); Solution solved = cbsSolver.solve(testInstance, new RunParameters(constraintSet, instanceReport, null)); S_Metrics.removeReport(instanceReport); @@ -191,10 +191,10 @@ void unsolvableBecauseConstraintsShouldReturnNull2() { MAPF_Instance testInstance = instanceSmallMaze; InstanceReport instanceReport = S_Metrics.newInstanceReport(); ConstraintSet constraintSet = new ConstraintSet(); - constraintSet.add(new Constraint(agent04to00, 2, testInstance.map.getMapCell(coor04))); - constraintSet.add(new Constraint(agent04to00, 2, testInstance.map.getMapCell(coor14))); - constraintSet.add(new Constraint(agent04to00, 2, testInstance.map.getMapCell(coor13))); - constraintSet.add(new Constraint(agent04to00, 2, testInstance.map.getMapCell(coor15))); + constraintSet.add(new Constraint(agent04to00, 2, testInstance.map.getMapLocation(coor04))); + constraintSet.add(new Constraint(agent04to00, 2, testInstance.map.getMapLocation(coor14))); + constraintSet.add(new Constraint(agent04to00, 2, testInstance.map.getMapLocation(coor13))); + constraintSet.add(new Constraint(agent04to00, 2, testInstance.map.getMapLocation(coor15))); Solution solved = cbsSolver.solve(testInstance, new RunParameters(constraintSet, instanceReport, null)); S_Metrics.removeReport(instanceReport); diff --git a/src/test/java/BasicCBS/Solvers/ConstraintSetTest.java b/src/test/java/BasicCBS/Solvers/ConstraintSetTest.java index d71baad1..d4cfc4d3 100644 --- a/src/test/java/BasicCBS/Solvers/ConstraintSetTest.java +++ b/src/test/java/BasicCBS/Solvers/ConstraintSetTest.java @@ -24,9 +24,9 @@ void setUp() { setWithDifferentAgentsAndPrevlocationsForSameTimeAndLocation = new ConstraintSet(); } - private final Enum_MapCellType e = Enum_MapCellType.EMPTY; - private final Enum_MapCellType w = Enum_MapCellType.WALL; - private Enum_MapCellType[][] map_2D_circle = { + private final Enum_MapLocationType e = Enum_MapLocationType.EMPTY; + private final Enum_MapLocationType w = Enum_MapLocationType.WALL; + private Enum_MapLocationType[][] map_2D_circle = { {w, w, w, w, w, w}, {w, w, e, e, e, w}, {w, w, e, w, e, w}, @@ -47,28 +47,28 @@ void acceptsForVertexConflict() { Agent agent2 = new Agent(0, coor24, coor24); // this move is just to illustrate why the constraint might exist, it isn't actually used - Move move1 = new Move(agent1, 1, map1.getMapCell(coor13), map1.getMapCell(coor14)); - Move moveConflicts = new Move(agent2, 1, map1.getMapCell(coor24), map1.getMapCell(coor14)); - Move moveDoesntConflict = new Move(agent2, 1, map1.getMapCell(coor24), map1.getMapCell(coor34)); + Move move1 = new Move(agent1, 1, map1.getMapLocation(coor13), map1.getMapLocation(coor14)); + Move moveConflicts = new Move(agent2, 1, map1.getMapLocation(coor24), map1.getMapLocation(coor14)); + Move moveDoesntConflict = new Move(agent2, 1, map1.getMapLocation(coor24), map1.getMapLocation(coor34)); - Constraint constraintHoldsSameAgent = new Constraint(agent2, 1, map1.getMapCell(coor14)); - Constraint constraintHoldsAllAgents = new Constraint(null, 1, map1.getMapCell(coor14)); + Constraint constraintHoldsSameAgent = new Constraint(agent2, 1, map1.getMapLocation(coor14)); + Constraint constraintHoldsAllAgents = new Constraint(null, 1, map1.getMapLocation(coor14)); setOfGoodConstraints.add(constraintHoldsSameAgent); - Constraint constraintDoesntHoldDifferentAgent = new Constraint(agent1, 1, map1.getMapCell(coor14)); - Constraint constraintDoesntHoldDifferentTime = new Constraint(agent2, 2, map1.getMapCell(coor14)); - Constraint constraintDoesntHoldDifferentlocation = new Constraint(agent2, 1, map1.getMapCell(coor13)); - Constraint constraintDoesntHoldPrevlocation = new Constraint(agent2, 1, map1.getMapCell(coor24)); + Constraint constraintDoesntHoldDifferentAgent = new Constraint(agent1, 1, map1.getMapLocation(coor14)); + Constraint constraintDoesntHoldDifferentTime = new Constraint(agent2, 2, map1.getMapLocation(coor14)); + Constraint constraintDoesntHoldDifferentlocation = new Constraint(agent2, 1, map1.getMapLocation(coor13)); + Constraint constraintDoesntHoldPrevlocation = new Constraint(agent2, 1, map1.getMapLocation(coor24)); setOfBadConstraints.add(constraintDoesntHoldDifferentAgent); setOfBadConstraints.add(constraintDoesntHoldDifferentTime); setOfBadConstraints.add(constraintDoesntHoldDifferentlocation); setOfBadConstraints.add(constraintDoesntHoldPrevlocation); setWithDifferentAgentsAndPrevlocationsForSameTimeAndLocation.add( - new Constraint(agent1, 1, map1.getMapCell(coor13), map1.getMapCell(coor14)) + new Constraint(agent1, 1, map1.getMapLocation(coor13), map1.getMapLocation(coor14)) ); setWithDifferentAgentsAndPrevlocationsForSameTimeAndLocation.add( - new Constraint(agent2, 1, map1.getMapCell(coor24), map1.getMapCell(coor14)) + new Constraint(agent2, 1, map1.getMapLocation(coor24), map1.getMapLocation(coor14)) ); /* =should accept= */ @@ -98,16 +98,16 @@ void acceptsForSwappingConflicts() { Agent agent2 = new Agent(0, coor24, coor24); // this move is just to illustrate why the constraint might exist, it isn't actually used - Move move1 = new Move(agent1, 1, map1.getMapCell(coor13), map1.getMapCell(coor14)); + Move move1 = new Move(agent1, 1, map1.getMapLocation(coor13), map1.getMapLocation(coor14)); - Move moveConflicts = new Move(agent2, 1, map1.getMapCell(coor14), map1.getMapCell(coor13)); - Move moveDoesntConflictOnMoveConstraint = new Move(agent2, 1, map1.getMapCell(coor12), map1.getMapCell(coor13)); + Move moveConflicts = new Move(agent2, 1, map1.getMapLocation(coor14), map1.getMapLocation(coor13)); + Move moveDoesntConflictOnMoveConstraint = new Move(agent2, 1, map1.getMapLocation(coor12), map1.getMapLocation(coor13)); - Constraint constraintHoldsSameAgent = new Constraint(agent2, 1, map1.getMapCell(coor14), map1.getMapCell(coor13)); - Constraint constraintHoldsAllAgents = new Constraint(null, 1, map1.getMapCell(coor14), map1.getMapCell(coor13)); + Constraint constraintHoldsSameAgent = new Constraint(agent2, 1, map1.getMapLocation(coor14), map1.getMapLocation(coor13)); + Constraint constraintHoldsAllAgents = new Constraint(null, 1, map1.getMapLocation(coor14), map1.getMapLocation(coor13)); setOfGoodConstraints.add(constraintHoldsSameAgent); - Constraint constraintDoesntHoldDifferentPrevlocation = new Constraint(agent2, 1, map1.getMapCell(coor12), map1.getMapCell(coor13)); + Constraint constraintDoesntHoldDifferentPrevlocation = new Constraint(agent2, 1, map1.getMapLocation(coor12), map1.getMapLocation(coor13)); setOfBadConstraints.add(constraintDoesntHoldDifferentPrevlocation); /* =should accept= */ @@ -117,10 +117,10 @@ void acceptsForSwappingConflicts() { assertTrue(setOfGoodConstraints.accepts(moveDoesntConflictOnMoveConstraint)); /* = =because the prevLocation constraint is for a different agent= */ assertTrue(setWithDifferentAgentsAndPrevlocationsForSameTimeAndLocation.accepts( - new Move(agent1, 1, map1.getMapCell(coor24), map1.getMapCell(coor14)) + new Move(agent1, 1, map1.getMapLocation(coor24), map1.getMapLocation(coor14)) )); assertTrue(setWithDifferentAgentsAndPrevlocationsForSameTimeAndLocation.accepts( - new Move(agent2, 1, map1.getMapCell(coor13), map1.getMapCell(coor14)) + new Move(agent2, 1, map1.getMapLocation(coor13), map1.getMapLocation(coor14)) )); /* =should reject (return false)= */ diff --git a/src/test/java/BasicCBS/Solvers/ConstraintTest.java b/src/test/java/BasicCBS/Solvers/ConstraintTest.java index 423dd9e9..55c0c390 100644 --- a/src/test/java/BasicCBS/Solvers/ConstraintTest.java +++ b/src/test/java/BasicCBS/Solvers/ConstraintTest.java @@ -11,9 +11,9 @@ class ConstraintTest { - private final Enum_MapCellType e = Enum_MapCellType.EMPTY; - private final Enum_MapCellType w = Enum_MapCellType.WALL; - private Enum_MapCellType[][] map_2D_circle = { + private final Enum_MapLocationType e = Enum_MapLocationType.EMPTY; + private final Enum_MapLocationType w = Enum_MapLocationType.WALL; + private Enum_MapLocationType[][] map_2D_circle = { {w, w, w, w, w, w}, {w, w, e, e, e, w}, {w, w, e, w, e, w}, @@ -34,17 +34,17 @@ void acceptsForVertexConflict() { Agent agent2 = new Agent(0, coor24, coor24); // this move is just to illustrate why the constraint might exist, it isn't actually used - Move move1 = new Move(agent1, 1, map1.getMapCell(coor13), map1.getMapCell(coor14)); - Move moveConflicts = new Move(agent2, 1, map1.getMapCell(coor24), map1.getMapCell(coor14)); - Move moveDoesntConflict = new Move(agent2, 1, map1.getMapCell(coor24), map1.getMapCell(coor34)); + Move move1 = new Move(agent1, 1, map1.getMapLocation(coor13), map1.getMapLocation(coor14)); + Move moveConflicts = new Move(agent2, 1, map1.getMapLocation(coor24), map1.getMapLocation(coor14)); + Move moveDoesntConflict = new Move(agent2, 1, map1.getMapLocation(coor24), map1.getMapLocation(coor34)); - Constraint constraintHoldsSameAgent = new Constraint(agent2, 1, map1.getMapCell(coor14)); - Constraint constraintHoldsAllAgents = new Constraint(null, 1, map1.getMapCell(coor14)); + Constraint constraintHoldsSameAgent = new Constraint(agent2, 1, map1.getMapLocation(coor14)); + Constraint constraintHoldsAllAgents = new Constraint(null, 1, map1.getMapLocation(coor14)); - Constraint constraintDoesntHoldDifferentAgent = new Constraint(agent1, 1, map1.getMapCell(coor14)); - Constraint constraintDoesntHoldDifferentTime = new Constraint(agent2, 2, map1.getMapCell(coor14)); - Constraint constraintDoesntHoldDifferentlocation = new Constraint(agent2, 1, map1.getMapCell(coor13)); - Constraint constraintDoesntHoldPrevlocation = new Constraint(agent2, 1, map1.getMapCell(coor24)); + Constraint constraintDoesntHoldDifferentAgent = new Constraint(agent1, 1, map1.getMapLocation(coor14)); + Constraint constraintDoesntHoldDifferentTime = new Constraint(agent2, 2, map1.getMapLocation(coor14)); + Constraint constraintDoesntHoldDifferentlocation = new Constraint(agent2, 1, map1.getMapLocation(coor13)); + Constraint constraintDoesntHoldPrevlocation = new Constraint(agent2, 1, map1.getMapLocation(coor24)); /* =should accept= */ /* = =because constraint doesn't hold= */ @@ -73,15 +73,15 @@ void acceptsForSwappingConflicts() { Agent agent2 = new Agent(0, coor24, coor24); // this move is just to illustrate why the constraint might exist, it isn't actually used - Move move1 = new Move(agent1, 1, map1.getMapCell(coor13), map1.getMapCell(coor14)); + Move move1 = new Move(agent1, 1, map1.getMapLocation(coor13), map1.getMapLocation(coor14)); - Move moveConflicts = new Move(agent2, 1, map1.getMapCell(coor14), map1.getMapCell(coor13)); - Move moveDoesntConflictOnMoveConstraint = new Move(agent2, 1, map1.getMapCell(coor12), map1.getMapCell(coor13)); + Move moveConflicts = new Move(agent2, 1, map1.getMapLocation(coor14), map1.getMapLocation(coor13)); + Move moveDoesntConflictOnMoveConstraint = new Move(agent2, 1, map1.getMapLocation(coor12), map1.getMapLocation(coor13)); - Constraint constraintHoldsSameAgent = new Constraint(agent2, 1, map1.getMapCell(coor14), map1.getMapCell(coor13)); - Constraint constraintHoldsAllAgents = new Constraint(null, 1, map1.getMapCell(coor14), map1.getMapCell(coor13)); + Constraint constraintHoldsSameAgent = new Constraint(agent2, 1, map1.getMapLocation(coor14), map1.getMapLocation(coor13)); + Constraint constraintHoldsAllAgents = new Constraint(null, 1, map1.getMapLocation(coor14), map1.getMapLocation(coor13)); - Constraint constraintDoesntHoldDifferentPrevlocation = new Constraint(agent2, 1, map1.getMapCell(coor12), map1.getMapCell(coor13)); + Constraint constraintDoesntHoldDifferentPrevlocation = new Constraint(agent2, 1, map1.getMapLocation(coor12), map1.getMapLocation(coor13)); /* =should accept= */ /* = =because constraint doesn't hold= */ diff --git a/src/test/java/BasicCBS/Solvers/ConstraintsAndConflicts/ConflictManagement/CorridorConflictManagerTest.java b/src/test/java/BasicCBS/Solvers/ConstraintsAndConflicts/ConflictManagement/CorridorConflictManagerTest.java index ab8d4da1..10723eb5 100644 --- a/src/test/java/BasicCBS/Solvers/ConstraintsAndConflicts/ConflictManagement/CorridorConflictManagerTest.java +++ b/src/test/java/BasicCBS/Solvers/ConstraintsAndConflicts/ConflictManagement/CorridorConflictManagerTest.java @@ -7,7 +7,7 @@ import BasicCBS.Instances.MAPF_Instance; import BasicCBS.Instances.Maps.Coordinates.Coordinate_2D; import BasicCBS.Instances.Maps.Coordinates.I_Coordinate; -import BasicCBS.Instances.Maps.Enum_MapCellType; +import BasicCBS.Instances.Maps.Enum_MapLocationType; import BasicCBS.Instances.Maps.I_Map; import BasicCBS.Instances.Maps.MapFactory; import BasicCBS.Solvers.CBS.CBS_Solver; @@ -32,9 +32,9 @@ */ class CorridorConflictManagerTest { - private final Enum_MapCellType e = Enum_MapCellType.EMPTY; - private final Enum_MapCellType w = Enum_MapCellType.WALL; - Enum_MapCellType[][] map_2D_H = { + private final Enum_MapLocationType e = Enum_MapLocationType.EMPTY; + private final Enum_MapLocationType w = Enum_MapLocationType.WALL; + Enum_MapLocationType[][] map_2D_H = { {e, w, w, e}, {e, w, w, e}, {e, e, e, e}, diff --git a/src/test/java/BasicCBS/Solvers/ConstraintsAndConflicts/ConflictManagerTest.java b/src/test/java/BasicCBS/Solvers/ConstraintsAndConflicts/ConflictManagerTest.java index de1bcf18..1e62ff0e 100644 --- a/src/test/java/BasicCBS/Solvers/ConstraintsAndConflicts/ConflictManagerTest.java +++ b/src/test/java/BasicCBS/Solvers/ConstraintsAndConflicts/ConflictManagerTest.java @@ -18,17 +18,17 @@ public class ConflictManagerTest { - private final Enum_MapCellType e = Enum_MapCellType.EMPTY; - private final Enum_MapCellType w = Enum_MapCellType.WALL; - private Enum_MapCellType[][] map_2D_H = { + private final Enum_MapLocationType e = Enum_MapLocationType.EMPTY; + private final Enum_MapLocationType w = Enum_MapLocationType.WALL; + private Enum_MapLocationType[][] map_2D_H = { { e, w, w, e}, { e, e, e, e}, { e, w, w, e}, }; private I_Map mapH = MapFactory.newSimple4Connected2D_GraphMap(map_2D_H); - private Enum_MapCellType[][] twoCellMap = new Enum_MapCellType[][]{{e,e}}; - private I_Map mapTwoCells = MapFactory.newSimple4Connected2D_GraphMap(twoCellMap); + private Enum_MapLocationType[][] twoLocationMap = new Enum_MapLocationType[][]{{e,e}}; + private I_Map mapTwoLocations = MapFactory.newSimple4Connected2D_GraphMap(twoLocationMap); @@ -52,11 +52,11 @@ public void goalConflict(){ Agent a1 = new Agent(1,new Coordinate_2D(0,0),new Coordinate_2D(0,1)); SingleAgentPlan a1_plan; ArrayList a1_moves = new ArrayList<>(); - a1_moves.add(new Move(a1,1, this.mapTwoCells.getMapCell(new Coordinate_2D(0,0)), this.mapTwoCells.getMapCell(new Coordinate_2D(0,0)))); - a1_moves.add(new Move(a1,2, this.mapTwoCells.getMapCell(new Coordinate_2D(0,0)), this.mapTwoCells.getMapCell(new Coordinate_2D(0,0)))); - a1_moves.add(new Move(a1,3, this.mapTwoCells.getMapCell(new Coordinate_2D(0,0)), this.mapTwoCells.getMapCell(new Coordinate_2D(0,0)))); - a1_moves.add(new Move(a1,4, this.mapTwoCells.getMapCell(new Coordinate_2D(0,0)), this.mapTwoCells.getMapCell(new Coordinate_2D(0,0)))); - a1_moves.add(new Move(a1,5, this.mapTwoCells.getMapCell(new Coordinate_2D(0,0)), this.mapTwoCells.getMapCell(new Coordinate_2D(0,1)))); + a1_moves.add(new Move(a1,1, this.mapTwoLocations.getMapLocation(new Coordinate_2D(0,0)), this.mapTwoLocations.getMapLocation(new Coordinate_2D(0,0)))); + a1_moves.add(new Move(a1,2, this.mapTwoLocations.getMapLocation(new Coordinate_2D(0,0)), this.mapTwoLocations.getMapLocation(new Coordinate_2D(0,0)))); + a1_moves.add(new Move(a1,3, this.mapTwoLocations.getMapLocation(new Coordinate_2D(0,0)), this.mapTwoLocations.getMapLocation(new Coordinate_2D(0,0)))); + a1_moves.add(new Move(a1,4, this.mapTwoLocations.getMapLocation(new Coordinate_2D(0,0)), this.mapTwoLocations.getMapLocation(new Coordinate_2D(0,0)))); + a1_moves.add(new Move(a1,5, this.mapTwoLocations.getMapLocation(new Coordinate_2D(0,0)), this.mapTwoLocations.getMapLocation(new Coordinate_2D(0,1)))); a1_plan = new SingleAgentPlan(a1,a1_moves); conflictAvoidanceTable.addPlan(a1_plan); @@ -73,7 +73,7 @@ public void goalConflict(){ Agent a2 = new Agent(2,new Coordinate_2D(0,1),new Coordinate_2D(0,1)); SingleAgentPlan a2_plan; ArrayList a2_moves = new ArrayList<>(); - a2_moves.add(new Move(a2,1, this.mapTwoCells.getMapCell(new Coordinate_2D(0,1)), mapTwoCells.getMapCell(new Coordinate_2D(0,1)))); + a2_moves.add(new Move(a2,1, this.mapTwoLocations.getMapLocation(new Coordinate_2D(0,1)), mapTwoLocations.getMapLocation(new Coordinate_2D(0,1)))); a2_plan = new SingleAgentPlan(a2,a2_moves); @@ -82,7 +82,7 @@ public void goalConflict(){ /* == Expected conflicts == */ - VertexConflict expectedGoalConflict = new VertexConflict(a1, a2, 5, this.mapTwoCells.getMapCell(new Coordinate_2D(0,1))); + VertexConflict expectedGoalConflict = new VertexConflict(a1, a2, 5, this.mapTwoLocations.getMapLocation(new Coordinate_2D(0,1))); HashSet expectedSet = new HashSet<>(); expectedSet.add(expectedGoalConflict); @@ -98,7 +98,7 @@ public void goalConflict(){ @Test - public void swappingConflict2CellMap(){ + public void swappingConflict2LocationMap(){ ConflictManager conflictAvoidanceTable = new ConflictManager(new MinTimeConflictSelectionStrategy()); @@ -112,7 +112,7 @@ public void swappingConflict2CellMap(){ Agent a1 = new Agent(1,new Coordinate_2D(0,0),new Coordinate_2D(0,1)); SingleAgentPlan a1_plan; ArrayList a1_moves = new ArrayList<>(); - a1_moves.add(new Move(a1,1, this.mapTwoCells.getMapCell(new Coordinate_2D(0,0)), this.mapTwoCells.getMapCell(new Coordinate_2D(0,1)))); + a1_moves.add(new Move(a1,1, this.mapTwoLocations.getMapLocation(new Coordinate_2D(0,0)), this.mapTwoLocations.getMapLocation(new Coordinate_2D(0,1)))); a1_plan = new SingleAgentPlan(a1,a1_moves); conflictAvoidanceTable.addPlan(a1_plan); @@ -128,7 +128,7 @@ public void swappingConflict2CellMap(){ Agent a2 = new Agent(2,new Coordinate_2D(0,1),new Coordinate_2D(0,0)); SingleAgentPlan a2_plan; ArrayList a2_moves = new ArrayList<>(); - a2_moves.add(new Move(a2,1, this.mapTwoCells.getMapCell(new Coordinate_2D(0,1)), mapTwoCells.getMapCell(new Coordinate_2D(0,0)))); + a2_moves.add(new Move(a2,1, this.mapTwoLocations.getMapLocation(new Coordinate_2D(0,1)), mapTwoLocations.getMapLocation(new Coordinate_2D(0,0)))); a2_plan = new SingleAgentPlan(a2,a2_moves); @@ -137,7 +137,7 @@ public void swappingConflict2CellMap(){ /* == Expected conflicts == */ - SwappingConflict expectedConflict_time1 = new SwappingConflict(a1,a2,1, this.mapTwoCells.getMapCell(new Coordinate_2D(0,1)), this.mapTwoCells.getMapCell(new Coordinate_2D(0,0))); + SwappingConflict expectedConflict_time1 = new SwappingConflict(a1,a2,1, this.mapTwoLocations.getMapLocation(new Coordinate_2D(0,1)), this.mapTwoLocations.getMapLocation(new Coordinate_2D(0,0))); HashSet expectedSet = new HashSet<>(); expectedSet.add(expectedConflict_time1); @@ -164,18 +164,18 @@ public void TwoAgentsWith4VertexConflicts_graphH() { T = Time S = Start G = Goal - EE = Empty cell + EE = Empty location WW = Wall */ Agent a1 = new Agent(1,new Coordinate_2D(0,0),new Coordinate_2D(0,3)); SingleAgentPlan a1_plan; ArrayList a1_moves = new ArrayList<>(); - a1_moves.add(new Move(a1,1, mapH.getMapCell(new Coordinate_2D(0,0)),mapH.getMapCell(new Coordinate_2D(1,0)))); - a1_moves.add(new Move(a1,2, mapH.getMapCell(new Coordinate_2D(1,0)),mapH.getMapCell(new Coordinate_2D(1,1)))); - a1_moves.add(new Move(a1,3, mapH.getMapCell(new Coordinate_2D(1,1)),mapH.getMapCell(new Coordinate_2D(1,2)))); - a1_moves.add(new Move(a1,4, mapH.getMapCell(new Coordinate_2D(1,2)),mapH.getMapCell(new Coordinate_2D(1,3)))); - a1_moves.add(new Move(a1,5, mapH.getMapCell(new Coordinate_2D(1,3)),mapH.getMapCell(new Coordinate_2D(0,3)))); + a1_moves.add(new Move(a1,1, mapH.getMapLocation(new Coordinate_2D(0,0)),mapH.getMapLocation(new Coordinate_2D(1,0)))); + a1_moves.add(new Move(a1,2, mapH.getMapLocation(new Coordinate_2D(1,0)),mapH.getMapLocation(new Coordinate_2D(1,1)))); + a1_moves.add(new Move(a1,3, mapH.getMapLocation(new Coordinate_2D(1,1)),mapH.getMapLocation(new Coordinate_2D(1,2)))); + a1_moves.add(new Move(a1,4, mapH.getMapLocation(new Coordinate_2D(1,2)),mapH.getMapLocation(new Coordinate_2D(1,3)))); + a1_moves.add(new Move(a1,5, mapH.getMapLocation(new Coordinate_2D(1,3)),mapH.getMapLocation(new Coordinate_2D(0,3)))); a1_plan = new SingleAgentPlan(a1,a1_moves); conflictAvoidanceTable.addPlan(a1_plan); @@ -187,18 +187,18 @@ public void TwoAgentsWith4VertexConflicts_graphH() { T = Time S = Start G = Goal - EE = Empty cell + EE = Empty location WW = Wall */ Agent a2 = new Agent(2,new Coordinate_2D(2,0),new Coordinate_2D(2,3)); SingleAgentPlan a2_plan; ArrayList a2_moves = new ArrayList<>(); - a2_moves.add(new Move(a2,1, mapH.getMapCell(new Coordinate_2D(2,0)), mapH.getMapCell(new Coordinate_2D(1,0)))); - a2_moves.add(new Move(a2,2, mapH.getMapCell(new Coordinate_2D(1,0)), mapH.getMapCell(new Coordinate_2D(1,1)))); - a2_moves.add(new Move(a2,3, mapH.getMapCell(new Coordinate_2D(1,1)), mapH.getMapCell(new Coordinate_2D(1,2)))); - a2_moves.add(new Move(a2,4, mapH.getMapCell(new Coordinate_2D(1,2)), mapH.getMapCell(new Coordinate_2D(1,3)))); - a2_moves.add(new Move(a2,5, mapH.getMapCell(new Coordinate_2D(1,3)), mapH.getMapCell(new Coordinate_2D(2,3)))); + a2_moves.add(new Move(a2,1, mapH.getMapLocation(new Coordinate_2D(2,0)), mapH.getMapLocation(new Coordinate_2D(1,0)))); + a2_moves.add(new Move(a2,2, mapH.getMapLocation(new Coordinate_2D(1,0)), mapH.getMapLocation(new Coordinate_2D(1,1)))); + a2_moves.add(new Move(a2,3, mapH.getMapLocation(new Coordinate_2D(1,1)), mapH.getMapLocation(new Coordinate_2D(1,2)))); + a2_moves.add(new Move(a2,4, mapH.getMapLocation(new Coordinate_2D(1,2)), mapH.getMapLocation(new Coordinate_2D(1,3)))); + a2_moves.add(new Move(a2,5, mapH.getMapLocation(new Coordinate_2D(1,3)), mapH.getMapLocation(new Coordinate_2D(2,3)))); a2_plan = new SingleAgentPlan(a2,a2_moves); conflictAvoidanceTable.addPlan(a2_plan); @@ -221,52 +221,52 @@ public void TwoAgentsWith4VertexConflicts_graphH() { Map> expected_timeLocationAgents = new HashMap<>(); // Agent 1 - TimeLocation time0_a1 = new TimeLocation(0, mapH.getMapCell(new Coordinate_2D(0,0))); + TimeLocation time0_a1 = new TimeLocation(0, mapH.getMapLocation(new Coordinate_2D(0,0))); expected_timeLocationAgents.computeIfAbsent(time0_a1,k -> new HashSet()); expected_timeLocationAgents.get(time0_a1).add(a1); - TimeLocation time1_a1 = new TimeLocation(1, mapH.getMapCell(new Coordinate_2D(1,0))); + TimeLocation time1_a1 = new TimeLocation(1, mapH.getMapLocation(new Coordinate_2D(1,0))); expected_timeLocationAgents.computeIfAbsent(time1_a1,k -> new HashSet()); expected_timeLocationAgents.get(time1_a1).add(a1); - TimeLocation time2_a1 = new TimeLocation(2, mapH.getMapCell(new Coordinate_2D(1,1))); + TimeLocation time2_a1 = new TimeLocation(2, mapH.getMapLocation(new Coordinate_2D(1,1))); expected_timeLocationAgents.computeIfAbsent(time2_a1,k -> new HashSet()); expected_timeLocationAgents.get(time2_a1).add(a1); - TimeLocation time3_a1 = new TimeLocation(3, mapH.getMapCell(new Coordinate_2D(1,2))); + TimeLocation time3_a1 = new TimeLocation(3, mapH.getMapLocation(new Coordinate_2D(1,2))); expected_timeLocationAgents.computeIfAbsent(time3_a1,k -> new HashSet()); expected_timeLocationAgents.get(time3_a1).add(a1); - TimeLocation time4_a1 = new TimeLocation(4, mapH.getMapCell(new Coordinate_2D(1,3))); + TimeLocation time4_a1 = new TimeLocation(4, mapH.getMapLocation(new Coordinate_2D(1,3))); expected_timeLocationAgents.computeIfAbsent(time4_a1,k -> new HashSet()); expected_timeLocationAgents.get(time4_a1).add(a1); - TimeLocation time5_a1 = new TimeLocation(5, mapH.getMapCell(new Coordinate_2D(0,3))); + TimeLocation time5_a1 = new TimeLocation(5, mapH.getMapLocation(new Coordinate_2D(0,3))); expected_timeLocationAgents.computeIfAbsent(time5_a1,k -> new HashSet()); expected_timeLocationAgents.get(time5_a1).add(a1); // Agent 2 - TimeLocation time0_a2 = new TimeLocation(0, mapH.getMapCell(new Coordinate_2D(2,0))); + TimeLocation time0_a2 = new TimeLocation(0, mapH.getMapLocation(new Coordinate_2D(2,0))); expected_timeLocationAgents.computeIfAbsent(time0_a2,k -> new HashSet()); expected_timeLocationAgents.get(time0_a2).add(a2); - TimeLocation time1_a2 = new TimeLocation(1, mapH.getMapCell(new Coordinate_2D(1,0))); + TimeLocation time1_a2 = new TimeLocation(1, mapH.getMapLocation(new Coordinate_2D(1,0))); expected_timeLocationAgents.computeIfAbsent(time1_a2,k -> new HashSet()); expected_timeLocationAgents.get(time1_a2).add(a2); - TimeLocation time2_a2 = new TimeLocation(2, mapH.getMapCell(new Coordinate_2D(1,1))); + TimeLocation time2_a2 = new TimeLocation(2, mapH.getMapLocation(new Coordinate_2D(1,1))); expected_timeLocationAgents.computeIfAbsent(time2_a2,k -> new HashSet()); expected_timeLocationAgents.get(time2_a2).add(a2); - TimeLocation time3_a2 = new TimeLocation(3, mapH.getMapCell(new Coordinate_2D(1,2))); + TimeLocation time3_a2 = new TimeLocation(3, mapH.getMapLocation(new Coordinate_2D(1,2))); expected_timeLocationAgents.computeIfAbsent(time3_a2,k -> new HashSet()); expected_timeLocationAgents.get(time3_a2).add(a2); - TimeLocation time4_a2 = new TimeLocation(4, mapH.getMapCell(new Coordinate_2D(1,3))); + TimeLocation time4_a2 = new TimeLocation(4, mapH.getMapLocation(new Coordinate_2D(1,3))); expected_timeLocationAgents.computeIfAbsent(time4_a2,k -> new HashSet()); expected_timeLocationAgents.get(time4_a2).add(a2); - TimeLocation time5_a2 = new TimeLocation(5, mapH.getMapCell(new Coordinate_2D(2,3))); + TimeLocation time5_a2 = new TimeLocation(5, mapH.getMapLocation(new Coordinate_2D(2,3))); expected_timeLocationAgents.computeIfAbsent(time5_a2,k -> new HashSet()); expected_timeLocationAgents.get(time5_a2).add(a2); /* == Expected conflicts == */ - VertexConflict expectedConflict_time1 = new VertexConflict(a1,a2,1,mapH.getMapCell(new Coordinate_2D(1,0))); - VertexConflict expectedConflict_time2 = new VertexConflict(a1,a2,2,mapH.getMapCell(new Coordinate_2D(1,1))); - VertexConflict expectedConflict_time3 = new VertexConflict(a1,a2,3,mapH.getMapCell(new Coordinate_2D(1,2))); - VertexConflict expectedConflict_time4 = new VertexConflict(a1,a2,4,mapH.getMapCell(new Coordinate_2D(1,3))); + VertexConflict expectedConflict_time1 = new VertexConflict(a1,a2,1,mapH.getMapLocation(new Coordinate_2D(1,0))); + VertexConflict expectedConflict_time2 = new VertexConflict(a1,a2,2,mapH.getMapLocation(new Coordinate_2D(1,1))); + VertexConflict expectedConflict_time3 = new VertexConflict(a1,a2,3,mapH.getMapLocation(new Coordinate_2D(1,2))); + VertexConflict expectedConflict_time4 = new VertexConflict(a1,a2,4,mapH.getMapLocation(new Coordinate_2D(1,3))); HashSet expectedSet = new HashSet<>(); expectedSet.add(expectedConflict_time1); @@ -294,12 +294,12 @@ public void TwoAgentsWith4VertexConflicts_graphH() { SingleAgentPlan a1_newPlan; ArrayList a1_newMoves = new ArrayList<>(); - a1_newMoves.add(new Move(a1,1, mapH.getMapCell(new Coordinate_2D(0,0)),mapH.getMapCell(new Coordinate_2D(0,0)))); - a1_newMoves.add(new Move(a1,2, mapH.getMapCell(new Coordinate_2D(0,0)),mapH.getMapCell(new Coordinate_2D(1,0)))); - a1_newMoves.add(new Move(a1,3, mapH.getMapCell(new Coordinate_2D(1,0)),mapH.getMapCell(new Coordinate_2D(1,1)))); - a1_newMoves.add(new Move(a1,4, mapH.getMapCell(new Coordinate_2D(1,1)),mapH.getMapCell(new Coordinate_2D(1,2)))); - a1_newMoves.add(new Move(a1,5, mapH.getMapCell(new Coordinate_2D(1,2)),mapH.getMapCell(new Coordinate_2D(1,3)))); - a1_newMoves.add(new Move(a1,6, mapH.getMapCell(new Coordinate_2D(1,3)),mapH.getMapCell(new Coordinate_2D(0,3)))); + a1_newMoves.add(new Move(a1,1, mapH.getMapLocation(new Coordinate_2D(0,0)),mapH.getMapLocation(new Coordinate_2D(0,0)))); + a1_newMoves.add(new Move(a1,2, mapH.getMapLocation(new Coordinate_2D(0,0)),mapH.getMapLocation(new Coordinate_2D(1,0)))); + a1_newMoves.add(new Move(a1,3, mapH.getMapLocation(new Coordinate_2D(1,0)),mapH.getMapLocation(new Coordinate_2D(1,1)))); + a1_newMoves.add(new Move(a1,4, mapH.getMapLocation(new Coordinate_2D(1,1)),mapH.getMapLocation(new Coordinate_2D(1,2)))); + a1_newMoves.add(new Move(a1,5, mapH.getMapLocation(new Coordinate_2D(1,2)),mapH.getMapLocation(new Coordinate_2D(1,3)))); + a1_newMoves.add(new Move(a1,6, mapH.getMapLocation(new Coordinate_2D(1,3)),mapH.getMapLocation(new Coordinate_2D(0,3)))); a1_newPlan = new SingleAgentPlan(a1,a1_newMoves); copiedTable.addPlan(a1_newPlan); @@ -335,18 +335,18 @@ public void TwoAgentsWith1SwappingConflict_graphH() { T = Time S = Start G = Goal - EE = Empty cell + EE = Empty location WW = Wall */ Agent a1 = new Agent(1,new Coordinate_2D(0,0),new Coordinate_2D(0,3)); SingleAgentPlan a1_plan; ArrayList a1_moves = new ArrayList<>(); - a1_moves.add(new Move(a1,1, mapH.getMapCell(new Coordinate_2D(0,0)),mapH.getMapCell(new Coordinate_2D(1,0)))); - a1_moves.add(new Move(a1,2, mapH.getMapCell(new Coordinate_2D(1,0)),mapH.getMapCell(new Coordinate_2D(1,1)))); - a1_moves.add(new Move(a1,3, mapH.getMapCell(new Coordinate_2D(1,1)),mapH.getMapCell(new Coordinate_2D(1,2)))); - a1_moves.add(new Move(a1,4, mapH.getMapCell(new Coordinate_2D(1,2)),mapH.getMapCell(new Coordinate_2D(1,3)))); - a1_moves.add(new Move(a1,5, mapH.getMapCell(new Coordinate_2D(1,3)),mapH.getMapCell(new Coordinate_2D(0,3)))); + a1_moves.add(new Move(a1,1, mapH.getMapLocation(new Coordinate_2D(0,0)),mapH.getMapLocation(new Coordinate_2D(1,0)))); + a1_moves.add(new Move(a1,2, mapH.getMapLocation(new Coordinate_2D(1,0)),mapH.getMapLocation(new Coordinate_2D(1,1)))); + a1_moves.add(new Move(a1,3, mapH.getMapLocation(new Coordinate_2D(1,1)),mapH.getMapLocation(new Coordinate_2D(1,2)))); + a1_moves.add(new Move(a1,4, mapH.getMapLocation(new Coordinate_2D(1,2)),mapH.getMapLocation(new Coordinate_2D(1,3)))); + a1_moves.add(new Move(a1,5, mapH.getMapLocation(new Coordinate_2D(1,3)),mapH.getMapLocation(new Coordinate_2D(0,3)))); a1_plan = new SingleAgentPlan(a1,a1_moves); conflictAvoidanceTable.addPlan(a1_plan); @@ -359,18 +359,18 @@ public void TwoAgentsWith1SwappingConflict_graphH() { T = Time S = Start G = Goal - EE = Empty cell + EE = Empty location WW = Wall */ Agent a2 = new Agent(2,new Coordinate_2D(2,3),new Coordinate_2D(2,0)); SingleAgentPlan a2_plan; ArrayList a2_moves = new ArrayList<>(); - a2_moves.add(new Move(a2,1, mapH.getMapCell(new Coordinate_2D(2,3)), mapH.getMapCell(new Coordinate_2D(1,3)))); - a2_moves.add(new Move(a2,2, mapH.getMapCell(new Coordinate_2D(1,3)), mapH.getMapCell(new Coordinate_2D(1,2)))); - a2_moves.add(new Move(a2,3, mapH.getMapCell(new Coordinate_2D(1,2)), mapH.getMapCell(new Coordinate_2D(1,1)))); - a2_moves.add(new Move(a2,4, mapH.getMapCell(new Coordinate_2D(1,1)), mapH.getMapCell(new Coordinate_2D(1,0)))); - a2_moves.add(new Move(a2,5, mapH.getMapCell(new Coordinate_2D(1,0)), mapH.getMapCell(new Coordinate_2D(2,0)))); + a2_moves.add(new Move(a2,1, mapH.getMapLocation(new Coordinate_2D(2,3)), mapH.getMapLocation(new Coordinate_2D(1,3)))); + a2_moves.add(new Move(a2,2, mapH.getMapLocation(new Coordinate_2D(1,3)), mapH.getMapLocation(new Coordinate_2D(1,2)))); + a2_moves.add(new Move(a2,3, mapH.getMapLocation(new Coordinate_2D(1,2)), mapH.getMapLocation(new Coordinate_2D(1,1)))); + a2_moves.add(new Move(a2,4, mapH.getMapLocation(new Coordinate_2D(1,1)), mapH.getMapLocation(new Coordinate_2D(1,0)))); + a2_moves.add(new Move(a2,5, mapH.getMapLocation(new Coordinate_2D(1,0)), mapH.getMapLocation(new Coordinate_2D(2,0)))); a2_plan = new SingleAgentPlan(a2,a2_moves); conflictAvoidanceTable.addPlan(a2_plan); @@ -393,49 +393,49 @@ public void TwoAgentsWith1SwappingConflict_graphH() { Map> expected_timeLocationAgents = new HashMap<>(); // Agent 1 - TimeLocation time0_a1 = new TimeLocation(0, mapH.getMapCell(new Coordinate_2D(0,0))); + TimeLocation time0_a1 = new TimeLocation(0, mapH.getMapLocation(new Coordinate_2D(0,0))); expected_timeLocationAgents.computeIfAbsent(time0_a1,k -> new HashSet()); expected_timeLocationAgents.get(time0_a1).add(a1); - TimeLocation time1_a1 = new TimeLocation(1, mapH.getMapCell(new Coordinate_2D(1,0))); + TimeLocation time1_a1 = new TimeLocation(1, mapH.getMapLocation(new Coordinate_2D(1,0))); expected_timeLocationAgents.computeIfAbsent(time1_a1,k -> new HashSet()); expected_timeLocationAgents.get(time1_a1).add(a1); - TimeLocation time2_a1 = new TimeLocation(2, mapH.getMapCell(new Coordinate_2D(1,1))); + TimeLocation time2_a1 = new TimeLocation(2, mapH.getMapLocation(new Coordinate_2D(1,1))); expected_timeLocationAgents.computeIfAbsent(time2_a1,k -> new HashSet()); expected_timeLocationAgents.get(time2_a1).add(a1); - TimeLocation time3_a1 = new TimeLocation(3, mapH.getMapCell(new Coordinate_2D(1,2))); + TimeLocation time3_a1 = new TimeLocation(3, mapH.getMapLocation(new Coordinate_2D(1,2))); expected_timeLocationAgents.computeIfAbsent(time3_a1,k -> new HashSet()); expected_timeLocationAgents.get(time3_a1).add(a1); - TimeLocation time4_a1 = new TimeLocation(4, mapH.getMapCell(new Coordinate_2D(1,3))); + TimeLocation time4_a1 = new TimeLocation(4, mapH.getMapLocation(new Coordinate_2D(1,3))); expected_timeLocationAgents.computeIfAbsent(time4_a1,k -> new HashSet()); expected_timeLocationAgents.get(time4_a1).add(a1); - TimeLocation time5_a1 = new TimeLocation(5, mapH.getMapCell(new Coordinate_2D(0,3))); + TimeLocation time5_a1 = new TimeLocation(5, mapH.getMapLocation(new Coordinate_2D(0,3))); expected_timeLocationAgents.computeIfAbsent(time5_a1,k -> new HashSet()); expected_timeLocationAgents.get(time5_a1).add(a1); // Agent 2 - TimeLocation time0_a2 = new TimeLocation(0, mapH.getMapCell(new Coordinate_2D(2,3))); + TimeLocation time0_a2 = new TimeLocation(0, mapH.getMapLocation(new Coordinate_2D(2,3))); expected_timeLocationAgents.computeIfAbsent(time0_a2,k -> new HashSet()); expected_timeLocationAgents.get(time0_a2).add(a2); - TimeLocation time1_a2 = new TimeLocation(1, mapH.getMapCell(new Coordinate_2D(1,3))); + TimeLocation time1_a2 = new TimeLocation(1, mapH.getMapLocation(new Coordinate_2D(1,3))); expected_timeLocationAgents.computeIfAbsent(time1_a2,k -> new HashSet()); expected_timeLocationAgents.get(time1_a2).add(a2); - TimeLocation time2_a2 = new TimeLocation(2, mapH.getMapCell(new Coordinate_2D(1,2))); + TimeLocation time2_a2 = new TimeLocation(2, mapH.getMapLocation(new Coordinate_2D(1,2))); expected_timeLocationAgents.computeIfAbsent(time2_a2,k -> new HashSet()); expected_timeLocationAgents.get(time2_a2).add(a2); - TimeLocation time3_a2 = new TimeLocation(3, mapH.getMapCell(new Coordinate_2D(1,1))); + TimeLocation time3_a2 = new TimeLocation(3, mapH.getMapLocation(new Coordinate_2D(1,1))); expected_timeLocationAgents.computeIfAbsent(time3_a2,k -> new HashSet()); expected_timeLocationAgents.get(time3_a2).add(a2); - TimeLocation time4_a2 = new TimeLocation(4, mapH.getMapCell(new Coordinate_2D(1,0))); + TimeLocation time4_a2 = new TimeLocation(4, mapH.getMapLocation(new Coordinate_2D(1,0))); expected_timeLocationAgents.computeIfAbsent(time4_a2,k -> new HashSet()); expected_timeLocationAgents.get(time4_a2).add(a2); - TimeLocation time5_a2 = new TimeLocation(5, mapH.getMapCell(new Coordinate_2D(2,0))); + TimeLocation time5_a2 = new TimeLocation(5, mapH.getMapLocation(new Coordinate_2D(2,0))); expected_timeLocationAgents.computeIfAbsent(time5_a2,k -> new HashSet()); expected_timeLocationAgents.get(time5_a2).add(a2); /* == Expected conflicts == */ - SwappingConflict expectedConflict_time3 = new SwappingConflict(a1,a2,3,mapH.getMapCell(new Coordinate_2D(1,2)),mapH.getMapCell(new Coordinate_2D(1,1))); + SwappingConflict expectedConflict_time3 = new SwappingConflict(a1,a2,3,mapH.getMapLocation(new Coordinate_2D(1,2)),mapH.getMapLocation(new Coordinate_2D(1,1))); HashSet expectedSet = new HashSet<>(); expectedSet.add(expectedConflict_time3); @@ -461,12 +461,12 @@ public void TwoAgentsWith1SwappingConflict_graphH() { SingleAgentPlan a1_newPlan; ArrayList a1_newMoves = new ArrayList<>(); - a1_newMoves.add(new Move(a1,1, mapH.getMapCell(new Coordinate_2D(0,0)),mapH.getMapCell(new Coordinate_2D(0,0)))); - a1_newMoves.add(new Move(a1,2, mapH.getMapCell(new Coordinate_2D(0,0)),mapH.getMapCell(new Coordinate_2D(1,0)))); - a1_newMoves.add(new Move(a1,3, mapH.getMapCell(new Coordinate_2D(1,0)),mapH.getMapCell(new Coordinate_2D(1,1)))); - a1_newMoves.add(new Move(a1,4, mapH.getMapCell(new Coordinate_2D(1,1)),mapH.getMapCell(new Coordinate_2D(1,2)))); - a1_newMoves.add(new Move(a1,5, mapH.getMapCell(new Coordinate_2D(1,2)),mapH.getMapCell(new Coordinate_2D(1,3)))); - a1_newMoves.add(new Move(a1,6, mapH.getMapCell(new Coordinate_2D(1,3)),mapH.getMapCell(new Coordinate_2D(0,3)))); + a1_newMoves.add(new Move(a1,1, mapH.getMapLocation(new Coordinate_2D(0,0)),mapH.getMapLocation(new Coordinate_2D(0,0)))); + a1_newMoves.add(new Move(a1,2, mapH.getMapLocation(new Coordinate_2D(0,0)),mapH.getMapLocation(new Coordinate_2D(1,0)))); + a1_newMoves.add(new Move(a1,3, mapH.getMapLocation(new Coordinate_2D(1,0)),mapH.getMapLocation(new Coordinate_2D(1,1)))); + a1_newMoves.add(new Move(a1,4, mapH.getMapLocation(new Coordinate_2D(1,1)),mapH.getMapLocation(new Coordinate_2D(1,2)))); + a1_newMoves.add(new Move(a1,5, mapH.getMapLocation(new Coordinate_2D(1,2)),mapH.getMapLocation(new Coordinate_2D(1,3)))); + a1_newMoves.add(new Move(a1,6, mapH.getMapLocation(new Coordinate_2D(1,3)),mapH.getMapLocation(new Coordinate_2D(0,3)))); a1_newPlan = new SingleAgentPlan(a1,a1_newMoves); copiedTable.addPlan(a1_newPlan); @@ -477,7 +477,7 @@ public void TwoAgentsWith1SwappingConflict_graphH() { /* = Expected values = */ expectedSet = new HashSet<>(); - VertexConflict expectedVertexConflict_time3 = new VertexConflict(a1,a2,3,mapH.getMapCell(new Coordinate_2D(1,1))); + VertexConflict expectedVertexConflict_time3 = new VertexConflict(a1,a2,3,mapH.getMapLocation(new Coordinate_2D(1,1))); expectedSet.add(expectedVertexConflict_time3); diff --git a/src/test/java/BasicCBS/Solvers/ICTS/ICTS_SolverTest.java b/src/test/java/BasicCBS/Solvers/ICTS/ICTS_SolverTest.java index 95941c13..81375dbc 100644 --- a/src/test/java/BasicCBS/Solvers/ICTS/ICTS_SolverTest.java +++ b/src/test/java/BasicCBS/Solvers/ICTS/ICTS_SolverTest.java @@ -3,19 +3,16 @@ import BasicCBS.Instances.Agent; import BasicCBS.Instances.InstanceBuilders.InstanceBuilder_BGU; import BasicCBS.Instances.InstanceBuilders.InstanceBuilder_MovingAI; -import BasicCBS.Instances.InstanceBuilders.Priorities; import BasicCBS.Instances.InstanceManager; import BasicCBS.Instances.InstanceProperties; import BasicCBS.Instances.MAPF_Instance; import BasicCBS.Instances.Maps.Coordinates.Coordinate_2D; import BasicCBS.Instances.Maps.Coordinates.I_Coordinate; -import BasicCBS.Instances.Maps.Enum_MapCellType; +import BasicCBS.Instances.Maps.Enum_MapLocationType; import BasicCBS.Instances.Maps.I_Map; import BasicCBS.Instances.Maps.MapDimensions; import BasicCBS.Instances.Maps.MapFactory; import BasicCBS.Solvers.CBS.CBS_Solver; -import BasicCBS.Solvers.ConstraintsAndConflicts.Constraint.Constraint; -import BasicCBS.Solvers.ConstraintsAndConflicts.Constraint.ConstraintSet; import BasicCBS.Solvers.ICTS.HighLevel.ICTS_Solver; import BasicCBS.Solvers.I_Solver; import BasicCBS.Solvers.RunParameters; @@ -36,9 +33,9 @@ class ICTS_SolverTest { - private final Enum_MapCellType e = Enum_MapCellType.EMPTY; - private final Enum_MapCellType w = Enum_MapCellType.WALL; - private Enum_MapCellType[][] map_2D_circle = { + private final Enum_MapLocationType e = Enum_MapLocationType.EMPTY; + private final Enum_MapLocationType w = Enum_MapLocationType.WALL; + private Enum_MapLocationType[][] map_2D_circle = { {w, w, w, w, w, w}, {w, w, e, e, e, w}, {w, w, e, w, e, w}, @@ -48,7 +45,7 @@ class ICTS_SolverTest { }; private I_Map mapCircle = MapFactory.newSimple4Connected2D_GraphMap(map_2D_circle); - Enum_MapCellType[][] map_2D_empty = { + Enum_MapLocationType[][] map_2D_empty = { {e, e, e, e, e, e}, {e, e, e, e, e, e}, {e, e, e, e, e, e}, @@ -58,7 +55,7 @@ class ICTS_SolverTest { }; private I_Map mapEmpty = MapFactory.newSimple4Connected2D_GraphMap(map_2D_empty); - Enum_MapCellType[][] map_2D_withPocket = { + Enum_MapLocationType[][] map_2D_withPocket = { {e, w, e, w, e, w}, {e, w, e, e, e, e}, {w, w, e, w, w, e}, @@ -68,7 +65,7 @@ class ICTS_SolverTest { }; private I_Map mapWithPocket = MapFactory.newSimple4Connected2D_GraphMap(map_2D_withPocket); - Enum_MapCellType[][] map_2D_smallMaze = { + Enum_MapLocationType[][] map_2D_smallMaze = { {e, e, e, w, e, w}, {e, w, e, e, e, e}, {e, w, e, w, w, e}, diff --git a/src/test/java/BasicCBS/Solvers/PrioritisedPlanning/PrioritisedPlanning_SolverTest.java b/src/test/java/BasicCBS/Solvers/PrioritisedPlanning/PrioritisedPlanning_SolverTest.java index b9f92f7b..1f706bed 100644 --- a/src/test/java/BasicCBS/Solvers/PrioritisedPlanning/PrioritisedPlanning_SolverTest.java +++ b/src/test/java/BasicCBS/Solvers/PrioritisedPlanning/PrioritisedPlanning_SolverTest.java @@ -29,9 +29,9 @@ class PrioritisedPlanning_SolverTest { - private final Enum_MapCellType e = Enum_MapCellType.EMPTY; - private final Enum_MapCellType w = Enum_MapCellType.WALL; - private Enum_MapCellType[][] map_2D_circle = { + private final Enum_MapLocationType e = Enum_MapLocationType.EMPTY; + private final Enum_MapLocationType w = Enum_MapLocationType.WALL; + private Enum_MapLocationType[][] map_2D_circle = { {w, w, w, w, w, w}, {w, w, e, e, e, w}, {w, w, e, w, e, w}, @@ -41,7 +41,7 @@ class PrioritisedPlanning_SolverTest { }; private I_Map mapCircle = MapFactory.newSimple4Connected2D_GraphMap(map_2D_circle); - Enum_MapCellType[][] map_2D_empty = { + Enum_MapLocationType[][] map_2D_empty = { {e, e, e, e, e, e}, {e, e, e, e, e, e}, {e, e, e, e, e, e}, @@ -51,7 +51,7 @@ class PrioritisedPlanning_SolverTest { }; private I_Map mapEmpty = MapFactory.newSimple4Connected2D_GraphMap(map_2D_empty); - Enum_MapCellType[][] map_2D_withPocket = { + Enum_MapLocationType[][] map_2D_withPocket = { {e, w, e, w, e, w}, {e, w, e, e, e, e}, {w, w, e, w, w, e}, @@ -80,26 +80,26 @@ class PrioritisedPlanning_SolverTest { private I_Coordinate coor01 = new Coordinate_2D(0,1); private I_Coordinate coor10 = new Coordinate_2D(1,0); - private I_Location cell12 = mapCircle.getMapCell(coor12); - private I_Location cell13 = mapCircle.getMapCell(coor13); - private I_Location cell14 = mapCircle.getMapCell(coor14); - private I_Location cell22 = mapCircle.getMapCell(coor22); - private I_Location cell24 = mapCircle.getMapCell(coor24); - private I_Location cell32 = mapCircle.getMapCell(coor32); - private I_Location cell33 = mapCircle.getMapCell(coor33); - private I_Location cell34 = mapCircle.getMapCell(coor34); - - private I_Location cell11 = mapCircle.getMapCell(coor11); - private I_Location cell43 = mapCircle.getMapCell(coor43); - private I_Location cell53 = mapCircle.getMapCell(coor53); - private I_Location cell54 = mapCircle.getMapCell(coor54); - private I_Location cell55 = mapCircle.getMapCell(coor55); - private I_Location cell05 = mapCircle.getMapCell(coor05); - - private I_Location cell04 = mapCircle.getMapCell(coor04); - private I_Location cell00 = mapCircle.getMapCell(coor00); - private I_Location cell01 = mapCircle.getMapCell(coor01); - private I_Location cell10 = mapCircle.getMapCell(coor10); + private I_Location location12 = mapCircle.getMapLocation(coor12); + private I_Location location13 = mapCircle.getMapLocation(coor13); + private I_Location location14 = mapCircle.getMapLocation(coor14); + private I_Location location22 = mapCircle.getMapLocation(coor22); + private I_Location location24 = mapCircle.getMapLocation(coor24); + private I_Location location32 = mapCircle.getMapLocation(coor32); + private I_Location location33 = mapCircle.getMapLocation(coor33); + private I_Location location34 = mapCircle.getMapLocation(coor34); + + private I_Location location11 = mapCircle.getMapLocation(coor11); + private I_Location location43 = mapCircle.getMapLocation(coor43); + private I_Location location53 = mapCircle.getMapLocation(coor53); + private I_Location location54 = mapCircle.getMapLocation(coor54); + private I_Location location55 = mapCircle.getMapLocation(coor55); + private I_Location location05 = mapCircle.getMapLocation(coor05); + + private I_Location location04 = mapCircle.getMapLocation(coor04); + private I_Location location00 = mapCircle.getMapLocation(coor00); + private I_Location location01 = mapCircle.getMapLocation(coor01); + private I_Location location10 = mapCircle.getMapLocation(coor10); private Agent agent33to12 = new Agent(0, coor33, coor12); private Agent agent12to33 = new Agent(1, coor12, coor33); diff --git a/src/test/java/BasicCBS/Solvers/SingleAgentPlanTest.java b/src/test/java/BasicCBS/Solvers/SingleAgentPlanTest.java index 17a5053e..4881773f 100644 --- a/src/test/java/BasicCBS/Solvers/SingleAgentPlanTest.java +++ b/src/test/java/BasicCBS/Solvers/SingleAgentPlanTest.java @@ -15,9 +15,9 @@ class SingleAgentPlanTest { - private final Enum_MapCellType e = Enum_MapCellType.EMPTY; - private final Enum_MapCellType w = Enum_MapCellType.WALL; - private Enum_MapCellType[][] map_2D_circle = { + private final Enum_MapLocationType e = Enum_MapLocationType.EMPTY; + private final Enum_MapLocationType w = Enum_MapLocationType.WALL; + private Enum_MapLocationType[][] map_2D_circle = { {w, w, w, w, w, w}, {w, w, e, e, e, w}, {w, w, e, w, e, w}, @@ -34,30 +34,30 @@ class SingleAgentPlanTest { private I_Coordinate coor32 = new Coordinate_2D(3,2); private I_Coordinate coor33 = new Coordinate_2D(3,3); private I_Coordinate coor34 = new Coordinate_2D(3,4); - private I_Location cell12 = map1.getMapCell(coor12); - private I_Location cell13 = map1.getMapCell(coor13); - private I_Location cell14 = map1.getMapCell(coor14); - private I_Location cell22 = map1.getMapCell(coor22); - private I_Location cell24 = map1.getMapCell(coor24); - private I_Location cell32 = map1.getMapCell(coor32); - private I_Location cell33 = map1.getMapCell(coor33); - private I_Location cell34 = map1.getMapCell(coor34); + private I_Location location12 = map1.getMapLocation(coor12); + private I_Location location13 = map1.getMapLocation(coor13); + private I_Location location14 = map1.getMapLocation(coor14); + private I_Location location22 = map1.getMapLocation(coor22); + private I_Location location24 = map1.getMapLocation(coor24); + private I_Location location32 = map1.getMapLocation(coor32); + private I_Location location33 = map1.getMapLocation(coor33); + private I_Location location34 = map1.getMapLocation(coor34); private Agent agent1 = new Agent(0, coor13, coor14); private Agent agent2 = new Agent(1, coor24, coor24); /* =valid inputs= */ //note that validity of move from one location to the next (neighbors or not) is not checked by SingleAgentPlan - private Move move1agent1 = new Move(agent1, 1, cell13, cell14); - private Move move2agent1 = new Move(agent1, 2, cell14, cell24); - private Move move3agent1 = new Move(agent1, 3, cell24, cell14); - private Move move1agent2 = new Move(agent2, 1, cell24, cell24); + private Move move1agent1 = new Move(agent1, 1, location13, location14); + private Move move2agent1 = new Move(agent1, 2, location14, location24); + private Move move3agent1 = new Move(agent1, 3, location24, location14); + private Move move1agent2 = new Move(agent2, 1, location24, location24); - private Move move4agent1 = new Move(agent1, 4, cell14, cell13); + private Move move4agent1 = new Move(agent1, 4, location14, location13); /* =invalid inputs= */ - private Move move4agent1BadTime = new Move(agent1, 1, cell14, cell24); - private Move move4agent1BadAgent = new Move(agent2, 4, cell14, cell24); + private Move move4agent1BadTime = new Move(agent1, 1, location14, location24); + private Move move4agent1BadAgent = new Move(agent2, 4, location14, location24); /* =plans= */ private SingleAgentPlan emptyPlanAgent1; @@ -106,7 +106,7 @@ void addMove() { @Test void addMoves() { List a1moves123 = Arrays.asList(move1agent1, move2agent1, move3agent1); - Move move5agent1 = new Move(agent1, 5, cell13, cell13); + Move move5agent1 = new Move(agent1, 5, location13, location13); List a1moves45 = Arrays.asList(move4agent1, move5agent1); /* =shouldn't throw= */ @@ -123,14 +123,14 @@ void addMoves() { assertThrows(IllegalArgumentException.class, ()-> emptyPlanAgent1.addMoves(Arrays.asList(move1agent2))); //bad agent assertThrows(IllegalArgumentException.class, - ()-> existingPlanAgent1.addMoves(Arrays.asList(new Move(agent2, 5, cell14, cell14)))); //bad agent + ()-> existingPlanAgent1.addMoves(Arrays.asList(new Move(agent2, 5, location14, location14)))); //bad agent assertThrows(IllegalArgumentException.class, ()-> emptyPlanAgent1.addMoves(Arrays.asList( - move1agent1, new Move(agent2, 2, cell14,cell14), move3agent1))); //bad agent middle + move1agent1, new Move(agent2, 2, location14,location14), move3agent1))); //bad agent middle assertThrows(IllegalArgumentException.class, ()-> existingPlanAgent1.addMoves(Arrays.asList( - move4agent1, new Move(agent2, 5, cell14,cell14), - new Move(agent1, 6, cell14, cell14)))); //bad agent middle + move4agent1, new Move(agent2, 5, location14,location14), + new Move(agent1, 6, location14, location14)))); //bad agent middle assertThrows(IllegalArgumentException.class, ()-> emptyPlanAgent1.addMoves(Arrays.asList(move1agent1, move3agent1, move3agent1))); //bad time middle assertThrows(IllegalArgumentException.class, @@ -142,8 +142,8 @@ move4agent1, new Move(agent2, 5, cell14,cell14), @Test void setMoves() { List a1moves123 = Arrays.asList(move1agent1, move2agent1, move3agent1); - Move move5agent1 = new Move(agent1, 5, cell13, cell13); - Move move4agent1 = new Move(agent1, 4, cell13, cell14); + Move move5agent1 = new Move(agent1, 5, location13, location13); + Move move4agent1 = new Move(agent1, 4, location13, location14); List a1moves45 = Arrays.asList(move4agent1, move5agent1); /* =shouldn't throw= */ @@ -159,14 +159,14 @@ void setMoves() { assertThrows(IllegalArgumentException.class, ()-> emptyPlanAgent1.setMoves(Arrays.asList(move1agent2))); //bad agent assertThrows(IllegalArgumentException.class, - ()-> existingPlanAgent1.setMoves(Arrays.asList(new Move(agent2, 5, cell14, cell14)))); //bad agent + ()-> existingPlanAgent1.setMoves(Arrays.asList(new Move(agent2, 5, location14, location14)))); //bad agent assertThrows(IllegalArgumentException.class, ()-> emptyPlanAgent1.setMoves(Arrays.asList( - move1agent1, new Move(agent2, 2, cell14,cell14), move3agent1))); //bad agent middle + move1agent1, new Move(agent2, 2, location14,location14), move3agent1))); //bad agent middle assertThrows(IllegalArgumentException.class, ()-> existingPlanAgent1.setMoves(Arrays.asList( - move4agent1, new Move(agent2, 5, cell14,cell14), - new Move(agent1, 6, cell14, cell14)))); //bad agent middle + move4agent1, new Move(agent2, 5, location14,location14), + new Move(agent1, 6, location14, location14)))); //bad agent middle assertThrows(IllegalArgumentException.class, ()-> emptyPlanAgent1.setMoves(Arrays.asList(move1agent1, move3agent1, move3agent1))); //bad time middle assertThrows(IllegalArgumentException.class, @@ -180,7 +180,7 @@ void getStartTime() { /* =as initiated= */ assertEquals(-1, emptyPlanAgent1.getPlanStartTime()); assertEquals(0, existingPlanAgent1.getPlanStartTime()); - SingleAgentPlan planStartsAt3 = new SingleAgentPlan(agent1, Arrays.asList(new Move(agent1, 4, cell13, cell12))); + SingleAgentPlan planStartsAt3 = new SingleAgentPlan(agent1, Arrays.asList(new Move(agent1, 4, location13, location12))); assertEquals(3, planStartsAt3.getPlanStartTime()); /* =when modified= */ @@ -195,7 +195,7 @@ void getEndTime() { /* =as initiated= */ assertEquals(-1, emptyPlanAgent1.getEndTime()); assertEquals(3, existingPlanAgent1.getEndTime()); - SingleAgentPlan planStartsAt3 = new SingleAgentPlan(agent1, Arrays.asList(new Move(agent1, 4, cell13, cell12))); + SingleAgentPlan planStartsAt3 = new SingleAgentPlan(agent1, Arrays.asList(new Move(agent1, 4, location13, location12))); assertEquals(4, planStartsAt3.getEndTime()); /* =when modified= */ @@ -210,7 +210,7 @@ void getElapsedTime() { /* =as initiated= */ assertEquals(0, emptyPlanAgent1.size()); assertEquals(3, existingPlanAgent1.size()); - SingleAgentPlan planStartsAt3 = new SingleAgentPlan(agent1, Arrays.asList(new Move(agent1, 4, cell13, cell12))); + SingleAgentPlan planStartsAt3 = new SingleAgentPlan(agent1, Arrays.asList(new Move(agent1, 4, location13, location12))); assertEquals(1, planStartsAt3.size()); /* =when modified= */ @@ -238,7 +238,7 @@ void moveAt() { assertEquals(move4agent1, existingPlanAgent1.moveAt(4)); //starting not at time 1 - move2agent1 = new Move(agent1, 2, cell13, cell14); + move2agent1 = new Move(agent1, 2, location13, location14); emptyPlanAgent1.addMove(move2agent1); assertEquals(move2agent1, emptyPlanAgent1.moveAt(2)); emptyPlanAgent1.addMove(move3agent1); @@ -253,22 +253,22 @@ void conflictsBecauseAgentStaysAtGoal() { Agent agent2 = new Agent(1, coor33, coor13); SingleAgentPlan planAgent1 = new SingleAgentPlan(agent1); - planAgent1.addMove(new Move(agent1, 1, cell13, cell12)); + planAgent1.addMove(new Move(agent1, 1, location13, location12)); SingleAgentPlan planAgent2 = new SingleAgentPlan(agent2); - planAgent2.addMove(new Move(agent2, 1, cell33, cell32)); - planAgent2.addMove(new Move(agent2, 2, cell32, cell22)); - planAgent2.addMove(new Move(agent2, 3, cell22, cell12)); - planAgent2.addMove(new Move(agent2, 4, cell12, cell13)); + planAgent2.addMove(new Move(agent2, 1, location33, location32)); + planAgent2.addMove(new Move(agent2, 2, location32, location22)); + planAgent2.addMove(new Move(agent2, 3, location22, location12)); + planAgent2.addMove(new Move(agent2, 4, location12, location13)); assertTrue(planAgent1.conflictsWith(planAgent2)); assertTrue(planAgent2.conflictsWith(planAgent1)); SingleAgentPlan alternateAgent2 = new SingleAgentPlan(agent2); - alternateAgent2.addMove(new Move(agent2, 1, cell33, cell34)); - alternateAgent2.addMove(new Move(agent2, 2, cell34, cell24)); - alternateAgent2.addMove(new Move(agent2, 3, cell24, cell14)); - alternateAgent2.addMove(new Move(agent2, 4, cell14, cell13)); + alternateAgent2.addMove(new Move(agent2, 1, location33, location34)); + alternateAgent2.addMove(new Move(agent2, 2, location34, location24)); + alternateAgent2.addMove(new Move(agent2, 3, location24, location14)); + alternateAgent2.addMove(new Move(agent2, 4, location14, location13)); assertFalse(planAgent1.conflictsWith(alternateAgent2)); assertFalse(alternateAgent2.conflictsWith(planAgent1)); diff --git a/src/test/resources/SampleMaps b/src/test/resources/SampleMaps index 7eee4897..63ff1f2b 100644 --- a/src/test/resources/SampleMaps +++ b/src/test/resources/SampleMaps @@ -1,4 +1,4 @@ -Enum_MapCellType[][] map_2D_1Cell_middle = { +Enum_MapLocationType[][] map_2D_1Location_middle = { {w, w, w, w, w, w}, {w, e, w, w, w, w}, {w, w, w, w, w, w}, @@ -7,7 +7,7 @@ Enum_MapCellType[][] map_2D_1Cell_middle = { {w, w, w, w, w, w}, }; -Enum_MapCellType[][] map_2D_1Cell_fringe = { +Enum_MapLocationType[][] map_2D_1Location_fringe = { {w, w, w, w, w, w}, {e, w, w, w, w, w}, {w, w, w, w, w, w}, @@ -16,7 +16,7 @@ Enum_MapCellType[][] map_2D_1Cell_fringe = { {w, w, w, w, w, w}, }; -Enum_MapCellType[][] map_2D_2Cells_middle = { +Enum_MapLocationType[][] map_2D_2Locations_middle = { {w, w, w, w, w, w}, {w, w, w, e, e, w}, {w, w, w, w, w, w}, @@ -25,7 +25,7 @@ Enum_MapCellType[][] map_2D_2Cells_middle = { {w, w, w, w, w, w}, }; -Enum_MapCellType[][] map_2D_2Cells_fringe = { +Enum_MapLocationType[][] map_2D_2Locations_fringe = { {w, w, w, w, e, w}, {w, w, w, w, e, w}, {w, w, w, w, w, w}, @@ -34,7 +34,7 @@ Enum_MapCellType[][] map_2D_2Cells_fringe = { {w, w, w, w, w, w}, }; -Enum_MapCellType[][] map_2D_3Cells_line = { +Enum_MapLocationType[][] map_2D_3Locations_line = { {w, w, w, e, w, w}, {w, w, w, e, w, w}, {w, w, w, e, w, w}, @@ -43,7 +43,7 @@ Enum_MapCellType[][] map_2D_3Cells_line = { {w, w, w, w, w, w}, }; -Enum_MapCellType[][] map_2D_4cells_clump = { +Enum_MapLocationType[][] map_2D_4locations_clump = { {w, w, w, w, w, w}, {w, w, w, e, e, w}, {w, w, w, e, e, w}, @@ -52,7 +52,7 @@ Enum_MapCellType[][] map_2D_4cells_clump = { {w, w, w, w, w, w}, }; -Enum_MapCellType[][] map_2D_circle = { +Enum_MapLocationType[][] map_2D_circle = { {w, w, w, w, w, w}, {w, w, e, e, e, w}, {w, w, e, w, e, w}, @@ -61,7 +61,7 @@ Enum_MapCellType[][] map_2D_circle = { {w, w, w, w, w, w}, }; -Enum_MapCellType[][] map_2D_empty = { +Enum_MapLocationType[][] map_2D_empty = { {e, e, e, e, e, e}, {e, e, e, e, e, e}, {e, e, e, e, e, e},