source: proiecte/ptvs/src/vnsim/vehicular/simulator/RegularPersonality.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 ***********************************************************************************/
6package vnsim.vehicular.simulator;
7
8import vnsim.applications.vitp.Statistics;
9import vnsim.map.object.Globals;
10import vnsim.map.object.Road;
11
12public class RegularPersonality implements Personality {
13
14        private double coef1, coef2, coef3, coef4, coef5, coef6, coef7, 
15                coef8, coef9, coef10, coef11, coef12;
16
17        public RegularPersonality() {
18                coef1=0.0;
19                coef2=1.0-Math.random()*2;
20                coef3=0.1-Math.random()*0.2;
21                coef4=5.0-Math.random()*10;
22                coef5=0.1-Math.random()*0.2;
23                coef6=1.0-Math.random()*2;
24                coef7=1.0-Math.random()*2;
25                coef8=1.0-Math.random()*2;
26                coef9=5.0-Math.random()*10;
27                coef10=0.1-Math.random()*0.2;
28                coef11=0.5-Math.random();
29                coef12=0.5-Math.random();
30        }
31
32        public double getSafetyDistance(double speed) { 
33                if(speed < 10)
34                        return (0.16+coef1)*speed+(8.0+coef2);
35                return (1.0/1.8)*speed+coef4;
36        }
37
38        public double getInfluenceDistance(double speed) {
39                return (1.6+coef3)*speed+(40.0+coef4); 
40        }
41
42        public double getDesiredDistance(double speed){
43                if(speed<10) {
44                        return 5.0;
45                }
46                return (0.4+coef5)*speed+(10.0+coef6);
47        }
48
49        public double getAccelerationFreeDriving() {
50                return (7.0+coef7);
51        }
52
53        public double getAccelerationMaximumBrake() {
54                return (-25.0+coef8);
55        }
56
57        public double getWantedSpeed(int roadIndex) {
58                Road r=Globals.map.roads.get(roadIndex);
59                switch(r.getRoadinfo()[1]) {
60                        case 49:
61                                return 100+coef9;
62                        case 50:
63                                return 90+coef9;
64                        case 51:
65                                return 80+coef9;
66                        case 52:
67                                return 70+coef9;
68                        default:
69                                return 50+coef9;
70                }
71        }
72
73        public double getLaneChangeSafetyDistance(double mySpeed, double folSpeed) {
74                double dif=folSpeed-mySpeed;
75               
76                if(dif<0)
77                        return 4.0;
78                if(dif<2 && mySpeed < 10) 
79                        return 4.0;
80                return dif*(0.6+coef10) + (10.0+coef11);
81        }
82
83        public double getLaneChangeSafetyDistanceInFront(double mySpeed, double precSpeed) {
84                double dif=mySpeed-precSpeed;
85                if(dif<0)
86                        return 4.0;
87                if(dif<5)
88                        return 6.0;
89                return dif*0.4+8.0;
90        }
91
92        public double getWantedSpeedInfluenced(double distanceFromIntersection, double requiredSpeed) {
93//              params = [km] [km/h] ; ret = [km/h]
94                //return requiredSpeed+distanceFromIntersection*1000/5.0;
95               
96               
97                double distMeters=distanceFromIntersection*1000;
98               
99                if(distMeters>90)
100                        return 100;
101                double ret=requiredSpeed+(-1.0/90.0*distMeters*distMeters+19/9*distMeters);
102               
103                return ret;
104        }
105
106        public double getReactionTimeFreeDriving() {
107                return (1.6+coef12);
108        }
109
110        public boolean estimateRoadChangePossible(double mySpeed, double otherSpeed, double myDist, double otherDist) {
111                //params = [km/h] [km]
112
113                if(otherSpeed<10) {
114                        if(otherDist > 0.03 && myDist < 0.03)
115                                return true;
116                        return false;
117                }
118
119                if(mySpeed>otherSpeed) {
120                        if(otherDist > 0.04 && myDist < 0.03) return true;
121                }
122
123                if(otherDist > 0.05 && myDist < 0.02) return true;
124
125                return false;
126        }
127}
Note: See TracBrowser for help on using the repository browser.