Skip to content

Commit

Permalink
Removal of 'as_distance_graph(container, map)'
Browse files Browse the repository at this point in the history
Totally redundant with 'as_distance_graph(container, distance, species)'
without any benefit of having this map argument.
  • Loading branch information
AlexisDrogoul committed Dec 20, 2021
1 parent ce409d7 commit 4f5bd45
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 99 deletions.
194 changes: 98 additions & 96 deletions msi.gama.core/src/msi/gaml/operators/Graphs.java
Expand Up @@ -1780,74 +1780,13 @@ static boolean lineInter(final Coordinate[] coord1, final Coordinate[] coord2) {
public static IGraph spatialDistanceGraph(final IScope scope, final IContainer vertices, final Double distance) {
final IGraph createdGraph = new GamaSpatialGraph(vertices, false, false, new DistanceRelation(distance), null,
scope, vertices.getGamlType().getContentType(), Types.GEOMETRY);
if (Types.AGENT.equals(vertices.getGamlType().getContentType())) {
// TODO
if (vertices.getGamlType().getContentType().isAgentType()) {
GraphFromAgentContainerSynchronizer.synchronize(scope, vertices, null, createdGraph);
}
return createdGraph;
}

/**
* Grid cells to graph.
*
* @param scope
* the scope
* @param vertices
* the vertices
* @return the i graph
*/
@operator (
value = "grid_cells_to_graph",
content_type = IType.GEOMETRY,
index_type = ITypeProvider.CONTENT_TYPE_AT_INDEX + 1,
category = { IOperatorCategory.GRAPH },
concept = { IConcept.GRAPH, IConcept.GRID, IConcept.CAST, IConcept.NEIGHBORS })
@doc (
value = "creates a graph from a list of cells (operand). An edge is created between neighbors.",
masterDoc = true,
comment = "",
examples = @example (
value = "my_cell_graph<-grid_cells_to_graph(cells_list)",
isExecutable = false),
see = {})
@no_test
public static IGraph gridCellsToGraph(final IScope scope, final IContainer vertices) {
final IGraph graph = new GamaSpatialGraph(vertices, false, false, new GridNeighborsRelation(), null, scope,
vertices.getGamlType().getContentType(), Types.GEOMETRY);
for (final Object e : graph.edgeSet()) { graph.setEdgeWeight(e, ((IShape) e).getPerimeter()); }
return graph;
}

/**
* Grid cells to graph.
*
* @param scope
* the scope
* @param vertices
* the vertices
* @param edgeSpecies
* the edge species
* @return the i graph
*/
@operator (
value = "grid_cells_to_graph",
content_type = IType.GEOMETRY,
index_type = IType.GEOMETRY,
category = { IOperatorCategory.GRAPH },
concept = {})
@doc (
value = "creates a graph from a list of cells (operand). An edge is created between neighbors.",
see = { "as_intersection_graph", "as_edge_graph" })
@no_test
public static IGraph gridCellsToGraph(final IScope scope, final IContainer vertices, final ISpecies edgeSpecies) {
final IType edgeType = scope.getType(edgeSpecies.getName());
final IGraph createdGraph = new GamaSpatialGraph(vertices, false, false, new GridNeighborsRelation(),
edgeSpecies, scope, vertices.getGamlType().getContentType(), edgeType);

for (final Object e : createdGraph.edgeSet()) { createdGraph.setEdgeWeight(e, ((IShape) e).getPerimeter()); }

return createdGraph;
}

/**
* Spatial distance graph.
*
Expand All @@ -1868,7 +1807,7 @@ public static IGraph gridCellsToGraph(final IScope scope, final IContainer verti
category = { IOperatorCategory.GRAPH },
concept = {})
@doc (
value = "creates a graph from a list of vertices (left-hand operand). An edge is created between each pair of vertices close enough (less than a distance, right-hand operand).",
value = "creates an undirected graph from a list of vertices (left-hand operand). An edge is created between each pair of vertices close enough (less than a distance, right-hand operand).",
see = { "as_intersection_graph", "as_edge_graph" })
@no_test
public static IGraph spatialDistanceGraph(final IScope scope, final IContainer vertices, final Double distance,
Expand All @@ -1881,38 +1820,39 @@ public static IGraph spatialDistanceGraph(final IScope scope, final IContainer v

return createdGraph;
}

/**
* Spatial distance graph.
*
* @param scope
* the scope
* @param vertices
* the vertices
* @param params
* the params
* @return the i graph
*/
@operator (
value = "as_distance_graph",
category = { IOperatorCategory.GRAPH },
concept = {})
@doc (
value = "creates a graph from a list of vertices (left-hand operand). An edge is created between each pair of vertices close enough (less than a distance, right-hand operand).",
see = { "as_intersection_graph", "as_edge_graph" })
@no_test
public static IGraph spatialDistanceGraph(final IScope scope, final IContainer vertices, final IMap params) {
final Double distance = (Double) params.get("distance");
final ISpecies edgeSpecies = (ISpecies) params.get("species");
final IType edgeType = edgeSpecies == null ? Types.GEOMETRY : scope.getType(edgeSpecies.getName());
final IGraph createdGraph = new GamaSpatialGraph(vertices, false, false, new DistanceRelation(distance),
edgeSpecies, scope, vertices.getGamlType().getContentType(), edgeType);

if (Types.AGENT.equals(vertices.getGamlType().getContentType())) {
GraphFromAgentContainerSynchronizer.synchronize(scope, vertices, edgeSpecies, createdGraph);
}
return createdGraph;
}
//
// /**
// * Spatial distance graph.
// *
// * @param scope
// * the scope
// * @param vertices
// * the vertices
// * @param params
// * the params
// * @return the i graph
// */
// @operator (
// value = "as_distance_graph",
// category = { IOperatorCategory.GRAPH },
// concept = {})
// @doc (
// value = "creates a graph from a list of vertices (left-hand operand). An edge is created between each pair of
// vertices close enough (less than a distance, right-hand operand).",
// see = { "as_intersection_graph", "as_edge_graph" })
// @no_test
// public static IGraph spatialDistanceGraph(final IScope scope, final IContainer vertices, final IMap params) {
// final Double distance = (Double) params.get("distance");
// final ISpecies edgeSpecies = (ISpecies) params.get("species");
// final IType edgeType = edgeSpecies == null ? Types.GEOMETRY : scope.getType(edgeSpecies.getName());
// final IGraph createdGraph = new GamaSpatialGraph(vertices, false, false, new DistanceRelation(distance),
// edgeSpecies, scope, vertices.getGamlType().getContentType(), edgeType);
//
// if (vertices.getGamlType().getContentType().isAgentType()) {
// GraphFromAgentContainerSynchronizer.synchronize(scope, vertices, edgeSpecies, createdGraph);
// }
// return createdGraph;
// }

/**
* Spatial graph.
Expand Down Expand Up @@ -1974,6 +1914,68 @@ public static ISpatialGraph as_spatial_graph(final IScope scope, final IGraph gr
return result;
}

/**
* Grid cells to graph.
*
* @param scope
* the scope
* @param vertices
* the vertices
* @return the i graph
*/
@operator (
value = "grid_cells_to_graph",
content_type = IType.GEOMETRY,
index_type = ITypeProvider.CONTENT_TYPE_AT_INDEX + 1,
category = { IOperatorCategory.GRAPH },
concept = { IConcept.GRAPH, IConcept.GRID, IConcept.CAST, IConcept.NEIGHBORS })
@doc (
value = "creates a graph from a list of cells (operand). An edge is created between neighbors.",
masterDoc = true,
comment = "",
examples = @example (
value = "my_cell_graph<-grid_cells_to_graph(cells_list)",
isExecutable = false),
see = {})
@no_test
public static IGraph gridCellsToGraph(final IScope scope, final IContainer vertices) {
final IGraph graph = new GamaSpatialGraph(vertices, false, false, new GridNeighborsRelation(), null, scope,
vertices.getGamlType().getContentType(), Types.GEOMETRY);
for (final Object e : graph.edgeSet()) { graph.setEdgeWeight(e, ((IShape) e).getPerimeter()); }
return graph;
}

/**
* Grid cells to graph.
*
* @param scope
* the scope
* @param vertices
* the vertices
* @param edgeSpecies
* the edge species
* @return the i graph
*/
@operator (
value = "grid_cells_to_graph",
content_type = IType.GEOMETRY,
index_type = IType.GEOMETRY,
category = { IOperatorCategory.GRAPH },
concept = {})
@doc (
value = "creates a graph from a list of cells (operand). An edge is created between neighbors.",
see = { "as_intersection_graph", "as_edge_graph" })
@no_test
public static IGraph gridCellsToGraph(final IScope scope, final IContainer vertices, final ISpecies edgeSpecies) {
final IType edgeType = scope.getType(edgeSpecies.getName());
final IGraph createdGraph = new GamaSpatialGraph(vertices, false, false, new GridNeighborsRelation(),
edgeSpecies, scope, vertices.getGamlType().getContentType(), edgeType);

for (final Object e : createdGraph.edgeSet()) { createdGraph.setEdgeWeight(e, ((IShape) e).getPerimeter()); }

return createdGraph;
}

/**
* Use cache for shortest paths.
*
Expand Down
Expand Up @@ -68,7 +68,7 @@ global {
speed <-0.1;
color<-#orange;
}
mazeGraph <- as_distance_graph(cell, ["distance"::10.0,"species"::edge_agent]);
mazeGraph <- as_distance_graph(cell, 10.0,edge_agent);

}
}
Expand Down
Expand Up @@ -26,7 +26,7 @@ global {
do die;
}
//Create a new graph using the distance to compute the edges
myGraph <- as_distance_graph(node_agent, ["distance"::distance, "species"::edge_agent]);
myGraph <- as_distance_graph(node_agent, distance, edge_agent);
}
}
//Species node_agent mirroring the bug species
Expand Down
Expand Up @@ -75,7 +75,7 @@ global {
//If we want a spatial graph in that case we create a graph according to their distance, else we create a barabasi albert graph
if(spatialGraph){
create node_agent number:nbAgent;
my_graph <- graph<node_agent, edge_agent>(as_distance_graph(node_agent, (["distance"::distance, "species"::edge_agent])));
my_graph <- graph<node_agent, edge_agent>(as_distance_graph(node_agent, distance, edge_agent));

}
else{
Expand Down

0 comments on commit 4f5bd45

Please sign in to comment.