to_partial_runtime.mvc 18 KB

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