@Test @Parameters({"/layout_graph_test/FromGraphConfigurationOperation_withPrecisionSeed_test.xml"}) public void fromConfiguration_loadsSingleVertexWithPrecision_WithSuccess(String configurationFile) throws Exception { createConfiguration(configurationFile); createConfiguration(configurationFile); SimulationState state = mock(SimulationState.class); graphOperation.callPreProcessing(state); Vertex vertexInSideArea = scenarioManager.getGraph().getVertex(4); boolean isSeed = vertexInSideArea.isSeed(); boolean isInArea = scenarioManager.getArea(1).getGeometry().contains(vertexInSideArea.getGeometry().getCenter()); assertTrue(isSeed && isInArea); }
@Override public void callPreProcessing(SimulationState simulationState) { Integer graphId = this.properties.getIntegerProperty(graphIdName); Double precisionSeed = this.properties.getDoubleProperty(precisionSeedName); Boolean insideAreaSeed = this.properties.getBooleanProperty(insideAreaSeedName); GraphScenarioConfiguration graphConfiguration = null; for(GraphScenarioConfiguration graphScenarioConfiguration : configurations.get(0).getGraphs()) { if(graphScenarioConfiguration.getId().intValue() == graphId) { graphConfiguration = graphScenarioConfiguration; } } HashSet<Area> alreadySeedAreas = new HashSet<>(); Graph graph = GraphTheoryFactory.createGraph(graphConfiguration.getName()); graph.setId(graphConfiguration.getId()); this.scenarioManager.getGraphs().add(graph); for(VertexConfiguration vertexConfiguration : graphConfiguration.getVertices()) { Vertex newVertex = null; Vector2D center = GeometryFactory.createVector(vertexConfiguration.getPoint().getX(), vertexConfiguration.getPoint().getY()); boolean isSeed = this.scenarioManager.getAreas() .stream() .filter(area -> { if(precisionSeed != null && FastMath.abs(area.getPointOfInterest().distance(center)) < precisionSeed) { return true; } else if (insideAreaSeed != null && insideAreaSeed && area.getGeometry().contains(center)) { return true; } return false; }) .count() > 0; if(isSeed) { Area area = this.scenarioManager.getAreas() .stream() .filter(existingArea -> { if(!alreadySeedAreas.contains(existingArea)) { if(precisionSeed != null && FastMath.abs(existingArea.getPointOfInterest().distance(center)) < precisionSeed) { return true; } else if (insideAreaSeed != null && insideAreaSeed && existingArea.getGeometry().contains(center)) { return true; } } return false; }) .findFirst() .orElse(null); if(area != null) { alreadySeedAreas.add(area); newVertex = GraphTheoryFactory.createVertex(area.getGeometry(), true, vertexConfiguration.getId()); } else { newVertex = GraphTheoryFactory.createVertexCyleBased(center, vertexConfiguration.getId()); } } else { newVertex = GraphTheoryFactory.createVertexCyleBased(center, vertexConfiguration.getId()); } graph.addVertex(newVertex); } for(EdgeConfiguration edgeConfiguration : graphConfiguration.getEdges()) { Vertex left = graph.getVertex(edgeConfiguration.getIdLeft()); Vertex right = graph.getVertex(edgeConfiguration.getIdRight()); graph.doublyConnectVertices(left, right); } }
FromConfigurationOperation extends GraphOperation { @Override public void callPreProcessing(SimulationState simulationState) { Integer graphId = this.properties.getIntegerProperty(graphIdName); Double precisionSeed = this.properties.getDoubleProperty(precisionSeedName); Boolean insideAreaSeed = this.properties.getBooleanProperty(insideAreaSeedName); GraphScenarioConfiguration graphConfiguration = null; for(GraphScenarioConfiguration graphScenarioConfiguration : configurations.get(0).getGraphs()) { if(graphScenarioConfiguration.getId().intValue() == graphId) { graphConfiguration = graphScenarioConfiguration; } } HashSet<Area> alreadySeedAreas = new HashSet<>(); Graph graph = GraphTheoryFactory.createGraph(graphConfiguration.getName()); graph.setId(graphConfiguration.getId()); this.scenarioManager.getGraphs().add(graph); for(VertexConfiguration vertexConfiguration : graphConfiguration.getVertices()) { Vertex newVertex = null; Vector2D center = GeometryFactory.createVector(vertexConfiguration.getPoint().getX(), vertexConfiguration.getPoint().getY()); boolean isSeed = this.scenarioManager.getAreas() .stream() .filter(area -> { if(precisionSeed != null && FastMath.abs(area.getPointOfInterest().distance(center)) < precisionSeed) { return true; } else if (insideAreaSeed != null && insideAreaSeed && area.getGeometry().contains(center)) { return true; } return false; }) .count() > 0; if(isSeed) { Area area = this.scenarioManager.getAreas() .stream() .filter(existingArea -> { if(!alreadySeedAreas.contains(existingArea)) { if(precisionSeed != null && FastMath.abs(existingArea.getPointOfInterest().distance(center)) < precisionSeed) { return true; } else if (insideAreaSeed != null && insideAreaSeed && existingArea.getGeometry().contains(center)) { return true; } } return false; }) .findFirst() .orElse(null); if(area != null) { alreadySeedAreas.add(area); newVertex = GraphTheoryFactory.createVertex(area.getGeometry(), true, vertexConfiguration.getId()); } else { newVertex = GraphTheoryFactory.createVertexCyleBased(center, vertexConfiguration.getId()); } } else { newVertex = GraphTheoryFactory.createVertexCyleBased(center, vertexConfiguration.getId()); } graph.addVertex(newVertex); } for(EdgeConfiguration edgeConfiguration : graphConfiguration.getEdges()) { Vertex left = graph.getVertex(edgeConfiguration.getIdLeft()); Vertex right = graph.getVertex(edgeConfiguration.getIdRight()); graph.doublyConnectVertices(left, right); } } }
FromConfigurationOperation extends GraphOperation { @Override public void callPreProcessing(SimulationState simulationState) { Integer graphId = this.properties.getIntegerProperty(graphIdName); Double precisionSeed = this.properties.getDoubleProperty(precisionSeedName); Boolean insideAreaSeed = this.properties.getBooleanProperty(insideAreaSeedName); GraphScenarioConfiguration graphConfiguration = null; for(GraphScenarioConfiguration graphScenarioConfiguration : configurations.get(0).getGraphs()) { if(graphScenarioConfiguration.getId().intValue() == graphId) { graphConfiguration = graphScenarioConfiguration; } } HashSet<Area> alreadySeedAreas = new HashSet<>(); Graph graph = GraphTheoryFactory.createGraph(graphConfiguration.getName()); graph.setId(graphConfiguration.getId()); this.scenarioManager.getGraphs().add(graph); for(VertexConfiguration vertexConfiguration : graphConfiguration.getVertices()) { Vertex newVertex = null; Vector2D center = GeometryFactory.createVector(vertexConfiguration.getPoint().getX(), vertexConfiguration.getPoint().getY()); boolean isSeed = this.scenarioManager.getAreas() .stream() .filter(area -> { if(precisionSeed != null && FastMath.abs(area.getPointOfInterest().distance(center)) < precisionSeed) { return true; } else if (insideAreaSeed != null && insideAreaSeed && area.getGeometry().contains(center)) { return true; } return false; }) .count() > 0; if(isSeed) { Area area = this.scenarioManager.getAreas() .stream() .filter(existingArea -> { if(!alreadySeedAreas.contains(existingArea)) { if(precisionSeed != null && FastMath.abs(existingArea.getPointOfInterest().distance(center)) < precisionSeed) { return true; } else if (insideAreaSeed != null && insideAreaSeed && existingArea.getGeometry().contains(center)) { return true; } } return false; }) .findFirst() .orElse(null); if(area != null) { alreadySeedAreas.add(area); newVertex = GraphTheoryFactory.createVertex(area.getGeometry(), true, vertexConfiguration.getId()); } else { newVertex = GraphTheoryFactory.createVertexCyleBased(center, vertexConfiguration.getId()); } } else { newVertex = GraphTheoryFactory.createVertexCyleBased(center, vertexConfiguration.getId()); } graph.addVertex(newVertex); } for(EdgeConfiguration edgeConfiguration : graphConfiguration.getEdges()) { Vertex left = graph.getVertex(edgeConfiguration.getIdLeft()); Vertex right = graph.getVertex(edgeConfiguration.getIdRight()); graph.doublyConnectVertices(left, right); } } FromConfigurationOperation(ArrayList<ScenarioConfiguration> scenarioConfigurations); }
FromConfigurationOperation extends GraphOperation { @Override public void callPreProcessing(SimulationState simulationState) { Integer graphId = this.properties.getIntegerProperty(graphIdName); Double precisionSeed = this.properties.getDoubleProperty(precisionSeedName); Boolean insideAreaSeed = this.properties.getBooleanProperty(insideAreaSeedName); GraphScenarioConfiguration graphConfiguration = null; for(GraphScenarioConfiguration graphScenarioConfiguration : configurations.get(0).getGraphs()) { if(graphScenarioConfiguration.getId().intValue() == graphId) { graphConfiguration = graphScenarioConfiguration; } } HashSet<Area> alreadySeedAreas = new HashSet<>(); Graph graph = GraphTheoryFactory.createGraph(graphConfiguration.getName()); graph.setId(graphConfiguration.getId()); this.scenarioManager.getGraphs().add(graph); for(VertexConfiguration vertexConfiguration : graphConfiguration.getVertices()) { Vertex newVertex = null; Vector2D center = GeometryFactory.createVector(vertexConfiguration.getPoint().getX(), vertexConfiguration.getPoint().getY()); boolean isSeed = this.scenarioManager.getAreas() .stream() .filter(area -> { if(precisionSeed != null && FastMath.abs(area.getPointOfInterest().distance(center)) < precisionSeed) { return true; } else if (insideAreaSeed != null && insideAreaSeed && area.getGeometry().contains(center)) { return true; } return false; }) .count() > 0; if(isSeed) { Area area = this.scenarioManager.getAreas() .stream() .filter(existingArea -> { if(!alreadySeedAreas.contains(existingArea)) { if(precisionSeed != null && FastMath.abs(existingArea.getPointOfInterest().distance(center)) < precisionSeed) { return true; } else if (insideAreaSeed != null && insideAreaSeed && existingArea.getGeometry().contains(center)) { return true; } } return false; }) .findFirst() .orElse(null); if(area != null) { alreadySeedAreas.add(area); newVertex = GraphTheoryFactory.createVertex(area.getGeometry(), true, vertexConfiguration.getId()); } else { newVertex = GraphTheoryFactory.createVertexCyleBased(center, vertexConfiguration.getId()); } } else { newVertex = GraphTheoryFactory.createVertexCyleBased(center, vertexConfiguration.getId()); } graph.addVertex(newVertex); } for(EdgeConfiguration edgeConfiguration : graphConfiguration.getEdges()) { Vertex left = graph.getVertex(edgeConfiguration.getIdLeft()); Vertex right = graph.getVertex(edgeConfiguration.getIdRight()); graph.doublyConnectVertices(left, right); } } FromConfigurationOperation(ArrayList<ScenarioConfiguration> scenarioConfigurations); @Override void callPreProcessing(SimulationState simulationState); @Override void callPostProcessing(SimulationState simulationState); }
FromConfigurationOperation extends GraphOperation { @Override public void callPreProcessing(SimulationState simulationState) { Integer graphId = this.properties.getIntegerProperty(graphIdName); Double precisionSeed = this.properties.getDoubleProperty(precisionSeedName); Boolean insideAreaSeed = this.properties.getBooleanProperty(insideAreaSeedName); GraphScenarioConfiguration graphConfiguration = null; for(GraphScenarioConfiguration graphScenarioConfiguration : configurations.get(0).getGraphs()) { if(graphScenarioConfiguration.getId().intValue() == graphId) { graphConfiguration = graphScenarioConfiguration; } } HashSet<Area> alreadySeedAreas = new HashSet<>(); Graph graph = GraphTheoryFactory.createGraph(graphConfiguration.getName()); graph.setId(graphConfiguration.getId()); this.scenarioManager.getGraphs().add(graph); for(VertexConfiguration vertexConfiguration : graphConfiguration.getVertices()) { Vertex newVertex = null; Vector2D center = GeometryFactory.createVector(vertexConfiguration.getPoint().getX(), vertexConfiguration.getPoint().getY()); boolean isSeed = this.scenarioManager.getAreas() .stream() .filter(area -> { if(precisionSeed != null && FastMath.abs(area.getPointOfInterest().distance(center)) < precisionSeed) { return true; } else if (insideAreaSeed != null && insideAreaSeed && area.getGeometry().contains(center)) { return true; } return false; }) .count() > 0; if(isSeed) { Area area = this.scenarioManager.getAreas() .stream() .filter(existingArea -> { if(!alreadySeedAreas.contains(existingArea)) { if(precisionSeed != null && FastMath.abs(existingArea.getPointOfInterest().distance(center)) < precisionSeed) { return true; } else if (insideAreaSeed != null && insideAreaSeed && existingArea.getGeometry().contains(center)) { return true; } } return false; }) .findFirst() .orElse(null); if(area != null) { alreadySeedAreas.add(area); newVertex = GraphTheoryFactory.createVertex(area.getGeometry(), true, vertexConfiguration.getId()); } else { newVertex = GraphTheoryFactory.createVertexCyleBased(center, vertexConfiguration.getId()); } } else { newVertex = GraphTheoryFactory.createVertexCyleBased(center, vertexConfiguration.getId()); } graph.addVertex(newVertex); } for(EdgeConfiguration edgeConfiguration : graphConfiguration.getEdges()) { Vertex left = graph.getVertex(edgeConfiguration.getIdLeft()); Vertex right = graph.getVertex(edgeConfiguration.getIdRight()); graph.doublyConnectVertices(left, right); } } FromConfigurationOperation(ArrayList<ScenarioConfiguration> scenarioConfigurations); @Override void callPreProcessing(SimulationState simulationState); @Override void callPostProcessing(SimulationState simulationState);  }