ctcbd_toPartialRuntime.mvc 16 KB

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