background preloader

eXplorerDemo

SimPy: Simulating Systems in Python by Klaus Müller and Tony Vignaux 02/27/2003 Simulating complex real-world systems is now possible with SimPy , an open source simulation package. SimPy, originally developed by the authors of this article, has been developed to production quality by a small team of enthusiastic open sourcerers around the world. As far as we know, it is the only existing discrete event Python simulation package. Actually, it is one of a very small number of fully object oriented simulation systems. Why consider simulation? To demonstrate using SimPy for simulation we will study a simple scenario. When customers call they may have to wait for a free line. To model "quality of service", we label a customer "happy" or "unhappy" depending on wait time. SimPy Setting up a simulation requires modeling the system under study, capturing the essential entities and their interactions, and then writing code to make the model executable. Simulated entities in SimPy are objects of the Process class. yield hold,self,t

18. Recursion — How to Think Like a Computer Scientist: Learning with Python 3 Recursion means “defining something in terms of itself” usually at some smaller scale, perhaps multiple times, to achieve your objective. For example, we might say “A human being is someone whose mother is a human being”, or “a directory is a structure that holds files and (smaller) directories”, or “a family tree starts with a couple who have children, each with their own family sub-trees”. Programming languages generally support recursion, which means that, in order to solve a problem, functions can call themselves to solve smaller subproblems. 18.1. Drawing Fractals For our purposes, a fractal is a drawing which also has self-similar structure, where it can be defined in terms of itself. Let us start by looking at the famous Koch fractal. An order 1 Koch fractal is obtained like this: instead of drawing just one line, draw instead four smaller segments, in the pattern shown here: Now what would happen if we repeated this Koch pattern again on each of the order 1 segments? 18.2. 18.3.

Related: