iode.Simulation.sort_algorithm
- property Simulation.sort_algorithm: str
Sorting algorithm used to reorganized the list of equations before the simulation is performed. This reorganization can be usefully to to speed up the simulation.
Two methods can be used separately or in combination. Both use algorithms from the graph theory.
Strongly Connected Component (SCC)
this involves dividing the model into non-interdependent blocks. This method limits the number of equations to be calculated, based on the dependencies of the equations on each other.
In the following example, blocks 1 and 3 are non-interdependent, meaning that only one calculation is required per period. The relaxation parameter is not used in these blocks. Block 2 is the interdependent part of the model. This block is the only one to be iterated on. This reduces the number of equations to be solved to 3, instead of the 6 that actually make up the model. Decomposition can result in more than three blocks:
Let's consider the following equations: A = f1(B,C,D) B = f2(C,A) C = f3(B,X) D = f4(X,Y) X = f5(Y) Z = f6(A,B,C,X) The following blocks are built (in this order): 1: X = f5(Y) depends only on exogenous Y D = f4(X,Y) depends on X 2: A = f1(B,C,D) loop with B and C B = f2(C,A) loop with A and C C = f3(B,X) loops with B, then with A 3: Z = f6(A,B,C,X) is not used by any equation
Pseudo-triangulation
This method reorganizes equations using a specific algorithm. Basically, dependencies are analyzed and equations are organized accordingly: if B depends on A, B is placed after A, and so on. Several passes are usually necessary to obtain a satisfactory result. The optimal number of passes depends on the model and is left to the user’s choice.
- Parameters:
- value: SimulationSort or str
New value for the used sorting algorithm. Possible values are:
NONE: do not use any sorting algorithm
CONNEX: use the Strongly Connected Component (SCC) method only
BOTH: use both the SCC and the Pseudo-triangulation methods
Examples
>>> from iode import Simulation, SimulationSort >>> simu = Simulation() >>> # default value >>> simu.sort_algorithm 'BOTH'
>>> simu.sort_algorithm = "none" >>> simu.sort_algorithm 'NONE' >>> simu.sort_algorithm = SimulationSort.NONE >>> simu.sort_algorithm 'NONE'
>>> simu.sort_algorithm = "connex" >>> simu.sort_algorithm 'CONNEX' >>> simu.sort_algorithm = SimulationSort.CONNEX >>> simu.sort_algorithm 'CONNEX'
>>> simu.sort_algorithm = "both" >>> simu.sort_algorithm 'BOTH' >>> simu.sort_algorithm = SimulationSort.BOTH >>> simu.sort_algorithm 'BOTH'