-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
3856 lines (3226 loc) · 538 KB
/
index.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>PyMoSim — PyMoSim v0.8 Manual</title>
<link href="_static/css/theme.css" rel="stylesheet" />
<link href="_static/css/index.c5995385ac14fb8791e8eb36b4908be2.css" rel="stylesheet" />
<link rel="stylesheet"
href="_static/vendor/fontawesome/5.13.0/css/all.min.css">
<link rel="preload" as="font" type="font/woff2" crossorigin
href="_static/vendor/fontawesome/5.13.0/webfonts/fa-solid-900.woff2">
<link rel="preload" as="font" type="font/woff2" crossorigin
href="_static/vendor/fontawesome/5.13.0/webfonts/fa-brands-400.woff2">
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="_static/basic.css" type="text/css" />
<link rel="stylesheet" type="text/css" href="_static/graphviz.css" />
<link rel="preload" as="script" href="_static/js/index.1c5a1a01449ed65a7b51.js">
<script id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>
<script src="_static/jquery.js"></script>
<script src="_static/underscore.js"></script>
<script src="_static/doctools.js"></script>
<script async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="comm package" href="comm.html" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="docsearch:language" content="en" />
</head>
<body data-spy="scroll" data-target="#bd-toc-nav" data-offset="80">
<div class="container-fluid" id="banner"></div>
<nav class="navbar navbar-light navbar-expand-lg bg-light fixed-top bd-navbar" id="navbar-main"><div class="container-xl">
<div id="navbar-start">
<a class="navbar-brand" href="#">
<img src="_static/icon.png" class="logo" alt="logo">
</a>
</div>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbar-collapsible" aria-controls="navbar-collapsible" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div id="navbar-collapsible" class="col-lg-9 collapse navbar-collapse">
<div id="navbar-center" class="mr-auto">
<div class="navbar-center-item">
<ul id="navbar-main-elements" class="navbar-nav">
<li class="toctree-l1 nav-item">
<a class="reference internal nav-link" href="comm.html">
comm package
</a>
</li>
<li class="toctree-l1 nav-item">
<a class="reference internal nav-link" href="node.html">
node package
</a>
</li>
<li class="toctree-l1 nav-item">
<a class="reference internal nav-link" href="sim.html">
sim package
</a>
</li>
<li class="toctree-l1 nav-item">
<a class="reference internal nav-link" href="map.html">
map package
</a>
</li>
</ul>
</div>
</div>
<div id="navbar-end">
<div class="navbar-end-item">
<form class="bd-search d-flex align-items-center" action="search.html" method="get">
<i class="icon fas fa-search"></i>
<input type="search" class="form-control" name="q" id="search-input" placeholder="Search the docs ..." aria-label="Search the docs ..." autocomplete="off" >
</form>
</div>
<div class="navbar-end-item">
<ul id="navbar-icon-links" class="navbar-nav" aria-label="Icon Links">
<li class="nav-item">
<a class="nav-link" href="https://github.com/cfoh/pymosim" rel="noopener" target="_blank" title="GitHub">
<span><i class="fab fa-github-square"></i></span>
<label class="sr-only">GitHub</label>
</a>
</li>
</ul>
</div>
</div>
</div>
</div>
</nav>
<div class="container-xl">
<div class="row">
<!-- Only show if we have sidebars configured, else just a small margin -->
<div class="col-12 col-md-3 bd-sidebar"><form class="bd-search d-flex align-items-center" action="search.html" method="get">
<i class="icon fas fa-search"></i>
<input type="search" class="form-control" name="q" id="search-input" placeholder="Search the docs ..." aria-label="Search the docs ..." autocomplete="off" >
</form><nav class="bd-links" id="bd-docs-nav" aria-label="Main navigation">
<div class="bd-toc-item active">
</div>
</nav>
</div>
<div class="d-none d-xl-block col-xl-2 bd-toc">
<div class="toc-item">
<div class="tocsection onthispage pt-5 pb-3">
<i class="fas fa-list"></i> On this page
</div>
<nav id="bd-toc-nav">
<ul class="visible nav section-nav flex-column">
<li class="toc-h1 nav-item toc-entry">
<a class="reference internal nav-link" href="#">
PyMoSim
</a>
</li>
<li class="toc-h1 nav-item toc-entry">
<a class="reference internal nav-link" href="#list-of-packages-and-modules">
List of Packages and Modules
</a>
</li>
<li class="toc-h1 nav-item toc-entry">
<a class="reference internal nav-link" href="#list-of-examples">
List of Examples
</a>
<ul class="visible nav section-nav flex-column">
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#module-example1">
Example 1
</a>
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#module-example2">
Example 2
</a>
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#module-example3">
Example 3
</a>
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#module-example4">
Example 4
</a>
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#module-example5">
Example 5
</a>
<ul class="visible nav section-nav flex-column">
<li class="toc-h3 nav-item toc-entry">
<a class="reference internal nav-link" href="#references">
References
</a>
</li>
<li class="toc-h3 nav-item toc-entry">
<a class="reference internal nav-link" href="#module-example5a">
Example 5a
</a>
</li>
<li class="toc-h3 nav-item toc-entry">
<a class="reference internal nav-link" href="#module-example5b">
Example 5b
</a>
</li>
<li class="toc-h3 nav-item toc-entry">
<a class="reference internal nav-link" href="#module-example5c">
Example 5c
</a>
</li>
</ul>
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#module-example6">
Example 6
</a>
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#module-example7">
Example 7
</a>
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#module-example8">
Example 8
</a>
<ul class="visible nav section-nav flex-column">
<li class="toc-h3 nav-item toc-entry">
<a class="reference internal nav-link" href="#id3">
References
</a>
</li>
<li class="toc-h3 nav-item toc-entry">
<a class="reference internal nav-link" href="#result-comparison">
Result Comparison
</a>
</li>
</ul>
</li>
</ul>
</li>
<li class="toc-h1 nav-item toc-entry">
<a class="reference internal nav-link" href="#indices-and-tables">
Indices and tables
</a>
</li>
</ul>
</nav>
</div>
<div class="toc-item">
</div>
</div>
<main class="col-12 col-md-9 col-xl-7 py-md-5 pl-md-5 pr-md-4 bd-content" role="main">
<div>
<div class="section" id="pymosim">
<h1>PyMoSim<a class="headerlink" href="#pymosim" title="Permalink to this headline">¶</a></h1>
<p><strong>PyMoSim</strong> is a mobility simulator written in Python. We plan to release
the source code to public in the near future.
If you want to access to the code, you need to make a request to
<cite>c.foh@surrey.ac.uk</cite>, we will grant you access to the code on our github
at: <a class="reference external" href="https://github.com/cfoh/pymosim">https://github.com/cfoh/pymosim</a>.</p>
</div>
<hr class="docutils" />
<div class="section" id="list-of-packages-and-modules">
<h1>List of Packages and Modules<a class="headerlink" href="#list-of-packages-and-modules" title="Permalink to this headline">¶</a></h1>
<div class="toctree-wrapper compound">
<ul>
<li class="toctree-l1"><a class="reference internal" href="comm.html">comm package</a><ul>
<li class="toctree-l2"><a class="reference internal" href="comm.html#submodules">Submodules</a><ul>
<li class="toctree-l3"><a class="reference internal" href="comm.channel.html">comm.channel module</a></li>
<li class="toctree-l3"><a class="reference internal" href="comm.ltemodel.html">comm.ltemodel module</a></li>
<li class="toctree-l3"><a class="reference internal" href="comm.mmwave28.html">comm.mmwave28 module</a></li>
<li class="toctree-l3"><a class="reference internal" href="comm.signalwave.html">comm.signalwave module</a></li>
<li class="toctree-l3"><a class="reference internal" href="comm.t28.html">comm.t28 module</a></li>
<li class="toctree-l3"><a class="reference internal" href="comm.transceiver.html">comm.transceiver module</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="comm.html#module-comm">Module contents</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="node.html">node package</a><ul>
<li class="toctree-l2"><a class="reference internal" href="node.html#submodules">Submodules</a><ul>
<li class="toctree-l3"><a class="reference internal" href="node.draw.html">node.draw module</a></li>
<li class="toctree-l3"><a class="reference internal" href="node.mobility.html">node.mobility module</a></li>
<li class="toctree-l3"><a class="reference internal" href="node.mobility2.html">node.mobility2 module</a></li>
<li class="toctree-l3"><a class="reference internal" href="node.mobility2b.html">node.mobility2b module</a></li>
<li class="toctree-l3"><a class="reference internal" href="node.mobility3.html">node.mobility3 module</a></li>
<li class="toctree-l3"><a class="reference internal" href="node.node.html">node.node module</a></li>
<li class="toctree-l3"><a class="reference internal" href="node.obstacle.html">node.obstacle module</a></li>
<li class="toctree-l3"><a class="reference internal" href="node.routemobi.html">node.routemobi module</a></li>
<li class="toctree-l3"><a class="reference internal" href="node.timer.html">node.timer module</a></li>
<li class="toctree-l3"><a class="reference internal" href="node.type.html">node.type module</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="node.html#module-node">Module contents</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="sim.html">sim package</a><ul>
<li class="toctree-l2"><a class="reference internal" href="sim.html#submodules">Submodules</a><ul>
<li class="toctree-l3"><a class="reference internal" href="sim.direction.html">sim.direction module</a></li>
<li class="toctree-l3"><a class="reference internal" href="sim.drawable.html">sim.drawable module</a></li>
<li class="toctree-l3"><a class="reference internal" href="sim.event.html">sim.event module</a></li>
<li class="toctree-l3"><a class="reference internal" href="sim.frame.html">sim.frame module</a></li>
<li class="toctree-l3"><a class="reference internal" href="sim.loc.html">sim.loc module</a></li>
<li class="toctree-l3"><a class="reference internal" href="sim.scenario.html">sim.scenario module</a></li>
<li class="toctree-l3"><a class="reference internal" href="sim.simsystem.html">sim.simsystem module</a></li>
<li class="toctree-l3"><a class="reference internal" href="sim.simulation.html">sim.simulation module</a></li>
<li class="toctree-l3"><a class="reference internal" href="sim.version.html">sim.version module</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="sim.html#module-sim">Module contents</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="map.html">map package</a><ul>
<li class="toctree-l2"><a class="reference internal" href="map.html#submodules">Submodules</a><ul>
<li class="toctree-l3"><a class="reference internal" href="map.mapinfo.html">map.mapinfo module</a></li>
<li class="toctree-l3"><a class="reference internal" href="map.pin.html">map.pin module</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="map.html#module-map">Module contents</a></li>
</ul>
</li>
</ul>
</div>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>The release version of this documentation can be found
here: <a class="reference internal" href="sim.version.html#sim.version.Version" title="sim.version.Version"><code class="xref py py-class docutils literal notranslate"><span class="pre">sim.version.Version</span></code></a>.</p>
</div>
</div>
<hr class="docutils" />
<div class="section" id="list-of-examples">
<h1>List of Examples<a class="headerlink" href="#list-of-examples" title="Permalink to this headline">¶</a></h1>
<div class="section" id="module-example1">
<span id="example-1"></span><h2>Example 1<a class="headerlink" href="#module-example1" title="Permalink to this headline">¶</a></h2>
<p>This is a simple example to show how a simulation can be created within 50 lines.</p>
<img alt="_images/example1.gif" src="_images/example1.gif" />
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 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</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="sd">'''This is a simple example to show how a simulation can be created within 50 lines.'''</span>
<span class="kn">from</span> <span class="nn">sim</span> <span class="kn">import</span> <span class="n">World</span><span class="p">,</span> <span class="n">BaseScenario</span><span class="p">,</span> <span class="n">ScreenXY</span> <span class="k">as</span> <span class="n">XY</span>
<span class="kn">from</span> <span class="nn">node</span> <span class="kn">import</span> <span class="n">BaseNode</span><span class="p">,</span> <span class="n">NodeType</span><span class="p">,</span> <span class="n">Stationary</span><span class="p">,</span> <span class="n">StaticPath</span>
<span class="kn">from</span> <span class="nn">comm</span> <span class="kn">import</span> <span class="n">Transceiver</span><span class="p">,</span> <span class="n">DiscModel</span>
<span class="k">class</span> <span class="nc">MyBS</span><span class="p">(</span><span class="n">BaseNode</span><span class="p">):</span>
<span class="sd">'''MyBS: This is a base station design.'''</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">simworld</span><span class="p">,</span> <span class="nb">id</span><span class="p">,</span> <span class="n">loc</span><span class="p">,</span> <span class="n">freq</span><span class="p">,</span> <span class="n">channel</span><span class="p">):</span>
<span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="n">simworld</span><span class="p">,</span> <span class="nb">id</span><span class="p">,</span> <span class="n">node_type</span><span class="o">=</span><span class="n">NodeType</span><span class="o">.</span><span class="n">BaseStation</span><span class="p">(</span><span class="bp">self</span><span class="p">))</span>
<span class="bp">self</span><span class="o">.</span><span class="n">set_transceiver</span><span class="p">(</span><span class="n">Transceiver</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">freq</span><span class="p">,</span> <span class="n">channel</span><span class="p">))</span>
<span class="bp">self</span><span class="o">.</span><span class="n">set_mobility</span><span class="p">(</span><span class="n">Stationary</span><span class="p">(</span><span class="n">loc</span><span class="p">))</span>
<span class="k">class</span> <span class="nc">MyVehicle</span><span class="p">(</span><span class="n">BaseNode</span><span class="p">):</span>
<span class="sd">'''MyVehicle: This is a vehicle design.'''</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">simworld</span><span class="p">,</span> <span class="nb">id</span><span class="p">,</span> <span class="n">start_loc</span><span class="p">,</span> <span class="n">path</span><span class="p">,</span> <span class="n">freq</span><span class="p">,</span> <span class="n">channel</span><span class="p">):</span>
<span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="n">simworld</span><span class="p">,</span> <span class="nb">id</span><span class="p">,</span> <span class="n">node_type</span><span class="o">=</span><span class="n">NodeType</span><span class="o">.</span><span class="n">Vehicle</span><span class="p">(</span><span class="bp">self</span><span class="p">))</span>
<span class="bp">self</span><span class="o">.</span><span class="n">set_transceiver</span><span class="p">(</span><span class="n">Transceiver</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">freq</span><span class="p">,</span> <span class="n">channel</span><span class="p">))</span>
<span class="bp">self</span><span class="o">.</span><span class="n">set_mobility</span><span class="p">(</span><span class="n">StaticPath</span><span class="p">(</span><span class="n">start_loc</span><span class="p">,</span><span class="n">path</span><span class="p">))</span>
<span class="k">class</span> <span class="nc">MyScenario</span><span class="p">(</span><span class="n">BaseScenario</span><span class="p">):</span>
<span class="sd">'''This is MyScenario. It reimplements on_create() and on_event().'''</span>
<span class="c1">## this will be called at the start</span>
<span class="k">def</span> <span class="nf">on_create</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">simworld</span><span class="p">)</span> <span class="o">-></span> <span class="nb">bool</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">set_name</span><span class="p">(</span><span class="s2">"A simulation in less than 50 lines"</span><span class="p">)</span>
<span class="n">omni</span> <span class="o">=</span> <span class="n">DiscModel</span><span class="p">(</span><span class="n">radius</span><span class="o">=</span><span class="mi">100</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">my_bs</span> <span class="o">=</span> <span class="n">MyBS</span><span class="p">(</span><span class="n">simworld</span><span class="p">,</span> <span class="s2">"BS"</span><span class="p">,</span> <span class="n">XY</span><span class="p">(</span><span class="mi">160</span><span class="p">,</span><span class="mi">100</span><span class="p">),</span> <span class="n">freq</span><span class="o">=</span><span class="mf">2.4</span><span class="p">,</span> <span class="n">channel</span><span class="o">=</span><span class="n">omni</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">my_vehicle</span> <span class="o">=</span> <span class="n">MyVehicle</span><span class="p">(</span><span class="n">simworld</span><span class="p">,</span> <span class="nb">id</span><span class="o">=</span><span class="s2">"Vehicle"</span><span class="p">,</span> <span class="n">freq</span><span class="o">=</span><span class="mf">2.4</span><span class="p">,</span> <span class="n">channel</span><span class="o">=</span><span class="n">omni</span><span class="p">,</span>
<span class="n">start_loc</span><span class="o">=</span><span class="n">XY</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span><span class="mi">130</span><span class="p">),</span> <span class="n">path</span><span class="o">=</span><span class="p">[(</span><span class="mi">60</span><span class="p">,</span><span class="n">XY</span><span class="p">(</span><span class="mi">350</span><span class="p">,</span><span class="mi">130</span><span class="p">))])</span>
<span class="k">return</span> <span class="kc">True</span>
<span class="c1">## this will be called repeatedly</span>
<span class="k">def</span> <span class="nf">on_event</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sim_time</span><span class="p">,</span> <span class="n">event_obj</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">my_bs</span><span class="o">.</span><span class="n">clear_drawing</span><span class="p">()</span>
<span class="bp">self</span><span class="o">.</span><span class="n">my_vehicle</span><span class="o">.</span><span class="n">clear_drawing</span><span class="p">()</span>
<span class="n">beacon_message</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">my_bs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"transceiver"</span><span class="p">)</span><span class="o">.</span><span class="n">create_signal</span><span class="p">()</span>
<span class="k">for</span> <span class="p">(</span><span class="n">node</span><span class="p">,</span><span class="n">signal</span><span class="p">)</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">my_bs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"transceiver"</span><span class="p">)</span><span class="o">.</span><span class="n">broadcast</span><span class="p">(</span><span class="n">beacon_message</span><span class="p">):</span>
<span class="k">if</span> <span class="n">node</span> <span class="ow">is</span> <span class="bp">self</span><span class="o">.</span><span class="n">my_vehicle</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">my_bs</span><span class="o">.</span><span class="n">draw_circle</span><span class="p">(</span><span class="mi">100</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">my_vehicle</span><span class="o">.</span><span class="n">draw_line</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">my_bs</span><span class="p">)</span>
<span class="k">if</span> <span class="vm">__name__</span> <span class="o">==</span> <span class="s2">"__main__"</span><span class="p">:</span>
<span class="n">sim</span> <span class="o">=</span> <span class="n">World</span><span class="p">()</span>
<span class="n">sim</span><span class="o">.</span><span class="n">config</span><span class="p">(</span><span class="n">sim_stop</span><span class="o">=</span><span class="mf">5.0</span><span class="p">,</span> <span class="n">sim_step</span><span class="o">=</span><span class="mf">0.1</span><span class="p">,</span> <span class="n">sim_speed</span><span class="o">=</span><span class="mf">1.0</span><span class="p">,</span>
<span class="n">display_option</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
<span class="n">scenario</span><span class="o">=</span><span class="n">MyScenario</span><span class="p">(</span><span class="n">sim</span><span class="p">))</span>
<span class="n">sim</span><span class="o">.</span><span class="n">run</span><span class="p">()</span>
</pre></div>
</td></tr></table></div>
</div>
<div class="section" id="module-example2">
<span id="example-2"></span><h2>Example 2<a class="headerlink" href="#module-example2" title="Permalink to this headline">¶</a></h2>
<p>This is an example which demonstrates a cluster of sectorized BSs serving vehicles in a
highway scenario. The mobility of vehicles is predefined and static in this example.
The simulation will run for 10 seconds.</p>
<p>In this example, we use vehicle centric where vehicle will send a hello message
to collect signal quality from all sectors of all BSs, and then associate with the sector
with the highest quality (i.e. strongest SNR). The example shows how to use Transceiver
class to send and detect signals, and measure the signal quality of a received signal.</p>
<img alt="_images/example2.gif" src="_images/example2.gif" />
<details class="summary-show-source-code">
<summary>Show source code</summary><div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="sd">'''</span>
<span class="sd">This is an example which demonstrates a cluster of sectorized BSs serving vehicles in a </span>
<span class="sd">highway scenario. The mobility of vehicles is predefined and static in this example.</span>
<span class="sd">The simulation will run for 10 seconds.</span>
<span class="sd">In this example, we use vehicle centric where vehicle will send a hello message</span>
<span class="sd">to collect signal quality from all sectors of all BSs, and then associate with the sector </span>
<span class="sd">with the highest quality (i.e. strongest SNR). The example shows how to use Transceiver</span>
<span class="sd">class to send and detect signals, and measure the signal quality of a received signal.</span>
<span class="sd">'''</span>
<span class="kn">import</span> <span class="nn">wx</span>
<span class="kn">import</span> <span class="nn">operator</span>
<span class="kn">import</span> <span class="nn">argparse</span>
<span class="kn">from</span> <span class="nn">argparse</span> <span class="kn">import</span> <span class="n">Namespace</span><span class="p">,</span> <span class="n">ArgumentParser</span>
<span class="kn">from</span> <span class="nn">sim</span> <span class="kn">import</span> <span class="n">World</span><span class="p">,</span> <span class="n">BaseScenario</span><span class="p">,</span> <span class="n">Event</span><span class="p">,</span> <span class="n">ScreenXY</span> <span class="k">as</span> <span class="n">XY</span>
<span class="kn">from</span> <span class="nn">node</span> <span class="kn">import</span> <span class="n">BaseNode</span><span class="p">,</span> <span class="n">NodeType</span><span class="p">,</span> <span class="n">Stationary</span><span class="p">,</span> <span class="n">StaticPath</span>
<span class="kn">from</span> <span class="nn">comm</span> <span class="kn">import</span> <span class="n">Transceiver</span><span class="p">,</span> <span class="n">TransceiverDir</span><span class="p">,</span> <span class="n">DiscModel</span>
<span class="c1">####################################################################</span>
<span class="c1">## Nodes</span>
<span class="c1">####################################################################</span>
<span class="k">class</span> <span class="nc">MySector</span><span class="p">(</span><span class="n">BaseNode</span><span class="p">):</span>
<span class="sd">'''</span>
<span class="sd"> MySector: This is a sector of a base station in the VANET sim world</span>
<span class="sd"> '''</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">simworld</span><span class="p">,</span> <span class="nb">id</span><span class="p">,</span> <span class="n">loc</span><span class="p">,</span> <span class="n">freq</span><span class="p">,</span> <span class="n">channel</span><span class="p">,</span> <span class="n">sector_width</span><span class="p">,</span> <span class="n">sector_dir</span><span class="p">):</span>
<span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="n">simworld</span><span class="p">,</span> <span class="nb">id</span><span class="p">,</span> <span class="n">node_type</span><span class="o">=</span><span class="n">NodeType</span><span class="o">.</span><span class="n">BaseStation</span><span class="p">(</span><span class="bp">self</span><span class="p">))</span>
<span class="bp">self</span><span class="o">.</span><span class="n">transceiver</span> <span class="o">=</span> <span class="n">TransceiverDir</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">freq</span><span class="p">,</span><span class="n">channel</span><span class="p">,</span><span class="n">sector_width</span><span class="p">,</span><span class="n">sector_dir</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">serving_node</span> <span class="o">=</span> <span class="kc">None</span>
<span class="c1">## setup the sector</span>
<span class="bp">self</span><span class="o">.</span><span class="n">set_transceiver</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">transceiver</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">set_mobility</span><span class="p">(</span><span class="n">Stationary</span><span class="p">(</span><span class="n">loc</span><span class="p">))</span>
<span class="c1">## show the coverage of this sector</span>
<span class="k">def</span> <span class="nf">show_coverage</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">clear_drawing</span><span class="p">()</span> <span class="c1"># this is persistent drawing, so need to clear the all first</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">serving_node</span><span class="o">!=</span><span class="kc">None</span><span class="p">:</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">transceiver</span><span class="o">.</span><span class="n">get_property</span><span class="p">(</span><span class="s2">"type"</span><span class="p">)</span><span class="o">==</span><span class="s2">"omni"</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">draw_circle</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">transceiver</span><span class="o">.</span><span class="n">get_property</span><span class="p">(</span><span class="s2">"radius"</span><span class="p">))</span>
<span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">transceiver</span><span class="o">.</span><span class="n">get_property</span><span class="p">(</span><span class="s2">"type"</span><span class="p">)</span><span class="o">==</span><span class="s2">"directional"</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">draw_sector</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">transceiver</span><span class="o">.</span><span class="n">get_property</span><span class="p">(</span><span class="s2">"radius"</span><span class="p">),</span>
<span class="bp">self</span><span class="o">.</span><span class="n">transceiver</span><span class="o">.</span><span class="n">get_property</span><span class="p">(</span><span class="s2">"azimuth"</span><span class="p">),</span>
<span class="bp">self</span><span class="o">.</span><span class="n">transceiver</span><span class="o">.</span><span class="n">get_property</span><span class="p">(</span><span class="s2">"beam width"</span><span class="p">))</span>
<span class="k">class</span> <span class="nc">MyVehicle</span><span class="p">(</span><span class="n">BaseNode</span><span class="p">):</span>
<span class="sd">'''</span>
<span class="sd"> MyVehicle: This is a transmitting node in the VANET sim world</span>
<span class="sd"> '''</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">simworld</span><span class="p">,</span> <span class="nb">id</span><span class="p">,</span> <span class="n">freq</span><span class="p">,</span> <span class="n">channel</span><span class="p">):</span>
<span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="n">simworld</span><span class="p">,</span> <span class="nb">id</span><span class="p">,</span> <span class="n">node_type</span><span class="o">=</span><span class="n">NodeType</span><span class="o">.</span><span class="n">Vehicle</span><span class="p">(</span><span class="bp">self</span><span class="p">))</span>
<span class="c1">## initialize some properties</span>
<span class="bp">self</span><span class="o">.</span><span class="n">transceiver</span> <span class="o">=</span> <span class="n">Transceiver</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">freq</span><span class="p">,</span><span class="n">channel</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">set_transceiver</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">transceiver</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">associated_sector</span> <span class="o">=</span> <span class="kc">None</span>
<span class="c1">## initialize some variables to collect statistics</span>
<span class="bp">self</span><span class="o">.</span><span class="n">connectivity</span> <span class="o">=</span> <span class="p">[</span> <span class="p">[</span><span class="kc">None</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">]</span> <span class="p">]</span> <span class="c1"># list of connections: [sector, start_time, end_time]</span>
<span class="c1">## associate with a sector</span>
<span class="k">def</span> <span class="nf">associate_sector</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">sector</span><span class="p">,</span><span class="n">time</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">associated_sector</span> <span class="o">=</span> <span class="n">sector</span>
<span class="n">sector</span><span class="o">.</span><span class="n">serving_node</span> <span class="o">=</span> <span class="bp">self</span>
<span class="bp">self</span><span class="o">.</span><span class="n">connectivity</span><span class="o">.</span><span class="n">append</span><span class="p">([</span><span class="n">sector</span><span class="p">,</span><span class="n">time</span><span class="p">,</span><span class="mi">0</span><span class="p">])</span>
<span class="c1">## remove sector association due to lost of connection</span>
<span class="k">def</span> <span class="nf">lost_sector</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">time</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">associated_sector</span><span class="o">.</span><span class="n">serving_node</span> <span class="o">=</span> <span class="kc">None</span>
<span class="bp">self</span><span class="o">.</span><span class="n">associated_sector</span> <span class="o">=</span> <span class="kc">None</span>
<span class="bp">self</span><span class="o">.</span><span class="n">connectivity</span><span class="p">[</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">connectivity</span><span class="p">)</span><span class="o">-</span><span class="mi">1</span><span class="p">][</span><span class="mi">2</span><span class="p">]</span> <span class="o">=</span> <span class="n">time</span>
<span class="c1">## draw a line to the associated sector, if any</span>
<span class="k">def</span> <span class="nf">show_connection</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">clear_drawing</span><span class="p">()</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">associated_sector</span><span class="o">!=</span><span class="kc">None</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">draw_line</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">associated_sector</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">set_color</span><span class="p">(</span><span class="n">wx</span><span class="o">.</span><span class="n">BLACK</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">set_color</span><span class="p">(</span><span class="n">wx</span><span class="o">.</span><span class="n">RED</span><span class="p">)</span>
<span class="c1">####################################################################</span>
<span class="c1">## Scenario</span>
<span class="c1">####################################################################</span>
<span class="k">class</span> <span class="nc">MyScenario</span><span class="p">(</span><span class="n">BaseScenario</span><span class="p">):</span>
<span class="sd">'''</span>
<span class="sd"> MyScenario: This is my scenario</span>
<span class="sd"> '''</span>
<span class="c1">##---------------------------------------------------------------</span>
<span class="c1">## This method will be called before the start of the simulation,</span>
<span class="c1">## build the simulation world here</span>
<span class="k">def</span> <span class="nf">on_create</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">simworld</span><span class="p">)</span> <span class="o">-></span> <span class="nb">bool</span><span class="p">:</span>
<span class="c1">## give a name</span>
<span class="bp">self</span><span class="o">.</span><span class="n">set_name</span><span class="p">(</span><span class="s2">"A simple example"</span><span class="p">)</span>
<span class="c1">## create a common channel</span>
<span class="n">carrier_freq</span> <span class="o">=</span> <span class="mf">2.4</span>
<span class="n">coverage_range</span> <span class="o">=</span> <span class="mi">100</span>
<span class="n">beam_width</span> <span class="o">=</span> <span class="mi">60</span>
<span class="n">sector_dir</span> <span class="o">=</span> <span class="p">[</span><span class="mi">180</span><span class="o">-</span><span class="mi">60</span><span class="p">,</span> <span class="mi">180</span><span class="p">,</span> <span class="mi">180</span><span class="o">+</span><span class="mi">60</span><span class="p">]</span>
<span class="n">ch_omni</span> <span class="o">=</span> <span class="n">DiscModel</span><span class="p">(</span><span class="n">coverage_range</span><span class="p">)</span>
<span class="c1">## create some nodes on the map</span>
<span class="n">bs_locs</span> <span class="o">=</span> <span class="p">[</span><span class="n">XY</span><span class="p">(</span><span class="mi">110</span><span class="p">,</span><span class="mi">140</span><span class="p">),</span><span class="n">XY</span><span class="p">(</span><span class="mi">160</span><span class="p">,</span><span class="mi">140</span><span class="p">),</span><span class="n">XY</span><span class="p">(</span><span class="mi">280</span><span class="p">,</span><span class="mi">135</span><span class="p">)]</span> <span class="c1"># locations</span>
<span class="bp">self</span><span class="o">.</span><span class="n">sectors</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="nb">len</span><span class="p">(</span><span class="n">bs_locs</span><span class="p">)):</span> <span class="c1"># BSs</span>
<span class="k">for</span> <span class="n">j</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="nb">len</span><span class="p">(</span><span class="n">sector_dir</span><span class="p">)):</span> <span class="c1"># sectors for each BS</span>
<span class="nb">id</span> <span class="o">=</span> <span class="s2">"BS-</span><span class="si">%d</span><span class="s2">.</span><span class="si">%d</span><span class="s2">"</span><span class="o">%</span><span class="p">(</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">,</span><span class="n">j</span><span class="o">+</span><span class="mi">1</span><span class="p">)</span>
<span class="n">sector</span> <span class="o">=</span> <span class="n">MySector</span><span class="p">(</span><span class="n">simworld</span><span class="p">,</span> <span class="nb">id</span><span class="p">,</span> <span class="n">bs_locs</span><span class="p">[</span><span class="n">i</span><span class="p">],</span> <span class="n">carrier_freq</span><span class="p">,</span> <span class="n">ch_omni</span><span class="p">,</span>
<span class="n">beam_width</span><span class="p">,</span> <span class="n">sector_dir</span><span class="p">[</span><span class="n">j</span><span class="p">])</span>
<span class="bp">self</span><span class="o">.</span><span class="n">sectors</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">sector</span><span class="p">)</span>
<span class="c1">## create some vehicles on the highway</span>
<span class="bp">self</span><span class="o">.</span><span class="n">vehicles</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">path</span> <span class="o">=</span> <span class="p">[</span> <span class="p">(</span><span class="mi">60</span><span class="p">,</span> <span class="n">XY</span><span class="p">(</span><span class="mi">200</span><span class="p">,</span><span class="mi">200</span><span class="p">)),</span> <span class="p">(</span><span class="mi">30</span><span class="p">,</span> <span class="n">XY</span><span class="p">(</span><span class="mi">400</span><span class="p">,</span><span class="mi">200</span><span class="p">))</span> <span class="p">]</span>
<span class="n">node</span> <span class="o">=</span> <span class="n">MyVehicle</span><span class="p">(</span><span class="n">simworld</span><span class="p">,</span> <span class="nb">id</span><span class="o">=</span><span class="s2">"Vehicle1"</span><span class="p">,</span> <span class="n">freq</span><span class="o">=</span><span class="n">carrier_freq</span><span class="p">,</span> <span class="n">channel</span><span class="o">=</span><span class="n">ch_omni</span><span class="p">)</span>
<span class="n">node</span><span class="o">.</span><span class="n">set_mobility</span><span class="p">(</span><span class="n">StaticPath</span><span class="p">(</span><span class="n">start_loc</span><span class="o">=</span><span class="n">XY</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span><span class="mi">200</span><span class="p">),</span><span class="n">path</span><span class="o">=</span><span class="n">path</span><span class="p">))</span>
<span class="bp">self</span><span class="o">.</span><span class="n">vehicles</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">node</span><span class="p">)</span>
<span class="n">path</span> <span class="o">=</span> <span class="p">[</span> <span class="p">(</span><span class="mi">40</span><span class="p">,</span> <span class="n">XY</span><span class="p">(</span><span class="mi">150</span><span class="p">,</span><span class="mi">180</span><span class="p">)),</span> <span class="p">(</span><span class="mi">50</span><span class="p">,</span> <span class="n">XY</span><span class="p">(</span><span class="mi">5</span><span class="p">,</span><span class="mi">180</span><span class="p">))</span> <span class="p">]</span>
<span class="n">node</span> <span class="o">=</span> <span class="n">MyVehicle</span><span class="p">(</span><span class="n">simworld</span><span class="p">,</span> <span class="nb">id</span><span class="o">=</span><span class="s2">"Vehicle2"</span><span class="p">,</span> <span class="n">freq</span><span class="o">=</span><span class="n">carrier_freq</span><span class="p">,</span> <span class="n">channel</span><span class="o">=</span><span class="n">ch_omni</span><span class="p">)</span>
<span class="n">node</span><span class="o">.</span><span class="n">set_mobility</span><span class="p">(</span><span class="n">StaticPath</span><span class="p">(</span><span class="n">start_loc</span><span class="o">=</span><span class="n">XY</span><span class="p">(</span><span class="mi">390</span><span class="p">,</span><span class="mi">180</span><span class="p">),</span><span class="n">path</span><span class="o">=</span><span class="n">path</span><span class="p">))</span>
<span class="bp">self</span><span class="o">.</span><span class="n">vehicles</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">node</span><span class="p">)</span>
<span class="k">return</span> <span class="kc">True</span>
<span class="c1">##-------------------------------------------------------------</span>
<span class="c1">## This method will be called repeatedly until the simulation</span>
<span class="c1">## is ended or stopped, perform any user simulation action here</span>
<span class="k">def</span> <span class="nf">on_event</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sim_time</span><span class="p">,</span> <span class="n">event_obj</span><span class="p">):</span>
<span class="n">all_vehicles</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">vehicles</span>
<span class="n">all_sectors</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">sectors</span>
<span class="c1">## check vehicle connectivity with its associated sector</span>
<span class="k">for</span> <span class="n">vehicle</span> <span class="ow">in</span> <span class="n">all_vehicles</span><span class="p">:</span>
<span class="n">my_sector</span> <span class="o">=</span> <span class="n">vehicle</span><span class="o">.</span><span class="n">associated_sector</span>
<span class="k">if</span> <span class="n">my_sector</span><span class="o">==</span><span class="kc">None</span><span class="p">:</span> <span class="k">continue</span> <span class="c1"># skip if none</span>
<span class="n">beacon</span> <span class="o">=</span> <span class="n">vehicle</span><span class="o">.</span><span class="n">transceiver</span><span class="o">.</span><span class="n">create_signal</span><span class="p">()</span>
<span class="k">if</span> <span class="n">vehicle</span><span class="o">.</span><span class="n">transceiver</span><span class="o">.</span><span class="n">unicast</span><span class="p">(</span><span class="n">beacon</span><span class="p">,</span><span class="n">my_sector</span><span class="p">)</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span> <span class="c1"># lost connection</span>
<span class="n">vehicle</span><span class="o">.</span><span class="n">lost_sector</span><span class="p">(</span><span class="n">sim_time</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">"at t=</span><span class="si">%1.2f</span><span class="s2">, </span><span class="si">%s</span><span class="s2"> lost connection with </span><span class="si">%s</span><span class="s2">"</span><span class="o">%</span><span class="p">(</span><span class="n">sim_time</span><span class="p">,</span><span class="n">vehicle</span><span class="o">.</span><span class="n">id</span><span class="p">,</span><span class="n">my_sector</span><span class="o">.</span><span class="n">id</span><span class="p">))</span>
<span class="c1">## make associatiation with sector if needed</span>
<span class="k">for</span> <span class="n">vehicle</span> <span class="ow">in</span> <span class="n">all_vehicles</span><span class="p">:</span>
<span class="c1">## step 1: check sector association, skip if already associated</span>
<span class="k">if</span> <span class="n">vehicle</span><span class="o">.</span><span class="n">associated_sector</span><span class="o">!=</span><span class="kc">None</span><span class="p">:</span> <span class="k">continue</span>
<span class="c1">## step 2: find strongest SNR to associate</span>
<span class="n">sector_max</span> <span class="o">=</span> <span class="kc">None</span>
<span class="n">detection_list</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">beacon</span> <span class="o">=</span> <span class="n">vehicle</span><span class="o">.</span><span class="n">transceiver</span><span class="o">.</span><span class="n">create_signal</span><span class="p">()</span>
<span class="n">reply_list</span> <span class="o">=</span> <span class="n">vehicle</span><span class="o">.</span><span class="n">transceiver</span><span class="o">.</span><span class="n">broadcast</span><span class="p">(</span><span class="n">beacon</span><span class="p">)</span>
<span class="k">for</span> <span class="p">(</span><span class="n">sector</span><span class="p">,</span><span class="n">signal</span><span class="p">)</span> <span class="ow">in</span> <span class="n">reply_list</span><span class="p">:</span>
<span class="c1">## 2.1 check that the reachable node is a sector currently not serving other</span>
<span class="k">if</span> <span class="n">sector</span><span class="o">.</span><span class="n">type</span><span class="o">!=</span><span class="n">NodeType</span><span class="o">.</span><span class="n">BaseStation</span><span class="p">:</span> <span class="k">continue</span> <span class="c1"># skip if not a base station type</span>
<span class="k">if</span> <span class="n">sector</span><span class="o">.</span><span class="n">serving_node</span><span class="o">!=</span><span class="kc">None</span><span class="p">:</span> <span class="k">continue</span> <span class="c1"># skip if sector is already serving other</span>
<span class="c1">## 2.2 sector beam replies beacon for vehicle to obtain the signal quality</span>
<span class="n">beacon_reply</span> <span class="o">=</span> <span class="n">sector</span><span class="o">.</span><span class="n">transceiver</span><span class="o">.</span><span class="n">create_signal</span><span class="p">()</span>
<span class="n">recv_signal</span> <span class="o">=</span> <span class="n">sector</span><span class="o">.</span><span class="n">transceiver</span><span class="o">.</span><span class="n">unicast</span><span class="p">(</span><span class="n">beacon_reply</span><span class="p">,</span><span class="n">vehicle</span><span class="p">)</span>
<span class="k">if</span> <span class="n">recv_signal</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span> <span class="k">continue</span> <span class="c1"># skip if failed, likely not in coverage</span>
<span class="c1">## 2.3 append to the detection list</span>
<span class="n">detection_list</span><span class="o">.</span><span class="n">append</span><span class="p">((</span><span class="n">sector</span><span class="p">,</span><span class="n">recv_signal</span><span class="o">.</span><span class="n">quality</span><span class="p">))</span>
<span class="c1">## step 3: associate with the sector with the strongest SNR, if exists</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">detection_list</span><span class="p">)</span><span class="o">!=</span><span class="mi">0</span><span class="p">:</span>
<span class="n">sector_max</span> <span class="o">=</span> <span class="nb">max</span><span class="p">(</span><span class="n">detection_list</span><span class="p">,</span><span class="n">key</span><span class="o">=</span><span class="n">operator</span><span class="o">.</span><span class="n">itemgetter</span><span class="p">(</span><span class="mi">1</span><span class="p">))[</span><span class="mi">0</span><span class="p">]</span>
<span class="k">if</span> <span class="n">sector_max</span><span class="o">!=</span><span class="kc">None</span><span class="p">:</span>
<span class="n">vehicle</span><span class="o">.</span><span class="n">associate_sector</span><span class="p">(</span><span class="n">sector_max</span><span class="p">,</span><span class="n">sim_time</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">"at t=</span><span class="si">%1.2f</span><span class="s2">, </span><span class="si">%s</span><span class="s2"> associated with </span><span class="si">%s</span><span class="s2">"</span><span class="o">%</span><span class="p">(</span><span class="n">sim_time</span><span class="p">,</span><span class="n">vehicle</span><span class="o">.</span><span class="n">id</span><span class="p">,</span><span class="n">sector_max</span><span class="o">.</span><span class="n">id</span><span class="p">))</span>
<span class="c1">## draw connectivity & beam coverage on the map</span>
<span class="k">for</span> <span class="n">vehicle</span> <span class="ow">in</span> <span class="n">all_vehicles</span><span class="p">:</span>
<span class="n">vehicle</span><span class="o">.</span><span class="n">show_connection</span><span class="p">()</span>
<span class="k">for</span> <span class="n">sector</span> <span class="ow">in</span> <span class="n">all_sectors</span><span class="p">:</span>
<span class="n">sector</span><span class="o">.</span><span class="n">show_coverage</span><span class="p">()</span>
<span class="c1">## print statistics at the end of the simulation</span>
<span class="k">if</span> <span class="n">event_obj</span><span class="o">==</span><span class="n">Event</span><span class="o">.</span><span class="n">SIM_END</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">"</span><span class="se">\n</span><span class="s2">Statistics (connected BS=duration):"</span><span class="p">)</span>
<span class="n">conn_info_all</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">average_all</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">vehicle</span> <span class="ow">in</span> <span class="n">all_vehicles</span><span class="p">:</span> <span class="c1"># get statistics into `conn_info_all[]`</span>
<span class="n">conn_info_each</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">sum_duration</span> <span class="o">=</span> <span class="mi">0</span>
<span class="n">connection_count</span> <span class="o">=</span> <span class="mi">0</span>
<span class="k">for</span> <span class="n">conn</span> <span class="ow">in</span> <span class="n">vehicle</span><span class="o">.</span><span class="n">connectivity</span><span class="p">:</span>
<span class="k">if</span> <span class="n">conn</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">==</span><span class="kc">None</span><span class="p">:</span> <span class="k">continue</span>
<span class="n">conn_info_each</span><span class="o">.</span><span class="n">append</span><span class="p">([</span><span class="n">conn</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">id</span><span class="p">,</span><span class="n">conn</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span><span class="o">-</span><span class="n">conn</span><span class="p">[</span><span class="mi">1</span><span class="p">]])</span>
<span class="n">sum_duration</span> <span class="o">+=</span> <span class="n">conn</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span><span class="o">-</span><span class="n">conn</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
<span class="n">connection_count</span> <span class="o">+=</span> <span class="mi">1</span>
<span class="n">conn_info_all</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">conn_info_each</span><span class="p">)</span>
<span class="n">average_all</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">sum_duration</span><span class="o">/</span><span class="n">connection_count</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">print_fixed</span><span class="p">(</span><span class="n">text</span><span class="p">):</span>
<span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">" </span><span class="si">{</span><span class="n">text</span><span class="si">:</span><span class="s2">15</span><span class="si">}</span><span class="s2">"</span><span class="p">,</span><span class="n">end</span><span class="o">=</span><span class="s1">''</span><span class="p">)</span>
<span class="k">for</span> <span class="n">vehicle</span> <span class="ow">in</span> <span class="n">all_vehicles</span><span class="p">:</span> <span class="c1"># line 1, heading</span>
<span class="n">print_fixed</span><span class="p">(</span><span class="n">vehicle</span><span class="o">.</span><span class="n">id</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">""</span><span class="p">)</span>
<span class="n">max_record</span> <span class="o">=</span> <span class="mi">0</span>
<span class="k">for</span> <span class="n">vehicle</span> <span class="ow">in</span> <span class="n">all_vehicles</span><span class="p">:</span> <span class="c1"># line 2, separator</span>
<span class="n">print_fixed</span><span class="p">(</span><span class="s2">"-"</span><span class="o">*</span><span class="nb">len</span><span class="p">(</span><span class="n">vehicle</span><span class="o">.</span><span class="n">id</span><span class="p">))</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">""</span><span class="p">)</span>
<span class="k">for</span> <span class="n">record</span> <span class="ow">in</span> <span class="n">conn_info_all</span><span class="p">:</span> <span class="c1"># line 3..., connection info</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">record</span><span class="p">)</span><span class="o">></span><span class="n">max_record</span><span class="p">:</span>
<span class="n">max_record</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">record</span><span class="p">)</span>
<span class="k">for</span> <span class="n">idx</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="n">max_record</span><span class="p">):</span>
<span class="k">for</span> <span class="n">vnode</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="nb">len</span><span class="p">(</span><span class="n">conn_info_all</span><span class="p">)):</span>
<span class="k">if</span> <span class="n">idx</span><span class="o"><</span><span class="nb">len</span><span class="p">(</span><span class="n">conn_info_all</span><span class="p">[</span><span class="n">vnode</span><span class="p">]):</span>
<span class="n">print_fixed</span><span class="p">(</span><span class="s2">"</span><span class="si">%s</span><span class="s2">=</span><span class="si">%1.2f</span><span class="s2">"</span><span class="o">%</span><span class="p">(</span><span class="n">conn_info_all</span><span class="p">[</span><span class="n">vnode</span><span class="p">][</span><span class="n">idx</span><span class="p">][</span><span class="mi">0</span><span class="p">],</span>
<span class="n">conn_info_all</span><span class="p">[</span><span class="n">vnode</span><span class="p">][</span><span class="n">idx</span><span class="p">][</span><span class="mi">1</span><span class="p">]))</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">print_fixed</span><span class="p">(</span><span class="s2">" "</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">""</span><span class="p">)</span>
<span class="k">for</span> <span class="n">vehicle</span> <span class="ow">in</span> <span class="n">all_vehicles</span><span class="p">:</span> <span class="c1"># 2nd last line, separator</span>
<span class="n">print_fixed</span><span class="p">(</span><span class="s2">"-"</span><span class="o">*</span><span class="nb">len</span><span class="p">(</span><span class="n">vehicle</span><span class="o">.</span><span class="n">id</span><span class="p">))</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">""</span><span class="p">)</span>
<span class="k">for</span> <span class="n">average</span> <span class="ow">in</span> <span class="n">average_all</span><span class="p">:</span> <span class="c1"># last line, average values</span>
<span class="n">print_fixed</span><span class="p">(</span><span class="s2">"Mean=</span><span class="si">%1.2f</span><span class="s2">"</span><span class="o">%</span><span class="n">average</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">""</span><span class="p">)</span>
<span class="c1">####################################################################</span>
<span class="c1">## main</span>
<span class="c1">####################################################################</span>
<span class="k">if</span> <span class="vm">__name__</span> <span class="o">==</span> <span class="s2">"__main__"</span><span class="p">:</span>
<span class="c1">## command line parameters</span>
<span class="n">parser</span><span class="p">:</span> <span class="n">ArgumentParser</span> <span class="o">=</span> <span class="n">argparse</span><span class="o">.</span><span class="n">ArgumentParser</span><span class="p">()</span>
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">"--nodisplay"</span><span class="p">,</span> <span class="n">help</span><span class="o">=</span><span class="s2">"Run in no GUI mode"</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s2">"store_true"</span><span class="p">)</span>
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">"--step"</span><span class="p">,</span> <span class="n">help</span><span class="o">=</span><span class="s2">"Mobility step time (in sec)"</span><span class="p">,</span> <span class="nb">type</span><span class="o">=</span><span class="nb">int</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="mf">0.1</span><span class="p">)</span>
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">"--speed"</span><span class="p">,</span> <span class="n">help</span><span class="o">=</span><span class="s2">"Animation playback speed (x times)"</span><span class="p">,</span> <span class="nb">type</span><span class="o">=</span><span class="nb">float</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="mf">1.0</span><span class="p">)</span>
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">"--duration"</span><span class="p">,</span> <span class="n">help</span><span class="o">=</span><span class="s2">"Simulation duration (in sec), -1 for non-stop"</span><span class="p">,</span> <span class="nb">type</span><span class="o">=</span><span class="nb">int</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="mf">10.0</span><span class="p">)</span>
<span class="n">args</span><span class="p">:</span> <span class="n">Namespace</span> <span class="o">=</span> <span class="n">parser</span><span class="o">.</span><span class="n">parse_args</span><span class="p">()</span>
<span class="c1">## welcome info</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">"A Simple VANET Environment. Press [^C] to quit"</span><span class="p">)</span>
<span class="k">if</span> <span class="n">args</span><span class="o">.</span><span class="n">nodisplay</span><span class="p">:</span> <span class="nb">print</span><span class="p">(</span><span class="s2">"- simulation will run without animation"</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span> <span class="nb">print</span><span class="p">(</span><span class="s2">"- animation will playback at x</span><span class="si">%1.2f</span><span class="s2"> speed"</span><span class="o">%</span><span class="n">args</span><span class="o">.</span><span class="n">speed</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">"- vehicles move a step every </span><span class="si">%1.2f</span><span class="s2"> s in simulation"</span><span class="o">%</span><span class="n">args</span><span class="o">.</span><span class="n">step</span><span class="p">)</span>
<span class="k">if</span> <span class="n">args</span><span class="o">.</span><span class="n">duration</span><span class="o">></span><span class="mi">0</span><span class="p">:</span> <span class="nb">print</span><span class="p">(</span><span class="s2">"- simulation will stop at </span><span class="si">%1.2f</span><span class="s2"> s"</span><span class="o">%</span><span class="n">args</span><span class="o">.</span><span class="n">duration</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span> <span class="nb">print</span><span class="p">(</span><span class="s2">"- simulation will run non-stop"</span><span class="p">)</span>
<span class="c1">## create, setup and run the simulation</span>
<span class="c1">## note that to run a simulation, we need to create a 'scenario'</span>
<span class="n">run_flag</span> <span class="o">=</span> <span class="kc">True</span>
<span class="k">while</span> <span class="n">run_flag</span><span class="p">:</span>
<span class="n">sim</span> <span class="o">=</span> <span class="n">World</span><span class="p">()</span>
<span class="n">sim</span><span class="o">.</span><span class="n">config</span><span class="p">(</span><span class="n">sim_stop</span> <span class="o">=</span> <span class="n">args</span><span class="o">.</span><span class="n">duration</span><span class="p">,</span>
<span class="n">sim_step</span> <span class="o">=</span> <span class="n">args</span><span class="o">.</span><span class="n">step</span><span class="p">,</span>
<span class="n">sim_speed</span> <span class="o">=</span> <span class="n">args</span><span class="o">.</span><span class="n">speed</span><span class="p">,</span>
<span class="n">display_option</span> <span class="o">=</span> <span class="ow">not</span> <span class="n">args</span><span class="o">.</span><span class="n">nodisplay</span><span class="p">,</span>
<span class="n">scenario</span> <span class="o">=</span> <span class="n">MyScenario</span><span class="p">(</span><span class="n">sim</span><span class="p">))</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">"</span><span class="se">\n</span><span class="s2">Running PyMoSim version v</span><span class="si">%d</span><span class="s2">.</span><span class="si">%d</span><span class="s2">.</span><span class="si">%d</span><span class="s2">"</span><span class="o">%</span><span class="n">sim</span><span class="o">.</span><span class="n">version</span><span class="p">())</span>
<span class="n">run_flag</span> <span class="o">=</span> <span class="n">sim</span><span class="o">.</span><span class="n">run</span><span class="p">()</span>
</pre></div>
</div>
</details></div>
<div class="section" id="module-example3">
<span id="example-3"></span><h2>Example 3<a class="headerlink" href="#module-example3" title="Permalink to this headline">¶</a></h2>
<p>This is an example which demonstrates a cluster of mmWave BSs serving vehicles
in a highway (M26) scenario. The background is a static image of M26 highway,
and the mobility of the vehicles is carefully designed so that they appear
moving on the highway.
The simulation run continuously. Our design and assumptions are:</p>
<ul class="simple">
<li><p>Vehicle Centric: Vehicle will send a hello beacon message to collect signal quality
from all BS sectors, and then choose a sector to assiciate.</p></li>
<li><p>Strongest SNR: When choosing a BS to associate, the vehicle always pick the one
with the highest signal quality (i.e. strongest SNR).</p></li>
<li><p>Simultaneous beams: A BS may have multiple radio heads (RHs), each RH radiates
a beam on a sector. The BS can use all beams at the same time, each beam can serve
a vehicle. If, say, the BS has 3 beams, and the condition is right, the BS can turn
all beams active to serve 3 different vehicles at the same time.</p></li>
<li><p>Interference: If a vehicle is simultaneously covered by two active beams,
interference occurs, and the transmission during that simulation time step is
considered unsuccessful. We assume that the vehicle remains associated with the
BS, but the transmission rate for that time step is zero.</p></li>
<li><p>Beam and channel model: There are two options in this example.</p>
<ul>
<li><p>Option 1: Vehicles use omni-directional ideal Disc model, BSs use 6 ideal sectors.
All 6 sectors combined give a perfect circle coverage. This is the default option.</p></li>
<li><p>Option 2: Vehicles use omni-directional Disc model, BSs use 28GHz mmWave beamforming
to create 6 sectors.</p></li>
</ul>
</li>
</ul>
<img alt="_images/example3.gif" src="_images/example3.gif" />
<details class="summary-show-source-code">
<summary>Show source code</summary><div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="sd">'''</span>
<span class="sd">This is an example which demonstrates a cluster of mmWave BSs serving vehicles </span>
<span class="sd">in a highway (M26) scenario. The background is a static image of M26 highway, </span>
<span class="sd">and the mobility of the vehicles is carefully designed so that they appear</span>
<span class="sd">moving on the highway. </span>
<span class="sd">The simulation run continuously. Our design and assumptions are:</span>
<span class="sd">- Vehicle Centric: Vehicle will send a hello beacon message to collect signal quality </span>
<span class="sd"> from all BS sectors, and then choose a sector to assiciate.</span>
<span class="sd">- Strongest SNR: When choosing a BS to associate, the vehicle always pick the one</span>
<span class="sd"> with the highest signal quality (i.e. strongest SNR).</span>
<span class="sd">- Simultaneous beams: A BS may have multiple radio heads (RHs), each RH radiates </span>
<span class="sd"> a beam on a sector. The BS can use all beams at the same time, each beam can serve </span>
<span class="sd"> a vehicle. If, say, the BS has 3 beams, and the condition is right, the BS can turn </span>
<span class="sd"> all beams active to serve 3 different vehicles at the same time.</span>
<span class="sd">- Interference: If a vehicle is simultaneously covered by two active beams,</span>
<span class="sd"> interference occurs, and the transmission during that simulation time step is </span>
<span class="sd"> considered unsuccessful. We assume that the vehicle remains associated with the</span>
<span class="sd"> BS, but the transmission rate for that time step is zero.</span>
<span class="sd">- Beam and channel model: There are two options in this example. </span>
<span class="sd"> - Option 1: Vehicles use omni-directional ideal Disc model, BSs use 6 ideal sectors. </span>
<span class="sd"> All 6 sectors combined give a perfect circle coverage. This is the default option.</span>
<span class="sd"> - Option 2: Vehicles use omni-directional Disc model, BSs use 28GHz mmWave beamforming </span>
<span class="sd"> to create 6 sectors.</span>
<span class="sd">'''</span>
<span class="kn">import</span> <span class="nn">wx</span>
<span class="kn">import</span> <span class="nn">operator</span>
<span class="kn">import</span> <span class="nn">argparse</span>
<span class="kn">import</span> <span class="nn">random</span>
<span class="kn">import</span> <span class="nn">math</span>
<span class="kn">from</span> <span class="nn">argparse</span> <span class="kn">import</span> <span class="n">Namespace</span><span class="p">,</span> <span class="n">ArgumentParser</span>
<span class="kn">from</span> <span class="nn">sim</span> <span class="kn">import</span> <span class="n">World</span><span class="p">,</span> <span class="n">BaseScenario</span><span class="p">,</span> <span class="n">Event</span><span class="p">,</span> <span class="n">ScreenXY</span> <span class="k">as</span> <span class="n">XY</span>
<span class="kn">from</span> <span class="nn">node</span> <span class="kn">import</span> <span class="n">BaseNode</span><span class="p">,</span> <span class="n">NodeType</span><span class="p">,</span> <span class="n">Stationary</span><span class="p">,</span> <span class="n">StaticPath</span>
<span class="kn">from</span> <span class="nn">comm</span> <span class="kn">import</span> <span class="n">Transceiver</span><span class="p">,</span> <span class="n">TransceiverDir</span><span class="p">,</span> <span class="n">DiscModel</span>
<span class="c1">## for mmWave transmission, we need the following:</span>
<span class="kn">from</span> <span class="nn">comm.mmwave28</span> <span class="kn">import</span> <span class="n">Channel28GHz</span><span class="p">,</span> <span class="n">Transceiver28GHz</span><span class="p">,</span> <span class="n">Transceiver28GHzOmni</span>
<span class="c1">## pick option 1 or option 2</span>
<span class="k">class</span> <span class="nc">GlobalVariable</span><span class="p">:</span> <span class="k">pass</span>
<span class="n">global_var</span> <span class="o">=</span> <span class="n">GlobalVariable</span><span class="p">()</span>
<span class="n">global_var</span><span class="o">.</span><span class="n">option</span> <span class="o">=</span> <span class="mi">1</span> <span class="c1"># option 1: ideal disc channel model</span>
<span class="c1">#global_var.option = 2 # option 2: mmWave beamforming model</span>
<span class="c1">####################################################################</span>
<span class="c1">## Helper</span>
<span class="c1">####################################################################</span>
<span class="k">class</span> <span class="nc">DebugPrint</span><span class="p">:</span>
<span class="k">def</span> <span class="nf">print</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kw</span><span class="p">):</span>
<span class="nb">print</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kw</span><span class="p">)</span> <span class="c1"># comment this line out to disable debug printing</span>
<span class="k">pass</span>
<span class="c1">####################################################################</span>
<span class="c1">## Nodes</span>
<span class="c1">####################################################################</span>
<span class="k">class</span> <span class="nc">MySector</span><span class="p">(</span><span class="n">BaseNode</span><span class="p">):</span>
<span class="sd">'''</span>
<span class="sd"> MySector: This is a base station in the VANET sim world implementing</span>
<span class="sd"> ideal sector radiation (option 1) or mmWave beamforming (option 2)</span>
<span class="sd"> '''</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">simworld</span><span class="p">,</span> <span class="nb">id</span><span class="p">,</span> <span class="n">loc</span><span class="p">,</span> <span class="n">freq</span><span class="p">,</span> <span class="n">channel</span><span class="p">,</span> <span class="n">sector_width</span><span class="p">,</span> <span class="n">sector_dir</span><span class="p">):</span>
<span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="n">simworld</span><span class="p">,</span> <span class="nb">id</span><span class="p">,</span> <span class="n">node_type</span><span class="o">=</span><span class="n">NodeType</span><span class="o">.</span><span class="n">BaseStation</span><span class="p">(</span><span class="bp">self</span><span class="p">))</span>
<span class="c1">## create transceiver</span>
<span class="k">if</span> <span class="n">global_var</span><span class="o">.</span><span class="n">option</span><span class="o">==</span><span class="mi">1</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">transceiver</span> <span class="o">=</span> <span class="n">TransceiverDir</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">freq</span><span class="p">,</span><span class="n">channel</span><span class="p">,</span><span class="n">sector_width</span><span class="p">,</span><span class="n">sector_dir</span><span class="p">)</span>
<span class="k">elif</span> <span class="n">global_var</span><span class="o">.</span><span class="n">option</span><span class="o">==</span><span class="mi">2</span><span class="p">:</span>
<span class="c1">## convert sector_width to beam_3dB</span>
<span class="c1"># for 6 sectors, sector_width=60. Based on 3GPP, beam_3dB = 35 </span>
<span class="c1"># for 3 sectors, sector_width=120. Based on 3GPP, beam_3dB = 70 </span>
<span class="c1"># so, beam_3dB = sector_width * 35/60 degree (to convert to rad)</span>
<span class="n">beam_3dB_rad</span> <span class="o">=</span> <span class="n">sector_width</span> <span class="o">*</span> <span class="mi">35</span><span class="o">/</span><span class="mi">60</span> <span class="o">*</span> <span class="n">math</span><span class="o">.</span><span class="n">pi</span><span class="o">/</span><span class="mi">180</span>
<span class="c1">## setup the transceiver to create coverage range around 80</span>
<span class="bp">self</span><span class="o">.</span><span class="n">transceiver</span> <span class="o">=</span> <span class="n">Transceiver28GHz</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">freq</span><span class="p">,</span> <span class="n">channel</span><span class="p">,</span>
<span class="n">tx_power</span><span class="o">=</span><span class="mi">20</span><span class="p">,</span> <span class="c1"># dBm</span>
<span class="n">gain_tx</span><span class="o">=</span><span class="mi">2</span><span class="p">,</span> <span class="c1"># dB</span>
<span class="n">beam_3dB</span><span class="o">=</span><span class="n">beam_3dB_rad</span><span class="p">,</span>
<span class="n">pointing_dir</span><span class="o">=</span><span class="n">sector_dir</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">serving_node</span> <span class="o">=</span> <span class="kc">None</span>
<span class="c1">## setup the sector</span>
<span class="bp">self</span><span class="o">.</span><span class="n">set_transceiver</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">transceiver</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">set_mobility</span><span class="p">(</span><span class="n">Stationary</span><span class="p">(</span><span class="n">loc</span><span class="p">))</span>
<span class="c1">## show the coverage of this sector</span>
<span class="k">def</span> <span class="nf">show_coverage</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">clear_drawing</span><span class="p">()</span> <span class="c1"># this is persistent drawing, so need to clear the all first</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">serving_node</span><span class="o">!=</span><span class="kc">None</span><span class="p">:</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">transceiver</span><span class="o">.</span><span class="n">get_property</span><span class="p">(</span><span class="s2">"type"</span><span class="p">)</span><span class="o">==</span><span class="s2">"omni"</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">draw_circle</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">transceiver</span><span class="o">.</span><span class="n">get_property</span><span class="p">(</span><span class="s2">"radius"</span><span class="p">))</span>
<span class="k">elif</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">transceiver</span><span class="o">.</span><span class="n">get_property</span><span class="p">(</span><span class="s2">"type"</span><span class="p">)</span><span class="o">==</span><span class="s2">"directional"</span>
<span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">transceiver</span><span class="o">.</span><span class="n">get_property</span><span class="p">(</span><span class="s2">"type"</span><span class="p">)</span><span class="o">==</span><span class="s2">"mmWaveBeam"</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">draw_sector</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">transceiver</span><span class="o">.</span><span class="n">get_property</span><span class="p">(</span><span class="s2">"radius"</span><span class="p">),</span>
<span class="bp">self</span><span class="o">.</span><span class="n">transceiver</span><span class="o">.</span><span class="n">get_property</span><span class="p">(</span><span class="s2">"azimuth"</span><span class="p">),</span>
<span class="bp">self</span><span class="o">.</span><span class="n">transceiver</span><span class="o">.</span><span class="n">get_property</span><span class="p">(</span><span class="s2">"beam width"</span><span class="p">))</span>
<span class="k">class</span> <span class="nc">MyVehicle</span><span class="p">(</span><span class="n">BaseNode</span><span class="p">):</span>
<span class="sd">'''</span>
<span class="sd"> MyVehicle: This is a transmitting node in the VANET sim world</span>
<span class="sd"> '''</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">simworld</span><span class="p">,</span> <span class="nb">id</span><span class="p">,</span> <span class="n">freq</span><span class="p">,</span> <span class="n">channel</span><span class="p">):</span>
<span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="n">simworld</span><span class="p">,</span> <span class="nb">id</span><span class="p">,</span> <span class="n">node_type</span><span class="o">=</span><span class="n">NodeType</span><span class="o">.</span><span class="n">Vehicle</span><span class="p">(</span><span class="bp">self</span><span class="p">))</span>
<span class="c1">## create transceiver</span>
<span class="k">if</span> <span class="n">global_var</span><span class="o">.</span><span class="n">option</span><span class="o">==</span><span class="mi">1</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">transceiver</span> <span class="o">=</span> <span class="n">Transceiver</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">freq</span><span class="p">,</span><span class="n">channel</span><span class="p">)</span>
<span class="k">elif</span> <span class="n">global_var</span><span class="o">.</span><span class="n">option</span><span class="o">==</span><span class="mi">2</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">transceiver</span> <span class="o">=</span> <span class="n">Transceiver28GHzOmni</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">freq</span><span class="p">,</span> <span class="n">channel</span><span class="p">,</span>
<span class="n">tx_power</span><span class="o">=</span><span class="mi">20</span><span class="p">,</span> <span class="c1"># dBm</span>
<span class="n">gain_tx</span><span class="o">=</span><span class="mi">2</span><span class="p">)</span> <span class="c1"># dB</span>
<span class="bp">self</span><span class="o">.</span><span class="n">set_transceiver</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">transceiver</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">associated_sector</span> <span class="o">=</span> <span class="kc">None</span>
<span class="bp">self</span><span class="o">.</span><span class="n">has_interference</span> <span class="o">=</span> <span class="kc">False</span>
<span class="bp">self</span><span class="o">.</span><span class="n">curr_conn</span> <span class="o">=</span> <span class="mi">0</span>
<span class="bp">self</span><span class="o">.</span><span class="n">connectivity</span> <span class="o">=</span> <span class="p">[</span> <span class="p">[</span><span class="kc">None</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">]</span> <span class="p">]</span> <span class="c1"># list of connections: [sector, start_time, end_time]</span>
<span class="k">def</span> <span class="nf">associate_sector</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">sector</span><span class="p">,</span><span class="n">time</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">associated_sector</span> <span class="o">=</span> <span class="n">sector</span>
<span class="n">sector</span><span class="o">.</span><span class="n">serving_node</span> <span class="o">=</span> <span class="bp">self</span>
<span class="bp">self</span><span class="o">.</span><span class="n">connectivity</span><span class="o">.</span><span class="n">append</span><span class="p">([</span><span class="n">sector</span><span class="p">,</span><span class="n">time</span><span class="p">,</span><span class="mi">0</span><span class="p">])</span>
<span class="bp">self</span><span class="o">.</span><span class="n">curr_conn</span> <span class="o">+=</span> <span class="mi">1</span>
<span class="k">def</span> <span class="nf">lost_sector</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">time</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">associated_sector</span><span class="o">.</span><span class="n">serving_node</span> <span class="o">=</span> <span class="kc">None</span>
<span class="bp">self</span><span class="o">.</span><span class="n">associated_sector</span> <span class="o">=</span> <span class="kc">None</span>
<span class="bp">self</span><span class="o">.</span><span class="n">connectivity</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">curr_conn</span><span class="p">][</span><span class="mi">2</span><span class="p">]</span> <span class="o">=</span> <span class="n">time</span>
<span class="c1">## draw a line to the associated sector, if any</span>
<span class="k">def</span> <span class="nf">show_connection</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">clear_drawing</span><span class="p">()</span> <span class="c1"># this is persistent drawing, so need to clear the all first</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">associated_sector</span><span class="o">!=</span><span class="kc">None</span><span class="p">:</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">has_interference</span><span class="p">:</span>
<span class="c1"># vehicle with a sector & has interference</span>
<span class="bp">self</span><span class="o">.</span><span class="n">set_color</span><span class="p">(</span><span class="n">wx</span><span class="o">.</span><span class="n">BLACK</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">draw_line</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">associated_sector</span><span class="p">,</span><span class="n">pen</span> <span class="o">=</span> <span class="n">wx</span><span class="o">.</span><span class="n">Pen</span><span class="p">(</span><span class="n">wx</span><span class="o">.</span><span class="n">BLACK</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="n">style</span><span class="o">=</span><span class="n">wx</span><span class="o">.</span><span class="n">PENSTYLE_SHORT_DASH</span><span class="p">))</span>
<span class="k">else</span><span class="p">:</span>
<span class="c1"># vehicle with a sector & has no interference</span>
<span class="bp">self</span><span class="o">.</span><span class="n">draw_line</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">associated_sector</span><span class="p">,</span><span class="n">pen</span> <span class="o">=</span> <span class="n">wx</span><span class="o">.</span><span class="n">Pen</span><span class="p">(</span><span class="n">wx</span><span class="o">.</span><span class="n">BLUE</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="n">style</span><span class="o">=</span><span class="n">wx</span><span class="o">.</span><span class="n">PENSTYLE_SOLID</span><span class="p">))</span>
<span class="bp">self</span><span class="o">.</span><span class="n">set_color</span><span class="p">(</span><span class="n">wx</span><span class="o">.</span><span class="n">BLUE</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="c1"># vehicle without a sector association</span>
<span class="bp">self</span><span class="o">.</span><span class="n">set_color</span><span class="p">(</span><span class="n">wx</span><span class="o">.</span><span class="n">RED</span><span class="p">)</span>
<span class="c1">####################################################################</span>
<span class="c1">## Scenario</span>
<span class="c1">####################################################################</span>
<span class="k">class</span> <span class="nc">MyScenario</span><span class="p">(</span><span class="n">BaseScenario</span><span class="p">,</span><span class="n">DebugPrint</span><span class="p">):</span>
<span class="sd">'''</span>
<span class="sd"> MyScenario: This is my scenario</span>
<span class="sd"> '''</span>
<span class="c1">## ------------------------------------------------------------</span>
<span class="c1">## This method will be called before the start of the simulation,</span>
<span class="c1">## build the simulation world here</span>
<span class="k">def</span> <span class="nf">on_create</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">simworld</span><span class="p">)</span> <span class="o">-></span> <span class="nb">bool</span><span class="p">:</span>
<span class="c1">## simulation variables</span>
<span class="bp">self</span><span class="o">.</span><span class="n">simworld</span> <span class="o">=</span> <span class="n">simworld</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">simworld</span><span class="o">.</span><span class="n">is_animation_shown</span><span class="p">():</span>
<span class="n">bitmap</span> <span class="o">=</span> <span class="n">wx</span><span class="o">.</span><span class="n">Bitmap</span><span class="p">()</span>
<span class="k">if</span> <span class="n">bitmap</span><span class="o">.</span><span class="n">LoadFile</span><span class="p">(</span><span class="s2">"M26.png"</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">set_background</span><span class="p">(</span><span class="n">bitmap</span><span class="p">,</span><span class="o">-</span><span class="mi">500</span><span class="p">,</span><span class="mi">0</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">"Error loading bitmap file, no background is applied."</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">set_name</span><span class="p">(</span><span class="s2">"A busy highway (M26)"</span><span class="p">)</span>
<span class="c1">## configure tranceiver property for each BS sector</span>
<span class="n">beam_radius</span> <span class="o">=</span> <span class="mi">80</span>
<span class="n">beam_num</span> <span class="o">=</span> <span class="mi">6</span> <span class="c1"># must be an integer</span>
<span class="n">beam_width</span> <span class="o">=</span> <span class="mi">360</span><span class="o">/</span><span class="n">beam_num</span>
<span class="n">beam_pointing</span> <span class="o">=</span> <span class="mi">0</span> <span class="c1"># 0 means north</span>
<span class="n">sector</span> <span class="o">=</span> <span class="p">{}</span>
<span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="n">beam_num</span><span class="p">):</span>
<span class="n">angle</span> <span class="o">=</span> <span class="n">beam_pointing</span> <span class="o">+</span> <span class="n">i</span><span class="o">*</span><span class="n">beam_width</span>
<span class="k">while</span> <span class="n">angle</span><span class="o">>=</span><span class="mi">360</span><span class="p">:</span> <span class="n">angle</span><span class="o">-=</span><span class="mi">360</span>
<span class="n">sector</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span><span class="s2">"angle"</span><span class="p">:</span><span class="n">angle</span><span class="p">,</span> <span class="s2">"width"</span><span class="p">:</span><span class="n">beam_width</span><span class="p">}</span>
<span class="c1">## create channel for signal propagation model</span>
<span class="n">carrier_freq</span> <span class="o">=</span> <span class="mi">28</span> <span class="c1"># GHz</span>
<span class="n">ch_disc</span> <span class="o">=</span> <span class="n">DiscModel</span><span class="p">(</span><span class="n">beam_radius</span><span class="p">)</span>
<span class="n">ch_28GHz</span> <span class="o">=</span> <span class="n">Channel28GHz</span><span class="p">()</span>
<span class="k">if</span> <span class="n">global_var</span><span class="o">.</span><span class="n">option</span><span class="o">==</span><span class="mi">1</span><span class="p">:</span> <span class="n">channel_model</span> <span class="o">=</span> <span class="n">ch_disc</span>
<span class="k">elif</span> <span class="n">global_var</span><span class="o">.</span><span class="n">option</span><span class="o">==</span><span class="mi">2</span><span class="p">:</span> <span class="n">channel_model</span> <span class="o">=</span> <span class="n">ch_28GHz</span>
<span class="k">else</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">"Error: Wrong option</span><span class="se">\n</span><span class="s2">"</span><span class="p">)</span>
<span class="k">return</span> <span class="kc">False</span>
<span class="c1">## create some nodes on the north and south sides of the highway</span>
<span class="n">bs_locs</span> <span class="o">=</span> <span class="p">[</span><span class="n">XY</span><span class="p">(</span><span class="mi">110</span><span class="p">,</span><span class="mi">260</span><span class="p">),</span><span class="n">XY</span><span class="p">(</span><span class="mi">210</span><span class="p">,</span><span class="mi">260</span><span class="p">),</span><span class="n">XY</span><span class="p">(</span><span class="mi">340</span><span class="p">,</span><span class="mi">260</span><span class="p">)]</span> <span class="c1"># south locations</span>
<span class="n">bs_locs</span> <span class="o">+=</span> <span class="p">[</span><span class="n">XY</span><span class="p">(</span><span class="mi">100</span><span class="p">,</span><span class="mi">180</span><span class="p">),</span><span class="n">XY</span><span class="p">(</span><span class="mi">220</span><span class="p">,</span><span class="mi">180</span><span class="p">),</span><span class="n">XY</span><span class="p">(</span><span class="mi">360</span><span class="p">,</span><span class="mi">180</span><span class="p">)]</span> <span class="c1"># north locations</span>
<span class="bp">self</span><span class="o">.</span><span class="n">bs_nodes</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="nb">len</span><span class="p">(</span><span class="n">bs_locs</span><span class="p">)):</span> <span class="c1"># each BS location</span>
<span class="k">for</span> <span class="n">j</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="nb">len</span><span class="p">(</span><span class="n">sector</span><span class="p">)):</span> <span class="c1"># create sectors for each BS</span>
<span class="n">this_id</span> <span class="o">=</span> <span class="s2">"BS</span><span class="si">%d</span><span class="s2">.</span><span class="si">%d</span><span class="s2">"</span><span class="o">%</span><span class="p">(</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">)</span>
<span class="n">this_node</span> <span class="o">=</span> <span class="n">MySector</span><span class="p">(</span><span class="n">simworld</span><span class="p">,</span> <span class="n">this_id</span><span class="p">,</span> <span class="n">bs_locs</span><span class="p">[</span><span class="n">i</span><span class="p">],</span>
<span class="n">carrier_freq</span><span class="p">,</span> <span class="n">channel_model</span><span class="p">,</span>
<span class="n">sector_width</span><span class="o">=</span><span class="n">sector</span><span class="p">[</span><span class="n">j</span><span class="p">][</span><span class="s2">"width"</span><span class="p">],</span>
<span class="n">sector_dir</span><span class="o">=</span><span class="n">sector</span><span class="p">[</span><span class="n">j</span><span class="p">][</span><span class="s2">"angle"</span><span class="p">])</span>
<span class="bp">self</span><span class="o">.</span><span class="n">bs_nodes</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">this_node</span><span class="p">)</span>
<span class="c1">## setup vehicle info</span>
<span class="bp">self</span><span class="o">.</span><span class="n">vehicle_info</span> <span class="o">=</span> <span class="p">{}</span> <span class="c1"># list of [start location, end location]</span>
<span class="n">y</span> <span class="o">=</span> <span class="mi">205</span><span class="p">;</span> <span class="n">space</span><span class="o">=</span><span class="mi">5</span>
<span class="bp">self</span><span class="o">.</span><span class="n">vehicle_info</span><span class="p">[</span><span class="s2">"car1"</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="n">XY</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="n">y</span><span class="p">),</span> <span class="n">XY</span><span class="p">(</span><span class="mi">480</span><span class="p">,</span><span class="n">y</span><span class="p">)];</span> <span class="n">y</span><span class="o">+=</span><span class="n">space</span>
<span class="bp">self</span><span class="o">.</span><span class="n">vehicle_info</span><span class="p">[</span><span class="s2">"car2"</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="n">XY</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="n">y</span><span class="p">),</span> <span class="n">XY</span><span class="p">(</span><span class="mi">480</span><span class="p">,</span><span class="n">y</span><span class="p">)];</span> <span class="n">y</span><span class="o">+=</span><span class="n">space</span>
<span class="bp">self</span><span class="o">.</span><span class="n">vehicle_info</span><span class="p">[</span><span class="s2">"car3"</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="n">XY</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="n">y</span><span class="p">),</span> <span class="n">XY</span><span class="p">(</span><span class="mi">480</span><span class="p">,</span><span class="n">y</span><span class="p">)];</span> <span class="n">y</span><span class="o">+=</span><span class="n">space</span><span class="o">+</span><span class="mi">3</span>
<span class="bp">self</span><span class="o">.</span><span class="n">vehicle_info</span><span class="p">[</span><span class="s2">"car4"</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="n">XY</span><span class="p">(</span><span class="mi">480</span><span class="p">,</span><span class="n">y</span><span class="p">),</span> <span class="n">XY</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="n">y</span><span class="p">)];</span> <span class="n">y</span><span class="o">+=</span><span class="n">space</span>
<span class="bp">self</span><span class="o">.</span><span class="n">vehicle_info</span><span class="p">[</span><span class="s2">"car5"</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="n">XY</span><span class="p">(</span><span class="mi">480</span><span class="p">,</span><span class="n">y</span><span class="p">),</span> <span class="n">XY</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="n">y</span><span class="p">)];</span> <span class="n">y</span><span class="o">+=</span><span class="n">space</span>
<span class="bp">self</span><span class="o">.</span><span class="n">vehicle_info</span><span class="p">[</span><span class="s2">"car6"</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="n">XY</span><span class="p">(</span><span class="mi">480</span><span class="p">,</span><span class="n">y</span><span class="p">),</span> <span class="n">XY</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="n">y</span><span class="p">)];</span> <span class="n">y</span><span class="o">+=</span><span class="n">space</span>
<span class="c1">## create the vehicles on the highway based on above info</span>
<span class="bp">self</span><span class="o">.</span><span class="n">vehicles</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">info</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">vehicle_info</span><span class="p">:</span>
<span class="n">start_loc</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">vehicle_info</span><span class="p">[</span><span class="n">info</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span>
<span class="n">end_loc</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">vehicle_info</span><span class="p">[</span><span class="n">info</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span>
<span class="n">path</span> <span class="o">=</span> <span class="p">[</span> <span class="p">(</span><span class="n">random</span><span class="o">.</span><span class="n">uniform</span><span class="p">(</span><span class="mi">30</span><span class="p">,</span><span class="mi">60</span><span class="p">),</span> <span class="n">end_loc</span><span class="p">)</span> <span class="p">]</span>
<span class="n">node</span> <span class="o">=</span> <span class="n">MyVehicle</span><span class="p">(</span><span class="n">simworld</span><span class="p">,</span> <span class="nb">id</span><span class="o">=</span><span class="n">info</span><span class="p">,</span> <span class="n">freq</span><span class="o">=</span><span class="n">carrier_freq</span><span class="p">,</span> <span class="n">channel</span><span class="o">=</span><span class="n">channel_model</span><span class="p">)</span>
<span class="n">node</span><span class="o">.</span><span class="n">set_mobility</span><span class="p">(</span><span class="n">StaticPath</span><span class="p">(</span><span class="n">start_loc</span><span class="o">=</span><span class="n">start_loc</span><span class="p">,</span><span class="n">path</span><span class="o">=</span><span class="n">path</span><span class="p">))</span>
<span class="bp">self</span><span class="o">.</span><span class="n">vehicles</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">node</span><span class="p">)</span>