Skip to content

Commit

Permalink
renamed many references to map "cell"s to be called "location"s, to f…
Browse files Browse the repository at this point in the history
…it current naming
  • Loading branch information
J-morag committed Nov 30, 2021
1 parent 06c9574 commit 1444b3c
Show file tree
Hide file tree
Showing 34 changed files with 579 additions and 538 deletions.
4 changes: 2 additions & 2 deletions Style Guide.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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]
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Character,Enum_MapCellType> cellTypeHashMap, InstanceProperties.ObstacleWrapper obstacle) {
static GraphMap buildGraphMap(String[] mapAsStrings, String mapSeparator, MapDimensions mapDimensions, HashMap<Character, Enum_MapLocationType> 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
}

Expand All @@ -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){

Expand Down Expand Up @@ -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<Character,Enum_MapCellType> cellTypeHashMap, MapDimensions.Enum_mapOrientation mapOrientation, InstanceProperties.ObstacleWrapper obstacle) {
static Enum_MapLocationType[][] build_2D_locationTypeMap(Character[][] mapAsCharacters , HashMap<Character, Enum_MapLocationType> locationTypeHashMap, MapDimensions.Enum_mapOrientation mapOrientation, InstanceProperties.ObstacleWrapper obstacle) {

if(mapAsCharacters == null){ return null; }

Expand All @@ -148,22 +148,22 @@ 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++) {

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;
}
}

Expand All @@ -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<Character,Enum_MapCellType> cellTypeHashMap, InstanceProperties.ObstacleWrapper obstacle) {
static Enum_MapLocationType[][][] build_3D_locationTypeMap(Character[][][] mapAsCharacters, HashMap<Character, Enum_MapLocationType> locationTypeHashMap, InstanceProperties.ObstacleWrapper obstacle) {
// niceToHave - no need to implement for now
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Character,Enum_MapCellType> cellTypeHashMap = new HashMap<>(){{
put(EMPTY,Enum_MapCellType.EMPTY);
put(WALL,Enum_MapCellType.WALL);
private HashMap<Character, Enum_MapLocationType> locationTypeHashMap = new HashMap<>(){{
put(EMPTY, Enum_MapLocationType.EMPTY);
put(WALL, Enum_MapLocationType.WALL);
}};


Expand Down Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,16 @@ public class InstanceBuilder_MovingAI implements I_InstanceBuilder {
private final ArrayList<MAPF_Instance> 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<Character, Enum_MapCellType> cellTypeHashMap = new HashMap<Character, Enum_MapCellType>(){{
put(EMPTY,Enum_MapCellType.EMPTY);
put(WALL,Enum_MapCellType.WALL);
put(TREE,Enum_MapCellType.TREE);
/* Mapping from char to Location type */
private HashMap<Character, Enum_MapLocationType> locationTypeHashMap = new HashMap<Character, Enum_MapLocationType>(){{
put(EMPTY, Enum_MapLocationType.EMPTY);
put(WALL, Enum_MapLocationType.WALL);
put(TREE, Enum_MapLocationType.TREE);
}};

private final Priorities priorities;
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/BasicCBS/Instances/InstanceProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 0 additions & 14 deletions src/main/java/BasicCBS/Instances/Maps/Enum_MapCellType.java

This file was deleted.

23 changes: 23 additions & 0 deletions src/main/java/BasicCBS/Instances/Maps/Enum_MapLocationType.java
Original file line number Diff line number Diff line change
@@ -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
}
24 changes: 12 additions & 12 deletions src/main/java/BasicCBS/Instances/Maps/GraphMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
*/
public class GraphMap implements I_ExplicitMap {

private HashMap<I_Coordinate, GraphMapVertex> allGraphCells;
private HashMap<I_Coordinate, GraphMapVertex> 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<I_Coordinate, GraphMapVertex> allGraphVertices) {
this.allGraphCells = allGraphVertices;
this.allGraphLocations = allGraphVertices;
}

/**
Expand All @@ -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
Expand All @@ -46,13 +46,13 @@ public I_Map getSubmapWithout(Collection<? extends I_Location> mapLocations) {

HashMap<I_Coordinate, GraphMapVertex> vertexMappings = new HashMap<>();
// populate with stub vertices (copies), except for vertices that we want to remove
for (Map.Entry<I_Coordinate, GraphMapVertex> pair : this.allGraphCells.entrySet()) {
for (Map.Entry<I_Coordinate, GraphMapVertex> 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<I_Coordinate, GraphMapVertex> pair : this.allGraphCells.entrySet()) {
for (Map.Entry<I_Coordinate, GraphMapVertex> pair : this.allGraphLocations.entrySet()) {
I_Coordinate coor = pair.getKey();
GraphMapVertex originalVertex = pair.getValue();
if(!mapLocations.contains(originalVertex)){
Expand All @@ -70,8 +70,8 @@ public I_Map getSubmapWithout(Collection<? extends I_Location> mapLocations) {
return new GraphMap(vertexMappings);
}

public int getNumMapCells(){
return allGraphCells.size();
public int getNumMapLocations(){
return allGraphLocations.size();
}


Expand All @@ -80,6 +80,6 @@ public int getNumMapCells(){
*/
@Override
public Collection<? extends I_Location> getAllLocations() {
return new ArrayList<>(this.allGraphCells.values());
return new ArrayList<>(this.allGraphLocations.values());
}
}
Loading

0 comments on commit 1444b3c

Please sign in to comment.