private OneWayCarsharingRDWithParkingStation findClosestAvailableParkingSpace(Link link) { // find the closest available car in the quad tree(?) reserve it (make it unavailable) // if no cars within certain radius return null double distanceSearch = Double.parseDouble( scenario .getConfig() .getModule("OneWayCarsharing") .getParams() .get("searchDistanceOneWayCarsharing")); Collection<OneWayCarsharingRDWithParkingStation> location = this.carSharingVehicles .getOneWayVehicles() .getQuadTree() .getDisk(link.getCoord().getX(), link.getCoord().getY(), distanceSearch); if (location.isEmpty()) return null; OneWayCarsharingRDWithParkingStation closest = null; for (OneWayCarsharingRDWithParkingStation station : location) { if (CoordUtils.calcEuclideanDistance(link.getCoord(), station.getLink().getCoord()) < distanceSearch && station.getNumberOfAvailableParkingSpaces() > 0) { closest = station; distanceSearch = CoordUtils.calcEuclideanDistance(link.getCoord(), station.getLink().getCoord()); } } // owvehiclesLocation.removeVehicle(closest.getLink()); return closest; }
private void createDemand() { Population pop = sc.getPopulation(); PopulationFactory fact = pop.getFactory(); for (int i = 1; i <= 400; i++) { Person p = fact.createPerson(Id.createPersonId(i)); Plan plan = fact.createPlan(); p.addPlan(plan); Leg leg = fact.createLeg(TransportMode.car); Activity home; Activity work; if (i % 2 == 0) { // o --d1 home = fact.createActivityFromCoord("o1", lo.getCoord()); home.setEndTime(7 * 3600 + i); work = fact.createActivityFromCoord("d1", ld1.getCoord()); } else /*if(i%2==0)*/ { // o --d2 home = fact.createActivityFromCoord("o1", lo.getCoord()); home.setEndTime(7 * 3600 + i); work = fact.createActivityFromCoord("d2", ld2.getCoord()); } plan.addActivity(home); plan.addLeg(leg); plan.addActivity(work); pop.addPerson(p); } new PopulationWriter(pop).write(outputDir + "/input/input_plans.xml.gz"); }
public static final QuadTree<ActivityFacility> createFacilityQuadTree(Controler controler) { double minx = (1.0D / 0.0D); double miny = (1.0D / 0.0D); double maxx = (-1.0D / 0.0D); double maxy = (-1.0D / 0.0D); for (Link l : controler.getScenario().getNetwork().getLinks().values()) { if (l.getCoord().getX() < minx) minx = l.getCoord().getX(); if (l.getCoord().getY() < miny) miny = l.getCoord().getY(); if (l.getCoord().getX() > maxx) maxx = l.getCoord().getX(); if (l.getCoord().getY() <= maxy) continue; maxy = l.getCoord().getY(); } minx -= 1.0D; miny -= 1.0D; maxx += 1.0D; maxy += 1.0D; QuadTree<ActivityFacility> facilityQuadTree = new QuadTree<ActivityFacility>(minx, miny, maxx, maxy); for (ActivityFacility f : controler.getScenario().getActivityFacilities().getFacilities().values()) { ((ActivityFacilityImpl) f) .setLinkId( NetworkUtils.getNearestLink( ((NetworkImpl) controler.getScenario().getNetwork()), f.getCoord()) .getId()); Coord c = f.getCoord(); facilityQuadTree.put(c.getX(), c.getY(), f); } return facilityQuadTree; }
public static void main(String[] args) { Matrix parkingTimesEC = GeneralLib.readStringMatrix( "A:/for marina/26. april 2012/parkingTimesAndEnergyConsumptionCH.txt"); Network network = GeneralLib.readNetwork( "H:/data/cvs/ivt/studies/switzerland/networks/teleatlas-ivtcheu/network.xml.gz"); HashMap<String, Id> agentIds = new HashMap(); BasicPointVisualizer basicPointVisualizer = new BasicPointVisualizer(); for (int i = 0; i < parkingTimesEC.getNumberOfRows(); i++) { String actType = parkingTimesEC.getString(i, 4); Id<Link> linkId = Id.create(parkingTimesEC.getString(i, 3), Link.class); Link link = network.getLinks().get(linkId); if (actType.equalsIgnoreCase("tta")) { agentIds.put(parkingTimesEC.getString(i, 0), null); // System.out.println("x"); basicPointVisualizer.addPointCoordinate( new Coord(link.getCoord().getX(), link.getCoord().getY()), "", Color.GREEN); } } // for (String agentId:agentIds.keySet()){ // System.out.println(agentId); // } basicPointVisualizer.write("c:/temp/abdd.kml"); }
@Override public void startTag(String name, Attributes atts, Stack<String> context) { if (name.equals("company")) { companyName = atts.getValue("name"); this.companyNames.add(companyName); createQuadTrees(); twowaycarsharingstationsMap = new HashMap<String, CarsharingStation>(); onewaycarsharingstationsMap = new HashMap<String, CarsharingStation>(); ffvehiclesMap = new HashMap<CSVehicle, Link>(); ffvehicleIdMap = new HashMap<String, CSVehicle>(); owvehicleIdMap = new HashMap<String, CSVehicle>(); owvehiclesMap = new HashMap<CSVehicle, Link>(); twvehicleIdMap = new HashMap<String, CSVehicle>(); twvehiclesMap = new HashMap<CSVehicle, Link>(); // allVehicles = new HashMap<String, CSVehicle>(); // companies = new HashMap<String, CompanyContainer>(); } else if (name.equals("twoway") || name.equals("oneway")) { csType = name; id = atts.getValue("id"); String xCoord = atts.getValue("x"); String yCoord = atts.getValue("y"); Coord coordStation = new Coord(Double.parseDouble(xCoord), Double.parseDouble(yCoord)); link = (Link) NetworkUtils.getNearestLinkExactly(network, coordStation); vehicles = new ArrayList<StationBasedVehicle>(); if (name.equals("oneway")) { avaialbleParkingSpots = Integer.parseInt(atts.getValue("freeparking")); hasOW = true; } else hasTW = true; } else if (name.equals("freefloating")) { hasFF = true; String xCoord = atts.getValue("x"); String yCoord = atts.getValue("y"); String type = atts.getValue("type"); Coord coordStation = new Coord(Double.parseDouble(xCoord), Double.parseDouble(yCoord)); link = (Link) NetworkUtils.getNearestLinkExactly(network, coordStation); FFVehicleImpl ffcsvehicle = new FFVehicleImpl(type, atts.getValue("id"), companyName); ffVehicleLocationQuadTree.put(link.getCoord().getX(), link.getCoord().getY(), ffcsvehicle); ffvehiclesMap.put(ffcsvehicle, link); ffvehicleIdMap.put(atts.getValue("id"), ffcsvehicle); this.allVehicles.put(atts.getValue("id"), ffcsvehicle); allVehicleLocations.put(ffcsvehicle, link); } else if (name.equals("vehicle")) { StationBasedVehicle vehicle = new StationBasedVehicle( atts.getValue("type"), atts.getValue("vehicleID"), id, csType, companyName); vehicles.add(vehicle); this.allVehicles.put(atts.getValue("vehicleID"), vehicle); this.allVehicleLocations.put(vehicle, link); } }
private void initializeCSVehicleLeg( String mode, double now, Link startLink, Link destinationLink) { double travelTime = 0.0; List<Id<Link>> ids = new ArrayList<Id<Link>>(); Coord coordStart = new Coord(startLink.getCoord().getX(), startLink.getCoord().getY()); TwoWayCSFacilityImpl dummyStartFacility = new TwoWayCSFacilityImpl( Id.create("1000000000", TwoWayCSFacility.class), coordStart, startLink.getId()); Coord coordEnd = new Coord(destinationLink.getCoord().getX(), destinationLink.getCoord().getY()); TwoWayCSFacilityImpl dummyEndFacility = new TwoWayCSFacilityImpl( Id.create("1000000001", TwoWayCSFacility.class), coordEnd, destinationLink.getId()); for (PlanElement pe1 : this.tripRouter.calcRoute("car", dummyStartFacility, dummyEndFacility, now, person)) { if (pe1 instanceof Leg) { ids = ((NetworkRoute) ((Leg) pe1).getRoute()).getLinkIds(); travelTime += ((Leg) pe1).getTravelTime(); } } LegImpl carLeg = new LegImpl(mode); carLeg.setTravelTime(travelTime); NetworkRoute route = ((PopulationFactoryImpl) scenario.getPopulation().getFactory()) .getModeRouteFactory() .createRoute(NetworkRoute.class, startLink.getId(), destinationLink.getId()); route.setLinkIds(startLink.getId(), ids, destinationLink.getId()); route.setTravelTime(travelTime); if (mode.equals("twowaycarsharing")) route.setVehicleId(Id.create("TW_" + (twVehId), Vehicle.class)); else if (mode.equals("onewaycarsharing")) route.setVehicleId(Id.create("OW_" + (owVehId), Vehicle.class)); else if (mode.equals("freefloating")) route.setVehicleId(Id.create("FF_" + (ffVehId), Vehicle.class)); carLeg.setRoute(route); this.cachedDestinationLinkId = route.getEndLinkId(); this.currentLeg = carLeg; this.cachedRouteLinkIds = null; this.currentLinkIdIndex = 0; this.cachedNextLinkId = null; }
private double computeDistances( final PersonArrivalEvent arrivalEvent, final PersonDepartureEvent departureEvent) { Link departureLink; Link arrivalLink; double distance; departureLink = this.network.getLinks().get(departureEvent.getLinkId()); arrivalLink = this.network.getLinks().get(arrivalEvent.getLinkId()); distance = CoordUtils.calcDistance(departureLink.getCoord(), arrivalLink.getCoord()); return distance; }
private FreeFloatingStation findClosestAvailableCar(Id<Link> linkId) { // find the closest available car in the quad tree(?) reserve it (make it unavailable) Link link = scenario.getNetwork().getLinks().get(linkId); FreeFloatingStation location = this.carSharingVehicles .getFreeFLoatingVehicles() .getQuadTree() .getClosest(link.getCoord().getX(), link.getCoord().getY()); return location; }
public void printLinkFlows() { // print for (Id linkId : linkOutFlow.keySet()) { int[] bins = linkOutFlow.get(linkId); Link link = filteredEquilNetLinks.get(linkId); boolean hasTraffic = false; for (int i = 0; i < bins.length; i++) { if (bins[i] != 0.0) { hasTraffic = true; break; } } if (hasTraffic) { System.out.print(linkId + " - " + link.getCoord() + ": \t"); for (int i = 0; i < bins.length; i++) { System.out.print(bins[i] * 3600 / binSizeInSeconds + "\t"); } System.out.println(); } } }
private Map<Double, Map<Id<Link>, Double>> filterLinks( Map<Double, Map<Id<Link>, Double>> time2LinksData) { Map<Double, Map<Id<Link>, Double>> time2LinksDataFiltered = new HashMap<Double, Map<Id<Link>, Double>>(); for (Double endOfTimeInterval : time2LinksData.keySet()) { Map<Id<Link>, Double> linksData = time2LinksData.get(endOfTimeInterval); Map<Id<Link>, Double> linksDataFiltered = new HashMap<Id<Link>, Double>(); for (Link link : network.getLinks().values()) { Coord linkCoord = link.getCoord(); if (this.sau.isInResearchArea(linkCoord)) { Id<Link> linkId = link.getId(); if (linksData.get(linkId) == null) { linksDataFiltered.put(linkId, 0.); } else { linksDataFiltered.put(linkId, linksData.get(linkId)); } } } time2LinksDataFiltered.put(endOfTimeInterval, linksDataFiltered); } return time2LinksDataFiltered; }
// Create external Facilities that are used by transit traffic agents. private static void createExternalFacilities(Scenario scenario, Set<Id<Node>> externalNodes) { ActivityFacilities activityFacilities = scenario.getActivityFacilities(); ActivityFacilitiesFactory factory = activityFacilities.getFactory(); /* * We check for all OutLinks of all external nodes if they already host a facility. If not, * a new facility with a tta ActivityOption will be created and added. */ for (Id<Node> id : externalNodes) { Node externalNode = scenario.getNetwork().getNodes().get(id); for (Link externalLink : externalNode.getOutLinks().values()) { ActivityFacility facility = activityFacilities.getFacilities().get(externalLink.getId()); // if already a facility exists we have nothing left to do if (facility != null) continue; /* * No Facility exists at that link therefore we create and add a new one. */ double fromX = externalLink.getFromNode().getCoord().getX(); double fromY = externalLink.getFromNode().getCoord().getY(); double toX = externalLink.getToNode().getCoord().getX(); double toY = externalLink.getToNode().getCoord().getY(); double dX = toX - fromX; double dY = toY - fromY; double length = Math.sqrt(Math.pow(dX, 2) + Math.pow(dY, 2)); double centerX = externalLink.getCoord().getX(); double centerY = externalLink.getCoord().getY(); /* * Unit vector that directs with an angle of 90° away from the link. */ double unitVectorX = dY / length; double unitVectorY = -dX / length; Coord coord = new Coord(centerX + unitVectorX, centerY + unitVectorY); facility = activityFacilities .getFactory() .createActivityFacility( Id.create(externalLink.getId().toString(), ActivityFacility.class), coord); activityFacilities.addActivityFacility(facility); ((ActivityFacilityImpl) facility).setLinkId(externalLink.getId()); ActivityOption activityOption = factory.createActivityOption(ttaActivityType); activityOption.addOpeningTime(new OpeningTimeImpl(0 * 3600, 24 * 3600)); activityOption.setCapacity(capacity); facility.addActivityOption(activityOption); } } }
public double getAngle(Link link) { Point2D fromPoint = new Point2D(link.getFromNode().getCoord().getX(), link.getFromNode().getCoord().getY()); Point2D toPoint = new Point2D(link.getToNode().getCoord().getX(), link.getToNode().getCoord().getY()); Vector2D linkVector = new Vector2D(fromPoint, toPoint); Vector2D shapeVector = getVector(link.getCoord()); return linkVector.getAngleTo(shapeVector); }
public Collection<Link> getNetworkLinks(double xMin, double yMin, double xMax, double yMax) { Collection<Link> links = new HashSet<Link>(); for (Link link : network.getLinks().values()) { Coord linkCenter = link.getCoord(); if (xMin - 10 * minDistance < linkCenter.getX() && yMin - 10 * minDistance < linkCenter.getY() && xMax + 10 * minDistance > linkCenter.getX() && yMax + 10 * minDistance > linkCenter.getY()) links.add(link); } return links; }
private Map<Link, Cell> mapLinksToGridCells(Collection<Link> links, SpatialGrid grid) { links2Cells = new HashMap<Link, Cell>(); for (Link link : links) { Cell cCell = grid.getCellForCoordinate(link.getCoord()); if (cCell != null) links2Cells.put(link, cCell); } System.out.println("Mapped " + links2Cells.size() + " links to grid"); System.out.println((links.size() - links2Cells.size()) + " links were not mapped."); return links2Cells; }
public static final void moveFacility(ActivityFacilityImpl f, Link link) { double[] vector = new double[2]; vector[0] = (link.getToNode().getCoord().getY() - link.getFromNode().getCoord().getY()); vector[1] = (-(link.getToNode().getCoord().getX() - link.getFromNode().getCoord().getX())); Coord coord = new CoordImpl( link.getCoord().getX() + vector[0] * EPSILON, link.getCoord().getY() + vector[1] * 0.0001D); f.setCoord(coord); f.setLinkId(link.getId()); }
private TwoWayCSStation findClosestAvailableTWCar(Id<Link> linkId) { // find the closest available car in the quad tree(?) reserve it (make it unavailable) // if no cars within certain radius return null Link link = scenario.getNetwork().getLinks().get(linkId); Collection<TwoWayCSStation> location = this.carSharingVehicles .getRoundTripVehicles() .getQuadTree() .getDisk( link.getCoord().getX(), link.getCoord().getY(), Double.parseDouble( scenario .getConfig() .getModule("TwoWayCarsharing") .getParams() .get("searchDistanceTwoWayCarsharing"))); if (location.isEmpty()) return null; double distanceSearch = Double.parseDouble( scenario .getConfig() .getModule("TwoWayCarsharing") .getParams() .get("searchDistanceTwoWayCarsharing")); TwoWayCSStation closest = null; for (TwoWayCSStation station : location) { if (CoordUtils.calcEuclideanDistance(link.getCoord(), station.getLink().getCoord()) < distanceSearch && station.getNumberOfVehicles() > 0) { closest = station; distanceSearch = CoordUtils.calcEuclideanDistance(link.getCoord(), station.getLink().getCoord()); } } return closest; }
private void createFreeLinks() { double referenceDensity = 120.0D; String freeLinksParameterString = "0.5"; Double freeLinksParameterInt = Double.valueOf(Double.parseDouble(freeLinksParameterString)); Integer newLinksMax = Integer.valueOf( (int) Math.round(this.currentLinks.size() * freeLinksParameterInt.doubleValue())); int numberLinks = this.scenario.getNetwork().getLinks().values().size(); log.info("number links = " + numberLinks); log.info("free links size will be = " + newLinksMax); int size = this.scenario.getNetwork().getLinks().values().toArray().length; Object[] arr = this.scenario.getNetwork().getLinks().values().toArray(); List<Object> list = Arrays.asList(arr); Collections.shuffle(list); int rd = -1; while (this.freeLinks.size() < newLinksMax.intValue() && rd < size - 1) { rd++; Link link = (Link) list.get(rd); if (this.currentLinks.contains((link))) { log.info("On the link " + link.getId() + " there is already a Station"); } else if (this.freeLinks.contains(link)) { log.info("The link " + link.getId() + " is already in the list"); } else { double density = this.personQuadTree .getDisk(link.getCoord().getX(), link.getCoord().getY(), 100.0D) .size(); if ((this.freeLinks.size() < newLinksMax.intValue()) && (density > referenceDensity)) { this.freeLinks.add(link); log.info("the link " + link.getId() + " has been added to the free links"); log.info("free links are" + this.freeLinks); this.allLinks.put(link.getId(), link); } } } }
private static void addIllegalParking(Network network, LinkedList<PParking> parkings) { double shareOfLinksWithIllegalParking = ZHScenarioGlobal.loadDoubleParam("ParkingLoader.shareOfLinksWithIllegalParking"); Coord coordinatesLindenhofZH = ParkingHerbieControler.getCoordinatesLindenhofZH(); Random rand = new Random( 19873); // fixing seed (scenarios with different simulation seeds should still have same // illegal parking infrastructure) int i = 0; for (Link link : network.getLinks().values()) { if (GeneralLib.getDistance(coordinatesLindenhofZH, link.getCoord()) < 7000 && rand.nextDouble() < shareOfLinksWithIllegalParking) { PublicParking parking = new PublicParking(link.getCoord()); parking.setMaxCapacity(1.0); parking.setParkingId(Id.create("illegal-" + i, PParking.class)); parking.setType("public"); parkings.add(parking); i++; } } System.out.println("number of illegal parking added: " + i / 1000.0 + "k"); }
private void createQuadTrees() { double minx = (1.0D / 0.0D); double miny = (1.0D / 0.0D); double maxx = (-1.0D / 0.0D); double maxy = (-1.0D / 0.0D); for (Link l : this.network.getLinks().values()) { if (l.getCoord().getX() < minx) minx = l.getCoord().getX(); if (l.getCoord().getY() < miny) miny = l.getCoord().getY(); if (l.getCoord().getX() > maxx) maxx = l.getCoord().getX(); if (l.getCoord().getY() <= maxy) continue; maxy = l.getCoord().getY(); } minx -= 1.0D; miny -= 1.0D; maxx += 1.0D; maxy += 1.0D; ffVehicleLocationQuadTree = new QuadTree<CSVehicle>(minx, miny, maxx, maxy); owvehicleLocationQuadTree = new QuadTree<CarsharingStation>(minx, miny, maxx, maxy); twvehicleLocationQuadTree = new QuadTree<CarsharingStation>(minx, miny, maxx, maxy); }
public void printLinkInFlow() { // print for (Id<Link> linkId : linkInFlow.keySet()) { int[] bins = linkInFlow.get(linkId); Link link = filteredEquilNetLinks.get(linkId); System.out.print(linkId + " - " + link.getCoord() + ": "); for (int i = 0; i < bins.length; i++) { System.out.print(bins[i] * 3600 / binSizeInSeconds + "\t"); } System.out.println(); } }
private void initializeCSWalkLeg(String mode, double now, Link startLink, Link destinationLink) { LegImpl walkLeg = new LegImpl(mode); GenericRouteImpl walkRoute = new GenericRouteImpl(startLink.getId(), destinationLink.getId()); final double dist = CoordUtils.calcEuclideanDistance(startLink.getCoord(), destinationLink.getCoord()); final double estimatedNetworkDistance = dist * beelineFactor; final int travTime = (int) (estimatedNetworkDistance / walkSpeed); walkRoute.setTravelTime(travTime); walkRoute.setDistance(estimatedNetworkDistance); walkLeg.setRoute(walkRoute); this.cachedDestinationLinkId = destinationLink.getId(); walkLeg.setDepartureTime(now); walkLeg.setTravelTime(travTime); walkLeg.setArrivalTime(now + travTime); // set the route according to the next leg this.currentLeg = walkLeg; this.cachedRouteLinkIds = null; this.currentLinkIdIndex = 0; this.cachedNextLinkId = null; }
private void replaceDoubtfulLegsByOtherMode() { for (Person p : scenario.getPopulation().getPersons().values()) { for (Plan plan : p.getPlans()) { Leg lastleg = null; Activity lastActivity = null; boolean personb = random.nextBoolean(); for (PlanElement pe : plan.getPlanElements()) { if (pe instanceof Activity) { if (lastActivity == null) { lastActivity = (Activity) pe; } else { Coord lastCoord; if (lastActivity.getCoord() != null) { lastCoord = lastActivity.getCoord(); } else { Link lastLink = scenario.getNetwork().getLinks().get(lastActivity.getLinkId()); lastCoord = lastLink.getCoord(); } Coord currentCoord; if (((Activity) pe).getCoord() != null) { currentCoord = ((Activity) pe).getCoord(); } else { currentCoord = scenario.getNetwork().getLinks().get(((Activity) pe).getLinkId()).getCoord(); } double distance = CoordUtils.calcDistance(lastCoord, currentCoord); if (distance > 3000 && lastleg.getMode().equals("walk")) { lastleg.setMode("pt"); } else if (distance > 20000 && lastleg.getMode().equals("bike")) { lastleg.setMode("pt"); } else if (distance < 2000 && (lastleg.getMode().equals("pt"))) { if (personb == true) lastleg.setMode("walk"); else lastleg.setMode("bike"); } lastActivity = (Activity) pe; } } else if (pe instanceof Leg) { lastleg = (Leg) pe; } } } } }
public static double getSearchTime(AgentWithParking aem, Id parkingId) { Link currentLink = aem.getCurrentLink(); double travelTime = ZHScenarioGlobal.ttMatrix.getTravelTime(aem.getMessageArrivalTime(), currentLink.getId()); double speed = currentLink.getLength() / travelTime; Id linkOfParking = AgentWithParking.parkingManager.getLinkOfParking(parkingId); double distance = GeneralLib.getDistance( ZHScenarioGlobal.scenario.getNetwork().getLinks().get(linkOfParking).getCoord(), currentLink.getCoord()); double searchTime = distance / speed * ZHScenarioGlobal.loadDoubleParam("Dummy_SearchTimeFactor"); return searchTime; }
// added methods private void initializeFreeFloatingStartWalkLeg(Leg leg, double now) { this.state = MobsimAgent.State.LEG; Route route = leg.getRoute(); ParkingLinkInfo vehicleLocation = this.parkingModule.getNextFreeFloatingVehicle( this.scenario.getNetwork().getLinks().get(route.getStartLinkId()).getCoord(), this.person.getId(), now); if (vehicleLocation == null || vehicleLocation.getLinkId() == null) { log.warn( "Agent with id: " + this.getId().toString() + " was aborted because the freefloating vehicle was not avaialble or the vehicle id was not set up."); this.state = MobsimAgent.State.ABORT; return; } vehID = vehicleLocation.getVehicleId().toString(); startLink = this.scenario.getNetwork().getLinks().get(vehicleLocation.getLinkId()); LegImpl walkLeg = new LegImpl("walk_ff"); GenericRouteImpl walkRoute = new GenericRouteImpl(route.getStartLinkId(), startLink.getId()); final double dist = CoordUtils.calcEuclideanDistance( scenario.getNetwork().getLinks().get(route.getStartLinkId()).getCoord(), startLink.getCoord()); final double estimatedNetworkDistance = dist * this.beelineFactor; final int travTime = (int) (estimatedNetworkDistance / this.walkSpeed); walkRoute.setTravelTime(travTime); walkRoute.setDistance(estimatedNetworkDistance); walkLeg.setRoute(walkRoute); this.cachedDestinationLinkId = startLink.getId(); walkLeg.setDepartureTime(now); walkLeg.setTravelTime(travTime); walkLeg.setArrivalTime(now + travTime); // set the route according to the next leg this.currentLeg = walkLeg; this.cachedRouteLinkIds = null; this.currentLinkIdIndex = 0; this.cachedNextLinkId = null; return; }
public static void main(String[] args) { String inputNetworkPath = "H:/data/experiments/ARTEMIS/zh/dumb charging/output/run2/output_network.xml.gz"; String outputFilePath = "H:/data/experiments/ARTEMIS/zh/dumb charging/output/run2/analysis/linksWithEnergyConsumpHigherThanThreshholdValue.kml"; LinkedList<Id<Link>> selectedLinks = new LinkedList<Id<Link>>(); selectedLinks.add(Id.create("17560000662724TF", Link.class)); selectedLinks.add(Id.create("17560002226916TF", Link.class)); selectedLinks.add(Id.create("17560000114875TF", Link.class)); selectedLinks.add(Id.create("17560000082333TF", Link.class)); selectedLinks.add(Id.create("17560002149918FT", Link.class)); selectedLinks.add(Id.create("17560000368213FT", Link.class)); selectedLinks.add(Id.create("17560002188272FT", Link.class)); selectedLinks.add(Id.create("17560001856956FT", Link.class)); selectedLinks.add(Id.create("17560001229496TF", Link.class)); selectedLinks.add(Id.create("17560001363425TF", Link.class)); selectedLinks.add(Id.create("17560001607380FT-1", Link.class)); selectedLinks.add(Id.create("17560000045386TF", Link.class)); selectedLinks.add(Id.create("17560000109095TF", Link.class)); selectedLinks.add(Id.create("17560001227588FT", Link.class)); selectedLinks.add(Id.create("17560000043382FT", Link.class)); selectedLinks.add(Id.create("17560000105015FT", Link.class)); selectedLinks.add(Id.create("17560000109323TF", Link.class)); selectedLinks.add(Id.create("17560001594646FT", Link.class)); selectedLinks.add(Id.create("17560001380278TF", Link.class)); BasicPointVisualizer basicPointVisualizer = new BasicPointVisualizer(); Network network = GeneralLib.readNetwork(inputNetworkPath); for (Link link : network.getLinks().values()) { if (selectedLinks.contains(link.getId())) { basicPointVisualizer.addPointCoordinate( link.getCoord(), link.getId().toString(), Color.GREEN); } } basicPointVisualizer.write(outputFilePath); }
/** * Looks in the network if the link has an opposite direction link and if so returns it. * * @param linkId of the link for which opposite direction links are searched. * @return List with the found links (resp. their Ids)... */ private List<Id<Link>> getOppositeDirection(Id<Link> linkId) { if (linkId == null) { return null; } List<Id<Link>> oppositeDirectionLinks = new ArrayList<>(); // If we find one with "opposite" direction, we return only this. Link lowerLink = this.network.getLinks().get(Id.createLinkId(Integer.parseInt(linkId.toString()) - 1)); Link link = this.network.getLinks().get(linkId); Link upperLink = this.network.getLinks().get(Id.createLinkId(Integer.parseInt(linkId.toString()) + 1)); if (lowerLink != null && lowerLink.getFromNode().getId().toString().equals(link.getToNode().getId().toString()) && lowerLink.getToNode().getId().toString().equals(link.getFromNode().getId().toString())) { oppositeDirectionLinks.add(lowerLink.getId()); } if (oppositeDirectionLinks.isEmpty() && upperLink != null && upperLink.getFromNode().getId().toString().equals(link.getToNode().getId().toString()) && upperLink.getToNode().getId().toString().equals(link.getFromNode().getId().toString())) { oppositeDirectionLinks.add(upperLink.getId()); } if (CONNECTION_TO_ALL_LINKS_WITHIN_SEARCH_AREA) { Set<Link> linksWithinRadius = getLinksWithinSearchRadius(link.getCoord()); if (linksWithinRadius != null) { for (Link presentLink : linksWithinRadius) { if (!presentLink.getId().toString().equals(link.getId().toString()) && oppositeDirectionLinks.contains(presentLink.getId())) { oppositeDirectionLinks.add(presentLink.getId()); } } } } return oppositeDirectionLinks; }
public Fixture() { firstLegStartTime = 7 * 3600; firstLegTravelTime = 30 * 60; thirdLegTravelTime = 30 * 60; secondLegStartTime = 10 * 3600; secondLegTravelTime = 15 * 60; thirdLegStartTime = 13 * 3600; fourthLegStartTime = 16 * 3600; fourthLegTravelTime = 15 * 60; // home act end 7am // work 7:30 to 10:00 // work 10:15 to 13:00 // work 13:30 to 16:00 // home 15:15 to ... this.config = ConfigUtils.createConfig(); PlanCalcScoreConfigGroup scoring = this.config.planCalcScore(); scoring.setBrainExpBeta(2.0); scoring.setConstantCar(0.0); scoring.setConstantPt(0.0); scoring.setConstantWalk(0.0); scoring.setConstantBike(0.0); scoring.setEarlyDeparture_utils_hr(0.0); scoring.setLateArrival_utils_hr(0.0); scoring.setMarginalUtlOfWaiting_utils_hr(0.0); scoring.setPerforming_utils_hr(0.0); scoring.setTraveling_utils_hr(0.0); scoring.setTravelingPt_utils_hr(0.0); scoring.setTravelingWalk_utils_hr(0.0); scoring.setTravelingBike_utils_hr(0.0); scoring.setMarginalUtilityOfMoney(1.); scoring.setMonetaryDistanceCostRateCar(0.0); scoring.setMonetaryDistanceCostRatePt(0.0); // setup activity types h and w for scoring PlanCalcScoreConfigGroup.ActivityParams params = new PlanCalcScoreConfigGroup.ActivityParams("h"); params.setTypicalDuration(15 * 3600); scoring.addActivityParams(params); params = new PlanCalcScoreConfigGroup.ActivityParams("w"); params.setTypicalDuration(3 * 3600); scoring.addActivityParams(params); this.scenario = ScenarioUtils.createScenario(config); this.network = (NetworkImpl) this.scenario.getNetwork(); Node node1 = this.network.createAndAddNode(Id.create("1", Node.class), new CoordImpl(0.0, 0.0)); Node node2 = this.network.createAndAddNode(Id.create("2", Node.class), new CoordImpl(500.0, 0.0)); Node node3 = this.network.createAndAddNode(Id.create("3", Node.class), new CoordImpl(5500.0, 0.0)); Node node4 = this.network.createAndAddNode(Id.create("4", Node.class), new CoordImpl(6000.0, 0.0)); Node node5 = this.network.createAndAddNode(Id.create("5", Node.class), new CoordImpl(11000.0, 0.0)); Node node6 = this.network.createAndAddNode(Id.create("6", Node.class), new CoordImpl(11500.0, 0.0)); Node node7 = this.network.createAndAddNode(Id.create("7", Node.class), new CoordImpl(16500.0, 0.0)); Node node8 = this.network.createAndAddNode(Id.create("8", Node.class), new CoordImpl(17000.0, 0.0)); Node node9 = this.network.createAndAddNode(Id.create("9", Node.class), new CoordImpl(22000.0, 0.0)); Node node10 = this.network.createAndAddNode(Id.create("10", Node.class), new CoordImpl(22500.0, 0.0)); Link link1 = this.network.createAndAddLink(Id.create("1", Link.class), node1, node2, 500, 25, 3600, 1); Link link2 = this.network.createAndAddLink( Id.create("2", Link.class), node2, node3, 25000, 50, 3600, 1); Link link3 = this.network.createAndAddLink(Id.create("3", Link.class), node3, node4, 500, 25, 3600, 1); this.network.createAndAddLink(Id.create("4", Link.class), node4, node5, 5000, 50, 3600, 1); Link link5 = this.network.createAndAddLink(Id.create("5", Link.class), node5, node6, 500, 25, 3600, 1); this.network.createAndAddLink(Id.create("6", Link.class), node6, node7, 5000, 50, 3600, 1); Link link7 = this.network.createAndAddLink(Id.create("7", Link.class), node7, node8, 500, 25, 3600, 1); this.network.createAndAddLink(Id.create("8", Link.class), node8, node9, 5000, 50, 3600, 1); Link link9 = this.network.createAndAddLink( Id.create("9", Link.class), node9, node10, 500, 25, 3600, 1); this.person = new PersonImpl(Id.create("1", Person.class)); this.plan = this.person.createAndAddPlan(true); ActivityImpl firstActivity = this.plan.createAndAddActivity("h", link1.getId()); firstActivity.setEndTime(firstLegStartTime); Leg leg = this.plan.createAndAddLeg(TransportMode.car); leg.setDepartureTime(firstLegStartTime); leg.setTravelTime(firstLegTravelTime); NetworkRoute route1 = new LinkNetworkRouteImpl(link1.getId(), link3.getId()); route1.setLinkIds(link1.getId(), Arrays.asList(link2.getId()), link3.getId()); route1.setTravelTime(firstLegTravelTime); route1.setDistance(RouteUtils.calcDistance(route1, this.network)); leg.setRoute(route1); ActivityImpl secondActivity = this.plan.createAndAddActivity("w", link3.getId()); secondActivity.setStartTime(firstLegStartTime + firstLegTravelTime); secondActivity.setEndTime(secondLegStartTime); leg = this.plan.createAndAddLeg(TransportMode.pt); leg.setDepartureTime(secondLegStartTime); leg.setTravelTime(secondLegTravelTime); Route route2 = new GenericRouteImpl(link3.getId(), link5.getId()); route2.setTravelTime(secondLegTravelTime); route2.setDistance(20000.0); leg.setRoute(route2); ActivityImpl thirdActivity = this.plan.createAndAddActivity("w", link5.getId()); thirdActivity.setStartTime(secondLegStartTime + secondLegTravelTime); thirdActivity.setEndTime(thirdLegStartTime); leg = this.plan.createAndAddLeg(TransportMode.walk); leg.setDepartureTime(thirdLegStartTime); leg.setTravelTime(thirdLegTravelTime); Route route3 = new GenericRouteImpl(link5.getId(), link7.getId()); route3.setTravelTime(thirdLegTravelTime); route3.setDistance(CoordUtils.calcDistance(link5.getCoord(), link7.getCoord())); leg.setRoute(route3); ActivityImpl fourthActivity = this.plan.createAndAddActivity("w", link7.getId()); fourthActivity.setStartTime(thirdLegStartTime + thirdLegTravelTime); fourthActivity.setEndTime(fourthLegStartTime); leg = this.plan.createAndAddLeg(TransportMode.bike); leg.setDepartureTime(fourthLegStartTime); leg.setTravelTime(fourthLegTravelTime); Route route4 = new GenericRouteImpl(link7.getId(), link9.getId()); route4.setTravelTime(fourthLegTravelTime); route4.setDistance(CoordUtils.calcDistance(link7.getCoord(), link9.getCoord())); leg.setRoute(route4); ActivityImpl fifthActivity = this.plan.createAndAddActivity("h", link9.getId()); fifthActivity.setStartTime(fourthLegStartTime + fourthLegTravelTime); this.scenario.getPopulation().addPerson(this.person); }
@Override public Coord getCoord() { return l.getCoord(); }
public static double getDistance(Coord coord, Link link) { return GeneralLib.getDistance(coord, link.getCoord()); }
@Override public Coord getCoord() { return wrapped.getCoord(); }