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.simulator; |
---|
7 | |
---|
8 | import vnsim.map.object.Globals; |
---|
9 | |
---|
10 | public class CalmPersonality implements Personality { |
---|
11 | |
---|
12 | private double coef1, coef2, coef3, coef4, coef5, coef6, coef7, |
---|
13 | coef8, coef9, coef10, coef11, coef12; |
---|
14 | |
---|
15 | public CalmPersonality() { |
---|
16 | coef1=0.0; |
---|
17 | coef2=1.0-Math.random()*2; |
---|
18 | coef3=0.1-Math.random()*0.2; |
---|
19 | coef4=5.0-Math.random()*10; |
---|
20 | coef5=0.1-Math.random()*0.2; |
---|
21 | coef6=1.0-Math.random()*2; |
---|
22 | coef7=1.0-Math.random()*2; |
---|
23 | coef8=1.0-Math.random()*2; |
---|
24 | coef9=5.0-Math.random()*10; |
---|
25 | coef10=0.1-Math.random()*0.2; |
---|
26 | coef11=0.5-Math.random(); |
---|
27 | coef12=0.5-Math.random(); |
---|
28 | } |
---|
29 | |
---|
30 | public double getSafetyDistance(double speed) { |
---|
31 | if(speed<10) |
---|
32 | return (0.18+coef1)*speed+(8.0+coef2); |
---|
33 | return (1.1/1.8)*speed+coef4; |
---|
34 | } |
---|
35 | |
---|
36 | public double getInfluenceDistance(double speed) { |
---|
37 | return (1.8+coef3)*speed+(50.0+coef4); |
---|
38 | } |
---|
39 | |
---|
40 | public double getDesiredDistance(double speed){ |
---|
41 | if(speed<10) { |
---|
42 | return 5.0; |
---|
43 | } |
---|
44 | return (0.5+coef5)*speed+(10.0+coef6); |
---|
45 | } |
---|
46 | |
---|
47 | public double getAccelerationFreeDriving() { |
---|
48 | return (6.0+coef7); |
---|
49 | } |
---|
50 | |
---|
51 | public double getAccelerationMaximumBrake() { |
---|
52 | return (-20.0+coef8); |
---|
53 | } |
---|
54 | |
---|
55 | public double getWantedSpeed(int roadIndex) { |
---|
56 | vnsim.map.object.Road r=Globals.map.roads.get(roadIndex); |
---|
57 | switch(r.getRoadinfo()[1]) { |
---|
58 | case 49: |
---|
59 | return 90+coef9; |
---|
60 | case 50: |
---|
61 | return 80+coef9; |
---|
62 | case 51: |
---|
63 | return 70+coef9; |
---|
64 | case 52: |
---|
65 | return 60+coef9; |
---|
66 | default: |
---|
67 | return 40+coef9; |
---|
68 | } |
---|
69 | } |
---|
70 | |
---|
71 | public double getLaneChangeSafetyDistance(double mySpeed, double folSpeed) { |
---|
72 | double dif=folSpeed-mySpeed; |
---|
73 | if(dif<0) |
---|
74 | return 4.0; |
---|
75 | |
---|
76 | if(dif<2 && mySpeed < 10) |
---|
77 | return 4.0; |
---|
78 | |
---|
79 | |
---|
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 | |
---|
88 | if(dif<5) |
---|
89 | return 6.0; |
---|
90 | |
---|
91 | return dif*0.4+8.0; |
---|
92 | } |
---|
93 | |
---|
94 | public double getWantedSpeedInfluenced(double distanceFromIntersection, double requiredSpeed) { |
---|
95 | // params = [km] [km/h] ; ret = [km/h] |
---|
96 | //return requiredSpeed+distanceFromIntersection*1000/5.0; |
---|
97 | |
---|
98 | double distMeters=distanceFromIntersection*1000; |
---|
99 | |
---|
100 | if(distMeters>90) |
---|
101 | return 100; |
---|
102 | |
---|
103 | return requiredSpeed+(-1.0/90.0*distMeters*distMeters+19/9*distMeters); |
---|
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 | } |
---|