public static Link getNearestLink(Network network, Coord coord) { return NetworkUtils.getNearestLink(network, coord) ; } public static Link getNearestLinkExactly( Network network, Coord coord ) {
@Test public void testRemoveLink_alsoInQuadTrees() { Network network = new NetworkImpl(); Node node1 = NetworkUtils.createNode(Id.create(1, Node.class), new Coord(100, 100)); Node node2 = NetworkUtils.createNode(Id.create(2, Node.class), new Coord(1000, 200)); Node node3 = NetworkUtils.createNode(Id.create(3, Node.class), new Coord(500, 700)); network.addNode(node1); network.addNode(node2); network.addNode(node3); Link link1 = NetworkUtils.createLink(Id.create(1, Link.class), node1, node2, network, 800, 13.4, 2000, 1); Link link2 = NetworkUtils.createLink(Id.create(2, Link.class), node2, node3, network, 800, 13.4, 2000, 1); Link link3 = NetworkUtils.createLink(Id.create(3, Link.class), node3, node1, network, 800, 13.4, 2000, 1); network.addLink(link1); network.addLink(link2); network.addLink(link3); Assert.assertEquals(3, network.getLinks().size()); Assert.assertEquals(link1, NetworkUtils.getNearestLink(network, new Coord(300, 200))); Assert.assertEquals(link1, NetworkUtils.getNearestLinkExactly(network, new Coord(300, 200))); network.removeLink(link1.getId()); Assert.assertEquals(2, network.getLinks().size()); Assert.assertEquals(link3, NetworkUtils.getNearestLink(network, new Coord(300, 200))); Assert.assertEquals(link3, NetworkUtils.getNearestLinkExactly(network, new Coord(300, 200))); network.removeLink(link3.getId()); Assert.assertEquals(1, network.getLinks().size()); Assert.assertEquals(link2, NetworkUtils.getNearestLinkExactly(network, new Coord(300, 200))); network.removeLink(link2.getId()); Assert.assertEquals(0, network.getLinks().size()); Assert.assertNull(NetworkUtils.getNearestLink(network, new Coord(300, 200))); Assert.assertNull(NetworkUtils.getNearestLinkExactly(network, new Coord(300, 200))); }
protected boolean modifyLocation(Activity act, Coord startCoord, Coord endCoord, double radius, int trialNr) { ArrayList<ActivityFacility> choiceSet = this.computeChoiceSetCircle(startCoord, endCoord, radius, act.getType()); if (choiceSet.size()>1) { //final Facility facility=(Facility)choiceSet.toArray()[ // MatsimRandom.random.nextInt(choiceSet.size())]; final ActivityFacility facility = choiceSet.get(super.random.nextInt(choiceSet.size())); act.setFacilityId(facility.getId()); act.setLinkId(NetworkUtils.getNearestLink(((Network) this.scenario.getNetwork()), facility.getCoord()).getId()); act.setCoord(facility.getCoord()); return true; } // else ... return false; }
@Test public void testAddLink_intoEmptyQuadTree() { Network network = new NetworkImpl(); Assert.assertEquals(0, network.getLinks().size()); Assert.assertNull(NetworkUtils.getNearestLink(network, new Coord(300, 200))); // this will force the node QuadTree to be built Assert.assertNull(NetworkUtils.getNearestLinkExactly(network, new Coord(300, 200))); // this will force the LinkQuadTree to be built Node node1 = NetworkUtils.createNode(Id.create(1, Node.class), new Coord(100, 100)); Node node2 = NetworkUtils.createNode(Id.create(2, Node.class), new Coord(1000, 200)); Node node3 = NetworkUtils.createNode(Id.create(3, Node.class), new Coord(500, 700)); network.addNode(node1); network.addNode(node2); network.addNode(node3); Link link1 = NetworkUtils.createLink(Id.create(1, Link.class), node1, node2, network, 800, 13.4, 2000, 1); Link link2 = NetworkUtils.createLink(Id.create(2, Link.class), node2, node3, network, 800, 13.4, 2000, 1); Link link3 = NetworkUtils.createLink(Id.create(3, Link.class), node3, node1, network, 800, 13.4, 2000, 1); network.addLink(link1); network.addLink(link2); network.addLink(link3); Assert.assertEquals(3, network.getLinks().size()); Assert.assertEquals(link1, NetworkUtils.getNearestLink(network, new Coord(300, 200))); Assert.assertEquals(link1, NetworkUtils.getNearestLinkExactly(network, new Coord(300, 200))); // this will force the LinkQuadTree to be built } }
linkNullWarn++; Link link = NetworkUtils.getNearestLink(network, activityFacility.getCoord()); if (link==null) { LOGGER.warn("No nearest link is found for coord "+activityFacility.getCoord());
@Test public void testAddLink_alsoInQuadTrees() { Network network = new NetworkImpl(); Node node1 = NetworkUtils.createNode(Id.create(1, Node.class), new Coord(100, 100)); Node node2 = NetworkUtils.createNode(Id.create(2, Node.class), new Coord(1000, 200)); Node node3 = NetworkUtils.createNode(Id.create(3, Node.class), new Coord(500, 700)); network.addNode(node1); network.addNode(node2); network.addNode(node3); Link link1 = NetworkUtils.createLink(Id.create(1, Link.class), node1, node2, network, 800, 13.4, 2000, 1); Link link2 = NetworkUtils.createLink(Id.create(2, Link.class), node2, node3, network, 800, 13.4, 2000, 1); Link link3 = NetworkUtils.createLink(Id.create(3, Link.class), node3, node1, network, 800, 13.4, 2000, 1); // do not yet add link1 network.addLink(link2); network.addLink(link3); Assert.assertEquals(2, network.getLinks().size()); Assert.assertEquals(link3, NetworkUtils.getNearestLink(network, new Coord(300, 200))); Assert.assertEquals(link3, NetworkUtils.getNearestLinkExactly(network, new Coord(300, 200))); // this will force the LinkQuadTree to be built network.addLink(link1); Assert.assertEquals(3, network.getLinks().size()); // check that the quad trees were correctly updated with the new link Assert.assertEquals(link1, NetworkUtils.getNearestLink(network, new Coord(300, 200))); Assert.assertEquals(link1, NetworkUtils.getNearestLinkExactly(network, new Coord(300, 200))); // this will force the LinkQuadTree to be built }
private void setNewLocationForAct(Activity act, int length) { ActivityFacilityImpl facility = this.facilitiesOfType.get(act.getType())[super.random.nextInt(length)]; act.setFacilityId(facility.getId()); act.setLinkId(NetworkUtils.getNearestLink(((Network) this.scenario.getNetwork()), facility.getCoord()).getId()); act.setCoord(facility.getCoord()); } }
accessActLink = NetworkUtils.getNearestLink(network, fromFacility.getCoord()) ; if ( accessActLink == null ) { int ii = 0 ;
protected final boolean modifyLocation(Activity act, Coord startCoord, Coord endCoord, double radius) { double midPointX = (startCoord.getX() + endCoord.getX()) / 2.0; double midPointY = (startCoord.getY() + endCoord.getY()) / 2.0; ArrayList<ActivityFacility> facilitySet = (ArrayList<ActivityFacility>) this.quadTreesOfType.get(this.defineFlexibleActivities.getConverter().convertType(act.getType())). getDisk(midPointX, midPointY, radius); ActivityFacility facility = null; if (facilitySet.size() > 1) { facility = facilitySet.get(super.random.nextInt(facilitySet.size())); } else { return false; } act.setFacilityId(facility.getId()); act.setLinkId(NetworkUtils.getNearestLink(((Network) this.scenario.getNetwork()), facility.getCoord()).getId()); act.setCoord(facility.getCoord()); return true; }
Link link = NetworkUtils.getNearestLink(this.network, act.getCoord());
public BestReplyDestinationChoice(Provider<TripRouter> tripRouterProvider, DestinationChoiceContext lcContext, ObjectAttributes personsMaxDCScoreUnscaled, ScoringFunctionFactory scoringFunctionFactory, Map<String, TravelTime> travelTimes, Map<String, TravelDisutilityFactory> travelDisutilities) { super(lcContext.getScenario().getConfig().global()); this.tripRouterProvider = tripRouterProvider; this.scoringFunctionFactory = scoringFunctionFactory; this.travelTimes = travelTimes; this.travelDisutilities = travelDisutilities; this.dccg = (DestinationChoiceConfigGroup) lcContext.getScenario().getConfig().getModule(DestinationChoiceConfigGroup.GROUP_NAME); if (!DestinationChoiceConfigGroup.Algotype.bestResponse.equals(this.dccg.getAlgorithm())) { throw new RuntimeException("wrong class for selected location choice algorithm type; aborting ...") ; } this.lcContext = lcContext; this.scenario = lcContext.getScenario(); this.personsMaxEpsUnscaled = personsMaxDCScoreUnscaled; this.forwardMultiNodeDijsktaFactory = new FastMultiNodeDijkstraFactory(true); this.backwardMultiNodeDijsktaFactory = new BackwardFastMultiNodeDijkstraFactory(true); // create cache which is used in ChoiceSet // instead of just the nearest link we probably should check whether the facility is attached to a link? cdobler, oct'14 this.nearestLinks = new HashMap<>(); for (ActivityFacility facility : this.scenario.getActivityFacilities().getFacilities().values()) { if (facility.getLinkId() != null) this.nearestLinks.put(facility.getId(), facility.getLinkId()); else this.nearestLinks.put(facility.getId(), NetworkUtils.getNearestLink(scenario.getNetwork(), facility.getCoord()).getId()); } initLocal(); }
final Link destLink = NetworkUtils.getNearestLink(getScenario().getNetwork(), coord ); Gbl.assertNotNull(destLink); final Link currentLink = scenario.getNetwork().getLinks().get( this.getMobsimAgentFromIdString(agentID).getCurrentLinkId() );
if (linkId != null) { destinationLink = this.network.getLinks().get(linkId); } else destinationLink = NetworkUtils.getNearestLink(((Network) this.network), destinationFacility.getCoord());
if ( fromLink==null ) { Gbl.assertNotNull( fromFacility.getCoord() ) ; fromLink = NetworkUtils.getNearestLink( network, fromFacility.getCoord()) ; toLink = NetworkUtils.getNearestLink(network, toFacility.getCoord());
final Link nearestLink = NetworkUtils.getNearestLink(model.getScenario().getNetwork(), coord ); Gbl.assertNotNull(nearestLink); Id<Link> newLinkId = nearestLink.getId();
final Link nearestLink = NetworkUtils.getNearestLink(model.getScenario().getNetwork(), coord ); Gbl.assertNotNull(nearestLink); Id<Link> newLinkId = nearestLink.getId();