source: proiecte/ptvs/src/vnsim/applications/adaptiveTL/IntersectionCarRecord.java @ 31

Last change on this file since 31 was 31, checked in by (none), 14 years ago
File size: 3.2 KB
Line 
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
7package vnsim.applications.adaptiveTL;
8
9
10import java.io.Serializable;
11
12import vnsim.applications.trafficview.SimulatedCarInfo;
13import vnsim.core.*;
14import vnsim.map.object.Globals;
15import vnsim.map.object.Point;
16import vnsim.map.object.Road;
17import vnsim.vehicular.simulator.intersections.DirectedRoadSegment;
18
19
20
21
22
23public class IntersectionCarRecord{
24        SimulatedCarInfo car;
25        WirelessTrafficLight iwtl;
26        public DirectedRoadSegment segment;
27        double distance;
28        int queuedTime = -1;
29        boolean passed = false;
30        IntersectionCarRecord old = null;
31       
32        boolean learnedFromWTL = false;
33       
34        boolean countedForDemand = false;
35       
36        public IntersectionCarRecord(SimulatedCarInfo sc){
37                this.car = sc;
38        }
39        public IntersectionCarRecord(IntersectionCarRecord icr, boolean copy){
40                this.segment = icr.segment;
41                this.iwtl = icr.iwtl;
42                this.distance = icr.distance;
43                this.queuedTime = icr.queuedTime;
44                this.passed = icr.passed;
45                this.old = icr.old;
46                this.learnedFromWTL = icr.learnedFromWTL;
47                this.countedForDemand = icr.countedForDemand;
48               
49        }
50       
51        // called the first time the traffic light finds out about this car
52        public void init(WirelessTrafficLight iwtl, DirectedRoadSegment segment, boolean learnedFromWTL){
53                this.iwtl = iwtl;
54                this.segment = segment;
55                // check if the car is queuing and update end of queue
56                if (segment.isCarQueuing(this)){
57                        if (getQueuedTime() == -1) 
58                                this.setQueuedTime(Globals.engine.crtTime);
59                }
60               
61                this.learnedFromWTL = learnedFromWTL;
62               
63        }
64        public void increaseDemand(){
65                // update demand for the segment the car is approaching on.
66                //all the paths, because I don't know which way will it go after de intersection
67                countedForDemand = true;
68                for (int i = 0; i < segment.paths.size(); i++){
69                        IntersectionPath ip = segment.paths.get(i);
70                        ip.demand(this);
71                }
72        }
73        public double distanceTillIntersection(){
74                Point p = segment.road.points.get(car.getPointIdx());
75                Point px = segment.road.points.get(segment.pointIndex);
76                return Math.abs(p.getDistance() - px.getDistance());
77        } 
78       
79        public boolean equals(Object arg0) {
80                IntersectionCarRecord record = (IntersectionCarRecord)arg0;
81                return car.equals(record.car);
82        }
83
84        public SimulatedCarInfo getCar() {
85                return car;
86        }
87
88        public void setCar(SimulatedCarInfo car) {
89                this.car = car;
90        }
91
92        public int getQueuedTime() {
93                return queuedTime;
94        }
95
96        public void setQueuedTime(int queuedTime) {
97                Road rx = Globals.map.roads.get(segment.roadIndex);
98                Point px = rx.points.get(segment.pointIndex);
99                Road r = Globals.map.roads.get(car.getRoadIdx());
100                Point p = r.points.get(car.getPointIdx());
101                distance = p.getDistance() - px.getDistance();
102                if (distance < 0)
103                        distance = -distance;
104                this.queuedTime = queuedTime;
105        }
106
107        public boolean isPassed() {
108                return passed;
109        }
110
111        public void setPassed(boolean passed) {
112                this.passed = passed;
113        }
114       
115       
116       
117       
118       
119}
Note: See TracBrowser for help on using the repository browser.