to_partial_runtime.mvc 18 KB

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