/************************************************************************************ * 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.applications.adaptiveTL; import java.io.Serializable; import vnsim.applications.trafficview.SimulatedCarInfo; import vnsim.core.*; import vnsim.map.object.Globals; import vnsim.map.object.Point; import vnsim.map.object.Road; import vnsim.vehicular.simulator.intersections.DirectedRoadSegment; public class IntersectionCarRecord{ SimulatedCarInfo car; WirelessTrafficLight iwtl; public DirectedRoadSegment segment; double distance; int queuedTime = -1; boolean passed = false; IntersectionCarRecord old = null; boolean learnedFromWTL = false; boolean countedForDemand = false; public IntersectionCarRecord(SimulatedCarInfo sc){ this.car = sc; } public IntersectionCarRecord(IntersectionCarRecord icr, boolean copy){ this.segment = icr.segment; this.iwtl = icr.iwtl; this.distance = icr.distance; this.queuedTime = icr.queuedTime; this.passed = icr.passed; this.old = icr.old; this.learnedFromWTL = icr.learnedFromWTL; this.countedForDemand = icr.countedForDemand; } // called the first time the traffic light finds out about this car public void init(WirelessTrafficLight iwtl, DirectedRoadSegment segment, boolean learnedFromWTL){ this.iwtl = iwtl; this.segment = segment; // check if the car is queuing and update end of queue if (segment.isCarQueuing(this)){ if (getQueuedTime() == -1) this.setQueuedTime(Globals.engine.crtTime); } this.learnedFromWTL = learnedFromWTL; } public void increaseDemand(){ // update demand for the segment the car is approaching on. //all the paths, because I don't know which way will it go after de intersection countedForDemand = true; for (int i = 0; i < segment.paths.size(); i++){ IntersectionPath ip = segment.paths.get(i); ip.demand(this); } } public double distanceTillIntersection(){ Point p = segment.road.points.get(car.getPointIdx()); Point px = segment.road.points.get(segment.pointIndex); return Math.abs(p.getDistance() - px.getDistance()); } public boolean equals(Object arg0) { IntersectionCarRecord record = (IntersectionCarRecord)arg0; return car.equals(record.car); } public SimulatedCarInfo getCar() { return car; } public void setCar(SimulatedCarInfo car) { this.car = car; } public int getQueuedTime() { return queuedTime; } public void setQueuedTime(int queuedTime) { Road rx = Globals.map.roads.get(segment.roadIndex); Point px = rx.points.get(segment.pointIndex); Road r = Globals.map.roads.get(car.getRoadIdx()); Point p = r.points.get(car.getPointIdx()); distance = p.getDistance() - px.getDistance(); if (distance < 0) distance = -distance; this.queuedTime = queuedTime; } public boolean isPassed() { return passed; } public void setPassed(boolean passed) { this.passed = passed; } }