reachability.alc 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556
  1. include "primitives.alh"
  2. include "modelling.alh"
  3. include "object_operations.alh"
  4. include "transform.alh"
  5. include "constructors.alh"
  6. include "compiler.alh"
  7. Boolean function reachability_graph(model : Element):
  8. Element workset
  9. Element transition_vectors_produce
  10. Element transition_vectors_consume
  11. Element all_transitions
  12. Element all_transitions_original
  13. Element enabled_transitions_set
  14. Element tv
  15. Element links
  16. Element mappings
  17. Element reachable_states
  18. Element keys
  19. Element enabled_transitions
  20. Element enabled_copy
  21. Element workset_copy
  22. Element curr_workset_el
  23. String transition
  24. String new_transition
  25. String tmp_transition
  26. String state
  27. String name
  28. String link
  29. String place
  30. String key
  31. String curr_transition
  32. String bp_name
  33. String curr_bp_name
  34. String to_construct
  35. String disable_on_trigger_str
  36. String user_input_s
  37. Integer link_weight
  38. Integer initial
  39. Integer state_id
  40. Integer next_id
  41. Integer user_input_i
  42. Boolean possible
  43. Boolean disable_on_trigger
  44. Element all_places
  45. Element dict_repr
  46. Element new_dict_repr
  47. Element work_unit
  48. Element curr_bp
  49. Element bp_keys
  50. Boolean bp_triggered
  51. Element reachable_keys_copy
  52. Element curr_reachable
  53. Element new_breakpoint
  54. Element curr_bp_function
  55. Element place_names_to_ids
  56. Element breakpoints
  57. breakpoints = create_node()
  58. Element cache
  59. cache = create_node()
  60. String user_input
  61. user_input = ""
  62. String mode
  63. mode = "paused"
  64. while (True):
  65. output('{"msg_type": "enabled_commands", "commands": ["step", "continuous", "manual", "add_breakpoint"]}')
  66. output('{"msg_type": "mode_change", "mode": "paused"}')
  67. log('waiting for user input')
  68. user_input = input()
  69. log(user_input)
  70. if (user_input == "simulation_mode"):
  71. user_input = input()
  72. if (user_input == "step"):
  73. output('{"msg_type": "enabled_commands", "commands": ["step", "continuous", "manual"]}')
  74. break!
  75. if (user_input == "continuous"):
  76. output('{"msg_type": "enabled_commands", "commands": []}')
  77. output('{"msg_type": "mode_change", "mode": "running"}')
  78. break!
  79. if (user_input == "manual"):
  80. output('{"msg_type": "enabled_commands", "commands": ["step", "continuous", "manual"]}')
  81. break!
  82. if (user_input == "add_breakpoint"):
  83. bp_name = ""
  84. while (bool_or(bp_name == "", dict_in(breakpoints, bp_name))):
  85. output('{"msg_type": "input_required", "name": "breakpoint name", "type": "string"}')
  86. bp_name = input()
  87. output('{"msg_type": "input_required", "name": "disable on trigger?", "type": "boolean"}')
  88. disable_on_trigger_str = input()
  89. if (disable_on_trigger_str == "True"):
  90. disable_on_trigger = True
  91. else:
  92. disable_on_trigger = False
  93. output('{"msg_type": "input_required", "name": "breakpoint function", "type": "code"}')
  94. new_breakpoint = create_node()
  95. String bp_code
  96. bp_code = input()
  97. dict_add_fast(new_breakpoint, "function", compile_code(bp_code))
  98. dict_add_fast(new_breakpoint, "disable_on_trigger", disable_on_trigger)
  99. dict_add_fast(new_breakpoint, "enabled", True)
  100. dict_add_fast(breakpoints, bp_name, new_breakpoint)
  101. output(('{"msg_type": "state_change", "state": "breakpoint_added", "breakpoint_name": "' + bp_name) + '"}')
  102. mode = user_input
  103. // Create a dictionary representation for each transition
  104. transition_vectors_produce = create_node()
  105. transition_vectors_consume = create_node()
  106. all_transitions = allInstances(model, "PetriNet/Transition")
  107. while (read_nr_out(all_transitions) > 0):
  108. transition = set_pop(all_transitions)
  109. String transition_name
  110. transition_name = read_attribute(model, transition, "name")
  111. tv = create_node()
  112. links = allIncomingAssociationInstances(model, transition, "PetriNet/P2T")
  113. while (read_nr_out(links) > 0):
  114. link = set_pop(links)
  115. name = reverseKeyLookup(model["model"], read_edge_src(model["model"][link]))
  116. link_weight = read_attribute(model, link, "weight")
  117. dict_add_fast(tv, name, link_weight)
  118. dict_add_fast(transition_vectors_consume, transition_name, tv)
  119. tv = create_node()
  120. links = allOutgoingAssociationInstances(model, transition, "PetriNet/T2P")
  121. while (read_nr_out(links) > 0):
  122. link = set_pop(links)
  123. name = reverseKeyLookup(model["model"], read_edge_dst(model["model"][link]))
  124. link_weight = read_attribute(model, link, "weight")
  125. dict_add_fast(tv, name, link_weight)
  126. dict_add_fast(transition_vectors_produce, transition_name, tv)
  127. workset = create_node()
  128. all_places = allInstances(model, "PetriNet/Place")
  129. dict_repr = create_node()
  130. place_names_to_ids = create_node()
  131. while (read_nr_out(all_places) > 0):
  132. place = set_pop(all_places)
  133. dict_add_fast(dict_repr, place, read_attribute(model, place, "tokens"))
  134. dict_add_fast(place_names_to_ids, read_attribute(model, place, "name"), place)
  135. all_transitions_original = allInstances(model, "PetriNet/Transition")
  136. mappings = create_node()
  137. state_id = 0
  138. next_id = 1
  139. reachable_states = create_node()
  140. dict_add_fast(reachable_states, state_id, dict_repr)
  141. dict_add_fast(mappings, state_id, create_node())
  142. // And add in the model itself
  143. state = instantiate_node(model, "ReachabilityGraph/InitialState", cast_i2s(state_id))
  144. instantiate_attribute(model, state, "name", cast_i2s(state_id))
  145. instantiate_attribute(model, state, "error", False)
  146. keys = dict_keys(dict_repr)
  147. while (read_nr_out(keys) > 0):
  148. key = set_pop(keys)
  149. place = instantiate_node(model, "ReachabilityGraph/Place", "")
  150. instantiate_attribute(model, place, "name", read_attribute(model, key, "name"))
  151. instantiate_attribute(model, place, "tokens", dict_repr[key])
  152. instantiate_link(model, "ReachabilityGraph/Contains", "", state, place)
  153. enabled_transitions = create_node()
  154. dict_repr = reachable_states[state_id]
  155. enabled_transitions_set = create_node()
  156. dict_add(enabled_transitions, state_id, enabled_transitions_set)
  157. // Compute how the PN behaves with this specific state
  158. // For this, we fetch all transitions and check if they are enabled
  159. all_transitions = set_copy(all_transitions_original)
  160. while (read_nr_out(all_transitions) > 0):
  161. transition = set_pop(all_transitions)
  162. String transition_name
  163. transition_name = read_attribute(model, transition, "name")
  164. keys = dict_keys(transition_vectors_consume[transition_name])
  165. possible = True
  166. while (read_nr_out(keys) > 0):
  167. key = set_pop(keys)
  168. // Compare the values in the state with those consumed by the transition
  169. if (integer_lt(dict_repr[key], transition_vectors_consume[transition_name][key])):
  170. // Impossible transition, so discard this one
  171. possible = False
  172. break!
  173. if (possible):
  174. set_add(enabled_transitions_set, transition_name)
  175. if (read_nr_out(enabled_transitions[state_id]) > 0):
  176. set_add(workset, state_id)
  177. if (bool_or(mode == "step", mode == "manual")):
  178. output('{"msg_type": "state_change", "state": "initialized"}')
  179. Element dict_values
  180. Element all_values
  181. String place
  182. dict_values = create_node()
  183. all_values = allAssociationDestinations(model, cast_i2s(state_id), "ReachabilityGraph/Contains")
  184. while (read_nr_out(all_values) > 0):
  185. place = set_pop(all_values)
  186. dict_add(dict_values, read_attribute(model, place, "name"), cast_v2s(read_attribute(model, place, "tokens")))
  187. String marking
  188. marking = dict_to_string(dict_values)
  189. output(((('{"msg_type": "node_added", "node_info": {"node_id": ' + cast_v2s(read_attribute(model, cast_i2s(state_id), "name"))) + ', "node_marking": ') + marking) + '}}')
  190. if (mode == "step"):
  191. mode = "paused"
  192. output('{"msg_type": "mode_change", "mode": "paused"}')
  193. while (True):
  194. if (mode == "manual"):
  195. break!
  196. user_input = input()
  197. if (user_input == "simulation_mode"):
  198. user_input = input()
  199. if (user_input == "step"):
  200. mode = user_input
  201. output('{"msg_type": "enabled_commands", "commands": ["step", "continuous", "manual"]}')
  202. break!
  203. if (user_input == "continuous"):
  204. mode = user_input
  205. output('{"msg_type": "enabled_commands", "commands": []}')
  206. break!
  207. if (user_input == "manual"):
  208. mode = user_input
  209. output('{"msg_type": "enabled_commands", "commands": ["step", "continuous", "manual"]}')
  210. break!
  211. while (read_nr_out(workset) > 0):
  212. if (mode == "manual"):
  213. String markings
  214. markings = '['
  215. workset_copy = set_copy(workset)
  216. while (read_nr_out(workset_copy) > 0):
  217. curr_workset_el = set_pop(workset_copy)
  218. markings = ((markings + '"') + cast_v2s(curr_workset_el)) + '"'
  219. if (read_nr_out(workset_copy) > 0):
  220. markings = markings + ", "
  221. markings = markings + "]"
  222. output(('{"msg_type": "unexplored_markings", "markings": ' + markings) + '}')
  223. log("Please choose a marking.")
  224. while (True):
  225. user_input_s = input()
  226. if (user_input_s == 'simulation_mode'):
  227. mode = input()
  228. if (mode != 'manual'):
  229. state_id = set_pop(workset)
  230. dict_repr = reachable_states[state_id]
  231. enabled_transitions_set = enabled_transitions[state_id]
  232. transition = set_pop(enabled_transitions_set)
  233. if (mode == 'continuous'):
  234. output('{"msg_type": "enabled_commands", "commands": []}')
  235. if (mode == "step"):
  236. output('{"msg_type": "enabled_commands", "commands": ["step", "continuous", "manual"]}')
  237. break!
  238. elif (user_input_s == 'selected_marking'):
  239. user_input_i = cast_s2i(input())
  240. if (set_in(workset, user_input_i)):
  241. state_id = user_input_i
  242. enabled_transitions_set = enabled_transitions[state_id]
  243. String enabled_transitions_output
  244. enabled_transitions_output = '['
  245. enabled_copy = set_copy(enabled_transitions_set)
  246. while (read_nr_out(enabled_copy) > 0):
  247. curr_transition = set_pop(enabled_copy)
  248. enabled_transitions_output = enabled_transitions_output + cast_v2s(curr_transition)
  249. if (read_nr_out(enabled_copy) > 0):
  250. enabled_transitions_output = enabled_transitions_output + ", "
  251. enabled_transitions_output = enabled_transitions_output + "]"
  252. output(('{"msg_type": "enabled_transitions", "transitions": ' + enabled_transitions_output) + '}')
  253. elif (user_input_s == 'selected_transition'):
  254. set_remove(workset, state_id)
  255. dict_repr = reachable_states[state_id]
  256. user_input_s = input()
  257. transition = user_input_s
  258. set_remove(enabled_transitions_set, transition)
  259. break!
  260. else:
  261. state_id = set_pop(workset)
  262. dict_repr = reachable_states[state_id]
  263. enabled_transitions_set = enabled_transitions[state_id]
  264. transition = set_pop(enabled_transitions_set)
  265. if (read_nr_out(enabled_transitions[state_id]) > 0):
  266. set_add(workset, state_id)
  267. new_dict_repr = dict_copy(dict_repr)
  268. // Transition can execute, so compute and add the new state based on the consume/produce vectors
  269. keys = dict_keys(transition_vectors_consume[transition])
  270. while (read_nr_out(keys) > 0):
  271. key = set_pop(keys)
  272. dict_overwrite(new_dict_repr, key, integer_subtraction(new_dict_repr[key], transition_vectors_consume[transition][key]))
  273. keys = dict_keys(transition_vectors_produce[transition])
  274. while (read_nr_out(keys) > 0):
  275. key = set_pop(keys)
  276. dict_overwrite(new_dict_repr, key, integer_addition(new_dict_repr[key], transition_vectors_produce[transition][key]))
  277. // Check if this state already has an associated ID
  278. Integer other_state_id
  279. Integer target_id
  280. keys = dict_keys(reachable_states)
  281. target_id = -1
  282. Float start
  283. while (read_nr_out(keys) > 0):
  284. other_state_id = set_pop(keys)
  285. if (dict_eq(reachable_states[other_state_id], new_dict_repr)):
  286. target_id = other_state_id
  287. break!
  288. Boolean new_node
  289. new_node = False
  290. if (target_id == -1):
  291. new_node = True
  292. // New state
  293. target_id = next_id
  294. next_id = next_id + 1
  295. // Add to all data structures
  296. dict_add_fast(reachable_states, target_id, new_dict_repr)
  297. dict_add_fast(mappings, target_id, create_node())
  298. // And add in the model itself
  299. state = instantiate_node(model, "ReachabilityGraph/State", cast_i2s(target_id))
  300. instantiate_attribute(model, state, "name", cast_i2s(target_id))
  301. instantiate_attribute(model, state, "error", False)
  302. keys = dict_keys(new_dict_repr)
  303. Element sub
  304. String name
  305. while (read_nr_out(keys) > 0):
  306. key = set_pop(keys)
  307. name = read_attribute(model, key, "name")
  308. if (bool_not(dict_in(cache, name))):
  309. dict_add_fast(cache, name, create_node())
  310. sub = cache[name]
  311. if (bool_not(dict_in(sub, new_dict_repr[key]))):
  312. place = instantiate_node(model, "ReachabilityGraph/Place", "")
  313. instantiate_attribute(model, place, "name", name)
  314. instantiate_attribute(model, place, "tokens", new_dict_repr[key])
  315. dict_add_fast(sub, new_dict_repr[key], place)
  316. else:
  317. place = sub[new_dict_repr[key]]
  318. instantiate_link(model, "ReachabilityGraph/Contains", "", state, place)
  319. // Compute how the PN behaves with this specific state
  320. // For this, we fetch all transitions and check if they are enabled
  321. enabled_transitions_set = create_node()
  322. dict_add(enabled_transitions, target_id, enabled_transitions_set)
  323. all_transitions = set_copy(all_transitions_original)
  324. while (read_nr_out(all_transitions) > 0):
  325. tmp_transition = set_pop(all_transitions)
  326. String transition_name
  327. transition_name = read_attribute(model, tmp_transition, "name")
  328. keys = dict_keys(transition_vectors_consume[transition_name])
  329. possible = True
  330. while (read_nr_out(keys) > 0):
  331. key = set_pop(keys)
  332. // Compare the values in the state with those consumed by the transition
  333. if (integer_lt(new_dict_repr[key], transition_vectors_consume[transition_name][key])):
  334. // Impossible transition, so discard this one
  335. possible = False
  336. break!
  337. if (possible):
  338. set_add(enabled_transitions_set, transition_name)
  339. if (read_nr_out(enabled_transitions[target_id]) > 0):
  340. set_add(workset, target_id)
  341. // Anyway, we have found a transition, which we should store
  342. dict_add_fast(mappings[state_id], transition, target_id)
  343. // And also store it in the model itself
  344. new_transition = instantiate_link(model, "ReachabilityGraph/Transition", "", cast_i2s(state_id), cast_i2s(target_id))
  345. instantiate_attribute(model, new_transition, "name", transition)
  346. if (bool_or(mode == "step", mode == "manual")):
  347. if (new_node):
  348. Element dict_values
  349. Element all_values
  350. String place
  351. dict_values = create_node()
  352. all_values = allAssociationDestinations(model, cast_i2s(target_id), "ReachabilityGraph/Contains")
  353. while (read_nr_out(all_values) > 0):
  354. place = set_pop(all_values)
  355. dict_add(dict_values, read_attribute(model, place, "name"), read_attribute(model, place, "tokens"))
  356. String marking
  357. marking = dict_to_string(dict_values)
  358. output(((('{"msg_type": "node_added", "node_info": {"node_id": ' + cast_v2s(read_attribute(model, cast_i2s(target_id), "name"))) + ', "node_marking": ') + marking) + '}}')
  359. String link_output
  360. link_output = '{"msg_type": "link_added", "link_info": {'
  361. link_output = link_output + '"transition": '
  362. link_output = link_output + cast_v2s(transition)
  363. link_output = link_output + ', "transition_id": '
  364. link_output = link_output + cast_v2s(new_transition)
  365. link_output = link_output + ', "source": "'
  366. link_output = link_output + cast_v2s(state_id)
  367. link_output = link_output + '", "target": "'
  368. link_output = link_output + cast_v2s(target_id)
  369. link_output = link_output + '"}}'
  370. output(link_output)
  371. if (mode == "step"):
  372. mode = "paused"
  373. output('{"msg_type": "mode_change", "mode": "paused"}')
  374. output('{"msg_type": "state_change", "state": "step_done"}')
  375. bp_keys = dict_keys(breakpoints)
  376. bp_triggered = False
  377. while (read_nr_out(bp_keys) > 0):
  378. curr_bp_name = set_pop(bp_keys)
  379. curr_bp = breakpoints[curr_bp_name]
  380. curr_bp_function = curr_bp["function"]
  381. if (bool_and(curr_bp["enabled"], curr_bp_function(reachable_states, mappings, place_names_to_ids))):
  382. output(('{"msg_type": "state_change", "state": "breakpoint_triggered", "breakpoint_name": "' + curr_bp_name) + '"}')
  383. bp_triggered = True
  384. log(curr_bp["disable_on_trigger"])
  385. if (curr_bp["disable_on_trigger"]):
  386. dict_delete(curr_bp, "enabled")
  387. dict_add_fast(curr_bp, "enabled", False)
  388. if (bp_triggered):
  389. Element all_states
  390. Element curr_state
  391. all_states = allInstances(model, "ReachabilityGraph/State")
  392. to_construct = '{"msg_type": "reachable_nodes", "nodes": ['
  393. while (read_nr_out(all_states) > 0):
  394. curr_state = set_pop(all_states)
  395. to_construct = to_construct + '{"node_id": '
  396. to_construct = to_construct + cast_v2s(curr_state)
  397. to_construct = to_construct + ', "node_marking": '
  398. Element dict_values
  399. Element all_values
  400. String place
  401. dict_values = create_node()
  402. all_values = allAssociationDestinations(model, curr_state, "ReachabilityGraph/Contains")
  403. while (set_len(all_values) > 0):
  404. place = set_pop(all_values)
  405. dict_add(dict_values, read_attribute(model, place, "name"), read_attribute(model, place, "tokens"))
  406. to_construct = to_construct + dict_to_string(dict_values)
  407. to_construct = to_construct + "}"
  408. if (read_nr_out(all_states) > 0):
  409. to_construct = to_construct + ', '
  410. to_construct = to_construct + ']}'
  411. output(to_construct)
  412. Element all_links
  413. Element curr_link
  414. all_links = allInstances(model, "ReachabilityGraph/Transition")
  415. to_construct = '{"msg_type": "node_links", "links": ['
  416. while (read_nr_out(all_links) > 0):
  417. curr_link = set_pop(all_links)
  418. to_construct = to_construct + '{"transition": '
  419. to_construct = to_construct + cast_v2s(read_attribute(model, curr_link, "name"))
  420. to_construct = to_construct + ', "transition_id": '
  421. to_construct = to_construct + cast_v2s(curr_link)
  422. to_construct = to_construct + ', "source": '
  423. to_construct = to_construct + cast_v2s(reverseKeyLookup(model["model"], read_edge_src(model["model"][curr_link])))
  424. to_construct = to_construct + ', "target": '
  425. to_construct = to_construct + cast_v2s(reverseKeyLookup(model["model"], read_edge_dst(model["model"][curr_link])))
  426. to_construct = to_construct + '}'
  427. if (read_nr_out(all_links) > 0):
  428. to_construct = to_construct + ', '
  429. to_construct = to_construct + ']}'
  430. output(to_construct)
  431. output('{"msg_type": "enabled_commands", "commands": ["step", "continuous", "manual"]}')
  432. if (bool_not(mode == "paused")):
  433. mode = "paused"
  434. output('{"msg_type": "mode_change", "mode": "paused"}')
  435. if (bool_not(mode == "continuous")):
  436. while (True):
  437. if (mode == "manual"):
  438. break!
  439. user_input = input()
  440. if (user_input == "simulation_mode"):
  441. user_input = input()
  442. if (user_input == "step"):
  443. mode = user_input
  444. output('{"msg_type": "enabled_commands", "commands": ["step", "continuous", "manual"]}')
  445. break!
  446. if (user_input == "continuous"):
  447. mode = user_input
  448. output('{"msg_type": "enabled_commands", "commands": []}')
  449. break!
  450. if (user_input == "manual"):
  451. mode = user_input
  452. output('{"msg_type": "enabled_commands", "commands": ["step", "continuous", "manual"]}')
  453. break!
  454. Element all_states
  455. Element curr_state
  456. all_states = allInstances(model, "ReachabilityGraph/State")
  457. to_construct = '{"msg_type": "reachable_nodes", "nodes": ['
  458. while (read_nr_out(all_states) > 0):
  459. curr_state = set_pop(all_states)
  460. to_construct = to_construct + '{"node_id": '
  461. to_construct = to_construct + cast_v2s(curr_state)
  462. to_construct = to_construct + ', "node_marking": '
  463. Element dict_values
  464. Element all_values
  465. String place
  466. dict_values = create_node()
  467. all_values = allAssociationDestinations(model, curr_state, "ReachabilityGraph/Contains")
  468. while (set_len(all_values) > 0):
  469. place = set_pop(all_values)
  470. dict_add(dict_values, read_attribute(model, place, "name"), read_attribute(model, place, "tokens"))
  471. to_construct = to_construct + dict_to_string(dict_values)
  472. to_construct = to_construct + "}"
  473. if (read_nr_out(all_states) > 0):
  474. to_construct = to_construct + ', '
  475. to_construct = to_construct + ']}'
  476. output(to_construct)
  477. Element all_links
  478. Element curr_link
  479. all_links = allInstances(model, "ReachabilityGraph/Transition")
  480. to_construct = '{"msg_type": "node_links", "links": ['
  481. while (read_nr_out(all_links) > 0):
  482. curr_link = set_pop(all_links)
  483. to_construct = to_construct + '{"transition": '
  484. to_construct = to_construct + cast_v2s(read_attribute(model, curr_link, "name"))
  485. to_construct = to_construct + ', "transition_id": '
  486. to_construct = to_construct + cast_v2s(curr_link)
  487. to_construct = to_construct + ', "source": '
  488. to_construct = to_construct + cast_v2s(reverseKeyLookup(model["model"], read_edge_src(model["model"][curr_link])))
  489. to_construct = to_construct + ', "target": '
  490. to_construct = to_construct + cast_v2s(reverseKeyLookup(model["model"], read_edge_dst(model["model"][curr_link])))
  491. to_construct = to_construct + '}'
  492. if (read_nr_out(all_links) > 0):
  493. to_construct = to_construct + ', '
  494. to_construct = to_construct + ']}'
  495. output(to_construct)
  496. output('{"msg_type": "mode_change", "mode": "finished"}')
  497. log("# reachable states: " + cast_v2s(next_id))
  498. return True!