I’m trying to simulate a real-time network where nodes are consumers and producers of different rates. How would I quickly implement a sample of this with Python? I was imagining that I’d write a simple program for each node, but I’m not sure how to connect them to each other.
I’m trying to simulate a real-time network where nodes are consumers and producers of
Share
Stick with traditional simulation structures, at least at first
Is it your goal to write an asynchronous system as an exercise? If so, then I guess you have to implement at least a multi-threaded if not multi-process or network system.
But if it’s really a simulation, and what you want are the analysis results, implementing an actual distributed model would be a horribly complex approach that is likely to yield far less data than an abstract simulation would, that is, the simulation itself doesn’t have to be a network of asynchronous actors communicating. That would just be a good way to make the problem so hard it won’t get solved.
I say, stick with the traditional simulation architecture.
The Classic Discrete Event Simulation
The way this works is that as a central data structure you have a sorted collection of pending events. The events are naturally sorted by increasing time.
The program has a main loop, where it takes the next (i.e., the lowest-valued) event out of the collection, advances the simulation clock to the time of this event, and then calls any task-specific processing associated with the event.
But, you ask, what if something was supposed to happen in the time delta that the simulator just jumped across? Well, by definition, there was nothing. If an individual element of the simulation needed something to happen in that interval, it was responsible for allocating an event and inserting it into the (sorted) collection.
While there are many packages and programs out there that are geared to simulation, the guts of a simulation are not that hard, and it’s perfectly reasonable to write it up from scratch in your favorite language.
Have fun!