Browse Source

Rewrote some parts to make runtime conversion work

Yentl Van Tendeloo 8 years ago
parent
commit
7f1480a37a
2 changed files with 28 additions and 12 deletions
  1. 10 9
      integration/code/cbd_runtime.mvc
  2. 18 3
      integration/code/cbd_semantics.alc

+ 10 - 9
integration/code/cbd_runtime.mvc

@@ -37,18 +37,19 @@ SCD CausalBlockDiagrams_Runtime{
     }
 
     Class Schedule {
-        block : Block {
-            target_lower_cardinality = 0
-            target_upper_cardinality = 1
-        }
-        next : Schedule {
-            target_lower_cardinality = 1
-            target_upper_cardinality = 1
-        }
-
         lower_cardinality = 1
     }
 
+    Association LinkedBlock(Schedule, Block){
+        target_lower_cardinality = 0
+        target_upper_cardinality = 1
+    }
+
+    Association NextSchedule(Schedule, Schedule){
+        target_lower_cardinality = 0
+        target_upper_cardinality = 1
+    }
+
     Association ActiveSchedule(Pointers, Schedule) {
         target_lower_cardinality = 1
         target_upper_cardinality = 1

+ 18 - 3
integration/code/cbd_semantics.alc

@@ -40,7 +40,7 @@ Void function translate_to_runtime(design_model : Element):
 	log("Translating to runtime model!")
 
 	log("Creating empty runtime model")
-	runtime_model = instantiate_model("models/CausalBlockDiagrams_Runtime")
+	runtime_model = instantiate_model(import_node("models/CausalBlockDiagrams_Runtime"))
 
 	log("Converting blocks")
 	all_blocks = allInstances(design_model, "Block")
@@ -97,45 +97,60 @@ Void function create_schedule(model : Element, is_time_zero : Boolean):
 	String new_schedule
 	Boolean ready
 
+	log("Fetching all blocks")
 	all_blocks = allInstances(model, "Block")
 	visited = create_node()
 	to_visit = create_node()
 	if (is_time_zero):
+		log("Make initial schedule!")
 		schedule = instantiate_node(model, "Schedule", "schedule_init")
 	else:
+		log("Make normal schedule!")
 		schedule = instantiate_node(model, "Schedule", "schedule_run")
 
 	while (read_nr_out(all_blocks) > 0):
+		log("Loop 1")
 		element_name = set_pop(all_blocks)
 		if (bool_not(set_in(visited, element_name))):
 			list_append(to_visit, element_name)
 
 		while (list_len(to_visit) > 0):
+			log("Loop 2")
 			element_name = list_read(to_visit, list_len(to_visit) - 1)
 			if (reverseKeyLookup(model["metamodel"]["model"], dict_read_node(model["type_mapping"], model["model"][element_name])) == "DelayBlock"):
 				if (is_time_zero):
+					log("Checking all incoming 0")
 					incoming_links = allIncomingAssociationInstances(model, element_name, "InitialCondition")
 				else:
 					incoming_links = create_node()
 			else:
+				log("Checking all incoming n")
 				incoming_links = allIncomingAssociationInstances(model, element_name, "Link")
 			ready = True
 
 			while (list_len(incoming_links) > 0):
+				log("Loop 3")
 				link = set_pop(incoming_links)
 				source = readAssociationSource(model, link)
+				log("Read association")
 				if (bool_not(set_in(visited, source))):
 					list_append(to_visit, source)
 					ready = False
 
+			log("Check ready!")
 			if (ready):
+				log("Ready!")
 				new_schedule = instantiate_node(model, "Schedule", "")
-				instantiate_attribute(model, reverseKeyLookup(model["model"], schedule), "block", model["model"][element_name])
-				instantiate_attribute(model, reverseKeyLookup(model["model"], schedule), "next", model["model"][new_schedule])
+				log("Instantiate 1")
+				instantiate_link(model, "ConnectedBlock", "", schedule, element_name)
+				log("Instantiate 2")
+				instantiate_link(model, "NextSchedule", "", schedule, new_schedule)
+				log("Instantiate 3")
 				schedule = new_schedule
 				list_delete(to_visit, list_len(to_visit) - 1)
 				set_add(visited, element_name)
 
+	log("Done!")
 	return !
 
 Void function execute_cbd(model : Element):