Skip to main content

Discrete Event Engine - Python

Following Python Discrete Event Engine (DES) can be use to build many discrete event simulators. It supports any data type or object and is capable of handling large event lists (use binary search to sort events). See source code for details.

Download from git Repo

Usage:
from DES import DES

events = DES()

#Add set of events
#event time, event type, node/customer/server ID, data
events.addEvent(5.5, 'Type1', 1, 'Test data 1')
events.addEvent(3.3, 'Type2', 2, [1, 2, 3, 4])
events.addEvent(1.5, 'Type3', 3, 567890)
events.addEvent(9.9, 'Type4')
events.addEvent(8.6, 'Type3', 1, 'Test data 5')

#remove event
#Provide at least event time & type
events.removeEvent(3.3, 'Type2', 2)

#Get remaining events in chronological order
event = events.getNextEvent()
print event.startTime, event.eventType
event = events.getNextEvent()
print event.startTime, event.eventType
event = events.getNextEvent()
print event.startTime, event.eventType

#Current simulation time
print 'Current time', events.now

event = events.getNextEvent()
print event.startTime, event.eventType
event = events.getNextEvent()
print event #No more events
 
Returns:
1.5 Type3
5.5 Type1
8.6 Type3
Current time 8.6
9.9 Type4
None

Comments

Hilda said…
This is awesome!

Popular posts from this blog

1. Building P2P Simulators with OverSim - Where to Begin

This could be a series of blog posts about extending or developing your own OverSim applications & overlay networks. OverSim has a minimal tutorial on writing your own application & overlay network; however, it doesn't show the big picture. So, I'm wasting lots of time playing with code & trying to understand the rest. Good thing is, I like it more & more as I understand. You need to change/develop only a few things, but finding out which ones is a hell of a task. I hope this will not only make my life easy but also will be useful to new comers. Here's what you need to do: You need some background on OMNeT++ OverSim extend OMNeT++. But sometime it has its own way of doing things (to make your task even simple) so understand the differences . Develop several OMNeT++ simulators. TicToc is a good one to start with. Extend it as you imagine. Read Towards a Common API for Structured Peer-to-Peer Overlays , which is the basis for OvseSim's AP...

Distributed Systems Mind Map

Though distributed systems are inherently distributed, autonomous, and parallel, all textbooks that I have read so far are boring & serial, going from one topic to another as they are independent topics. Wondering about how best to present all related topics and their relationships in my class, I came up with the following mind map. I was able to explain most of the key concepts using a single example of a web-based business that started selling flowers. It was a student who suggested that we consider selling flowers. It turned out to be a good example, as there had to be a connection to the physical world where the business also needed a geographical distributed delivery system. Taught of sharing the mind map. Though most of those branches can be broken down further this level of detailed was sufficient for my class (by the way it took 1 hour to finish the discussion on this slide). Distributed Systems Mind Map

Small Basic for biginners

Microsoft recently introduced Small Basic, a programming language for beginners. It's a strip down version of BASIC with only 15 key words. It seems to be a fun programming environment & definitely worth while trying. You can write both console & graphical interface enabled programs & even develop your own version of Logo. Some of the features include: Its free 15 key words that support basic programming concepts including conditions & iterations Intellisense & context sensitive help Define variables on the fly, no need to explicitly define them Graphic programming Subroutines Third-party libraries can be plugged, API is given It even comes with a simple but comprehensive user guide that introduce basic programming concepts & Small Basic. Though it's intended for beginners, even advanced develops can use it to write scripts that perform simple day to day tasks.