1 | /************************************************************************************ |
---|
2 | * Copyright (C) 2008 by Politehnica University of Bucharest and Rutgers University |
---|
3 | * All rights reserved. |
---|
4 | * Refer to LICENSE for terms and conditions of use. |
---|
5 | ***********************************************************************************/ |
---|
6 | package vnsim.vehicular.routePlan.infrastructureRouted; |
---|
7 | |
---|
8 | import vnsim.map.object.Cross; |
---|
9 | import vnsim.map.object.Globals; |
---|
10 | import vnsim.map.object.Point; |
---|
11 | import vnsim.map.object.Road; |
---|
12 | import vnsim.vehicular.simulator.intersections.DirectedRoadSegment; |
---|
13 | import vnsim.vehicular.simulator.intersections.Intersection; |
---|
14 | import vnsim.vehicular.simulator.intersections.IntersectionWithTrafficLights; |
---|
15 | public class DelayRecord { |
---|
16 | |
---|
17 | public DirectedRoadSegment roadSegment; |
---|
18 | |
---|
19 | public int previosCrossPoint; |
---|
20 | |
---|
21 | long segmentsCapacity = 0L; |
---|
22 | |
---|
23 | long aproxTravelTime = 0L; |
---|
24 | |
---|
25 | long segmentsDelay = 0L; |
---|
26 | |
---|
27 | public DelayRecord(DirectedRoadSegment d, Intersection it, int pos) { |
---|
28 | this.roadSegment = d; |
---|
29 | this.segmentsCapacity = (long) (30 * 60); |
---|
30 | this.segmentsCapacity = (long) (this.segmentsCapacity * Globals.map.roads |
---|
31 | .get(d.roadIndex).laneNo); |
---|
32 | int green = 0; |
---|
33 | green = ((IntersectionWithTrafficLights) it).segments.get(pos).getLightInfo().greenEnd |
---|
34 | - ((IntersectionWithTrafficLights) it).segments.get(pos).getLightInfo().greenStart; |
---|
35 | this.segmentsCapacity = (long) (this.segmentsCapacity * green); |
---|
36 | |
---|
37 | this.segmentsCapacity = (this.segmentsCapacity / (long) (((IntersectionWithTrafficLights) it).cycleLength));// nuber |
---|
38 | // of |
---|
39 | // cars |
---|
40 | // that |
---|
41 | // can pass the |
---|
42 | // intersection in an |
---|
43 | // hour |
---|
44 | |
---|
45 | if (d.direction) { |
---|
46 | this.previosCrossPoint = Globals.map.roads.get(d.roadIndex).points |
---|
47 | .size() - 1; |
---|
48 | } else { |
---|
49 | this.previosCrossPoint = 0; |
---|
50 | } |
---|
51 | |
---|
52 | for (int i = 0; i < Globals.map.roads.get(d.roadIndex).crosses.size(); i++) { |
---|
53 | Cross c = Globals.map.roads.get(d.roadIndex).crosses.get(i); |
---|
54 | if (d.direction) { |
---|
55 | if (c.getPointIndex() > d.pointIndex |
---|
56 | && c.getPointIndex() < this.previosCrossPoint) { |
---|
57 | this.previosCrossPoint = c.getPointIndex(); |
---|
58 | } |
---|
59 | } else { |
---|
60 | if (c.getPointIndex() < d.pointIndex |
---|
61 | && c.getPointIndex() > this.previosCrossPoint) { |
---|
62 | this.previosCrossPoint = c.getPointIndex(); |
---|
63 | } |
---|
64 | |
---|
65 | } |
---|
66 | } |
---|
67 | |
---|
68 | double speed, dist; |
---|
69 | |
---|
70 | if (Globals.map.roads.get(d.roadIndex).getRoadinfo()[1] == 49) { |
---|
71 | speed = 60.0f; |
---|
72 | } else { |
---|
73 | speed = 60.0f; |
---|
74 | } |
---|
75 | |
---|
76 | dist = 0.0; |
---|
77 | Road r = Globals.map.roads.get(d.roadIndex); |
---|
78 | Point p1 = r.points.get(d.pointIndex); |
---|
79 | Point p2 = r.points.get(this.previosCrossPoint); |
---|
80 | dist = Math.abs((double) (p1.getDistance() - p2.getDistance())); |
---|
81 | // aproximated travel time in ms |
---|
82 | this.aproxTravelTime = (long) (((dist * 3600.0) / speed) * 1000.0); |
---|
83 | this.segmentsDelay = aproxTravelTime; |
---|
84 | System.out.println("DRS " + d + " has segmentsCapacity" + this.segmentsCapacity |
---|
85 | + " and previous crpoint" + this.previosCrossPoint |
---|
86 | + " and aproxtraveltime " + this.aproxTravelTime); |
---|
87 | } |
---|
88 | |
---|
89 | public boolean equals(DelayRecord r) { |
---|
90 | |
---|
91 | return this.roadSegment.equals(r.roadSegment); |
---|
92 | } |
---|
93 | |
---|
94 | public boolean equals(DirectedRoadSegment r) { |
---|
95 | |
---|
96 | return this.roadSegment.equals(r); |
---|
97 | } |
---|
98 | |
---|
99 | public long getCapacity() { |
---|
100 | return this.segmentsCapacity; |
---|
101 | } |
---|
102 | |
---|
103 | public static void initDelays() { |
---|
104 | |
---|
105 | int i, j; |
---|
106 | |
---|
107 | Intersection it; |
---|
108 | DirectedRoadSegment s; |
---|
109 | DelayRecord dr; |
---|
110 | boolean found; |
---|
111 | System.out.println("Starting segmentsDelay adding"); |
---|
112 | for (i = 0; i < Globals.map.allIntersections.size(); i++) { |
---|
113 | it = Globals.map.allIntersections.get(i); |
---|
114 | for (j = 0; j < it.segments.size(); j++) { |
---|
115 | s = it.segments.get(j); |
---|
116 | dr = new DelayRecord(s, it, j); |
---|
117 | if (!Globals.routePlanConstants.delays.contains(dr)) { |
---|
118 | Globals.routePlanConstants.delays.add(dr); |
---|
119 | } |
---|
120 | } |
---|
121 | } |
---|
122 | } |
---|
123 | |
---|
124 | public void setCapacity(long capacity) { |
---|
125 | this.segmentsCapacity = capacity; |
---|
126 | } |
---|
127 | |
---|
128 | public long getDelay() { |
---|
129 | return this.segmentsDelay; |
---|
130 | } |
---|
131 | |
---|
132 | public void setDelay(Long d) { |
---|
133 | this.segmentsDelay = d + this.aproxTravelTime; |
---|
134 | //System.out.println("Updating segmentsDelay for "+this.location+ "to "+this.delay); |
---|
135 | } |
---|
136 | |
---|
137 | } |
---|