ctcbd_toPartialRuntime.mvc 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451
  1. include "primitives.alh"
  2. include "modelling.alh"
  3. include "object_operations.alh"
  4. Composite schedule {
  5. {Contains} Success success {}
  6. {Contains} Atomic expand {
  7. LHS {
  8. Pre_Design/Block expand_lhs_0 {
  9. label = "0"
  10. }
  11. Pre_Design/IntegratorBlock expand_lhs_1 {
  12. label = "1"
  13. }
  14. Pre_Design/Block expand_lhs_2 {
  15. label = "2"
  16. }
  17. Pre_Design/Block expand_lhs_3 {
  18. label = "3"
  19. }
  20. Pre_Design/InitialCondition (expand_lhs_3, expand_lhs_1) {
  21. label = "4"
  22. }
  23. Pre_Design/Link (expand_lhs_0, expand_lhs_1) {
  24. label = "5"
  25. }
  26. Pre_Design/Link (expand_lhs_1, expand_lhs_2) {
  27. label = "6"
  28. }
  29. }
  30. RHS {
  31. Post_Design/Block expand_rhs_0 {
  32. label = "0"
  33. }
  34. Post_Design/IntegratorBlock expand_rhs_1 {
  35. label = "1"
  36. }
  37. Post_Design/Block expand_rhs_2 {
  38. label = "2"
  39. }
  40. Post_Design/Block expand_rhs_3 {
  41. label = "3"
  42. }
  43. Post_Design/InitialCondition (expand_rhs_3, expand_rhs_1) {
  44. label = "4"
  45. }
  46. Post_Design/Link (expand_rhs_0, expand_rhs_1) {
  47. label = "5"
  48. }
  49. Post_Design/ConstantBlock expand_rhs_7 {
  50. label = "7"
  51. value_value = $
  52. Float function value(model : Element, name : String, mapping : Element):
  53. return 0.01!
  54. $
  55. }
  56. Post_Design/MultiplyBlock expand_rhs_8 {
  57. label = "8"
  58. }
  59. Post_Design/AdditionBlock expand_rhs_9 {
  60. label = "9"
  61. }
  62. Post_Design/DelayBlock expand_rhs_10 {
  63. label = "10"
  64. }
  65. Post_Design/DelayBlock expand_rhs_11 {
  66. label = "11"
  67. }
  68. Post_Design/ConstantBlock expand_rhs_12 {
  69. label = "12"
  70. value_value = $
  71. Float function value(model : Element, name : String, mapping : Element):
  72. return 0!
  73. $
  74. }
  75. Post_Design/Link (expand_rhs_0, expand_rhs_10) {
  76. label = "13"
  77. }
  78. Post_Design/Link (expand_rhs_7, expand_rhs_8) {
  79. label = "14"
  80. }
  81. Post_Design/Link (expand_rhs_10, expand_rhs_8) {
  82. label = "15"
  83. }
  84. Post_Design/Link (expand_rhs_8, expand_rhs_9) {
  85. label = "16"
  86. }
  87. Post_Design/Link (expand_rhs_9, expand_rhs_2) {
  88. label = "17"
  89. }
  90. Post_Design/Link (expand_rhs_9, expand_rhs_11) {
  91. label = "18"
  92. }
  93. Post_Design/Link (expand_rhs_11, expand_rhs_9) {
  94. label = "19"
  95. }
  96. Post_Design/InitialCondition (expand_rhs_12, expand_rhs_10) {
  97. label = "20"
  98. }
  99. Post_Design/InitialCondition (expand_rhs_3, expand_rhs_11) {
  100. label = "21"
  101. }
  102. }
  103. }
  104. {Contains} ForAll optimize_inverse {
  105. LHS {
  106. Pre_Design/ConstantBlock opt_inv_lhs_0 {
  107. label = "0"
  108. }
  109. Pre_Design/InverseBlock opt_inv_lhs_1 {
  110. label = "1"
  111. }
  112. Pre_Design/Block opt_inv_lhs_2 {
  113. label = "2"
  114. }
  115. Pre_Design/Link (opt_inv_lhs_0, opt_inv_lhs_1) {
  116. label = "3"
  117. }
  118. Pre_Design/Link (opt_inv_lhs_1, opt_inv_lhs_2) {
  119. label = "4"
  120. }
  121. }
  122. RHS {
  123. Post_Design/ConstantBlock opt_inv_rhs_0 {
  124. label = "0"
  125. }
  126. Post_Design/InverseBlock opt_inv_rhs_1 {
  127. label = "1"
  128. }
  129. Post_Design/Block opt_inv_rhs_2 {
  130. label = "2"
  131. }
  132. Post_Design/Link (opt_inv_rhs_0, opt_inv_rhs_1) {
  133. label = "3"
  134. }
  135. Post_Design/ConstantBlock opt_inv_rhs_5 {
  136. label = "5"
  137. value_value = $
  138. Float function value(model : Element, name : String, mapping : Element):
  139. return float_division(1, read_attribute(model, mapping["0"], "value"))!
  140. $
  141. }
  142. Post_Design/Link (opt_inv_rhs_5, opt_inv_rhs_2) {
  143. label = "6"
  144. }
  145. }
  146. }
  147. {Contains} ForAll optimize_negator {
  148. LHS {
  149. Pre_Design/ConstantBlock opt_neg_lhs_0 {
  150. label = "0"
  151. }
  152. Pre_Design/InverseBlock opt_neg_lhs_1 {
  153. label = "1"
  154. }
  155. Pre_Design/Block opt_neg_lhs_2 {
  156. label = "2"
  157. }
  158. Pre_Design/Link (opt_neg_lhs_0, opt_neg_lhs_1) {
  159. label = "3"
  160. }
  161. Pre_Design/Link (opt_neg_lhs_1, opt_neg_lhs_2) {
  162. label = "4"
  163. }
  164. }
  165. RHS {
  166. Post_Design/ConstantBlock opt_neg_rhs_0 {
  167. label = "0"
  168. }
  169. Post_Design/InverseBlock opt_neg_rhs_1 {
  170. label = "1"
  171. }
  172. Post_Design/Block opt_neg_rhs_2 {
  173. label = "2"
  174. }
  175. Post_Design/Link (opt_neg_rhs_0, opt_neg_rhs_1) {
  176. label = "3"
  177. }
  178. Post_Design/ConstantBlock opt_neg_rhs_5 {
  179. label = "5"
  180. value_value = $
  181. Float function value(model : Element, name : String, mapping : Element):
  182. return float_subtraction(0, read_attribute(model, mapping["0"], "value"))!
  183. $
  184. }
  185. Post_Design/Link (opt_neg_rhs_5, opt_neg_rhs_2) {
  186. label = "6"
  187. }
  188. }
  189. }
  190. {Contains} ForAll remove_blocks {
  191. LHS {
  192. Pre_Design/Block rem_lhs_0 {
  193. label = "0"
  194. constraint = $
  195. Boolean function constraint(model : Element, name : String):
  196. if (set_len(allOutgoingAssociationInstances(model, name, "Design/Link")) > 0):
  197. return False!
  198. elif (set_len(allOutgoingAssociationInstances(model, name, "Design/InitialCondition")) > 0):
  199. return False!
  200. else:
  201. return read_type(model, name) != "Design/ProbeBlock"!
  202. $
  203. }
  204. }
  205. RHS {}
  206. }
  207. {Contains} ForAll optimize_adder {
  208. LHS {
  209. Pre_Design/ConstantBlock opt_add_lhs_0 {
  210. label = "0"
  211. }
  212. Pre_Design/ConstantBlock opt_add_lhs_1 {
  213. label = "1"
  214. }
  215. Pre_Design/AdditionBlock opt_add_lhs_2 {
  216. label = "2"
  217. }
  218. Pre_Design/Block opt_add_lhs_3 {
  219. label = "3"
  220. }
  221. Pre_Design/Link (opt_add_lhs_0, opt_add_lhs_2) {
  222. label = "4"
  223. }
  224. Pre_Design/Link (opt_add_lhs_1, opt_add_lhs_2) {
  225. label = "5"
  226. }
  227. Pre_Design/Link (opt_add_lhs_2, opt_add_lhs_3) {
  228. label = "6"
  229. }
  230. }
  231. RHS {
  232. Post_Design/ConstantBlock opt_add_rhs_0 {
  233. label = "0"
  234. }
  235. Post_Design/ConstantBlock opt_add_rhs_1 {
  236. label = "1"
  237. }
  238. Post_Design/AdditionBlock opt_add_rhs_2 {
  239. label = "2"
  240. }
  241. Post_Design/Block opt_add_rhs_3 {
  242. label = "3"
  243. }
  244. Post_Design/Link (opt_add_rhs_0, opt_add_rhs_2) {
  245. label = "4"
  246. }
  247. Post_Design/Link (opt_add_rhs_1, opt_add_rhs_2) {
  248. label = "5"
  249. }
  250. Post_Design/ConstantBlock opt_add_rhs_7 {
  251. label = "7"
  252. value_value = $
  253. Float function value(model : Element, name : String, mapping : Element):
  254. return float_addition(read_attribute(model, mapping["0"], "value"), read_attribute(model, mapping["1"], "value"))!
  255. $
  256. }
  257. Post_Design/Link (opt_add_rhs_7, opt_add_rhs_3) {
  258. label = "8"
  259. }
  260. }
  261. }
  262. {Contains} ForAll optimize_multiplier {
  263. LHS {
  264. Pre_Design/ConstantBlock opt_mult_lhs_0 {
  265. label = "0"
  266. }
  267. Pre_Design/ConstantBlock opt_mult_lhs_1 {
  268. label = "1"
  269. }
  270. Pre_Design/MultiplyBlock opt_mult_lhs_2 {
  271. label = "2"
  272. }
  273. Pre_Design/Block opt_mult_lhs_3 {
  274. label = "3"
  275. }
  276. Pre_Design/Link (opt_mult_lhs_0, opt_mult_lhs_2) {
  277. label = "4"
  278. }
  279. Pre_Design/Link (opt_mult_lhs_1, opt_mult_lhs_2) {
  280. label = "5"
  281. }
  282. Pre_Design/Link (opt_mult_lhs_2, opt_mult_lhs_3) {
  283. label = "6"
  284. }
  285. }
  286. RHS {
  287. Post_Design/ConstantBlock opt_mult_rhs_0 {
  288. label = "0"
  289. }
  290. Post_Design/ConstantBlock opt_mult_rhs_1 {
  291. label = "1"
  292. }
  293. Post_Design/MultiplyBlock opt_mult_rhs_2 {
  294. label = "2"
  295. }
  296. Post_Design/Block opt_mult_rhs_3 {
  297. label = "3"
  298. }
  299. Post_Design/Link (opt_mult_rhs_0, opt_mult_rhs_2) {
  300. label = "4"
  301. }
  302. Post_Design/Link (opt_mult_rhs_1, opt_mult_rhs_2) {
  303. label = "5"
  304. }
  305. Post_Design/ConstantBlock opt_mult_rhs_7 {
  306. label = "7"
  307. value_value = $
  308. Float function value(model : Element, name : String, mapping : Element):
  309. return float_multiplication(read_attribute(model, mapping["0"], "value"), read_attribute(model, mapping["1"], "value"))!
  310. $
  311. }
  312. Post_Design/Link (opt_mult_rhs_7, opt_mult_rhs_3) {
  313. label = "8"
  314. }
  315. }
  316. }
  317. {Contains} ForAll optimize_constant {
  318. LHS {
  319. Pre_Design/ConstantBlock opt_const_lhs_0 {
  320. label = "0"
  321. }
  322. Pre_Design/Block opt_const_lhs_1 {
  323. label = "1"
  324. }
  325. Pre_Design/ConstantBlock opt_const_lhs_2 {
  326. label = "2"
  327. }
  328. Pre_Design/Block opt_const_lhs_3 {
  329. label = "3"
  330. }
  331. Pre_Design/Link (opt_const_lhs_0, opt_const_lhs_1) {
  332. label = "4"
  333. }
  334. Pre_Design/Link (opt_const_lhs_2, opt_const_lhs_3) {
  335. label = "5"
  336. }
  337. constraint = $
  338. Boolean function constraint(model : Element, mapping : Element):
  339. return (cast_integer(cast_id(mapping["0"])) < cast_integer(cast_id(mapping["2"])))!
  340. $
  341. }
  342. RHS {
  343. Post_Design/ConstantBlock opt_const_rhs_0 {
  344. label = "0"
  345. }
  346. Post_Design/Block opt_const_rhs_1 {
  347. label = "1"
  348. }
  349. Post_Design/ConstantBlock opt_const_rhs_2 {
  350. label = "2"
  351. }
  352. Post_Design/Block opt_const_rhs_3 {
  353. label = "3"
  354. }
  355. Post_Design/Link (opt_const_rhs_0, opt_const_rhs_1) {
  356. label = "4"
  357. }
  358. Post_Design/Link (opt_const_rhs_0, opt_const_rhs_3) {
  359. label = "6"
  360. }
  361. }
  362. }
  363. {Contains} Atomic map_to_partial {
  364. LHS {}
  365. RHS {
  366. action = $
  367. Void function action(model : Element, mapping : Element):
  368. Element all_blocks
  369. String element_name
  370. String new_element_name
  371. String mm_type_name
  372. Element all_links
  373. all_blocks = allInstances(model, "Design/Block")
  374. while (set_len(all_blocks) > 0):
  375. element_name = set_pop(all_blocks)
  376. mm_type_name = "PartialRuntime/" + cast_string(list_read(string_split(read_type(model, element_name), "/"), 1))
  377. if (set_len(allOutgoingAssociationInstances(model, element_name, "D2P_block")) == 0):
  378. // New design element, so create in partial runtime model as well
  379. new_element_name = instantiate_node(model, mm_type_name, "")
  380. instantiate_link(model, "D2P_block", "", element_name, new_element_name)
  381. // Always update the value of attributes of PartialRuntime
  382. new_element_name = map_D2P(model, element_name)
  383. if (mm_type_name == "PartialRuntime/ConstantBlock"):
  384. instantiate_attribute(model, new_element_name, "value", read_attribute(model, element_name, "value"))
  385. elif (mm_type_name == "PartialRuntime/ProbeBlock"):
  386. instantiate_attribute(model, new_element_name, "name", read_attribute(model, element_name, "name"))
  387. all_blocks = allInstances(model, "PartialRuntime/Block")
  388. while (set_len(all_blocks) > 0):
  389. element_name = set_pop(all_blocks)
  390. if (set_len(allIncomingAssociationInstances(model, element_name, "D2P_block")) == 0):
  391. // Old partial runtime element, so remove
  392. model_delete_element(model, element_name)
  393. // Delete all existing links
  394. all_links = allInstances(model, "PartialRuntime/Link")
  395. while (set_len(all_links) > 0):
  396. model_delete_element(model, set_pop(all_links))
  397. all_links = allInstances(model, "PartialRuntime/InitialCondition")
  398. while (set_len(all_links) > 0):
  399. model_delete_element(model, set_pop(all_links))
  400. // Recreate all of them
  401. all_links = allInstances(model, "Design/Link")
  402. while (set_len(all_links) > 0):
  403. element_name = set_pop(all_links)
  404. instantiate_link(model, "PartialRuntime/Link", "", map_D2P(model, readAssociationSource(model, element_name)), map_D2P(model, readAssociationDestination(model, element_name)))
  405. all_links = allInstances(model, "Design/InitialCondition")
  406. while (set_len(all_links) > 0):
  407. element_name = set_pop(all_links)
  408. instantiate_link(model, "PartialRuntime/InitialCondition", "", map_D2P(model, readAssociationSource(model, element_name)), map_D2P(model, readAssociationDestination(model, element_name)))
  409. return!
  410. String function map_D2P(model : Element, name : String):
  411. Element destinations
  412. String pick
  413. destinations = allAssociationDestinations(model, name, "D2P_block")
  414. pick = name
  415. while (pick == name):
  416. pick = set_pop(destinations)
  417. return pick!
  418. $
  419. }
  420. }
  421. }
  422. Initial (schedule, expand) {}
  423. OnSuccess (expand, expand) {}
  424. OnFailure (expand, remove_blocks) {}
  425. OnSuccess (remove_blocks, map_to_partial) {}
  426. OnSuccess (map_to_partial, success) {}