/usr/share/doc/python-simpy-doc/html/Manuals/Examples.html is in python-simpy-doc 2.3.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Additional examples — SimPy 2.3.1 documentation</title>
<link rel="stylesheet" href="../_static/default.css" type="text/css" />
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '../',
VERSION: '2.3.1',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
};
</script>
<script type="text/javascript" src="../_static/jquery.js"></script>
<script type="text/javascript" src="../_static/underscore.js"></script>
<script type="text/javascript" src="../_static/doctools.js"></script>
<link rel="top" title="SimPy 2.3.1 documentation" href="../index.html" />
<link rel="up" title="Manuals" href="../Manuals.html" />
<link rel="next" title="SimPy Tutorials" href="../SimPy_Tutorials.html" />
<link rel="prev" title="Cheatsheets" href="../Cheatsheets.html" />
</head>
<body>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="../SimPy_Tutorials.html" title="SimPy Tutorials"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="../Cheatsheets.html" title="Cheatsheets"
accesskey="P">previous</a> |</li>
<li><a href="../index.html">SimPy 2.3.1 documentation</a> »</li>
<li><a href="../Manuals.html" accesskey="U">Manuals</a> »</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body">
<div class="section" id="additional-examples">
<h1>Additional examples<a class="headerlink" href="#additional-examples" title="Permalink to this headline">¶</a></h1>
<p>The following examples are included in the SimPy source distribution.</p>
<div class="section" id="car">
<h2>Car<a class="headerlink" href="#car" title="Permalink to this headline">¶</a></h2>
<div class="highlight-python" id="index-0"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">SimPy.Simulation</span> <span class="kn">import</span> <span class="n">Process</span><span class="p">,</span> <span class="n">activate</span><span class="p">,</span> <span class="n">hold</span><span class="p">,</span> <span class="n">initialize</span><span class="p">,</span> <span class="n">now</span><span class="p">,</span> <span class="n">simulate</span>
<span class="k">class</span> <span class="nc">Car</span><span class="p">(</span><span class="n">Process</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">cc</span><span class="p">):</span>
<span class="n">Process</span><span class="o">.</span><span class="n">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="n">name</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">cc</span> <span class="o">=</span> <span class="n">cc</span>
<span class="k">def</span> <span class="nf">go</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">print</span><span class="p">(</span><span class="s">'</span><span class="si">%s</span><span class="s"> </span><span class="si">%s</span><span class="s"> </span><span class="si">%s</span><span class="s">'</span> <span class="o">%</span> <span class="p">(</span><span class="n">now</span><span class="p">(),</span> <span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="s">'Starting'</span><span class="p">))</span>
<span class="k">yield</span> <span class="n">hold</span><span class="p">,</span> <span class="bp">self</span><span class="p">,</span> <span class="mf">100.0</span>
<span class="k">print</span><span class="p">(</span><span class="s">'</span><span class="si">%s</span><span class="s"> </span><span class="si">%s</span><span class="s"> </span><span class="si">%s</span><span class="s">'</span> <span class="o">%</span> <span class="p">(</span><span class="n">now</span><span class="p">(),</span> <span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="s">'Arrived'</span><span class="p">))</span>
<span class="n">initialize</span><span class="p">()</span>
<span class="n">c1</span> <span class="o">=</span> <span class="n">Car</span><span class="p">(</span><span class="s">'Car1'</span><span class="p">,</span> <span class="mi">2000</span><span class="p">)</span> <span class="c"># a new car</span>
<span class="n">activate</span><span class="p">(</span><span class="n">c1</span><span class="p">,</span> <span class="n">c1</span><span class="o">.</span><span class="n">go</span><span class="p">(),</span> <span class="n">at</span><span class="o">=</span><span class="mf">6.0</span><span class="p">)</span> <span class="c"># activate at time 6.0</span>
<span class="n">c2</span> <span class="o">=</span> <span class="n">Car</span><span class="p">(</span><span class="s">'Car2'</span><span class="p">,</span> <span class="mi">1600</span><span class="p">)</span> <span class="c"># another new car</span>
<span class="n">activate</span><span class="p">(</span><span class="n">c2</span><span class="p">,</span> <span class="n">c2</span><span class="o">.</span><span class="n">go</span><span class="p">())</span> <span class="c"># activate at time 0</span>
<span class="n">simulate</span><span class="p">(</span><span class="n">until</span><span class="o">=</span><span class="mi">200</span><span class="p">)</span>
<span class="k">print</span><span class="p">(</span><span class="s">'Current time is </span><span class="si">%s</span><span class="s">'</span> <span class="o">%</span> <span class="n">now</span><span class="p">())</span> <span class="c"># will print 106.0</span>
</pre></div>
</div>
<p>Output:</p>
<div class="highlight-python"><pre>0 Car2 Starting
6.0 Car1 Starting
100.0 Car2 Arrived
106.0 Car1 Arrived
Current time is 106.0
</pre>
</div>
</div>
<div class="section" id="cart">
<h2>CarT<a class="headerlink" href="#cart" title="Permalink to this headline">¶</a></h2>
<div class="highlight-python" id="index-1"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">SimPy.SimulationTrace</span> <span class="kn">import</span> <span class="p">(</span><span class="n">Process</span><span class="p">,</span> <span class="n">activate</span><span class="p">,</span> <span class="n">initialize</span><span class="p">,</span> <span class="n">hold</span><span class="p">,</span> <span class="n">now</span><span class="p">,</span>
<span class="n">simulate</span><span class="p">)</span>
<span class="k">class</span> <span class="nc">Car</span><span class="p">(</span><span class="n">Process</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">cc</span><span class="p">):</span>
<span class="n">Process</span><span class="o">.</span><span class="n">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="n">name</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">cc</span> <span class="o">=</span> <span class="n">cc</span>
<span class="k">def</span> <span class="nf">go</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">print</span><span class="p">(</span><span class="s">'</span><span class="si">%s</span><span class="s"> </span><span class="si">%s</span><span class="s"> </span><span class="si">%s</span><span class="s">'</span> <span class="o">%</span> <span class="p">(</span><span class="n">now</span><span class="p">(),</span> <span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="s">'Starting'</span><span class="p">))</span>
<span class="k">yield</span> <span class="n">hold</span><span class="p">,</span> <span class="bp">self</span><span class="p">,</span> <span class="mf">100.0</span>
<span class="k">print</span><span class="p">(</span><span class="s">'</span><span class="si">%s</span><span class="s"> </span><span class="si">%s</span><span class="s"> </span><span class="si">%s</span><span class="s">'</span> <span class="o">%</span> <span class="p">(</span><span class="n">now</span><span class="p">(),</span> <span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="s">'Arrived'</span><span class="p">))</span>
<span class="n">initialize</span><span class="p">()</span>
<span class="n">c1</span> <span class="o">=</span> <span class="n">Car</span><span class="p">(</span><span class="s">'Car1'</span><span class="p">,</span> <span class="mi">2000</span><span class="p">)</span> <span class="c"># a new car</span>
<span class="n">activate</span><span class="p">(</span><span class="n">c1</span><span class="p">,</span> <span class="n">c1</span><span class="o">.</span><span class="n">go</span><span class="p">(),</span> <span class="n">at</span><span class="o">=</span><span class="mf">6.0</span><span class="p">)</span> <span class="c"># activate at time 6.0</span>
<span class="n">c2</span> <span class="o">=</span> <span class="n">Car</span><span class="p">(</span><span class="s">'Car2'</span><span class="p">,</span> <span class="mi">1600</span><span class="p">)</span> <span class="c"># another new car</span>
<span class="n">activate</span><span class="p">(</span><span class="n">c2</span><span class="p">,</span> <span class="n">c2</span><span class="o">.</span><span class="n">go</span><span class="p">())</span> <span class="c"># activate at time 0</span>
<span class="n">simulate</span><span class="p">(</span><span class="n">until</span><span class="o">=</span><span class="mi">200</span><span class="p">)</span>
<span class="k">print</span><span class="p">(</span><span class="s">'Current time is </span><span class="si">%s</span><span class="s">'</span> <span class="o">%</span> <span class="n">now</span><span class="p">())</span> <span class="c"># will print 106.0</span>
</pre></div>
</div>
<p>Output:</p>
<div class="highlight-python"><pre>0 activate <Car1> at time: 6.0 prior: False
0 activate <Car2> at time: 0 prior: False
0 Car2 Starting
0 hold <Car2> delay: 100.0
6.0 Car1 Starting
6.0 hold <Car1> delay: 100.0
100.0 Car2 Arrived
100.0 <Car2> terminated
106.0 Car1 Arrived
106.0 <Car1> terminated
Current time is 106.0
</pre>
</div>
</div>
<div class="section" id="cars">
<h2>Cars<a class="headerlink" href="#cars" title="Permalink to this headline">¶</a></h2>
<div class="highlight-python" id="index-2"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">SimPy.Simulation</span> <span class="kn">import</span> <span class="p">(</span><span class="n">Process</span><span class="p">,</span> <span class="n">Resource</span><span class="p">,</span> <span class="n">activate</span><span class="p">,</span> <span class="n">initialize</span><span class="p">,</span> <span class="n">hold</span><span class="p">,</span>
<span class="n">now</span><span class="p">,</span> <span class="n">release</span><span class="p">,</span> <span class="n">request</span><span class="p">,</span> <span class="n">simulate</span><span class="p">)</span>
<span class="k">class</span> <span class="nc">Car</span><span class="p">(</span><span class="n">Process</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">cc</span><span class="p">):</span>
<span class="n">Process</span><span class="o">.</span><span class="n">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="n">name</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">cc</span> <span class="o">=</span> <span class="n">cc</span>
<span class="k">def</span> <span class="nf">go</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">print</span><span class="p">(</span><span class="s">'</span><span class="si">%s</span><span class="s"> </span><span class="si">%s</span><span class="s"> </span><span class="si">%s</span><span class="s">'</span> <span class="o">%</span> <span class="p">(</span><span class="n">now</span><span class="p">(),</span> <span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="s">'Starting'</span><span class="p">))</span>
<span class="k">yield</span> <span class="n">request</span><span class="p">,</span> <span class="bp">self</span><span class="p">,</span> <span class="n">gasstation</span>
<span class="k">print</span><span class="p">(</span><span class="s">'</span><span class="si">%s</span><span class="s"> </span><span class="si">%s</span><span class="s"> </span><span class="si">%s</span><span class="s">'</span> <span class="o">%</span> <span class="p">(</span><span class="n">now</span><span class="p">(),</span> <span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="s">'Got a pump'</span><span class="p">))</span>
<span class="k">yield</span> <span class="n">hold</span><span class="p">,</span> <span class="bp">self</span><span class="p">,</span> <span class="mf">100.0</span>
<span class="k">yield</span> <span class="n">release</span><span class="p">,</span> <span class="bp">self</span><span class="p">,</span> <span class="n">gasstation</span>
<span class="k">print</span><span class="p">(</span><span class="s">'</span><span class="si">%s</span><span class="s"> </span><span class="si">%s</span><span class="s"> </span><span class="si">%s</span><span class="s">'</span> <span class="o">%</span> <span class="p">(</span><span class="n">now</span><span class="p">(),</span> <span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="s">'Leaving'</span><span class="p">))</span>
<span class="n">gasstation</span> <span class="o">=</span> <span class="n">Resource</span><span class="p">(</span><span class="n">capacity</span><span class="o">=</span><span class="mi">2</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s">'gasStation'</span><span class="p">,</span> <span class="n">unitName</span><span class="o">=</span><span class="s">'pump'</span><span class="p">)</span>
<span class="n">initialize</span><span class="p">()</span>
<span class="n">c1</span> <span class="o">=</span> <span class="n">Car</span><span class="p">(</span><span class="s">'Car1'</span><span class="p">,</span> <span class="mi">2000</span><span class="p">)</span>
<span class="n">c2</span> <span class="o">=</span> <span class="n">Car</span><span class="p">(</span><span class="s">'Car2'</span><span class="p">,</span> <span class="mi">1600</span><span class="p">)</span>
<span class="n">c3</span> <span class="o">=</span> <span class="n">Car</span><span class="p">(</span><span class="s">'Car3'</span><span class="p">,</span> <span class="mi">3000</span><span class="p">)</span>
<span class="n">c4</span> <span class="o">=</span> <span class="n">Car</span><span class="p">(</span><span class="s">'Car4'</span><span class="p">,</span> <span class="mi">1600</span><span class="p">)</span>
<span class="n">activate</span><span class="p">(</span><span class="n">c1</span><span class="p">,</span> <span class="n">c1</span><span class="o">.</span><span class="n">go</span><span class="p">(),</span> <span class="n">at</span><span class="o">=</span><span class="mf">4.0</span><span class="p">)</span> <span class="c"># activate at time 4.0</span>
<span class="n">activate</span><span class="p">(</span><span class="n">c2</span><span class="p">,</span> <span class="n">c2</span><span class="o">.</span><span class="n">go</span><span class="p">())</span> <span class="c"># activate at time 0.0</span>
<span class="n">activate</span><span class="p">(</span><span class="n">c3</span><span class="p">,</span> <span class="n">c3</span><span class="o">.</span><span class="n">go</span><span class="p">(),</span> <span class="n">at</span><span class="o">=</span><span class="mf">3.0</span><span class="p">)</span> <span class="c"># activate at time 3.0</span>
<span class="n">activate</span><span class="p">(</span><span class="n">c4</span><span class="p">,</span> <span class="n">c4</span><span class="o">.</span><span class="n">go</span><span class="p">(),</span> <span class="n">at</span><span class="o">=</span><span class="mf">3.0</span><span class="p">)</span> <span class="c"># activate at time 2.0</span>
<span class="n">simulate</span><span class="p">(</span><span class="n">until</span><span class="o">=</span><span class="mi">300</span><span class="p">)</span>
<span class="k">print</span><span class="p">(</span><span class="s">'Current time is </span><span class="si">%s</span><span class="s">'</span> <span class="o">%</span> <span class="n">now</span><span class="p">())</span>
</pre></div>
</div>
<p>Output:</p>
<div class="highlight-python"><pre>0 Car2 Starting
0 Car2 Got a pump
3.0 Car3 Starting
3.0 Car3 Got a pump
3.0 Car4 Starting
4.0 Car1 Starting
100.0 Car2 Leaving
100.0 Car4 Got a pump
103.0 Car3 Leaving
103.0 Car1 Got a pump
200.0 Car4 Leaving
203.0 Car1 Leaving
Current time is 203.0
</pre>
</div>
</div>
<div class="section" id="carst">
<h2>CarsT<a class="headerlink" href="#carst" title="Permalink to this headline">¶</a></h2>
<div class="highlight-python" id="index-3"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">SimPy.SimulationTrace</span> <span class="kn">import</span> <span class="p">(</span><span class="n">Process</span><span class="p">,</span> <span class="n">Resource</span><span class="p">,</span> <span class="n">activate</span><span class="p">,</span> <span class="n">initialize</span><span class="p">,</span>
<span class="n">hold</span><span class="p">,</span> <span class="n">now</span><span class="p">,</span> <span class="n">release</span><span class="p">,</span> <span class="n">request</span><span class="p">,</span> <span class="n">simulate</span><span class="p">)</span>
<span class="k">class</span> <span class="nc">Car</span><span class="p">(</span><span class="n">Process</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">cc</span><span class="p">):</span>
<span class="n">Process</span><span class="o">.</span><span class="n">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="n">name</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">cc</span> <span class="o">=</span> <span class="n">cc</span>
<span class="k">def</span> <span class="nf">go</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">print</span><span class="p">(</span><span class="s">'</span><span class="si">%s</span><span class="s"> </span><span class="si">%s</span><span class="s"> </span><span class="si">%s</span><span class="s">'</span> <span class="o">%</span> <span class="p">(</span><span class="n">now</span><span class="p">(),</span> <span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="s">'Starting'</span><span class="p">))</span>
<span class="k">yield</span> <span class="n">request</span><span class="p">,</span> <span class="bp">self</span><span class="p">,</span> <span class="n">gasstation</span>
<span class="k">print</span><span class="p">(</span><span class="s">'</span><span class="si">%s</span><span class="s"> </span><span class="si">%s</span><span class="s"> </span><span class="si">%s</span><span class="s">'</span> <span class="o">%</span> <span class="p">(</span><span class="n">now</span><span class="p">(),</span> <span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="s">'Got a pump'</span><span class="p">))</span>
<span class="k">yield</span> <span class="n">hold</span><span class="p">,</span> <span class="bp">self</span><span class="p">,</span> <span class="mf">100.0</span>
<span class="k">yield</span> <span class="n">release</span><span class="p">,</span> <span class="bp">self</span><span class="p">,</span> <span class="n">gasstation</span>
<span class="k">print</span><span class="p">(</span><span class="s">'</span><span class="si">%s</span><span class="s"> </span><span class="si">%s</span><span class="s"> </span><span class="si">%s</span><span class="s">'</span> <span class="o">%</span> <span class="p">(</span><span class="n">now</span><span class="p">(),</span> <span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="s">'Leaving'</span><span class="p">))</span>
<span class="n">gasstation</span> <span class="o">=</span> <span class="n">Resource</span><span class="p">(</span><span class="n">capacity</span><span class="o">=</span><span class="mi">2</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s">'gasStation'</span><span class="p">,</span> <span class="n">unitName</span><span class="o">=</span><span class="s">'pump'</span><span class="p">)</span>
<span class="n">initialize</span><span class="p">()</span>
<span class="n">c1</span> <span class="o">=</span> <span class="n">Car</span><span class="p">(</span><span class="s">'Car1'</span><span class="p">,</span> <span class="mi">2000</span><span class="p">)</span>
<span class="n">c2</span> <span class="o">=</span> <span class="n">Car</span><span class="p">(</span><span class="s">'Car2'</span><span class="p">,</span> <span class="mi">1600</span><span class="p">)</span>
<span class="n">c3</span> <span class="o">=</span> <span class="n">Car</span><span class="p">(</span><span class="s">'Car3'</span><span class="p">,</span> <span class="mi">3000</span><span class="p">)</span>
<span class="n">c4</span> <span class="o">=</span> <span class="n">Car</span><span class="p">(</span><span class="s">'Car4'</span><span class="p">,</span> <span class="mi">1600</span><span class="p">)</span>
<span class="n">activate</span><span class="p">(</span><span class="n">c1</span><span class="p">,</span> <span class="n">c1</span><span class="o">.</span><span class="n">go</span><span class="p">(),</span> <span class="n">at</span><span class="o">=</span><span class="mf">4.0</span><span class="p">)</span> <span class="c"># activate at time 4.0</span>
<span class="n">activate</span><span class="p">(</span><span class="n">c2</span><span class="p">,</span> <span class="n">c2</span><span class="o">.</span><span class="n">go</span><span class="p">())</span> <span class="c"># activate at time 0.0</span>
<span class="n">activate</span><span class="p">(</span><span class="n">c3</span><span class="p">,</span> <span class="n">c3</span><span class="o">.</span><span class="n">go</span><span class="p">(),</span> <span class="n">at</span><span class="o">=</span><span class="mf">3.0</span><span class="p">)</span> <span class="c"># activate at time 3.0</span>
<span class="n">activate</span><span class="p">(</span><span class="n">c4</span><span class="p">,</span> <span class="n">c4</span><span class="o">.</span><span class="n">go</span><span class="p">(),</span> <span class="n">at</span><span class="o">=</span><span class="mf">3.0</span><span class="p">)</span> <span class="c"># activate at time 2.0</span>
<span class="n">simulate</span><span class="p">(</span><span class="n">until</span><span class="o">=</span><span class="mi">300</span><span class="p">)</span>
<span class="k">print</span><span class="p">(</span><span class="s">'Current time is </span><span class="si">%s</span><span class="s">'</span> <span class="o">%</span> <span class="n">now</span><span class="p">())</span>
</pre></div>
</div>
<p>Output:</p>
<div class="highlight-python"><pre>0 activate <Car1> at time: 4.0 prior: False
0 activate <Car2> at time: 0 prior: False
0 activate <Car3> at time: 3.0 prior: False
0 activate <Car4> at time: 3.0 prior: False
0 Car2 Starting
0 request <Car2> <gasStation> priority: default
. . .waitQ: []
. . .activeQ: ['Car2']
0 Car2 Got a pump
0 hold <Car2> delay: 100.0
3.0 Car3 Starting
3.0 request <Car3> <gasStation> priority: default
. . .waitQ: []
. . .activeQ: ['Car2', 'Car3']
3.0 Car3 Got a pump
3.0 hold <Car3> delay: 100.0
3.0 Car4 Starting
3.0 request <Car4> <gasStation> priority: default
. . .waitQ: ['Car4']
. . .activeQ: ['Car2', 'Car3']
4.0 Car1 Starting
4.0 request <Car1> <gasStation> priority: default
. . .waitQ: ['Car4', 'Car1']
. . .activeQ: ['Car2', 'Car3']
100.0 reactivate <Car4> time: 100.0 prior: 1
100.0 release <Car2> <gasStation>
. . .waitQ: ['Car1']
. . .activeQ: ['Car3', 'Car4']
100.0 Car2 Leaving
100.0 <Car2> terminated
100.0 Car4 Got a pump
100.0 hold <Car4> delay: 100.0
103.0 reactivate <Car1> time: 103.0 prior: 1
103.0 release <Car3> <gasStation>
. . .waitQ: []
. . .activeQ: ['Car4', 'Car1']
103.0 Car3 Leaving
103.0 <Car3> terminated
103.0 Car1 Got a pump
103.0 hold <Car1> delay: 100.0
200.0 release <Car4> <gasStation>
. . .waitQ: []
. . .activeQ: ['Car1']
200.0 Car4 Leaving
200.0 <Car4> terminated
203.0 release <Car1> <gasStation>
. . .waitQ: []
. . .activeQ: []
203.0 Car1 Leaving
203.0 <Car1> terminated
Current time is 203.0
</pre>
</div>
</div>
<div class="section" id="carwash">
<h2>Carwash<a class="headerlink" href="#carwash" title="Permalink to this headline">¶</a></h2>
<div class="highlight-python" id="index-4"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">SimPy.Simulation</span> <span class="kn">import</span> <span class="p">(</span><span class="n">Process</span><span class="p">,</span> <span class="n">SimEvent</span><span class="p">,</span> <span class="n">Store</span><span class="p">,</span> <span class="n">activate</span><span class="p">,</span> <span class="n">get</span><span class="p">,</span>
<span class="n">initialize</span><span class="p">,</span> <span class="n">hold</span><span class="p">,</span> <span class="n">now</span><span class="p">,</span> <span class="n">put</span><span class="p">,</span> <span class="n">simulate</span><span class="p">,</span> <span class="n">waitevent</span><span class="p">)</span>
<span class="sd">"""Carwash is master"""</span>
<span class="k">class</span> <span class="nc">Carwash</span><span class="p">(</span><span class="n">Process</span><span class="p">):</span>
<span class="sd">"""Carwash is master"""</span>
<span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">):</span>
<span class="n">Process</span><span class="o">.</span><span class="n">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="n">name</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">lifecycle</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">while</span> <span class="bp">True</span><span class="p">:</span>
<span class="k">yield</span> <span class="n">get</span><span class="p">,</span> <span class="bp">self</span><span class="p">,</span> <span class="n">waitingCars</span><span class="p">,</span> <span class="mi">1</span>
<span class="n">carBeingWashed</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">got</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
<span class="k">yield</span> <span class="n">hold</span><span class="p">,</span> <span class="bp">self</span><span class="p">,</span> <span class="n">washtime</span>
<span class="n">carBeingWashed</span><span class="o">.</span><span class="n">doneSignal</span><span class="o">.</span><span class="n">signal</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
<span class="k">class</span> <span class="nc">Car</span><span class="p">(</span><span class="n">Process</span><span class="p">):</span>
<span class="sd">"""Car is slave"""</span>
<span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">):</span>
<span class="n">Process</span><span class="o">.</span><span class="n">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="n">name</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">doneSignal</span> <span class="o">=</span> <span class="n">SimEvent</span><span class="p">()</span>
<span class="k">def</span> <span class="nf">lifecycle</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">yield</span> <span class="n">put</span><span class="p">,</span> <span class="bp">self</span><span class="p">,</span> <span class="n">waitingCars</span><span class="p">,</span> <span class="p">[</span><span class="bp">self</span><span class="p">]</span>
<span class="k">yield</span> <span class="n">waitevent</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">doneSignal</span>
<span class="n">whichWash</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">doneSignal</span><span class="o">.</span><span class="n">signalparam</span>
<span class="k">print</span><span class="p">(</span><span class="s">'</span><span class="si">%s</span><span class="s"> car </span><span class="si">%s</span><span class="s"> done by </span><span class="si">%s</span><span class="s">'</span> <span class="o">%</span> <span class="p">(</span><span class="n">now</span><span class="p">(),</span> <span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="n">whichWash</span><span class="p">))</span>
<span class="k">class</span> <span class="nc">CarGenerator</span><span class="p">(</span><span class="n">Process</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">generate</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="n">i</span> <span class="o">=</span> <span class="mi">0</span>
<span class="k">while</span> <span class="bp">True</span><span class="p">:</span>
<span class="k">yield</span> <span class="n">hold</span><span class="p">,</span> <span class="bp">self</span><span class="p">,</span> <span class="mi">2</span>
<span class="n">c</span> <span class="o">=</span> <span class="n">Car</span><span class="p">(</span><span class="s">'</span><span class="si">%d</span><span class="s">'</span> <span class="o">%</span> <span class="n">i</span><span class="p">)</span>
<span class="n">activate</span><span class="p">(</span><span class="n">c</span><span class="p">,</span> <span class="n">c</span><span class="o">.</span><span class="n">lifecycle</span><span class="p">())</span>
<span class="n">i</span> <span class="o">+=</span> <span class="mi">1</span>
<span class="n">washtime</span> <span class="o">=</span> <span class="mi">5</span>
<span class="n">initialize</span><span class="p">()</span>
<span class="c"># put four cars into the queue of waiting cars</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">1</span><span class="p">,</span> <span class="mi">5</span><span class="p">):</span>
<span class="n">c</span> <span class="o">=</span> <span class="n">Car</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s">'</span><span class="si">%d</span><span class="s">'</span> <span class="o">%</span> <span class="o">-</span><span class="n">j</span><span class="p">)</span>
<span class="n">activate</span><span class="p">(</span><span class="n">c</span><span class="p">,</span> <span class="n">c</span><span class="o">.</span><span class="n">lifecycle</span><span class="p">())</span>
<span class="n">waitingCars</span> <span class="o">=</span> <span class="n">Store</span><span class="p">(</span><span class="n">capacity</span><span class="o">=</span><span class="mi">40</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">2</span><span class="p">):</span>
<span class="n">cw</span> <span class="o">=</span> <span class="n">Carwash</span><span class="p">(</span><span class="s">'Carwash </span><span class="si">%s</span><span class="s">'</span> <span class="o">%</span> <span class="n">i</span><span class="p">)</span>
<span class="n">activate</span><span class="p">(</span><span class="n">cw</span><span class="p">,</span> <span class="n">cw</span><span class="o">.</span><span class="n">lifecycle</span><span class="p">())</span>
<span class="n">cg</span> <span class="o">=</span> <span class="n">CarGenerator</span><span class="p">()</span>
<span class="n">activate</span><span class="p">(</span><span class="n">cg</span><span class="p">,</span> <span class="n">cg</span><span class="o">.</span><span class="n">generate</span><span class="p">())</span>
<span class="n">simulate</span><span class="p">(</span><span class="n">until</span><span class="o">=</span><span class="mi">30</span><span class="p">)</span>
<span class="k">print</span><span class="p">(</span><span class="s">'waitingCars </span><span class="si">%s</span><span class="s">'</span> <span class="o">%</span> <span class="p">[</span><span class="n">x</span><span class="o">.</span><span class="n">name</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">waitingCars</span><span class="o">.</span><span class="n">theBuffer</span><span class="p">])</span>
</pre></div>
</div>
<p>Output:</p>
<div class="highlight-python"><pre>5 car -1 done by Carwash 0
5 car -2 done by Carwash 1
10 car -3 done by Carwash 0
10 car -4 done by Carwash 1
15 car 0 done by Carwash 0
15 car 1 done by Carwash 1
20 car 2 done by Carwash 0
20 car 3 done by Carwash 1
25 car 4 done by Carwash 0
25 car 5 done by Carwash 1
30 car 6 done by Carwash 0
30 car 7 done by Carwash 1
waitingCars ['10', '11', '12', '13', '14']
</pre>
</div>
</div>
<div class="section" id="breakdown">
<h2>Breakdown<a class="headerlink" href="#breakdown" title="Permalink to this headline">¶</a></h2>
<div class="highlight-python" id="index-5"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">SimPy.Simulation</span> <span class="kn">import</span> <span class="p">(</span><span class="n">Process</span><span class="p">,</span> <span class="n">activate</span><span class="p">,</span> <span class="n">hold</span><span class="p">,</span> <span class="n">initialize</span><span class="p">,</span> <span class="n">now</span><span class="p">,</span>
<span class="n">reactivate</span><span class="p">,</span> <span class="n">simulate</span><span class="p">)</span>
<span class="k">class</span> <span class="nc">Bus</span><span class="p">(</span><span class="n">Process</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">operate</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">repairduration</span><span class="p">,</span> <span class="n">triplength</span><span class="p">):</span> <span class="c"># PEM</span>
<span class="n">tripleft</span> <span class="o">=</span> <span class="n">triplength</span> <span class="c"># time needed to finish trip</span>
<span class="k">while</span> <span class="n">tripleft</span> <span class="o">></span> <span class="mi">0</span><span class="p">:</span>
<span class="k">yield</span> <span class="n">hold</span><span class="p">,</span> <span class="bp">self</span><span class="p">,</span> <span class="n">tripleft</span> <span class="c"># try to finish the trip</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">interrupted</span><span class="p">():</span> <span class="c"># if another breakdown occurs</span>
<span class="k">print</span><span class="p">(</span><span class="s">'</span><span class="si">%s</span><span class="s"> at </span><span class="si">%s</span><span class="s">'</span> <span class="o">%</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">interruptCause</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="n">now</span><span class="p">()))</span>
<span class="n">tripleft</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">interruptLeft</span> <span class="c"># time to finish the trip</span>
<span class="bp">self</span><span class="o">.</span><span class="n">interruptReset</span><span class="p">()</span> <span class="c"># end interrupt state</span>
<span class="n">reactivate</span><span class="p">(</span><span class="n">br</span><span class="p">,</span> <span class="n">delay</span><span class="o">=</span><span class="n">repairduration</span><span class="p">)</span> <span class="c"># restart breakdown br</span>
<span class="k">yield</span> <span class="n">hold</span><span class="p">,</span> <span class="bp">self</span><span class="p">,</span> <span class="n">repairduration</span> <span class="c"># delay for repairs</span>
<span class="k">print</span><span class="p">(</span><span class="s">'Bus repaired at </span><span class="si">%s</span><span class="s">'</span> <span class="o">%</span> <span class="n">now</span><span class="p">())</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">break</span> <span class="c"># no more breakdowns, bus finished trip</span>
<span class="k">print</span><span class="p">(</span><span class="s">'Bus has arrived at </span><span class="si">%s</span><span class="s">'</span> <span class="o">%</span> <span class="n">now</span><span class="p">())</span>
<span class="k">class</span> <span class="nc">Breakdown</span><span class="p">(</span><span class="n">Process</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">myBus</span><span class="p">):</span>
<span class="n">Process</span><span class="o">.</span><span class="n">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s">'Breakdown '</span> <span class="o">+</span> <span class="n">myBus</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">bus</span> <span class="o">=</span> <span class="n">myBus</span>
<span class="k">def</span> <span class="nf">breakBus</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">interval</span><span class="p">):</span> <span class="c"># process execution method</span>
<span class="k">while</span> <span class="bp">True</span><span class="p">:</span>
<span class="k">yield</span> <span class="n">hold</span><span class="p">,</span> <span class="bp">self</span><span class="p">,</span> <span class="n">interval</span> <span class="c"># breakdown interarrivals</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">bus</span><span class="o">.</span><span class="n">terminated</span><span class="p">():</span>
<span class="k">break</span>
<span class="bp">self</span><span class="o">.</span><span class="n">interrupt</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">bus</span><span class="p">)</span> <span class="c"># breakdown to myBus</span>
<span class="n">initialize</span><span class="p">()</span>
<span class="n">b</span> <span class="o">=</span> <span class="n">Bus</span><span class="p">(</span><span class="s">'Bus'</span><span class="p">)</span> <span class="c"># create a bus object</span>
<span class="n">activate</span><span class="p">(</span><span class="n">b</span><span class="p">,</span> <span class="n">b</span><span class="o">.</span><span class="n">operate</span><span class="p">(</span><span class="n">repairduration</span><span class="o">=</span><span class="mi">20</span><span class="p">,</span> <span class="n">triplength</span><span class="o">=</span><span class="mi">1000</span><span class="p">))</span>
<span class="n">br</span> <span class="o">=</span> <span class="n">Breakdown</span><span class="p">(</span><span class="n">b</span><span class="p">)</span> <span class="c"># create breakdown br to bus b</span>
<span class="n">activate</span><span class="p">(</span><span class="n">br</span><span class="p">,</span> <span class="n">br</span><span class="o">.</span><span class="n">breakBus</span><span class="p">(</span><span class="mi">300</span><span class="p">))</span>
<span class="n">simulate</span><span class="p">(</span><span class="n">until</span><span class="o">=</span><span class="mi">4000</span><span class="p">)</span>
<span class="k">print</span><span class="p">(</span><span class="s">'SimPy: No more events at time </span><span class="si">%s</span><span class="s">'</span> <span class="o">%</span> <span class="n">now</span><span class="p">())</span>
</pre></div>
</div>
<p>Output:</p>
<div class="highlight-python"><pre>Breakdown Bus at 300
Bus repaired at 320
Breakdown Bus at 620
Bus repaired at 640
Breakdown Bus at 940
Bus repaired at 960
Bus has arrived at 1060
SimPy: No more events at time 1260
</pre>
</div>
</div>
<div class="section" id="firework">
<h2>Firework<a class="headerlink" href="#firework" title="Permalink to this headline">¶</a></h2>
<div class="highlight-python" id="index-6"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">SimPy.Simulation</span> <span class="kn">import</span> <span class="n">Process</span><span class="p">,</span> <span class="n">activate</span><span class="p">,</span> <span class="n">initialize</span><span class="p">,</span> <span class="n">hold</span><span class="p">,</span> <span class="n">now</span><span class="p">,</span> <span class="n">simulate</span>
<span class="k">class</span> <span class="nc">Firework</span><span class="p">(</span><span class="n">Process</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">execute</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">print</span><span class="p">(</span><span class="s">'</span><span class="si">%s</span><span class="s"> firework launched'</span> <span class="o">%</span> <span class="n">now</span><span class="p">())</span>
<span class="k">yield</span> <span class="n">hold</span><span class="p">,</span> <span class="bp">self</span><span class="p">,</span> <span class="mf">10.0</span> <span class="c"># wait 10.0 time units</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">10</span><span class="p">):</span>
<span class="k">yield</span> <span class="n">hold</span><span class="p">,</span> <span class="bp">self</span><span class="p">,</span> <span class="mf">1.0</span>
<span class="k">print</span><span class="p">(</span><span class="s">'</span><span class="si">%s</span><span class="s"> tick'</span> <span class="o">%</span> <span class="n">now</span><span class="p">())</span>
<span class="k">yield</span> <span class="n">hold</span><span class="p">,</span> <span class="bp">self</span><span class="p">,</span> <span class="mf">10.0</span> <span class="c"># wait another 10.0 time units</span>
<span class="k">print</span><span class="p">(</span><span class="s">'</span><span class="si">%s</span><span class="s"> Boom!!'</span> <span class="o">%</span> <span class="n">now</span><span class="p">())</span>
<span class="n">initialize</span><span class="p">()</span>
<span class="n">f</span> <span class="o">=</span> <span class="n">Firework</span><span class="p">()</span> <span class="c"># create a Firework object, and</span>
<span class="c"># activate it (with some default parameters)</span>
<span class="n">activate</span><span class="p">(</span><span class="n">f</span><span class="p">,</span> <span class="n">f</span><span class="o">.</span><span class="n">execute</span><span class="p">(),</span> <span class="n">at</span><span class="o">=</span><span class="mf">0.0</span><span class="p">)</span>
<span class="n">simulate</span><span class="p">(</span><span class="n">until</span><span class="o">=</span><span class="mi">100</span><span class="p">)</span>
</pre></div>
</div>
<p>Output:</p>
<div class="highlight-python"><pre>0 firework launched
11.0 tick
12.0 tick
13.0 tick
14.0 tick
15.0 tick
16.0 tick
17.0 tick
18.0 tick
19.0 tick
20.0 tick
30.0 Boom!!
</pre>
</div>
</div>
<div class="section" id="levelinventory">
<h2>Levelinventory<a class="headerlink" href="#levelinventory" title="Permalink to this headline">¶</a></h2>
<div class="highlight-python" id="index-7"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">random</span> <span class="kn">import</span> <span class="n">normalvariate</span><span class="p">,</span> <span class="n">seed</span>
<span class="kn">from</span> <span class="nn">SimPy.Simulation</span> <span class="kn">import</span> <span class="p">(</span><span class="n">Level</span><span class="p">,</span> <span class="n">Process</span><span class="p">,</span> <span class="n">activate</span><span class="p">,</span> <span class="n">get</span><span class="p">,</span> <span class="n">initialize</span><span class="p">,</span> <span class="n">hold</span><span class="p">,</span>
<span class="n">now</span><span class="p">,</span> <span class="n">put</span><span class="p">,</span> <span class="n">simulate</span><span class="p">)</span>
<span class="k">class</span> <span class="nc">Deliver</span><span class="p">(</span><span class="n">Process</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">deliver</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> <span class="c"># an "offeror" PEM</span>
<span class="k">while</span> <span class="bp">True</span><span class="p">:</span>
<span class="n">lead</span> <span class="o">=</span> <span class="mf">10.0</span> <span class="c"># time between refills</span>
<span class="n">delivery</span> <span class="o">=</span> <span class="mf">10.0</span> <span class="c"># amount in each refill</span>
<span class="k">yield</span> <span class="n">put</span><span class="p">,</span> <span class="bp">self</span><span class="p">,</span> <span class="n">stock</span><span class="p">,</span> <span class="n">delivery</span>
<span class="k">print</span><span class="p">(</span><span class="s">'at </span><span class="si">%6.4f</span><span class="s">, add </span><span class="si">%6.4f</span><span class="s"> units, now amount = </span><span class="si">%6.4f</span><span class="s">'</span> <span class="o">%</span>
<span class="p">(</span><span class="n">now</span><span class="p">(),</span> <span class="n">delivery</span><span class="p">,</span> <span class="n">stock</span><span class="o">.</span><span class="n">amount</span><span class="p">))</span>
<span class="k">yield</span> <span class="n">hold</span><span class="p">,</span> <span class="bp">self</span><span class="p">,</span> <span class="n">lead</span>
<span class="k">class</span> <span class="nc">Demand</span><span class="p">(</span><span class="n">Process</span><span class="p">):</span>
<span class="n">stockout</span> <span class="o">=</span> <span class="mf">0.0</span> <span class="c"># initialize initial stockout amount</span>
<span class="k">def</span> <span class="nf">demand</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> <span class="c"># a "requester" PEM</span>
<span class="n">day</span> <span class="o">=</span> <span class="mf">1.0</span> <span class="c"># set time-step to one day</span>
<span class="k">while</span> <span class="bp">True</span><span class="p">:</span>
<span class="k">yield</span> <span class="n">hold</span><span class="p">,</span> <span class="bp">self</span><span class="p">,</span> <span class="n">day</span>
<span class="n">dd</span> <span class="o">=</span> <span class="n">normalvariate</span><span class="p">(</span><span class="mf">1.20</span><span class="p">,</span> <span class="mf">0.20</span><span class="p">)</span> <span class="c"># today's random demand</span>
<span class="n">ds</span> <span class="o">=</span> <span class="n">dd</span> <span class="o">-</span> <span class="n">stock</span><span class="o">.</span><span class="n">amount</span>
<span class="c"># excess of demand over current stock amount</span>
<span class="k">if</span> <span class="n">dd</span> <span class="o">></span> <span class="n">stock</span><span class="o">.</span><span class="n">amount</span><span class="p">:</span> <span class="c"># can't supply requested amount</span>
<span class="k">yield</span> <span class="n">get</span><span class="p">,</span> <span class="bp">self</span><span class="p">,</span> <span class="n">stock</span><span class="p">,</span> <span class="n">stock</span><span class="o">.</span><span class="n">amount</span>
<span class="c"># supply all available amount</span>
<span class="bp">self</span><span class="o">.</span><span class="n">stockout</span> <span class="o">+=</span> <span class="n">ds</span>
<span class="c"># add unsupplied demand to self.stockout</span>
<span class="k">print</span><span class="p">(</span><span class="s">'day </span><span class="si">%6.4f</span><span class="s">, demand = </span><span class="si">%6.4f</span><span class="s">, shortfall = </span><span class="si">%6.4f</span><span class="s">'</span> <span class="o">%</span>
<span class="p">(</span><span class="n">now</span><span class="p">(),</span> <span class="n">dd</span><span class="p">,</span> <span class="o">-</span><span class="n">ds</span><span class="p">))</span>
<span class="k">else</span><span class="p">:</span> <span class="c"># can supply requested amount</span>
<span class="k">yield</span> <span class="n">get</span><span class="p">,</span> <span class="bp">self</span><span class="p">,</span> <span class="n">stock</span><span class="p">,</span> <span class="n">dd</span>
<span class="k">print</span><span class="p">(</span><span class="s">'day </span><span class="si">%6.4f</span><span class="s">, supplied </span><span class="si">%6.4f</span><span class="s">, now amount = </span><span class="si">%6.4f</span><span class="s">'</span> <span class="o">%</span>
<span class="p">(</span><span class="n">now</span><span class="p">(),</span> <span class="n">dd</span><span class="p">,</span> <span class="n">stock</span><span class="o">.</span><span class="n">amount</span><span class="p">))</span>
<span class="n">stock</span> <span class="o">=</span> <span class="n">Level</span><span class="p">(</span><span class="n">monitored</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span> <span class="c"># 'unbounded' capacity and other defaults</span>
<span class="n">seed</span><span class="p">(</span><span class="mi">99999</span><span class="p">)</span>
<span class="n">initialize</span><span class="p">()</span>
<span class="n">offeror</span> <span class="o">=</span> <span class="n">Deliver</span><span class="p">()</span>
<span class="n">activate</span><span class="p">(</span><span class="n">offeror</span><span class="p">,</span> <span class="n">offeror</span><span class="o">.</span><span class="n">deliver</span><span class="p">())</span>
<span class="n">requester</span> <span class="o">=</span> <span class="n">Demand</span><span class="p">()</span>
<span class="n">activate</span><span class="p">(</span><span class="n">requester</span><span class="p">,</span> <span class="n">requester</span><span class="o">.</span><span class="n">demand</span><span class="p">())</span>
<span class="n">simulate</span><span class="p">(</span><span class="n">until</span><span class="o">=</span><span class="mf">49.9</span><span class="p">)</span>
<span class="n">result</span> <span class="o">=</span> <span class="p">(</span><span class="n">stock</span><span class="o">.</span><span class="n">bufferMon</span><span class="o">.</span><span class="n">mean</span><span class="p">(),</span> <span class="n">requester</span><span class="o">.</span><span class="n">stockout</span><span class="p">)</span>
<span class="k">print</span><span class="p">(</span><span class="s">''</span><span class="p">)</span>
<span class="k">print</span><span class="p">(</span><span class="s">'Summary of results through end of day </span><span class="si">%6.4f</span><span class="s">:'</span> <span class="o">%</span> <span class="nb">int</span><span class="p">(</span><span class="n">now</span><span class="p">()))</span>
<span class="k">print</span><span class="p">(</span><span class="s">'average stock = </span><span class="si">%6.4f</span><span class="s">, cumulative stockout = </span><span class="si">%6.4f</span><span class="s">'</span> <span class="o">%</span> <span class="n">result</span><span class="p">)</span>
</pre></div>
</div>
<p>Output:</p>
<div class="highlight-python"><pre>at 0.0000, add 10.0000 units, now amount = 10.0000
day 1.0000, supplied 1.0115, now amount = 8.9885
day 2.0000, supplied 1.1377, now amount = 7.8508
day 3.0000, supplied 0.7743, now amount = 7.0766
day 4.0000, supplied 1.4056, now amount = 5.6709
day 5.0000, supplied 0.9736, now amount = 4.6973
day 6.0000, supplied 1.1061, now amount = 3.5912
day 7.0000, supplied 1.4067, now amount = 2.1845
day 8.0000, supplied 1.2884, now amount = 0.8961
day 9.0000, demand = 1.4426, shortfall = -0.5465
at 10.0000, add 10.0000 units, now amount = 10.0000
day 10.0000, supplied 1.5850, now amount = 8.4150
day 11.0000, supplied 0.7974, now amount = 7.6176
day 12.0000, supplied 0.8854, now amount = 6.7323
day 13.0000, supplied 1.4893, now amount = 5.2430
day 14.0000, supplied 1.0522, now amount = 4.1908
day 15.0000, supplied 1.0492, now amount = 3.1416
day 16.0000, supplied 1.2013, now amount = 1.9403
day 17.0000, supplied 1.4026, now amount = 0.5377
day 18.0000, demand = 1.0874, shortfall = -0.5497
day 19.0000, demand = 1.3043, shortfall = -1.3043
at 20.0000, add 10.0000 units, now amount = 10.0000
day 20.0000, supplied 1.2737, now amount = 8.7263
day 21.0000, supplied 0.9550, now amount = 7.7713
day 22.0000, supplied 1.3646, now amount = 6.4067
day 23.0000, supplied 0.8629, now amount = 5.5438
day 24.0000, supplied 1.2893, now amount = 4.2545
day 25.0000, supplied 1.1897, now amount = 3.0648
day 26.0000, supplied 0.9708, now amount = 2.0940
day 27.0000, supplied 1.1397, now amount = 0.9543
day 28.0000, demand = 1.1286, shortfall = -0.1743
day 29.0000, demand = 0.8891, shortfall = -0.8891
at 30.0000, add 10.0000 units, now amount = 10.0000
day 30.0000, supplied 0.9496, now amount = 9.0504
day 31.0000, supplied 1.1515, now amount = 7.8988
day 32.0000, supplied 1.3724, now amount = 6.5264
day 33.0000, supplied 0.6977, now amount = 5.8287
day 34.0000, supplied 1.2291, now amount = 4.5996
day 35.0000, supplied 1.3502, now amount = 3.2494
day 36.0000, supplied 1.0396, now amount = 2.2098
day 37.0000, supplied 1.3442, now amount = 0.8656
day 38.0000, demand = 1.0919, shortfall = -0.2263
day 39.0000, demand = 1.4077, shortfall = -1.4077
at 40.0000, add 10.0000 units, now amount = 10.0000
day 40.0000, supplied 0.9053, now amount = 9.0947
day 41.0000, supplied 1.2982, now amount = 7.7965
day 42.0000, supplied 1.3458, now amount = 6.4508
day 43.0000, supplied 1.2357, now amount = 5.2151
day 44.0000, supplied 1.2822, now amount = 3.9329
day 45.0000, supplied 1.1809, now amount = 2.7519
day 46.0000, supplied 1.0891, now amount = 1.6629
day 47.0000, supplied 1.1926, now amount = 0.4702
day 48.0000, demand = 1.3927, shortfall = -0.9224
day 49.0000, demand = 1.2690, shortfall = -1.2690
Summary of results through end of day 49.0000:
average stock = 4.4581, cumulative stockout = 7.2894
</pre>
</div>
</div>
<div class="section" id="message">
<h2>Message<a class="headerlink" href="#message" title="Permalink to this headline">¶</a></h2>
<div class="highlight-python" id="index-8"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">SimPy.Simulation</span> <span class="kn">import</span> <span class="n">Process</span><span class="p">,</span> <span class="n">activate</span><span class="p">,</span> <span class="n">initialize</span><span class="p">,</span> <span class="n">hold</span><span class="p">,</span> <span class="n">now</span><span class="p">,</span> <span class="n">simulate</span>
<span class="k">class</span> <span class="nc">Message</span><span class="p">(</span><span class="n">Process</span><span class="p">):</span>
<span class="sd">"""A simple Process"""</span>
<span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">i</span><span class="p">,</span> <span class="nb">len</span><span class="p">):</span>
<span class="n">Process</span><span class="o">.</span><span class="n">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s">'Message'</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">i</span><span class="p">))</span>
<span class="bp">self</span><span class="o">.</span><span class="n">i</span> <span class="o">=</span> <span class="n">i</span>
<span class="bp">self</span><span class="o">.</span><span class="n">len</span> <span class="o">=</span> <span class="nb">len</span>
<span class="k">def</span> <span class="nf">go</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">print</span><span class="p">(</span><span class="s">'</span><span class="si">%s</span><span class="s"> </span><span class="si">%s</span><span class="s"> </span><span class="si">%s</span><span class="s">'</span> <span class="o">%</span> <span class="p">(</span><span class="n">now</span><span class="p">(),</span> <span class="bp">self</span><span class="o">.</span><span class="n">i</span><span class="p">,</span> <span class="s">'Starting'</span><span class="p">))</span>
<span class="k">yield</span> <span class="n">hold</span><span class="p">,</span> <span class="bp">self</span><span class="p">,</span> <span class="mf">100.0</span>
<span class="k">print</span><span class="p">(</span><span class="s">'</span><span class="si">%s</span><span class="s"> </span><span class="si">%s</span><span class="s"> </span><span class="si">%s</span><span class="s">'</span> <span class="o">%</span> <span class="p">(</span><span class="n">now</span><span class="p">(),</span> <span class="bp">self</span><span class="o">.</span><span class="n">i</span><span class="p">,</span> <span class="s">'Arrived'</span><span class="p">))</span>
<span class="n">initialize</span><span class="p">()</span>
<span class="n">p1</span> <span class="o">=</span> <span class="n">Message</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">203</span><span class="p">)</span> <span class="c"># new message</span>
<span class="n">activate</span><span class="p">(</span><span class="n">p1</span><span class="p">,</span> <span class="n">p1</span><span class="o">.</span><span class="n">go</span><span class="p">())</span> <span class="c"># activate it</span>
<span class="n">p2</span> <span class="o">=</span> <span class="n">Message</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">33</span><span class="p">)</span>
<span class="n">activate</span><span class="p">(</span><span class="n">p2</span><span class="p">,</span> <span class="n">p2</span><span class="o">.</span><span class="n">go</span><span class="p">(),</span> <span class="n">at</span><span class="o">=</span><span class="mf">6.0</span><span class="p">)</span>
<span class="n">simulate</span><span class="p">(</span><span class="n">until</span><span class="o">=</span><span class="mi">200</span><span class="p">)</span>
<span class="k">print</span><span class="p">(</span><span class="s">'Current time is </span><span class="si">%s</span><span class="s">'</span> <span class="o">%</span> <span class="n">now</span><span class="p">())</span> <span class="c"># will print 106.0</span>
</pre></div>
</div>
<p>Output:</p>
<div class="highlight-python"><pre>0 1 Starting
6.0 2 Starting
100.0 1 Arrived
106.0 2 Arrived
Current time is 106.0
</pre>
</div>
</div>
<div class="section" id="resource">
<h2>Resource<a class="headerlink" href="#resource" title="Permalink to this headline">¶</a></h2>
<div class="highlight-python" id="index-9"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">SimPy.Simulation</span> <span class="kn">import</span> <span class="p">(</span><span class="n">Process</span><span class="p">,</span> <span class="n">Resource</span><span class="p">,</span> <span class="n">activate</span><span class="p">,</span> <span class="n">initialize</span><span class="p">,</span> <span class="n">hold</span><span class="p">,</span>
<span class="n">now</span><span class="p">,</span> <span class="n">release</span><span class="p">,</span> <span class="n">request</span><span class="p">,</span> <span class="n">simulate</span><span class="p">)</span>
<span class="k">class</span> <span class="nc">Client</span><span class="p">(</span><span class="n">Process</span><span class="p">):</span>
<span class="n">inClients</span> <span class="o">=</span> <span class="p">[]</span> <span class="c"># list the clients in order by their requests</span>
<span class="n">outClients</span> <span class="o">=</span> <span class="p">[]</span> <span class="c"># list the clients in order by completion of service</span>
<span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">):</span>
<span class="n">Process</span><span class="o">.</span><span class="n">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">getserved</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">servtime</span><span class="p">,</span> <span class="n">priority</span><span class="p">,</span> <span class="n">myServer</span><span class="p">):</span>
<span class="n">Client</span><span class="o">.</span><span class="n">inClients</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
<span class="k">print</span><span class="p">(</span><span class="s">'</span><span class="si">%s</span><span class="s"> requests 1 unit at t = </span><span class="si">%s</span><span class="s">'</span> <span class="o">%</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="n">now</span><span class="p">()))</span>
<span class="c"># request use of a resource unit</span>
<span class="k">yield</span> <span class="n">request</span><span class="p">,</span> <span class="bp">self</span><span class="p">,</span> <span class="n">myServer</span><span class="p">,</span> <span class="n">priority</span>
<span class="k">yield</span> <span class="n">hold</span><span class="p">,</span> <span class="bp">self</span><span class="p">,</span> <span class="n">servtime</span>
<span class="c"># release the resource</span>
<span class="k">yield</span> <span class="n">release</span><span class="p">,</span> <span class="bp">self</span><span class="p">,</span> <span class="n">myServer</span>
<span class="k">print</span><span class="p">(</span><span class="s">'</span><span class="si">%s</span><span class="s"> done at t = </span><span class="si">%s</span><span class="s">'</span> <span class="o">%</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="n">now</span><span class="p">()))</span>
<span class="n">Client</span><span class="o">.</span><span class="n">outClients</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
<span class="n">initialize</span><span class="p">()</span>
<span class="c"># the next line creates the ``server`` Resource object</span>
<span class="n">server</span> <span class="o">=</span> <span class="n">Resource</span><span class="p">(</span><span class="n">capacity</span><span class="o">=</span><span class="mi">2</span><span class="p">)</span> <span class="c"># server defaults to qType==FIFO</span>
<span class="c"># the next lines create some Client process objects</span>
<span class="n">c1</span><span class="p">,</span> <span class="n">c2</span> <span class="o">=</span> <span class="n">Client</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s">'c1'</span><span class="p">),</span> <span class="n">Client</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s">'c2'</span><span class="p">)</span>
<span class="n">c3</span><span class="p">,</span> <span class="n">c4</span> <span class="o">=</span> <span class="n">Client</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s">'c3'</span><span class="p">),</span> <span class="n">Client</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s">'c4'</span><span class="p">)</span>
<span class="n">c5</span><span class="p">,</span> <span class="n">c6</span> <span class="o">=</span> <span class="n">Client</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s">'c5'</span><span class="p">),</span> <span class="n">Client</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s">'c6'</span><span class="p">)</span>
<span class="c"># in the next lines each client requests</span>
<span class="c"># one of the ``server``'s Resource units</span>
<span class="n">activate</span><span class="p">(</span><span class="n">c1</span><span class="p">,</span> <span class="n">c1</span><span class="o">.</span><span class="n">getserved</span><span class="p">(</span><span class="n">servtime</span><span class="o">=</span><span class="mi">100</span><span class="p">,</span> <span class="n">priority</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">myServer</span><span class="o">=</span><span class="n">server</span><span class="p">))</span>
<span class="n">activate</span><span class="p">(</span><span class="n">c2</span><span class="p">,</span> <span class="n">c2</span><span class="o">.</span><span class="n">getserved</span><span class="p">(</span><span class="n">servtime</span><span class="o">=</span><span class="mi">100</span><span class="p">,</span> <span class="n">priority</span><span class="o">=</span><span class="mi">2</span><span class="p">,</span> <span class="n">myServer</span><span class="o">=</span><span class="n">server</span><span class="p">))</span>
<span class="n">activate</span><span class="p">(</span><span class="n">c3</span><span class="p">,</span> <span class="n">c3</span><span class="o">.</span><span class="n">getserved</span><span class="p">(</span><span class="n">servtime</span><span class="o">=</span><span class="mi">100</span><span class="p">,</span> <span class="n">priority</span><span class="o">=</span><span class="mi">3</span><span class="p">,</span> <span class="n">myServer</span><span class="o">=</span><span class="n">server</span><span class="p">))</span>
<span class="n">activate</span><span class="p">(</span><span class="n">c4</span><span class="p">,</span> <span class="n">c4</span><span class="o">.</span><span class="n">getserved</span><span class="p">(</span><span class="n">servtime</span><span class="o">=</span><span class="mi">100</span><span class="p">,</span> <span class="n">priority</span><span class="o">=</span><span class="mi">4</span><span class="p">,</span> <span class="n">myServer</span><span class="o">=</span><span class="n">server</span><span class="p">))</span>
<span class="n">activate</span><span class="p">(</span><span class="n">c5</span><span class="p">,</span> <span class="n">c5</span><span class="o">.</span><span class="n">getserved</span><span class="p">(</span><span class="n">servtime</span><span class="o">=</span><span class="mi">100</span><span class="p">,</span> <span class="n">priority</span><span class="o">=</span><span class="mi">5</span><span class="p">,</span> <span class="n">myServer</span><span class="o">=</span><span class="n">server</span><span class="p">))</span>
<span class="n">activate</span><span class="p">(</span><span class="n">c6</span><span class="p">,</span> <span class="n">c6</span><span class="o">.</span><span class="n">getserved</span><span class="p">(</span><span class="n">servtime</span><span class="o">=</span><span class="mi">100</span><span class="p">,</span> <span class="n">priority</span><span class="o">=</span><span class="mi">6</span><span class="p">,</span> <span class="n">myServer</span><span class="o">=</span><span class="n">server</span><span class="p">))</span>
<span class="n">simulate</span><span class="p">(</span><span class="n">until</span><span class="o">=</span><span class="mi">500</span><span class="p">)</span>
<span class="k">print</span><span class="p">(</span><span class="s">'Request order: </span><span class="si">%s</span><span class="s">'</span> <span class="o">%</span> <span class="n">Client</span><span class="o">.</span><span class="n">inClients</span><span class="p">)</span>
<span class="k">print</span><span class="p">(</span><span class="s">'Service order: </span><span class="si">%s</span><span class="s">'</span> <span class="o">%</span> <span class="n">Client</span><span class="o">.</span><span class="n">outClients</span><span class="p">)</span>
</pre></div>
</div>
<p>Output:</p>
<div class="highlight-python"><pre>c1 requests 1 unit at t = 0
c2 requests 1 unit at t = 0
c3 requests 1 unit at t = 0
c4 requests 1 unit at t = 0
c5 requests 1 unit at t = 0
c6 requests 1 unit at t = 0
c1 done at t = 100
c2 done at t = 100
c3 done at t = 200
c4 done at t = 200
c5 done at t = 300
c6 done at t = 300
Request order: ['c1', 'c2', 'c3', 'c4', 'c5', 'c6']
Service order: ['c1', 'c2', 'c3', 'c4', 'c5', 'c6']
</pre>
</div>
</div>
<div class="section" id="resource-monitor">
<h2>Resource monitor<a class="headerlink" href="#resource-monitor" title="Permalink to this headline">¶</a></h2>
<div class="highlight-python" id="index-10"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">math</span> <span class="kn">import</span> <span class="n">sqrt</span>
<span class="kn">from</span> <span class="nn">SimPy.Simulation</span> <span class="kn">import</span> <span class="p">(</span><span class="n">Monitor</span><span class="p">,</span> <span class="n">Process</span><span class="p">,</span> <span class="n">Resource</span><span class="p">,</span> <span class="n">activate</span><span class="p">,</span> <span class="n">initialize</span><span class="p">,</span>
<span class="n">hold</span><span class="p">,</span> <span class="n">now</span><span class="p">,</span> <span class="n">release</span><span class="p">,</span> <span class="n">request</span><span class="p">,</span> <span class="n">simulate</span><span class="p">)</span>
<span class="k">class</span> <span class="nc">Client</span><span class="p">(</span><span class="n">Process</span><span class="p">):</span>
<span class="n">inClients</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">outClients</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">):</span>
<span class="n">Process</span><span class="o">.</span><span class="n">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">getserved</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">servtime</span><span class="p">,</span> <span class="n">myServer</span><span class="p">):</span>
<span class="k">print</span><span class="p">(</span><span class="s">'</span><span class="si">%s</span><span class="s"> requests 1 unit at t = </span><span class="si">%s</span><span class="s">'</span> <span class="o">%</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="n">now</span><span class="p">()))</span>
<span class="k">yield</span> <span class="n">request</span><span class="p">,</span> <span class="bp">self</span><span class="p">,</span> <span class="n">myServer</span>
<span class="k">yield</span> <span class="n">hold</span><span class="p">,</span> <span class="bp">self</span><span class="p">,</span> <span class="n">servtime</span>
<span class="k">yield</span> <span class="n">release</span><span class="p">,</span> <span class="bp">self</span><span class="p">,</span> <span class="n">myServer</span>
<span class="k">print</span><span class="p">(</span><span class="s">'</span><span class="si">%s</span><span class="s"> done at t = </span><span class="si">%s</span><span class="s">'</span> <span class="o">%</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="n">now</span><span class="p">()))</span>
<span class="n">initialize</span><span class="p">()</span>
<span class="n">server</span> <span class="o">=</span> <span class="n">Resource</span><span class="p">(</span><span class="n">capacity</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">monitored</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span> <span class="n">monitorType</span><span class="o">=</span><span class="n">Monitor</span><span class="p">)</span>
<span class="n">c1</span><span class="p">,</span> <span class="n">c2</span> <span class="o">=</span> <span class="n">Client</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s">'c1'</span><span class="p">),</span> <span class="n">Client</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s">'c2'</span><span class="p">)</span>
<span class="n">c3</span><span class="p">,</span> <span class="n">c4</span> <span class="o">=</span> <span class="n">Client</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s">'c3'</span><span class="p">),</span> <span class="n">Client</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s">'c4'</span><span class="p">)</span>
<span class="n">activate</span><span class="p">(</span><span class="n">c1</span><span class="p">,</span> <span class="n">c1</span><span class="o">.</span><span class="n">getserved</span><span class="p">(</span><span class="n">servtime</span><span class="o">=</span><span class="mi">100</span><span class="p">,</span> <span class="n">myServer</span><span class="o">=</span><span class="n">server</span><span class="p">))</span>
<span class="n">activate</span><span class="p">(</span><span class="n">c2</span><span class="p">,</span> <span class="n">c2</span><span class="o">.</span><span class="n">getserved</span><span class="p">(</span><span class="n">servtime</span><span class="o">=</span><span class="mi">100</span><span class="p">,</span> <span class="n">myServer</span><span class="o">=</span><span class="n">server</span><span class="p">))</span>
<span class="n">activate</span><span class="p">(</span><span class="n">c3</span><span class="p">,</span> <span class="n">c3</span><span class="o">.</span><span class="n">getserved</span><span class="p">(</span><span class="n">servtime</span><span class="o">=</span><span class="mi">100</span><span class="p">,</span> <span class="n">myServer</span><span class="o">=</span><span class="n">server</span><span class="p">))</span>
<span class="n">activate</span><span class="p">(</span><span class="n">c4</span><span class="p">,</span> <span class="n">c4</span><span class="o">.</span><span class="n">getserved</span><span class="p">(</span><span class="n">servtime</span><span class="o">=</span><span class="mi">100</span><span class="p">,</span> <span class="n">myServer</span><span class="o">=</span><span class="n">server</span><span class="p">))</span>
<span class="n">simulate</span><span class="p">(</span><span class="n">until</span><span class="o">=</span><span class="mi">500</span><span class="p">)</span>
<span class="k">print</span><span class="p">(</span><span class="s">''</span><span class="p">)</span>
<span class="k">print</span><span class="p">(</span><span class="s">'(TimeAverage no. waiting: </span><span class="si">%s</span><span class="s">'</span> <span class="o">%</span> <span class="n">server</span><span class="o">.</span><span class="n">waitMon</span><span class="o">.</span><span class="n">timeAverage</span><span class="p">())</span>
<span class="k">print</span><span class="p">(</span><span class="s">'(Number) Average no. waiting: </span><span class="si">%.4f</span><span class="s">'</span> <span class="o">%</span> <span class="n">server</span><span class="o">.</span><span class="n">waitMon</span><span class="o">.</span><span class="n">mean</span><span class="p">())</span>
<span class="k">print</span><span class="p">(</span><span class="s">'(Number) Var of no. waiting: </span><span class="si">%.4f</span><span class="s">'</span> <span class="o">%</span> <span class="n">server</span><span class="o">.</span><span class="n">waitMon</span><span class="o">.</span><span class="n">var</span><span class="p">())</span>
<span class="k">print</span><span class="p">(</span><span class="s">'(Number) SD of no. waiting: </span><span class="si">%.4f</span><span class="s">'</span> <span class="o">%</span> <span class="n">sqrt</span><span class="p">(</span><span class="n">server</span><span class="o">.</span><span class="n">waitMon</span><span class="o">.</span><span class="n">var</span><span class="p">()))</span>
<span class="k">print</span><span class="p">(</span><span class="s">'(TimeAverage no. in service: </span><span class="si">%s</span><span class="s">'</span> <span class="o">%</span> <span class="n">server</span><span class="o">.</span><span class="n">actMon</span><span class="o">.</span><span class="n">timeAverage</span><span class="p">())</span>
<span class="k">print</span><span class="p">(</span><span class="s">'(Number) Average no. in service: </span><span class="si">%.4f</span><span class="s">'</span> <span class="o">%</span> <span class="n">server</span><span class="o">.</span><span class="n">actMon</span><span class="o">.</span><span class="n">mean</span><span class="p">())</span>
<span class="k">print</span><span class="p">(</span><span class="s">'(Number) Var of no. in service: </span><span class="si">%.4f</span><span class="s">'</span> <span class="o">%</span> <span class="n">server</span><span class="o">.</span><span class="n">actMon</span><span class="o">.</span><span class="n">var</span><span class="p">())</span>
<span class="k">print</span><span class="p">(</span><span class="s">'(Number) SD of no. in service: </span><span class="si">%.4f</span><span class="s">'</span> <span class="o">%</span> <span class="n">sqrt</span><span class="p">(</span><span class="n">server</span><span class="o">.</span><span class="n">actMon</span><span class="o">.</span><span class="n">var</span><span class="p">()))</span>
<span class="k">print</span><span class="p">(</span><span class="s">'='</span> <span class="o">*</span> <span class="mi">40</span><span class="p">)</span>
<span class="k">print</span><span class="p">(</span><span class="s">'Time history for the "server" waitQ:'</span><span class="p">)</span>
<span class="k">print</span><span class="p">(</span><span class="s">'[time, waitQ]'</span><span class="p">)</span>
<span class="k">for</span> <span class="n">item</span> <span class="ow">in</span> <span class="n">server</span><span class="o">.</span><span class="n">waitMon</span><span class="p">:</span>
<span class="k">print</span><span class="p">(</span><span class="n">item</span><span class="p">)</span>
<span class="k">print</span><span class="p">(</span><span class="s">'='</span> <span class="o">*</span> <span class="mi">40</span><span class="p">)</span>
<span class="k">print</span><span class="p">(</span><span class="s">'Time history for the "server" activeQ:'</span><span class="p">)</span>
<span class="k">print</span><span class="p">(</span><span class="s">'[time, activeQ]'</span><span class="p">)</span>
<span class="k">for</span> <span class="n">item</span> <span class="ow">in</span> <span class="n">server</span><span class="o">.</span><span class="n">actMon</span><span class="p">:</span>
<span class="k">print</span><span class="p">(</span><span class="n">item</span><span class="p">)</span>
</pre></div>
</div>
<p>Output:</p>
<div class="highlight-python"><pre>c1 requests 1 unit at t = 0
c2 requests 1 unit at t = 0
c3 requests 1 unit at t = 0
c4 requests 1 unit at t = 0
c1 done at t = 100
c2 done at t = 200
c3 done at t = 300
c4 done at t = 400
(TimeAverage no. waiting: 1.5
(Number) Average no. waiting: 1.2857
(Number) Var of no. waiting: 1.0612
(Number) SD of no. waiting: 1.0302
(TimeAverage no. in service: 1.0
(Number) Average no. in service: 0.4444
(Number) Var of no. in service: 0.2469
(Number) SD of no. in service: 0.4969
========================================
Time history for the "server" waitQ:
[time, waitQ]
[0, 0]
[0, 1]
[0, 2]
[0, 3]
[100, 2]
[200, 1]
[300, 0]
========================================
Time history for the "server" activeQ:
[time, activeQ]
[0, 0]
[0, 1]
[100, 0]
[100, 1]
[200, 0]
[200, 1]
[300, 0]
[300, 1]
[400, 0]
</pre>
</div>
</div>
<div class="section" id="shopping">
<h2>Shopping<a class="headerlink" href="#shopping" title="Permalink to this headline">¶</a></h2>
<div class="highlight-python" id="index-11"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">SimPy.Simulation</span> <span class="kn">import</span> <span class="n">Process</span><span class="p">,</span> <span class="n">activate</span><span class="p">,</span> <span class="n">hold</span><span class="p">,</span> <span class="n">initialize</span><span class="p">,</span> <span class="n">simulate</span>
<span class="k">class</span> <span class="nc">Customer</span><span class="p">(</span><span class="n">Process</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">buy</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">budget</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>
<span class="k">print</span><span class="p">(</span><span class="s">'Here I am at the shops </span><span class="si">%s</span><span class="s">'</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
<span class="n">t</span> <span class="o">=</span> <span class="mf">5.0</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">4</span><span class="p">):</span>
<span class="k">yield</span> <span class="n">hold</span><span class="p">,</span> <span class="bp">self</span><span class="p">,</span> <span class="n">t</span>
<span class="c"># executed 4 times at intervals of t time units</span>
<span class="k">print</span><span class="p">(</span><span class="s">'I just bought something </span><span class="si">%s</span><span class="s">'</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
<span class="n">budget</span> <span class="o">-=</span> <span class="mf">10.00</span>
<span class="k">print</span><span class="p">(</span><span class="s">'All I have left is </span><span class="si">%s</span><span class="s"> I am going home </span><span class="si">%s</span><span class="s">'</span> <span class="o">%</span> <span class="p">(</span><span class="n">budget</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">))</span>
<span class="n">initialize</span><span class="p">()</span>
<span class="c"># create a customer named "Evelyn",</span>
<span class="n">C</span> <span class="o">=</span> <span class="n">Customer</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s">'Evelyn'</span><span class="p">)</span>
<span class="c"># and activate her with a budget of 100</span>
<span class="n">activate</span><span class="p">(</span><span class="n">C</span><span class="p">,</span> <span class="n">C</span><span class="o">.</span><span class="n">buy</span><span class="p">(</span><span class="n">budget</span><span class="o">=</span><span class="mi">100</span><span class="p">),</span> <span class="n">at</span><span class="o">=</span><span class="mf">10.0</span><span class="p">)</span>
<span class="n">simulate</span><span class="p">(</span><span class="n">until</span><span class="o">=</span><span class="mf">100.0</span><span class="p">)</span>
</pre></div>
</div>
<p>Output:</p>
<div class="highlight-python"><pre>Here I am at the shops Evelyn
I just bought something Evelyn
I just bought something Evelyn
I just bought something Evelyn
I just bought something Evelyn
All I have left is 60.0 I am going home Evelyn
</pre>
</div>
</div>
<div class="section" id="storewidget">
<h2>Storewidget<a class="headerlink" href="#storewidget" title="Permalink to this headline">¶</a></h2>
<div class="highlight-python" id="index-12"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">SimPy.Simulation</span> <span class="kn">import</span> <span class="p">(</span><span class="n">Lister</span><span class="p">,</span> <span class="n">Process</span><span class="p">,</span> <span class="n">Store</span><span class="p">,</span> <span class="n">activate</span><span class="p">,</span> <span class="n">get</span><span class="p">,</span> <span class="n">hold</span><span class="p">,</span>
<span class="n">initialize</span><span class="p">,</span> <span class="n">now</span><span class="p">,</span> <span class="n">put</span><span class="p">,</span> <span class="n">simulate</span><span class="p">)</span>
<span class="k">class</span> <span class="nc">ProducerD</span><span class="p">(</span><span class="n">Process</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="n">Process</span><span class="o">.</span><span class="n">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">produce</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> <span class="c"># the ProducerD PEM</span>
<span class="k">while</span> <span class="bp">True</span><span class="p">:</span>
<span class="k">yield</span> <span class="n">put</span><span class="p">,</span> <span class="bp">self</span><span class="p">,</span> <span class="n">buf</span><span class="p">,</span> <span class="p">[</span><span class="n">Widget</span><span class="p">(</span><span class="mi">9</span><span class="p">),</span> <span class="n">Widget</span><span class="p">(</span><span class="mi">7</span><span class="p">)]</span>
<span class="k">yield</span> <span class="n">hold</span><span class="p">,</span> <span class="bp">self</span><span class="p">,</span> <span class="mi">10</span>
<span class="k">class</span> <span class="nc">ConsumerD</span><span class="p">(</span><span class="n">Process</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="n">Process</span><span class="o">.</span><span class="n">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">consume</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> <span class="c"># the ConsumerD PEM</span>
<span class="k">while</span> <span class="bp">True</span><span class="p">:</span>
<span class="n">toGet</span> <span class="o">=</span> <span class="mi">3</span>
<span class="k">yield</span> <span class="n">get</span><span class="p">,</span> <span class="bp">self</span><span class="p">,</span> <span class="n">buf</span><span class="p">,</span> <span class="n">toGet</span>
<span class="k">assert</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">got</span><span class="p">)</span> <span class="o">==</span> <span class="n">toGet</span>
<span class="k">print</span><span class="p">(</span><span class="s">'</span><span class="si">%s</span><span class="s"> Get widget weights </span><span class="si">%s</span><span class="s">'</span> <span class="o">%</span> <span class="p">(</span><span class="n">now</span><span class="p">(),</span>
<span class="p">[</span><span class="n">x</span><span class="o">.</span><span class="n">weight</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">got</span><span class="p">]))</span>
<span class="k">yield</span> <span class="n">hold</span><span class="p">,</span> <span class="bp">self</span><span class="p">,</span> <span class="mi">11</span>
<span class="k">class</span> <span class="nc">Widget</span><span class="p">(</span><span class="n">Lister</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">weight</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">weight</span> <span class="o">=</span> <span class="n">weight</span>
<span class="n">widgbuf</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">10</span><span class="p">):</span>
<span class="n">widgbuf</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">Widget</span><span class="p">(</span><span class="mi">5</span><span class="p">))</span>
<span class="n">initialize</span><span class="p">()</span>
<span class="n">buf</span> <span class="o">=</span> <span class="n">Store</span><span class="p">(</span><span class="n">capacity</span><span class="o">=</span><span class="mi">11</span><span class="p">,</span> <span class="n">initialBuffered</span><span class="o">=</span><span class="n">widgbuf</span><span class="p">,</span> <span class="n">monitored</span><span class="o">=</span><span class="bp">True</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">3</span><span class="p">):</span> <span class="c"># define and activate 3 producer objects</span>
<span class="n">p</span> <span class="o">=</span> <span class="n">ProducerD</span><span class="p">()</span>
<span class="n">activate</span><span class="p">(</span><span class="n">p</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">produce</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">3</span><span class="p">):</span> <span class="c"># define and activate 3 consumer objects</span>
<span class="n">c</span> <span class="o">=</span> <span class="n">ConsumerD</span><span class="p">()</span>
<span class="n">activate</span><span class="p">(</span><span class="n">c</span><span class="p">,</span> <span class="n">c</span><span class="o">.</span><span class="n">consume</span><span class="p">())</span>
<span class="n">simulate</span><span class="p">(</span><span class="n">until</span><span class="o">=</span><span class="mi">50</span><span class="p">)</span>
<span class="k">print</span><span class="p">(</span><span class="s">'LenBuffer: </span><span class="si">%s</span><span class="s">'</span> <span class="o">%</span> <span class="n">buf</span><span class="o">.</span><span class="n">bufferMon</span><span class="p">)</span> <span class="c"># length of buffer</span>
<span class="k">print</span><span class="p">(</span><span class="s">'getQ: </span><span class="si">%s</span><span class="s">'</span> <span class="o">%</span> <span class="n">buf</span><span class="o">.</span><span class="n">getQMon</span><span class="p">)</span> <span class="c"># length of getQ</span>
<span class="k">print</span><span class="p">(</span><span class="s">'putQ </span><span class="si">%s</span><span class="s">'</span> <span class="o">%</span> <span class="n">buf</span><span class="o">.</span><span class="n">putQMon</span><span class="p">)</span> <span class="c"># length of putQ</span>
</pre></div>
</div>
<p>Output:</p>
<div class="highlight-python"><pre>0 Get widget weights [5, 5, 5]
0 Get widget weights [5, 5, 5]
0 Get widget weights [5, 5, 5]
11 Get widget weights [5, 9, 7]
11 Get widget weights [9, 7, 9]
11 Get widget weights [7, 9, 7]
22 Get widget weights [9, 7, 9]
22 Get widget weights [7, 9, 7]
22 Get widget weights [9, 7, 9]
33 Get widget weights [7, 9, 7]
33 Get widget weights [9, 7, 9]
40 Get widget weights [7, 9, 7]
44 Get widget weights [9, 7, 9]
50 Get widget weights [7, 9, 7]
LenBuffer: [[0, 10], [0, 7], [0, 9], [0, 11], [0, 8], [0, 10], [0, 7], [10, 9], [10, 11], [11, 8], [11, 10], [11, 7], [11, 4], [20, 6], [20, 8], [21, 10], [22, 7], [22, 4], [22, 1], [30, 3], [30, 5], [31, 7], [33, 4], [33, 1], [40, 3], [40, 0], [40, 2], [41, 4], [44, 1], [50, 3], [50, 0], [50, 2]]
getQ: [[0, 0], [33, 1], [40, 0], [44, 1], [50, 0]]
putQ [[0, 0], [0, 1], [0, 2], [0, 3], [0, 2], [0, 1], [0, 0], [10, 1], [11, 0]]
</pre>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar">
<div class="sphinxsidebarwrapper">
<p class="logo"><a href="../index.html">
<img class="logo" src="../_static/sm_SimPy_Logo.png" alt="Logo"/>
</a></p>
<h3><a href="../index.html">Table Of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">Additional examples</a><ul>
<li><a class="reference internal" href="#car">Car</a></li>
<li><a class="reference internal" href="#cart">CarT</a></li>
<li><a class="reference internal" href="#cars">Cars</a></li>
<li><a class="reference internal" href="#carst">CarsT</a></li>
<li><a class="reference internal" href="#carwash">Carwash</a></li>
<li><a class="reference internal" href="#breakdown">Breakdown</a></li>
<li><a class="reference internal" href="#firework">Firework</a></li>
<li><a class="reference internal" href="#levelinventory">Levelinventory</a></li>
<li><a class="reference internal" href="#message">Message</a></li>
<li><a class="reference internal" href="#resource">Resource</a></li>
<li><a class="reference internal" href="#resource-monitor">Resource monitor</a></li>
<li><a class="reference internal" href="#shopping">Shopping</a></li>
<li><a class="reference internal" href="#storewidget">Storewidget</a></li>
</ul>
</li>
</ul>
<h4>Previous topic</h4>
<p class="topless"><a href="../Cheatsheets.html"
title="previous chapter">Cheatsheets</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="../SimPy_Tutorials.html"
title="next chapter">SimPy Tutorials</a></p>
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../_sources/Manuals/Examples.txt"
rel="nofollow">Show Source</a></li>
</ul>
<div id="searchbox" style="display: none">
<h3>Quick search</h3>
<form class="search" action="../search.html" method="get">
<input type="text" name="q" />
<input type="submit" value="Go" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../SimPy_Tutorials.html" title="SimPy Tutorials"
>next</a> |</li>
<li class="right" >
<a href="../Cheatsheets.html" title="Cheatsheets"
>previous</a> |</li>
<li><a href="../index.html">SimPy 2.3.1 documentation</a> »</li>
<li><a href="../Manuals.html" >Manuals</a> »</li>
</ul>
</div>
<div class="footer">
© Copyright 2002-2011, Klaus Müller, Tony Vignaux, Ontje Lünsdorf, Stefan Scherfke.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3.
</div>
</body>
</html>
|