DEPRECATED_cbdsim.sccd 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. Diagram(name = 'CBDSimulator',
  2. author = 'Sadaf Mustafiz and Claudio Gomes',
  3. description = 'SCCD HUTN model of a CBD simulator'):
  4. Top {
  5. from CBD_Controller import CBDController
  6. import Options
  7. }
  8. Class(name = 'CBDSimulator', default = True):
  9. Attribute(name='iteration')
  10. Attribute(name='strongComponentList')
  11. Attribute(name='currentCompIdx')
  12. Attribute(name='clock')
  13. Attribute(name='delta')
  14. Attribute(name='cbdController')
  15. Attribute(name='model')
  16. Attribute(name='depGraph')
  17. Constructor(options, model) {
  18. self.options = options
  19. self.delta = self.options->getDeltaT()
  20. self.model = model
  21. }
  22. Method currentComponentIsCycle() {
  23. return self.cbdController->componentIsCycle(self.strongComponentList[self.currentCompIdx], self.depGraph)
  24. }
  25. Method hasNextStrongComponent() {
  26. return (self.currentCompIdx + 1) < len(self.strongComponentList)
  27. }
  28. Method advanceTime() {
  29. self.iteration = self.iteration + 1
  30. self.clock = self.clock + self.delta
  31. self.cbdController->advanceTimeStep()
  32. }
  33. Method maxIterationsReached() {
  34. return self.iteration >= self.options->getMaxIterations()
  35. }
  36. StateMachine:
  37. initial = 'Initialize'
  38. State('Initialize'):
  39. Transition(target='../CheckTerminationCondition'):
  40. Actions {
  41. print('Transition to CheckTerminationCondition')
  42. }
  43. OnEnter {
  44. print('Performing initialization...')
  45. self.iteration = 0
  46. self.clock = 0
  47. self.cbdController = CBDController(self.model,self.delta)
  48. self.cbdController->initSimulation()
  49. print('Performing initialization... DONE')
  50. }
  51. State('CheckTerminationCondition'):
  52. Transition(target='../CreateDependencyGraph'):
  53. guard = {not self->maxIterationsReached()}
  54. Actions {
  55. print('Transition to CreateDependencyGraph')
  56. }
  57. Transition(target='../SimulationComplete'):
  58. guard = {self->maxIterationsReached()}
  59. Actions {
  60. print('Transition to SimulationComplete')
  61. }
  62. State('CreateDependencyGraph'):
  63. Transition(target='../IsolateStrongComponents'):
  64. Actions {
  65. print('Transition to IsolateStrongComponents')
  66. }
  67. OnEnter {
  68. print('Performing dependency graph creation...')
  69. self.depGraph = self.cbdController->createDepGraph(self.iteration)
  70. print('Performing dependency graph creation... DONE')
  71. }
  72. State('IsolateStrongComponents'):
  73. Transition(target='../ExecuteSimulationStep'):
  74. Actions {
  75. print('Transition to ExecuteSimulationStep')
  76. self.currentCompIdx = -1
  77. }
  78. OnEnter {
  79. print('Performing strong components isolation...')
  80. self.strongComponentList = self.cbdController->createStrongComponents(self.depGraph, self.iteration)
  81. print('Performing strong components isolation... DONE')
  82. }
  83. State('ExecuteSimulationStep'):
  84. initial = 'CheckNextComponent'
  85. State('CheckNextComponent'):
  86. Transition(target='../CheckCycle'):
  87. guard = {self->hasNextStrongComponent()}
  88. Actions {
  89. print('Transition to CheckCycle')
  90. self.currentCompIdx = self.currentCompIdx + 1
  91. }
  92. Transition(target='../../CheckTerminationCondition'):
  93. guard = {not self->hasNextStrongComponent()}
  94. Actions {
  95. print('Transition to CheckTerminationCondition')
  96. self->advanceTime()
  97. }
  98. OnEnter {
  99. print('Performing CheckNextComponent...')
  100. print('Performing CheckNextComponent... DONE')
  101. }
  102. State('CheckCycle'):
  103. Transition(target='../CheckNextComponent'):
  104. guard = {self->currentComponentIsCycle()}
  105. Actions {
  106. print('Transition to CheckNextComponent')
  107. self.cbdController->computeNextAlgebraicLoop(self.strongComponentList[self.currentCompIdx], self.iteration)
  108. }
  109. Transition(target='../CheckNextComponent'):
  110. guard = {not self->currentComponentIsCycle()}
  111. Actions {
  112. print('Transition to CheckNextComponent')
  113. self.cbdController->computeNextBlock(self.strongComponentList[self.currentCompIdx], self.iteration)
  114. }
  115. OnEnter {
  116. print('Performing CheckCycle...')
  117. print('Performing CheckCycle... DONE')
  118. }
  119. State('SimulationComplete')