-
Notifications
You must be signed in to change notification settings - Fork 0
/
sim.scenario.html
622 lines (527 loc) · 38.5 KB
/
sim.scenario.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>sim.scenario module — 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="sim.simsystem module" href="sim.simsystem.html" />
<link rel="prev" title="sim.loc module" href="sim.loc.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="index.html">
<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 current active 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">
<ul class="current nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="sim.direction.html">
sim.direction module
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="sim.drawable.html">
sim.drawable module
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="sim.event.html">
sim.event module
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="sim.frame.html">
sim.frame module
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="sim.loc.html">
sim.loc module
</a>
</li>
<li class="toctree-l1 current active">
<a class="current reference internal" href="#">
sim.scenario module
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="sim.simsystem.html">
sim.simsystem module
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="sim.simulation.html">
sim.simulation module
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="sim.version.html">
sim.version module
</a>
</li>
</ul>
</div>
</nav>
</div>
<div class="d-none d-xl-block col-xl-2 bd-toc">
<div class="toc-item">
<nav id="bd-toc-nav">
</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="module-sim.scenario">
<span id="sim-scenario-module"></span><h1>sim.scenario module<a class="headerlink" href="#module-sim.scenario" title="Permalink to this headline">¶</a></h1>
<p>This module contains <cite>BaseScenario</cite> which is an abstract base class providing
specification to create a scenario. It contains no implementation.
It should be extended to a subclass to describe the actual scenario.</p>
<p><a class="reference internal" href="#sim.scenario.BaseScenario" title="sim.scenario.BaseScenario"><code class="xref py py-class docutils literal notranslate"><span class="pre">sim.scenario.BaseScenario</span></code></a> class is designed to be extended where the
extended subclass instance should act as a container to carry entities for
the simulation.</p>
<p>The subclass should use it to describe how each entity appears
in the world. Reimplement <a class="reference internal" href="#sim.scenario.BaseScenario.on_create" title="sim.scenario.BaseScenario.on_create"><code class="xref py py-meth docutils literal notranslate"><span class="pre">sim.scenario.BaseScenario.on_create()</span></code></a>
method to build a scenario in the world.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<ul class="simple">
<li><p>Created by: CH Foh (2021)</p></li>
</ul>
</div>
<dl class="py class">
<dt id="sim.scenario.BaseScenario">
<em class="property">class </em><code class="sig-prename descclassname">sim.scenario.</code><code class="sig-name descname">BaseScenario</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">simworld</span></em><span class="sig-paren">)</span><a class="headerlink" href="#sim.scenario.BaseScenario" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">abc.ABC</span></code></p>
<p>This is an abstract base class providing
specification to create a scenario. It contains no implementation.
It should be extended to a subclass to describe the actual scenario.</p>
<p>See example1.py to learn how to create a scenario using this
abstract class.</p>
<details class="summary-show-example1-py-source-code">
<summary>Show example1.py source code</summary><div class="highlight-python notranslate"><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>
</div>
</details><p class="rubric">Methods</p>
<table class="longtable table autosummary">
<colgroup>
<col style="width: 10%" />
<col style="width: 90%" />
</colgroup>
<tbody>
<tr class="row-odd"><td><p><a class="reference internal" href="#sim.scenario.BaseScenario.add_button" title="sim.scenario.BaseScenario.add_button"><code class="xref py py-obj docutils literal notranslate"><span class="pre">add_button</span></code></a>(id, label)</p></td>
<td><p>Add a button to the user defined space on the simulation window.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="#sim.scenario.BaseScenario.add_drawable" title="sim.scenario.BaseScenario.add_drawable"><code class="xref py py-obj docutils literal notranslate"><span class="pre">add_drawable</span></code></a>(drawable)</p></td>
<td><p>Use this method to add a persistent drawable on the scenario background.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="#sim.scenario.BaseScenario.change_sim_stop_time" title="sim.scenario.BaseScenario.change_sim_stop_time"><code class="xref py py-obj docutils literal notranslate"><span class="pre">change_sim_stop_time</span></code></a>(new_time)</p></td>
<td><p>Change the simulation stop time to a new stop time.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="#sim.scenario.BaseScenario.get_setting" title="sim.scenario.BaseScenario.get_setting"><code class="xref py py-obj docutils literal notranslate"><span class="pre">get_setting</span></code></a>(setting_str)</p></td>
<td><p>Get the simulation setting.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="#sim.scenario.BaseScenario.has_map" title="sim.scenario.BaseScenario.has_map"><code class="xref py py-obj docutils literal notranslate"><span class="pre">has_map</span></code></a>()</p></td>
<td><p>Check whether this scenario has a valid street map object.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="#sim.scenario.BaseScenario.on_create" title="sim.scenario.BaseScenario.on_create"><code class="xref py py-obj docutils literal notranslate"><span class="pre">on_create</span></code></a>()</p></td>
<td><p>This is an event listener which will be called when the scenario object is being created.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="#sim.scenario.BaseScenario.on_event" title="sim.scenario.BaseScenario.on_event"><code class="xref py py-obj docutils literal notranslate"><span class="pre">on_event</span></code></a>(sim_time, event_obj)</p></td>
<td><p>This is an event listener which will be called when an event occurs.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="#sim.scenario.BaseScenario.remove_drawable" title="sim.scenario.BaseScenario.remove_drawable"><code class="xref py py-obj docutils literal notranslate"><span class="pre">remove_drawable</span></code></a>(drawable)</p></td>
<td><p>Use this method to remove a persistent drawable from the scenario background.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="#sim.scenario.BaseScenario.set_background" title="sim.scenario.BaseScenario.set_background"><code class="xref py py-obj docutils literal notranslate"><span class="pre">set_background</span></code></a>(bitmap[, x, y, zoom])</p></td>
<td><p>Set a background bitmap image for this scenario.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="#sim.scenario.BaseScenario.set_name" title="sim.scenario.BaseScenario.set_name"><code class="xref py py-obj docutils literal notranslate"><span class="pre">set_name</span></code></a>(name)</p></td>
<td><p>Set a name for this scenario to show on the window.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="#sim.scenario.BaseScenario.sim__get_control" title="sim.scenario.BaseScenario.sim__get_control"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sim__get_control</span></code></a>()</p></td>
<td><p>Get the user defined contols.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="#sim.scenario.BaseScenario.use_map" title="sim.scenario.BaseScenario.use_map"><code class="xref py py-obj docutils literal notranslate"><span class="pre">use_map</span></code></a>(map[, x, y, zoom])</p></td>
<td><p>Set a street map info object for this scenario to describe the map.</p></td>
</tr>
</tbody>
</table>
<dl class="py method">
<dt id="sim.scenario.BaseScenario.__init__">
<code class="sig-name descname">__init__</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">simworld</span></em><span class="sig-paren">)</span><a class="headerlink" href="#sim.scenario.BaseScenario.__init__" title="Permalink to this definition">¶</a></dt>
<dd><p>This is the constructor.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><dl class="simple">
<dt><strong>simworld</strong><span class="classifier">sim.simulation.World</span></dt><dd></dd>
<dt><strong>It is the container where this scenario will be put to run.</strong></dt><dd></dd>
</dl>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="sim.scenario.BaseScenario.on_create">
<em class="property">abstract </em><code class="sig-name descname">on_create</code><span class="sig-paren">(</span><span class="sig-paren">)</span> → bool<a class="headerlink" href="#sim.scenario.BaseScenario.on_create" title="Permalink to this definition">¶</a></dt>
<dd><p>This is an event listener which will be called when the scenario
object is being created. The subclass should extend this method
to create the simulation world.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>When creating variables for the subclass, DO NOT use variable names
beginning with two underscores. This might clash with the variable
used internally in the base class.</p>
</div>
<dl class="field-list simple">
<dt class="field-odd">Returns</dt>
<dd class="field-odd"><dl class="simple">
<dt>bool</dt><dd><p>True if the scenario is created successfully, False otherwise.
Returning False will cause the simulation to throw a runtime error.</p>
</dd>
</dl>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="sim.scenario.BaseScenario.on_event">
<em class="property">abstract </em><code class="sig-name descname">on_event</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">sim_time</span></em>, <em class="sig-param"><span class="n">event_obj</span></em><span class="sig-paren">)</span><a class="headerlink" href="#sim.scenario.BaseScenario.on_event" title="Permalink to this definition">¶</a></dt>
<dd><p>This is an event listener which will be called when an event occurs.</p>
<p>The simulation periodically calls this method to allow user to perform
any user simulation for every time step of mobility. In other words,
the simulation continuously progresses a simulation time step, freezes
the time and calls this method.</p>
<p>A subclass must extend this method to perform any necessary user
simulation on the simulation world.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><dl>
<dt><strong>sim_time</strong><span class="classifier">float</span></dt><dd><p>The simulation time that the event happens.</p>
</dd>
<dt><strong>event_object</strong><span class="classifier"><a class="reference internal" href="sim.event.html#sim.event.Event" title="sim.event.Event"><code class="xref py py-class docutils literal notranslate"><span class="pre">sim.event.Event</span></code></a></span></dt><dd><p>The event object describing what has happened. The user should
check the type of the event object and handle the event accordingly.</p>
</dd>
</dl>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="sim.scenario.BaseScenario.add_button">
<code class="sig-name descname">add_button</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">id</span></em>, <em class="sig-param"><span class="n">label</span></em><span class="sig-paren">)</span><a class="headerlink" href="#sim.scenario.BaseScenario.add_button" title="Permalink to this definition">¶</a></dt>
<dd><p>Add a button to the user defined space on the simulation window.
This method should only be called within <cite>on_create()</cite> event. After
the event, calling to this method will have no effect.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><dl class="simple">
<dt><strong>id</strong><span class="classifier">int</span></dt><dd><p>The id of the button. When this button is clicked, an event
will be triggered and user simulation will be called to pass
the button clicked event carrying this id.</p>
</dd>
<dt><strong>label :</strong></dt><dd><p>The text to show on the button.</p>
</dd>
</dl>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="sim.scenario.BaseScenario.sim__get_control">
<code class="sig-name descname">sim__get_control</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#sim.scenario.BaseScenario.sim__get_control" title="Permalink to this definition">¶</a></dt>
<dd><p>Get the user defined contols.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>User simulation should not use this method. It is used for the
simulation engine to retrieve user defined controls after the
scenario setup.</p>
</div>
</dd></dl>
<dl class="py method">
<dt id="sim.scenario.BaseScenario.set_background">
<code class="sig-name descname">set_background</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">bitmap</span></em>, <em class="sig-param"><span class="n">x</span><span class="o">=</span><span class="default_value">0</span></em>, <em class="sig-param"><span class="n">y</span><span class="o">=</span><span class="default_value">0</span></em>, <em class="sig-param"><span class="n">zoom</span><span class="o">=</span><span class="default_value">1.0</span></em><span class="sig-paren">)</span><a class="headerlink" href="#sim.scenario.BaseScenario.set_background" title="Permalink to this definition">¶</a></dt>
<dd><p>Set a background bitmap image for this scenario. The background
image will be placed on the window at (x,y) position. That is, the
left-top position of the image is placed at (x,y) position of the
window. This method should be used when the scenario is not using
a map. If the scenario uses a map, the associated map image will
be used as the background, and there is no need to provide another
background image.</p>
<p>The input is an instance of <cite>wx.Bitmap</cite>. To load a bitmap from a file,
simply use <cite>wx.Bitmap(file_name)</cite>.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><dl class="simple">
<dt><strong>bitmap</strong><span class="classifier">wx.Bitmap</span></dt><dd><p>The bitmap to use for the scenario.</p>
</dd>
<dt><strong>x,y</strong><span class="classifier">integer, default is (0,0)</span></dt><dd><p>The position to show the bitmap on the window. The position (x,y)
will be the left-top position of the image.</p>
</dd>
<dt><strong>zoom</strong><span class="classifier">float, default is 1.0 which is original scale</span></dt><dd><p>The zoom scale of the image to view.</p>
</dd>
</dl>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="sim.scenario.BaseScenario.set_name">
<code class="sig-name descname">set_name</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">name</span><span class="p">:</span> <span class="n">str</span></em><span class="sig-paren">)</span><a class="headerlink" href="#sim.scenario.BaseScenario.set_name" title="Permalink to this definition">¶</a></dt>
<dd><p>Set a name for this scenario to show on the window.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><dl class="simple">
<dt><strong>name</strong><span class="classifier">str</span></dt><dd><p>The name for this scenario.</p>
</dd>
</dl>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="sim.scenario.BaseScenario.change_sim_stop_time">
<code class="sig-name descname">change_sim_stop_time</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">new_time</span></em><span class="sig-paren">)</span><a class="headerlink" href="#sim.scenario.BaseScenario.change_sim_stop_time" title="Permalink to this definition">¶</a></dt>
<dd><p>Change the simulation stop time to a new stop time. The input must be
a future simulation time, otherwise the new setting will not apply.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><dl class="simple">
<dt><strong>new_time</strong><span class="classifier">float</span></dt><dd><p>The new simulation stop time, which must be a future simulation time.</p>
</dd>
</dl>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="sim.scenario.BaseScenario.get_setting">
<code class="sig-name descname">get_setting</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">setting_str</span><span class="p">:</span> <span class="n">str</span></em><span class="sig-paren">)</span><a class="headerlink" href="#sim.scenario.BaseScenario.get_setting" title="Permalink to this definition">¶</a></dt>
<dd><p>Get the simulation setting. This method throws a warning if <cite>setting_str</cite> is
unrecognized.</p>
<p>The following is a list of available settings to get:</p>
<ul class="simple">
<li><p>“name”: the scenario name.</p></li>
<li><p>“sim step”: the simulation mobility time step.</p></li>
<li><p>“sim speed”: the current simulation speed.</p></li>
<li><p>“stop time”: the stop time of the simulation.</p></li>
<li><p>“background”: the background image assigned to this scenario. A tuple
(wx.Bitmap, int, int) is returned specifying the bitmap used and its (x,y)
screen position on the viewing window.</p></li>
<li><p>“simworld”: the instance of <cite>sim.sulation.World</cite> which hosts this scenario.</p></li>
<li><p>“map”: the map object encapsulating the map information. None if no street map is
assigned to this scenario.</p></li>
<li><p>“drawables”: a list of drawable instances added to the scenario.</p></li>
</ul>
<dl class="field-list simple">
<dt class="field-odd">Returns</dt>
<dd class="field-odd"><dl class="simple">
<dt>any</dt><dd><p>The method returns the requested setting, or <cite>None</cite> if the input
requested setting string is not recognized.</p>
</dd>
</dl>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="sim.scenario.BaseScenario.use_map">
<code class="sig-name descname">use_map</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">map</span></em>, <em class="sig-param"><span class="n">x</span><span class="o">=</span><span class="default_value">0</span></em>, <em class="sig-param"><span class="n">y</span><span class="o">=</span><span class="default_value">0</span></em>, <em class="sig-param"><span class="n">zoom</span><span class="o">=</span><span class="default_value">1.0</span></em><span class="sig-paren">)</span><a class="headerlink" href="#sim.scenario.BaseScenario.use_map" title="Permalink to this definition">¶</a></dt>
<dd><p>Set a street map info object for this scenario to describe the map.</p>
<p>The input <cite>map</cite> is an object of <a class="reference internal" href="map.mapinfo.html#map.mapinfo.MapInfo" title="map.mapinfo.MapInfo"><code class="xref py py-class docutils literal notranslate"><span class="pre">map.mapinfo.MapInfo</span></code></a>. The object
contains graph information describing a map and user defined pins. The object
also contains the image of the map. Once used, the scenario will apply
the map image as the background of the simulation.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>The map object must be ready for use. This method will assume the
map object is ready. It will access to the map information without
further check, and throw errors when accessing a non-ready map.
Check for map readiness before using this method to avoid run-time
error.</p>
</div>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><dl>
<dt><strong>map</strong><span class="classifier"><a class="reference internal" href="map.mapinfo.html#map.mapinfo.MapInfo" title="map.mapinfo.MapInfo"><code class="xref py py-class docutils literal notranslate"><span class="pre">map.mapinfo.MapInfo</span></code></a></span></dt><dd><p>The object encapsulating the map information.</p>
</dd>
<dt><strong>x,y</strong><span class="classifier">integer, default is (0,0)</span></dt><dd><p>The map image position to show on the window. The position (x,y)
on the map will be shifted to the left-top position of the window.</p>
</dd>
<dt><strong>zoom</strong><span class="classifier">float, default is 1.0 which is original scale</span></dt><dd><p>The zoom scale of the map to view.</p>
</dd>
</dl>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="sim.scenario.BaseScenario.has_map">
<code class="sig-name descname">has_map</code><span class="sig-paren">(</span><span class="sig-paren">)</span> → bool<a class="headerlink" href="#sim.scenario.BaseScenario.has_map" title="Permalink to this definition">¶</a></dt>
<dd><p>Check whether this scenario has a valid street map object.</p>
</dd></dl>
<dl class="py method">
<dt id="sim.scenario.BaseScenario.add_drawable">
<code class="sig-name descname">add_drawable</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">drawable</span></em><span class="sig-paren">)</span><a class="headerlink" href="#sim.scenario.BaseScenario.add_drawable" title="Permalink to this definition">¶</a></dt>
<dd><p>Use this method to add a persistent drawable on the scenario background.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><dl>
<dt><strong>drawable</strong><span class="classifier"><a class="reference internal" href="sim.drawable.html#sim.drawable.Drawable" title="sim.drawable.Drawable"><code class="xref py py-class docutils literal notranslate"><span class="pre">sim.drawable.Drawable</span></code></a></span></dt><dd><p>The drawable instance to put on the background.</p>
</dd>
</dl>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="sim.scenario.BaseScenario.remove_drawable">
<code class="sig-name descname">remove_drawable</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">drawable</span></em><span class="sig-paren">)</span><a class="headerlink" href="#sim.scenario.BaseScenario.remove_drawable" title="Permalink to this definition">¶</a></dt>
<dd><p>Use this method to remove a persistent drawable from the scenario
background.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><dl>
<dt><strong>drawable</strong><span class="classifier"><a class="reference internal" href="sim.drawable.html#sim.drawable.Drawable" title="sim.drawable.Drawable"><code class="xref py py-class docutils literal notranslate"><span class="pre">sim.drawable.Drawable</span></code></a></span></dt><dd><p>The drawable instance to be removed. If the drawable instance is not
earlier added, nothing will happen.</p>
</dd>
</dl>
</dd>
</dl>
</dd></dl>
</dd></dl>
</div>
</div>
</main>
</div>
</div>
<script src="_static/js/index.1c5a1a01449ed65a7b51.js"></script>
<footer class="footer mt-5 mt-md-0">
<div class="container">
<div class="footer-item">
<p class="copyright">
© Copyright 2021, cfoh.<br/>
</p>
</div>
<div class="footer-item">
<p class="sphinx-version">
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 3.4.3.<br/>
</p>
</div>
</div>
</footer>
</body>
</html>