资源说明:Block-based model simulation engine
Simulate A Graphical C++ & Python based model simulation engine By Kevin Cuzner At the moment this is less of a readme and more of a place for me to write down my ideas and details on how this works. Later these details will be moved to documentation. SUMMARY: Owing to the lack of variety in open souce model simulation, it was decided to create this simulation engine. The engine operates under the following principles: A Model is the basic container for a simulation. It contains Blocks which are connected together in order to represent a single step in a mathematical equation. Blocks may have any number of Inputs and Outputs. Outputs can be connected to multiple Inputs, but Inputs may only be connected to one Output. Models define special blocks called Entry and Exit points which represent both initial/static values in the model and persistant values. If an Entry and an Exit have the same name, when a step in a simulation completes, the Entry will be set to the value of the corrisponding Exit block before the next step executes, effectively creating a stepped loop. The special ModelBlock is a block which is attached to a Model. The Entry and Exit points of the attached model, so long as they do not have matching names, will be trasformed into the Inputs and Outputs of the ModelBlock. When a simulation is executed, a Context is created. This Context contains all the persistent values for blocks and a list of all the Inputs and Outputs for a block. At the beginning of each step, the blocks are asked to initialize themselves for the step. After this initialization, all the blocks which do not have any inputs have their step() method executed. When a block executes, it asks the Context to set its Outputs to computed values. The Context then goes through the Outputs and sets any Inputs connected to them to the Outputs' assigned values. The cycle then continues by the Context executing all the Blocks completed by setting those inputs. A step ends when a context no longer has Blocks to execute. To determine the approximate length of a step, the context records the number of blocks which had to execute before the step was completed. This number is approximate because it is possible to have blocks which trigger looping or conditional portions of the simulation which may not fire under all circimstances. Threading is accomplished by delegating the execution of Block steps in a context to separate threads. The number of threads is determined by either a limit or the number of processors in the computer plus one. When Blocks finished executing in the separate thread, the resulting block execution requests are sent back to the main context for execution in a different thread. Networking is also possible in the case where there are multiple large child ModelBlocks to execute in a Model. DETAILS: Context-Model Relationship: A context is instantiated being attached to a model. If this model is null, lots of exceptions will be thrown later. After a context is reset or created and before any blocks are executed, the context will scan all the blocks in a model. Context-Block Relationship: When a context initializes itself before any steps are run, it scans each block and populates a QHash with keys which are pointers to the Block's Inputs. The hash links an Input* to a SignalValue*. StepContext: A StepContext is used as a parent for all objects which are considered local to a given step and need to be deleted at the end of a step. A StepContext is created by a Context for every step and is passed into all block execution methods and input/output set methods. It has a link to its parent context. The StepContext should be used as a factory for anything that is destroyed when a step is completed (such as a SignalValue).
本源码包内暂不包含可直接显示的源代码文件,请下载源码包。