/************************************************************************************ * Copyright (C) 2008 by Politehnica University of Bucharest and Rutgers University * All rights reserved. * Refer to LICENSE for terms and conditions of use. ***********************************************************************************/ package vnsim.vehicular.routePlan.infrastructureRouted; import vnsim.map.object.Cross; import vnsim.map.object.Globals; import vnsim.map.object.Point; import vnsim.map.object.Road; import vnsim.vehicular.simulator.intersections.DirectedRoadSegment; import vnsim.vehicular.simulator.intersections.Intersection; import vnsim.vehicular.simulator.intersections.IntersectionWithTrafficLights; public class DelayRecord { public DirectedRoadSegment roadSegment; public int previosCrossPoint; long segmentsCapacity = 0L; long aproxTravelTime = 0L; long segmentsDelay = 0L; public DelayRecord(DirectedRoadSegment d, Intersection it, int pos) { this.roadSegment = d; this.segmentsCapacity = (long) (30 * 60); this.segmentsCapacity = (long) (this.segmentsCapacity * Globals.map.roads .get(d.roadIndex).laneNo); int green = 0; green = ((IntersectionWithTrafficLights) it).segments.get(pos).getLightInfo().greenEnd - ((IntersectionWithTrafficLights) it).segments.get(pos).getLightInfo().greenStart; this.segmentsCapacity = (long) (this.segmentsCapacity * green); this.segmentsCapacity = (this.segmentsCapacity / (long) (((IntersectionWithTrafficLights) it).cycleLength));// nuber // of // cars // that // can pass the // intersection in an // hour if (d.direction) { this.previosCrossPoint = Globals.map.roads.get(d.roadIndex).points .size() - 1; } else { this.previosCrossPoint = 0; } for (int i = 0; i < Globals.map.roads.get(d.roadIndex).crosses.size(); i++) { Cross c = Globals.map.roads.get(d.roadIndex).crosses.get(i); if (d.direction) { if (c.getPointIndex() > d.pointIndex && c.getPointIndex() < this.previosCrossPoint) { this.previosCrossPoint = c.getPointIndex(); } } else { if (c.getPointIndex() < d.pointIndex && c.getPointIndex() > this.previosCrossPoint) { this.previosCrossPoint = c.getPointIndex(); } } } double speed, dist; if (Globals.map.roads.get(d.roadIndex).getRoadinfo()[1] == 49) { speed = 60.0f; } else { speed = 60.0f; } dist = 0.0; Road r = Globals.map.roads.get(d.roadIndex); Point p1 = r.points.get(d.pointIndex); Point p2 = r.points.get(this.previosCrossPoint); dist = Math.abs((double) (p1.getDistance() - p2.getDistance())); // aproximated travel time in ms this.aproxTravelTime = (long) (((dist * 3600.0) / speed) * 1000.0); this.segmentsDelay = aproxTravelTime; System.out.println("DRS " + d + " has segmentsCapacity" + this.segmentsCapacity + " and previous crpoint" + this.previosCrossPoint + " and aproxtraveltime " + this.aproxTravelTime); } public boolean equals(DelayRecord r) { return this.roadSegment.equals(r.roadSegment); } public boolean equals(DirectedRoadSegment r) { return this.roadSegment.equals(r); } public long getCapacity() { return this.segmentsCapacity; } public static void initDelays() { int i, j; Intersection it; DirectedRoadSegment s; DelayRecord dr; boolean found; System.out.println("Starting segmentsDelay adding"); for (i = 0; i < Globals.map.allIntersections.size(); i++) { it = Globals.map.allIntersections.get(i); for (j = 0; j < it.segments.size(); j++) { s = it.segments.get(j); dr = new DelayRecord(s, it, j); if (!Globals.routePlanConstants.delays.contains(dr)) { Globals.routePlanConstants.delays.add(dr); } } } } public void setCapacity(long capacity) { this.segmentsCapacity = capacity; } public long getDelay() { return this.segmentsDelay; } public void setDelay(Long d) { this.segmentsDelay = d + this.aproxTravelTime; //System.out.println("Updating segmentsDelay for "+this.location+ "to "+this.delay); } }