-
Notifications
You must be signed in to change notification settings - Fork 4
/
DrivingSkill.java
1853 lines (1687 loc) · 63.3 KB
/
DrivingSkill.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*******************************************************************************************************
*
* simtools.gaml.extensions.traffic.AdvancedDrivingSkill.java, in plugin simtools.gaml.extensions.traffic, is part of
* the source code of the GAMA modeling and simulation platform (v. 1.8.1)
*
* (c) 2007-2020 UMI 209 UMMISCO IRD/SU & Partners
*
* Visit https://github.com/gama-platform/gama for license information and contacts.
*
********************************************************************************************************/
package simtools.gaml.extensions.traffic;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import org.apache.commons.lang3.tuple.Pair;
import org.locationtech.jts.geom.Coordinate;
import msi.gama.common.interfaces.IKeyword;
import msi.gama.metamodel.agent.AbstractAgent;
import msi.gama.metamodel.agent.IAgent;
import msi.gama.metamodel.shape.GamaPoint;
import msi.gama.metamodel.shape.IShape;
import msi.gama.metamodel.topology.graph.GamaSpatialGraph;
import msi.gama.precompiler.GamlAnnotations.action;
import msi.gama.precompiler.GamlAnnotations.arg;
import msi.gama.precompiler.GamlAnnotations.doc;
import msi.gama.precompiler.GamlAnnotations.example;
import msi.gama.precompiler.GamlAnnotations.getter;
import msi.gama.precompiler.GamlAnnotations.setter;
import msi.gama.precompiler.GamlAnnotations.skill;
import msi.gama.precompiler.GamlAnnotations.variable;
import msi.gama.precompiler.GamlAnnotations.vars;
import msi.gama.precompiler.IConcept;
import msi.gama.runtime.IScope;
import msi.gama.runtime.exceptions.GamaRuntimeException;
import msi.gama.util.GamaListFactory;
import msi.gama.util.IList;
import msi.gama.util.graph.GamaGraph;
import msi.gama.util.path.IPath;
import msi.gama.util.path.PathFactory;
import msi.gaml.descriptions.ConstantExpressionDescription;
import msi.gaml.operators.Random;
import msi.gaml.operators.Spatial.Queries;
import msi.gaml.skills.MovingSkill;
import msi.gaml.species.ISpecies;
import msi.gaml.statements.Arguments;
import msi.gaml.statements.IStatement;
import msi.gaml.types.IType;
import msi.gaml.types.Types;
import simtools.gaml.extensions.traffic.carfollowing.MOBIL;
import ummisco.gama.dev.utils.DEBUG;
@vars({
@variable(
name = IKeyword.SPEED,
type = IType.FLOAT,
init = "0.0",
doc = @doc("the speed of the agent (in meter/second)")
),
@variable(
name = IKeyword.REAL_SPEED,
type = IType.FLOAT,
init = "0.0",
doc = @doc(
value = "the actual speed of the agent (in meter/second)",
deprecated = "there is now only one speed value, which is located in `speed`"
)
),
@variable(
name = DrivingSkill.ACCELERATION,
type = IType.FLOAT,
init = "0.0",
doc = @doc("the current acceleration of the vehicle (in m/s^2)")
),
@variable(
name = DrivingSkill.CURRENT_PATH,
type = IType.PATH,
init = "nil",
doc = @doc("the path which the agent is currently following")
),
@variable(
name = DrivingSkill.FINAL_TARGET,
type = IType.AGENT,
init = "nil",
doc = @doc("the final target of the agent")
),
@variable(
name = DrivingSkill.CURRENT_TARGET,
type = IType.AGENT,
init = "nil",
doc = @doc("the current target of the agent")
),
@variable(
name = DrivingSkill.CURRENT_INDEX,
type = IType.INT,
init = "0",
doc = @doc("the index of the current edge (road) in the path")
),
@variable(
name = DrivingSkill.TARGETS,
type = IType.LIST,
of = IType.POINT,
init = "[]",
doc = @doc(
value = "the current list of points that the agent has to reach (path)",
deprecated = "this can be accessed using current_path.vertices"
)
),
@variable(
name = DrivingSkill.SECURITY_DISTANCE_COEFF,
type = IType.FLOAT,
init = "1.0",
doc = @doc(
deprecated = "use safety_distance_coeff instead",
value = "the coefficient for the computation of the the min distance between two vehicles (according to the vehicle speed - safety_distance =max(min_safety_distance, safety_distance_coeff `*` min(self.real_speed, other.real_speed) )"
)
),
@variable(
name = DrivingSkill.SAFETY_DISTANCE_COEFF,
type = IType.FLOAT,
init = "1.0",
doc = @doc("the coefficient for the computation of the the min distance between two vehicles (according to the vehicle speed - security_distance =max(min_security_distance, security_distance_coeff `*` min(self.real_speed, other.real_speed) )")
),
@variable(
name = DrivingSkill.MIN_SECURITY_DISTANCE,
type = IType.FLOAT,
init = "0.5",
doc = @doc(
deprecated = "use min_safety_distance instead",
value = "the minimal distance to another vehicle"
)
),
@variable(
name = DrivingSkill.MIN_SAFETY_DISTANCE,
type = IType.FLOAT,
init = "0.5",
doc = @doc("the minimum distance of the vehicle's front bumper to the leading vehicle's rear bumper, " +
"known as the parameter s0 in the Intelligent Driver Model")
),
@variable(
name = DrivingSkill.CURRENT_LANE,
type = IType.INT,
init = "0",
doc = @doc("the current lane on which the agent is")
),
@variable(
name = DrivingSkill.LOWEST_LANE,
type = IType.INT,
init = "0",
doc = @doc("the lane with the smallest index that the vehicle is in")
),
@variable(
name = DrivingSkill.NUM_LANES_OCCUPIED,
type = IType.INT,
init = "1",
doc = @doc(
value = "the number of lanes that the vehicle occupies",
comment = "e.g. if `num_lanes_occupied=3` and `lowest_lane=1`, the vehicle will be in lane 1, 2 and 3`"
)
),
@variable(
name = DrivingSkill.VEHICLE_LENGTH,
type = IType.FLOAT,
init = "0.0",
doc = @doc("the length of the vehicle (in meters)")
),
@variable(
name = DrivingSkill.SPEED_COEFF,
type = IType.FLOAT,
init = "1.0",
doc = @doc("speed coefficient for the speed that the vehicle want to reach (according to the max speed of the road)")
),
@variable(
name = DrivingSkill.MAX_SPEED,
type = IType.FLOAT,
init = "50.0",
doc = @doc("the maximum speed that the vehicle can achieve. " +
"Known as the parameter 'v0' in the Intelligent Driver Model"
)
),
@variable(
name = DrivingSkill.TIME_HEADWAY,
type = IType.FLOAT,
init = "1.5",
doc = @doc("the time gap that to the leading vehicle that the driver must maintain. " +
"Known as the parameter 'T' in the Intelligent Driver Model"
)
),
@variable(
name = DrivingSkill.MAX_ACCELERATION,
type = IType.FLOAT,
init = "0.3",
doc = @doc("the maximum acceleration of the vehicle. " +
"Known as the parameter 'a' in the Intelligent Driver Model"
)
),
@variable(
name = DrivingSkill.MAX_DECELERATION,
type = IType.FLOAT,
init = "3.0",
doc = @doc("the maximum deceleration of the vehicle. " +
"Known as the parameter 'b' in the Intelligent Driver Model"
)
),
@variable(
name = DrivingSkill.DELTA_IDM,
type = IType.FLOAT,
init = "4.0",
doc = @doc("the exponent used in the computation of free-road acceleration in the Intelligent Driver Model")
),
@variable(
name = DrivingSkill.POLITENESS_FACTOR,
type = IType.FLOAT,
init = "0.5",
doc = @doc("determines the politeness level of the vehicle when changing lanes. " +
"Known as the parameter 'p' in the MOBIL lane changing model"
)
),
@variable(
name = DrivingSkill.MAX_SAFE_DECELERATION,
type = IType.FLOAT,
init = "4",
doc = @doc("the maximum deceleration that the vehicle is willing to induce on its back vehicle when changing lanes. " +
"Known as the parameter 'b_save' in the MOBIL lane changing model"
)
),
@variable(
name = DrivingSkill.ACC_GAIN_THRESHOLD,
type = IType.FLOAT,
init = "0.2",
doc = @doc("the minimum acceleration gain for the vehicle to switch to another lane, " +
"introduced to prevent frantic lane changing. " +
"Known as the parameter 'a_th' in the MOBIL lane changing model"
)
),
@variable(
name = DrivingSkill.ACC_BIAS,
type = IType.FLOAT,
init = "0.25",
doc = @doc("the bias term used for asymmetric lane changing, parameter 'a_bias' in MOBIL")
),
@variable(
name = DrivingSkill.LC_COOLDOWN,
type = IType.FLOAT,
init = "4",
doc = @doc("the duration that a vehicle must wait before changing lanes again")
),
@variable(
name = DrivingSkill.TIME_SINCE_LC,
type = IType.FLOAT,
init = "0.0",
doc = @doc("the elapsed time since the last lane change")
),
@variable(
name = DrivingSkill.IGNORE_ONEWAY,
type = IType.BOOL,
init = "false",
doc = @doc("if set to `true`, the vehicle will be able to violate one-way traffic rule")
),
@variable(
name = DrivingSkill.VIOLATING_ONEWAY,
type = IType.BOOL,
init = "false",
doc = @doc("indicates if the vehicle is moving in the wrong direction on an one-way (unlinked) road")
),
@variable(
name = DrivingSkill.CURRENT_ROAD,
type = IType.AGENT,
init = "nil",
doc = @doc("the road which the vehicle is currently on")
),
@variable(
name = DrivingSkill.NEXT_ROAD,
type = IType.AGENT,
init = "nil",
doc = @doc("the road which the vehicle will enter next")
),
@variable(
name = DrivingSkill.ON_LINKED_ROAD,
type = IType.BOOL,
init = "false",
doc = @doc(
deprecated = "use using_linked_road instead",
value = "is the agent on the linked road?"
)
),
@variable(
name = DrivingSkill.USING_LINKED_ROAD,
type = IType.BOOL,
init = "false",
doc = @doc("indicates if the vehicle is occupying at least one lane on the linked road")
),
@variable(
name = DrivingSkill.ALLOWED_LANES,
type = IType.LIST,
init = "[]",
doc = @doc("a list containing possible lane index values for the attribute lowest_lane")
),
@variable(
name = DrivingSkill.LINKED_LANE_LIMIT,
type = IType.INT,
init = "-1",
doc = @doc("the maximum number of linked lanes that the vehicle can use; the default value is -1, i.e. the vehicle can use all available linked lanes")
),
@variable(
name = DrivingSkill.LANE_CHANGE_LIMIT,
type = IType.INT,
init = "1",
doc = @doc("the maximum number of lanes that the vehicle can change during a simulation step")
),
@variable(
name = DrivingSkill.PROBA_LANE_CHANGE_UP,
type = IType.FLOAT,
init = "1.0",
doc = @doc(
value = "probability to change to a upper lane (left lane if right side driving) to gain acceleration, within one second",
deprecated = "use MOBIL parameters to control this instead"
)
),
@variable(
name = DrivingSkill.PROBA_LANE_CHANGE_DOWN,
type = IType.FLOAT,
init = "1.0",
doc = @doc(
value = "probability to change to a lower lane (right lane if right side driving) to gain acceleration, within one second",
deprecated = "use MOBIL parameters to control this instead"
)
),
@variable(
name = DrivingSkill.PROBA_USE_LINKED_ROAD,
type = IType.FLOAT,
init = "0.0",
doc = @doc("probability to change to a linked lane to gain acceleration, within one second")
),
@variable(
name = DrivingSkill.PROBA_RESPECT_PRIORITIES,
type = IType.FLOAT,
init = "1.0",
doc = @doc("probability to respect priority (right or left) laws, within one second")
),
@variable(
name = DrivingSkill.PROBA_RESPECT_STOPS,
type = IType.LIST,
of = IType.FLOAT,
init = "[]",
doc = @doc("probability to respect stop laws - one value for each type of stop, within one second")
),
@variable(
name = DrivingSkill.PROBA_BLOCK_NODE,
type = IType.FLOAT,
init = "0.0",
doc = @doc("probability to block a node (do not let other vehicle cross the crossroad), within one second")
),
@variable(
name = DrivingSkill.RIGHT_SIDE_DRIVING,
type = IType.BOOL,
init = "true",
doc = @doc("are vehicles driving on the right size of the road?")
),
@variable(
name = DrivingSkill.DISTANCE_TO_GOAL,
type = IType.FLOAT,
init = "0.0",
doc = @doc("euclidean distance to the endpoint of the current segment")
),
@variable(
name = DrivingSkill.DISTANCE_TO_CURRENT_TARGET,
type = IType.FLOAT,
init = "0.0",
doc = @doc("euclidean distance to the current target node")
),
@variable(
name = DrivingSkill.SEGMENT_INDEX,
type = IType.INT,
init = "-1",
doc = @doc("current segment index of the agent on the current road ")
),
@variable(
name = DrivingSkill.LEADING_VEHICLE,
type = IType.AGENT,
init = "nil",
doc = @doc("the vehicle which is right ahead of the current vehicle.\n" +
"If this is set to nil, the leading vehicle does not exist or might be very far away."
)
),
@variable(
name = DrivingSkill.LEADING_DISTANCE,
type = IType.FLOAT,
init = "nil",
doc = @doc("the distance to the leading vehicle")
),
@variable(
name = DrivingSkill.LEADING_SPEED,
type = IType.FLOAT,
init = "nil",
doc = @doc("the speed of the leading vehicle")
),
@variable(
name = DrivingSkill.FOLLOWER,
type = IType.AGENT,
init = "nil",
doc = @doc("the vehicle following this vehicle")
)
})
@skill(
name = DrivingSkill.ADVANCED_DRIVING,
concept = { IConcept.TRANSPORT, IConcept.SKILL },
doc = @doc ("A skill that provides driving primitives and operators")
)
@SuppressWarnings ({ "unchecked", "rawtypes" })
public class DrivingSkill extends MovingSkill {
static {
DEBUG.OFF();
}
public static final String ADVANCED_DRIVING = "advanced_driving";
@Deprecated public static final String SECURITY_DISTANCE_COEFF = "security_distance_coeff";
public static final String SAFETY_DISTANCE_COEFF = "safety_distance_coeff";
@Deprecated public static final String MIN_SECURITY_DISTANCE = "min_security_distance";
public static final String MIN_SAFETY_DISTANCE = "min_safety_distance";
public static final String CURRENT_ROAD = "current_road";
public static final String NEXT_ROAD = "next_road";
@Deprecated public static final String CURRENT_LANE = "current_lane";
public static final String LOWEST_LANE = "lowest_lane";
public static final String DISTANCE_TO_GOAL = "distance_to_goal";
public static final String DISTANCE_TO_CURRENT_TARGET = "distance_to_current_target";
public static final String VEHICLE_LENGTH = "vehicle_length";
@Deprecated public static final String PROBA_LANE_CHANGE_UP = "proba_lane_change_up";
@Deprecated public static final String PROBA_LANE_CHANGE_DOWN = "proba_lane_change_down";
public static final String PROBA_RESPECT_PRIORITIES = "proba_respect_priorities";
public static final String PROBA_RESPECT_STOPS = "proba_respect_stops";
public static final String PROBA_BLOCK_NODE = "proba_block_node";
public static final String PROBA_USE_LINKED_ROAD = "proba_use_linked_road";
public static final String RIGHT_SIDE_DRIVING = "right_side_driving";
public static final String IGNORE_ONEWAY = "ignore_oneway";
public static final String VIOLATING_ONEWAY = "violating_oneway";
public static final String ON_LINKED_ROAD = "on_linked_road";
public static final String USING_LINKED_ROAD = "using_linked_road";
public static final String LINKED_LANE_LIMIT = "linked_lane_limit";
public static final String ALLOWED_LANES = "allowed_lanes";
@Deprecated public static final String TARGETS = "targets";
public static final String CURRENT_TARGET = "current_target";
public static final String CURRENT_INDEX = "current_index";
public static final String FINAL_TARGET = "final_target";
public static final String CURRENT_PATH = "current_path";
public static final String ACCELERATION = "acceleration";
public static final String MAX_ACCELERATION = "max_acceleration";
public static final String MAX_DECELERATION = "max_deceleration";
public static final String TIME_HEADWAY = "time_headway";
public static final String DELTA_IDM = "delta_idm";
public static final String POLITENESS_FACTOR = "politeness_factor";
public static final String MAX_SAFE_DECELERATION = "max_safe_deceleration";
public static final String ACC_GAIN_THRESHOLD = "acc_gain_threshold";
public static final String ACC_BIAS = "acc_bias";
public static final String TIME_SINCE_LC = "time_since_lane_change";
public static final String LC_COOLDOWN = "lane_change_cooldown";
public static final String SPEED_COEFF = "speed_coeff";
public static final String MAX_SPEED = "max_speed";
public static final String SEGMENT_INDEX = "segment_index_on_road";
public static final String NUM_LANES_OCCUPIED = "num_lanes_occupied";
public static final String LANE_CHANGE_LIMIT = "lane_change_limit";
public static final String LEADING_VEHICLE = "leading_vehicle";
public static final String LEADING_DISTANCE = "leading_distance";
public static final String LEADING_SPEED = "leading_speed";
public static final String FOLLOWER = "follower";
// NOTE: Due to approximations in IDM, vehicles will never have the exact same location as its target.
// Therefore we consider the vehicle has reached its goal when distToGoal is smaller than this threshold.
private static final double EPSILON = 1e-2;
@getter (IKeyword.SPEED)
public static double getSpeed(final IAgent agent) {
// The second condition is used when `agent` is a road_node with a stop signal
if (agent == null || !agent.hasAttribute(IKeyword.SPEED)) {
return 0.0;
} else {
return (Double) agent.getAttribute(IKeyword.SPEED);
}
}
@setter (IKeyword.SPEED)
public static void setSpeed(final IAgent vehicle, final double speed) {
if (vehicle == null) { return; }
vehicle.setAttribute(IKeyword.SPEED, speed);
}
@getter(IKeyword.REAL_SPEED)
@Deprecated
public static double getRealSpeed(final IAgent vehicle) {
return getSpeed(vehicle);
}
@setter(IKeyword.REAL_SPEED)
@Deprecated
public static void setRealSpeed(final IAgent vehicle, final double speed) {
setSpeed(vehicle, speed);
}
@setter(ACCELERATION)
public static void setAccelerationReadOnly(final IAgent vehicle, final Double val) {
// read-only
}
private static void setAcceleration(final IAgent vehicle, final Double val) {
vehicle.setAttribute(ACCELERATION, val);
}
@getter(MAX_ACCELERATION)
public static double getMaxAcceleration(final IAgent vehicle) {
return (Double) vehicle.getAttribute(MAX_ACCELERATION);
}
@setter(MAX_ACCELERATION)
public static void setMaxAcceleration(final IAgent vehicle, final Double val) {
vehicle.setAttribute(MAX_ACCELERATION, val);
}
@getter(MAX_DECELERATION)
public static double getMaxDeceleration(final IAgent vehicle) {
return (Double) vehicle.getAttribute(MAX_DECELERATION);
}
@getter(TIME_HEADWAY)
public static double getTimeHeadway(final IAgent vehicle) {
return (Double) vehicle.getAttribute(TIME_HEADWAY);
}
@getter(DELTA_IDM)
public static double getDeltaIDM(final IAgent vehicle) {
return (Double) vehicle.getAttribute(DELTA_IDM);
}
@getter(POLITENESS_FACTOR)
public static double getPolitenessFactor(final IAgent vehicle) {
return (Double) vehicle.getAttribute(POLITENESS_FACTOR);
}
@getter(MAX_SAFE_DECELERATION)
public static double getMaxSafeDeceleration(final IAgent vehicle) {
return (Double) vehicle.getAttribute(MAX_SAFE_DECELERATION);
}
@getter(ACC_GAIN_THRESHOLD)
public static double getAccGainThreshold(final IAgent vehicle) {
return (Double) vehicle.getAttribute(ACC_GAIN_THRESHOLD);
}
@getter(ACC_BIAS)
public static double getAccBias(final IAgent vehicle) {
return (Double) vehicle.getAttribute(ACC_BIAS);
}
@getter(TIME_SINCE_LC)
public static double getTimeSinceLC(final IAgent vehicle) {
return (Double) vehicle.getAttribute(TIME_SINCE_LC);
}
// @setter(TIME_SINCE_LC)
public static void setTimeSinceLCReadOnly(final IAgent vehicle, final double time) {
// read-only
}
@setter(TIME_SINCE_LC)
public static void setTimeSinceLC(final IAgent vehicle, final double time) {
vehicle.setAttribute(TIME_SINCE_LC, time);
}
@getter(LC_COOLDOWN)
public static double getLCCooldown(final IAgent vehicle) {
return (Double) vehicle.getAttribute(LC_COOLDOWN);
}
@getter(SPEED_COEFF)
public static double getSpeedCoeff(final IAgent vehicle) {
return (Double) vehicle.getAttribute(SPEED_COEFF);
}
@setter(SPEED_COEFF)
public static void setSpeedCoeff(final IAgent vehicle, final Double val) {
vehicle.setAttribute(SPEED_COEFF, val);
}
@getter(MAX_SPEED)
public static double getMaxSpeed(final IAgent vehicle) {
return (Double) vehicle.getAttribute(MAX_SPEED);
}
@setter(MAX_SPEED)
public static void setMaxSpeed(final IAgent vehicle, final Double val) {
vehicle.setAttribute(MAX_SPEED, val);
}
@getter(CURRENT_TARGET)
public static IAgent getCurrentTarget(final IAgent vehicle) {
return (IAgent) vehicle.getAttribute(CURRENT_TARGET);
}
@setter(CURRENT_TARGET)
public static void setCurrentTarget(final IAgent vehicle, final IAgent target) {
vehicle.setAttribute(CURRENT_TARGET, target);
}
@getter(FINAL_TARGET)
public static IAgent getFinalTarget(final IAgent vehicle) {
return (IAgent) vehicle.getAttribute(FINAL_TARGET);
}
@setter(FINAL_TARGET)
public static void setFinalTarget(final IAgent vehicle, final IAgent point) {
vehicle.setAttribute(FINAL_TARGET, point);
}
@getter(CURRENT_INDEX)
public static Integer getCurrentIndex(final IAgent vehicle) {
return (Integer) vehicle.getAttribute(CURRENT_INDEX);
}
@setter(CURRENT_INDEX)
public static void setCurrentIndex(final IAgent vehicle, final Integer index) {
vehicle.setAttribute(CURRENT_INDEX, index);
}
@getter(SEGMENT_INDEX)
public static Integer getSegmentIndex(final IAgent vehicle) {
return (Integer) vehicle.getAttribute(SEGMENT_INDEX);
}
@setter(SEGMENT_INDEX)
public static void setSegmentIndex(final IAgent vehicle, final Integer index) {
vehicle.setAttribute(SEGMENT_INDEX, index);
}
@getter(CURRENT_PATH)
public static IPath getCurrentPath(final IAgent vehicle) {
return (IPath) vehicle.getAttribute(CURRENT_PATH);
}
@setter(CURRENT_PATH)
public static void setCurrentPath(final IAgent vehicle, final IPath path) {
vehicle.setAttribute(CURRENT_PATH, path);
if (path != null) {
// Also set other states
IAgent source = (IAgent) path.getStartVertex();
IAgent target = (IAgent) path.getEndVertex();
vehicle.setLocation(source.getLocation());
setCurrentIndex(vehicle, -1);
setCurrentTarget(vehicle, (IAgent) path.getVertexList().get(0));
setFinalTarget(vehicle, target);
}
}
public static List<IAgent> getTargets(final IAgent vehicle) {
IPath path = getCurrentPath(vehicle);
return path == null ? null : path.getVertexList();
}
@setter(TARGETS)
public static void setTargets(final IAgent vehicle, final List<IAgent> points) {
// read-only
}
@getter(PROBA_USE_LINKED_ROAD)
public static double getProbaUseLinkedRoad(final IAgent vehicle) {
return (Double) vehicle.getAttribute(PROBA_USE_LINKED_ROAD);
}
@setter(PROBA_USE_LINKED_ROAD)
public static void setProbaUseLinkedRoad(final IAgent vehicle, final Double proba) {
vehicle.setAttribute(PROBA_USE_LINKED_ROAD, proba);
}
@getter(PROBA_LANE_CHANGE_DOWN)
@Deprecated
public static double getProbaLaneChangeDown(final IAgent vehicle) {
return (Double) vehicle.getAttribute(PROBA_LANE_CHANGE_DOWN);
}
@setter(PROBA_LANE_CHANGE_DOWN)
@Deprecated
public static void setProbaLaneChangeDown(final IAgent vehicle, final Double proba) {
vehicle.setAttribute(PROBA_LANE_CHANGE_DOWN, proba);
}
@getter(PROBA_LANE_CHANGE_UP)
@Deprecated
public static double getProbaLaneChangeUp(final IAgent vehicle) {
return (Double) vehicle.getAttribute(PROBA_LANE_CHANGE_UP);
}
@setter(PROBA_LANE_CHANGE_UP)
@Deprecated
public static void setProbaLaneChangeUp(final IAgent vehicle, final Double proba) {
vehicle.setAttribute(PROBA_LANE_CHANGE_UP, proba);
}
@getter(PROBA_RESPECT_PRIORITIES)
public static double getProbaRespectPriorities(final IAgent vehicle) {
return (Double) vehicle.getAttribute(PROBA_RESPECT_PRIORITIES);
}
@setter(PROBA_RESPECT_PRIORITIES)
public static void setProbaRespectPriorities(final IAgent vehicle, final Double proba) {
vehicle.setAttribute(PROBA_RESPECT_PRIORITIES, proba);
}
@getter(PROBA_BLOCK_NODE)
public static double getProbaBlockNode(final IAgent vehicle) {
return (Double) vehicle.getAttribute(PROBA_BLOCK_NODE);
}
@setter(PROBA_BLOCK_NODE)
public static void setProbaBlockNode(final IAgent vehicle, final Double proba) {
vehicle.setAttribute(PROBA_BLOCK_NODE, proba);
}
@getter(PROBA_RESPECT_STOPS)
public static List<Double> getProbasRespectStops(final IAgent vehicle) {
return (List<Double>) vehicle.getAttribute(PROBA_RESPECT_STOPS);
}
@setter(PROBA_RESPECT_STOPS)
public static void setProbasRespectStops(final IAgent vehicle, final List<Boolean> probas) {
vehicle.setAttribute(PROBA_RESPECT_STOPS, probas);
}
@Deprecated
@getter(ON_LINKED_ROAD)
public static boolean getOnLinkedRoad(final IAgent vehicle) {
return isUsingLinkedRoad(vehicle);
}
@Deprecated
@setter(ON_LINKED_ROAD)
public static void setOnLinkedRoad(final IAgent vehicle, final Boolean onLinkedRoad) {
// read-only
}
@getter(USING_LINKED_ROAD)
public static boolean isUsingLinkedRoad(final IAgent vehicle) {
IAgent currentRoad = getCurrentRoad(vehicle);
if (currentRoad == null) return false;
int lowestLane = getLowestLane(vehicle);
int numLanesCurrent = RoadSkill.getNumLanes(currentRoad);
int numLanesOccupied = getNumLanesOccupied(vehicle);
return lowestLane > numLanesCurrent - numLanesOccupied;
}
@setter(USING_LINKED_ROAD)
public static void setUsingLinkedRoad(final IAgent vehicle, final boolean usingLinkedRoad) {
// read-only
}
@getter(IGNORE_ONEWAY)
public static boolean canIgnoreOneway(final IAgent vehicle) {
return (boolean) vehicle.getAttribute(IGNORE_ONEWAY);
}
@getter(VIOLATING_ONEWAY)
public static boolean isViolatingOneway(final IAgent vehicle) {
return (boolean) vehicle.getAttribute(VIOLATING_ONEWAY);
}
@setter(VIOLATING_ONEWAY)
public static void setViolatingOneway(final IAgent vehicle, final boolean violatingOneway) {
vehicle.setAttribute(VIOLATING_ONEWAY, violatingOneway);
}
@getter(ALLOWED_LANES)
public static List<Integer> getAllowedLanes(final IAgent vehicle) {
return (List<Integer>) vehicle.getAttribute(ALLOWED_LANES);
}
@getter(LINKED_LANE_LIMIT)
public static int getLinkedLaneLimit(final IAgent vehicle) {
return (int) vehicle.getAttribute(LINKED_LANE_LIMIT);
}
@setter(LINKED_LANE_LIMIT)
public static void setLinkedLaneLimit(final IAgent vehicle, final int linkedLaneLimit) {
vehicle.setAttribute(LINKED_LANE_LIMIT, linkedLaneLimit);
}
@getter(LANE_CHANGE_LIMIT)
public static int getLaneChangeLimit(final IAgent vehicle) {
return (int) vehicle.getAttribute(LANE_CHANGE_LIMIT);
}
@getter(RIGHT_SIDE_DRIVING)
public static boolean getRightSideDriving(final IAgent vehicle) {
return (Boolean) vehicle.getAttribute(RIGHT_SIDE_DRIVING);
}
@setter(RIGHT_SIDE_DRIVING)
public static void setRightSideDriving(final IAgent vehicle, final Boolean isRight) {
vehicle.setAttribute(RIGHT_SIDE_DRIVING, isRight);
}
@Deprecated
@getter(SECURITY_DISTANCE_COEFF)
public static double getSecurityDistanceCoeff(final IAgent vehicle) {
return (Double) vehicle.getAttribute(SECURITY_DISTANCE_COEFF);
}
@Deprecated
@setter(SECURITY_DISTANCE_COEFF)
public static void setSecurityDistanceCoeff(final IAgent vehicle, final double ls) {
vehicle.setAttribute(SECURITY_DISTANCE_COEFF, ls);
}
@getter(SAFETY_DISTANCE_COEFF)
public static double getSafetyDistanceCoeff(final IAgent vehicle) {
return (Double) vehicle.getAttribute(SAFETY_DISTANCE_COEFF);
}
@setter(SAFETY_DISTANCE_COEFF)
public static void setSafetyDistanceCoeff(final IAgent vehicle, final double ls) {
vehicle.setAttribute(SAFETY_DISTANCE_COEFF, ls);
}
@getter(CURRENT_ROAD)
public static IAgent getCurrentRoad(final IAgent vehicle) {
return (IAgent) vehicle.getAttribute(CURRENT_ROAD);
}
@setter(CURRENT_ROAD)
public static void setCurrentRoad(final IAgent vehicle, final IAgent road) {
vehicle.setAttribute(CURRENT_ROAD, road);
}
@getter(NEXT_ROAD)
public static IAgent getNextRoad(final IAgent vehicle) {
return (IAgent) vehicle.getAttribute(NEXT_ROAD);
}
@setter(NEXT_ROAD)
public static void setNextRoad(final IAgent vehicle, final IAgent road) {
vehicle.setAttribute(NEXT_ROAD, road);
}
@getter(VEHICLE_LENGTH)
public static double getVehicleLength(final IAgent vehicle) {
return (Double) vehicle.getAttribute(VEHICLE_LENGTH);
}
@Deprecated
@getter(CURRENT_LANE)
public static int getCurrentLane(final IAgent vehicle) {
return getLowestLane(vehicle);
}
@Deprecated
@setter(CURRENT_LANE)
public static void setCurrentLane(final IAgent vehicle, final int newLane) {
setLowestLane(vehicle, newLane);
}
@getter(LOWEST_LANE)
public static int getLowestLane(final IAgent vehicle) {
return (int) vehicle.getAttribute(LOWEST_LANE);
}
@setter(LOWEST_LANE)
public static void setLowestLane(final IAgent vehicle, final int lowestLane) {
vehicle.setAttribute(LOWEST_LANE, lowestLane);
}
@getter(DISTANCE_TO_GOAL)
public static double getDistanceToGoal(final IAgent vehicle) {
return (Double) vehicle.getAttribute(DISTANCE_TO_GOAL);
}
@getter(DISTANCE_TO_CURRENT_TARGET)
public static double getDistanceToCurrentTarget(final IAgent vehicle) {
return (Double) vehicle.getAttribute(DISTANCE_TO_CURRENT_TARGET);
}
@setter(DISTANCE_TO_CURRENT_TARGET)
public static void setDistanceToCurrentTarget(final IAgent vehicle, final double dist) {
vehicle.setAttribute(DISTANCE_TO_CURRENT_TARGET, dist);
}
@getter(MIN_SECURITY_DISTANCE)
public static double getMinSecurityDistance(final IAgent vehicle) {
return (Double) vehicle.getAttribute(MIN_SECURITY_DISTANCE);
}
@setter(MIN_SECURITY_DISTANCE)
public static void setMinSecDistance(final IAgent vehicle, final double msd) {
vehicle.setAttribute(MIN_SECURITY_DISTANCE, msd);
}
@getter(MIN_SAFETY_DISTANCE)
public static double getMinSafetyDistance(final IAgent vehicle) {
return (Double) vehicle.getAttribute(MIN_SAFETY_DISTANCE);
}
@setter(DISTANCE_TO_GOAL)
public static void setDistanceToGoal(final IAgent vehicle, final double dg) {
vehicle.setAttribute(DISTANCE_TO_GOAL, dg);
}
@getter(NUM_LANES_OCCUPIED)
public static Integer getNumLanesOccupied(final IAgent vehicle) {
return (Integer) vehicle.getAttribute(NUM_LANES_OCCUPIED);
}
@setter(NUM_LANES_OCCUPIED)
public static void setNumLanesOccupied(final IAgent vehicle, final Integer value) {
vehicle.setAttribute(NUM_LANES_OCCUPIED, value);
}
@getter(LEADING_VEHICLE)
public static IAgent getLeadingVehicle(final IAgent vehicle) {
return (IAgent) vehicle.getAttribute(LEADING_VEHICLE);
}
@setter(LEADING_VEHICLE)
public static void setLeadingVehicleReadOnly(final IAgent vehicle, final IAgent leadingVehicle) {
// read-only
}
public static void setLeadingVehicle(final IAgent vehicle, final IAgent leadingVehicle) {
vehicle.setAttribute(LEADING_VEHICLE, leadingVehicle);
}
@getter(LEADING_DISTANCE)
public static double getLeadingDistance(final IAgent vehicle) {
return (double) vehicle.getAttribute(LEADING_DISTANCE);
}
@setter(LEADING_DISTANCE)
public static void setLeadingDistanceReadOnly(final IAgent vehicle, final double leadingDist) {
// read-only
}
public static void setLeadingDistance(final IAgent vehicle, final double leadingDist) {
vehicle.setAttribute(LEADING_DISTANCE, leadingDist);
}
@setter(LEADING_SPEED)
public static void setLeadingSpeedReadOnly(final IAgent vehicle, final double leadingSpeed) {
// read-only
}
public static void setLeadingSpeed(final IAgent vehicle, final double leadingSpeed) {
vehicle.setAttribute(LEADING_SPEED, leadingSpeed);
}
public static void setFollower(final IAgent vehicle, final IAgent follower) {
vehicle.setAttribute(FOLLOWER, follower);
}
@action(
name = "advanced_follow_driving",
args = {
@arg(
name = "path",
type = IType.PATH,
optional = false,
doc = @doc ("a path to be followed.")
),
@arg(
name = "target",
type = IType.POINT,
optional = true,
doc = @doc ("the target to reach")
),
@arg(
name = IKeyword.SPEED,
type = IType.FLOAT,
optional = true,
doc = @doc ("the speed to use for this move (replaces the current value of speed)")
),
@arg(
name = "time",
type = IType.FLOAT,
optional = true,
doc = @doc ("time to travel")
)
},
doc = @doc(
deprecated = "apparently this action does not do what is described in the documentation",
value = "moves the agent towards along the path passed in the arguments while considering the other agents in the network (only for graph topology)",
returns = "the remaining time",
examples = { @example ("do osm_follow path: the_path on: road_network;") }
)
)
@Deprecated
public Double primAdvancedFollow(final IScope scope) throws GamaRuntimeException {
// Double t = scope.hasArg("time") ? scope.getFloatArg("time") : scope.getClock().getStepInSeconds();
// GamaPath path = scope.hasArg("path") ? (GamaPath) scope.getArg("path", IType.NONE) : null;