Pārlūkot izejas kodu

Merge branch 'AL_transform' into testing

Yentl Van Tendeloo 8 gadi atpakaļ
vecāks
revīzija
4bc304fa53

BIN
bootstrap/bootstrap.m.gz


+ 1 - 1
bootstrap/conformance_scd.alc

@@ -214,7 +214,7 @@ String function conformance_scd(model : Element):
 				String result
 				Element func
 
-				func = get_func_AL_model(constraint_function)
+				func = get_func_AL_model(import_node(constraint_function))
 				result = func(model, model_name)
 
 				if (result != "OK"):

+ 0 - 1
bootstrap/metamodels.alc

@@ -17,7 +17,6 @@ String function constraint_Natural(model : Element, name : String):
 
 Element function constraint_String(model : Element, name : String):
 	Element self
-	log("Invoked!")
 	self = model["model"][name]
 	if (is_physical_string(self)):
 		return "OK"!

+ 0 - 3
bootstrap/model_management.alc

@@ -56,9 +56,6 @@ Element function model_copy(src_model : Element):
 	String type
 
 	dst_model = instantiate_model(src_model["metamodel"])
-	dict_add(dst_model, "model", create_node())
-	dict_add(dst_model, "type_mapping", create_node())
-
 	queue = set_to_list(dict_keys(src_model["model"]))
 
 	while (read_nr_out(queue) > 0):

+ 2 - 9
bootstrap/modelling.alc

@@ -372,7 +372,7 @@ Element function read_attribute(model : Element, element : String, attribute : S
 			i = i + 1
 
 	else:
-		log("Element does not exist!")
+		log("Element does not exist: " + element)
 
 	// Not found: either element doesn't exist, or we couldn't find it
 	return read_root()!
@@ -629,14 +629,10 @@ Element function construct_model_raw(metamodel : Element):
 		else:
 			log("Modelling error: did not understand command " + command)
 
-Element function get_func_AL_model(model_location : String):
+Element function get_func_AL_model(al_model : Element):
 	Element result
-	Element al_model
 	Element initial_function
 
-	// Fetch the model to execute
-	al_model = import_node(model_location)
-
 	// Find the initial function
 	initial_function = allInstances(al_model, "Initial")
 
@@ -648,8 +644,5 @@ Element function get_func_AL_model(model_location : String):
 		return create_node()!
 	else:
 		initial_function = al_model["model"][set_pop(allAssociationDestinations(al_model, set_pop(initial_function), "initial_funcdef"))]
-		log("Found initial_function: " + cast_e2s(initial_function))
-		log("Keys: " + set_to_string(dict_keys(initial_function)))
-		log("Resolved " + model_location)
 
 	return initial_function!

+ 7 - 7
bootstrap/transform.alc

@@ -4,6 +4,7 @@ include "modelling.alh"
 include "random.alh"
 include "conformance_scd.alh"
 include "model_management.alh"
+include "library.alh"
 
 Element function make_matching_schedule(schedule_model : Element, LHS : String, ignore : Element):
 	Element schedule
@@ -120,7 +121,6 @@ Element function get_possible_bindings(host_model : Element, schedule_model : El
 			options = allInstances(host_model, original_typename)
 		elif (read_nr_out(options) > 1):
 			// Multiple "only" options, which will not work out: no options!
-			log("    multi!")
 			return create_node()!
 
 	// Filter options further
@@ -146,7 +146,7 @@ Element function get_possible_bindings(host_model : Element, schedule_model : El
 				Element func
 
 				constraint_function = read_attribute(schedule_model, current_element, "constraint")
-				func = get_func_AL_model(constraint_function)
+				func = get_func_AL_model(import_node(constraint_function))
 				result = func(host_model, option)
 
 				if (result):
@@ -178,7 +178,7 @@ Element function get_possible_bindings(host_model : Element, schedule_model : El
 			value = read_attribute(schedule_model, current_element, attribute)
 			// Attribute might be undefined, so skip if it is
 			if (element_neq(value, read_root())):
-				func = get_func_AL_model(value)
+				func = get_func_AL_model(import_node(value))
 				result = func(read_attribute(host_model, option, string_substr(attribute, string_len("constraint_"), string_len(attribute) + 1)))
 			else:
 				result = True
@@ -276,7 +276,7 @@ Element function match(host_model : Element, schedule_model : Element, LHS : Str
 	if (element_neq(constraint, read_root())):
 		while (read_nr_out(mappings) > 0):
 			map = set_pop(mappings)
-			func = get_func_AL_model(constraint)
+			func = get_func_AL_model(import_node(constraint))
 			result = func(host_model, map)
 
 			if (result):
@@ -373,7 +373,7 @@ Void function rewrite(host_model : Element, schedule_model : Element, RHS : Stri
 
 			value = read_attribute(schedule_model, RHS_map[label], attribute)
 			if (element_neq(value, read_root())):
-				func = get_func_AL_model(value)
+				func = get_func_AL_model(import_node(value))
 				result = func(host_model, new_mapping[label], mapping)
 
 				if (has_value(result)):
@@ -387,7 +387,7 @@ Void function rewrite(host_model : Element, schedule_model : Element, RHS : Stri
 		action = read_attribute(schedule_model, RHS_map[label], "action")
 		if (element_neq(action, read_root())):
 			Element func
-			func = get_func_AL_model(action)
+			func = get_func_AL_model(import_node(action))
 			func(host_model, new_mapping[label], mapping)
 
 	while (read_nr_out(labels_to_remove) > 0):
@@ -400,7 +400,7 @@ Void function rewrite(host_model : Element, schedule_model : Element, RHS : Stri
 	action = read_attribute(schedule_model, RHS, "action")
 	if (element_neq(action, read_root())):
 		Element func
-		func = get_func_AL_model(action)
+		func = get_func_AL_model(import_node(action))
 		func(host_model, new_mapping)
 
 	return!

+ 145 - 4
core/core_algorithm.alc

@@ -21,16 +21,21 @@ Void function main():
 	String core_model
 	String core_formalism_model
 	String scd_model
+	Element al_model
 	String admin_group
 	String admin_user
 	String nobody_group
 	String instance_of
 	String core_formalism
 	Element scd
+	Element al
 
 	String scd_location
+	String al_location
 	scd_location = "models/SimpleClassDiagrams"
 	scd = import_node(scd_location)
+	al_location = "models/ActionLanguage"
+	al = import_node(al_location)
 
 	// Create the Model itself and make public
 	core_formalism = import_node(core_location)
@@ -94,6 +99,18 @@ Void function main():
 	instantiate_link(core, "group", "", scd_model, admin_group)
 	instantiate_link(core, "owner", "", scd_model, admin_user)
 
+	// Add the Action Language formalism
+	al_model = instantiate_node(core, "Model", "")
+	instantiate_attribute(core, al_model, "name", "ActionLanguage")
+	instantiate_attribute(core, al_model, "location", al_location + "/model")
+	instantiate_attribute(core, al_model, "permissions", "221")
+	instance_of = instantiate_link(core, "instanceOf", "", al_model, scd_model)
+	instantiate_attribute(core, instance_of, "type_mapping", al["type_mapping"])
+
+	// Make necessary links for the formalism to the owners
+	instantiate_link(core, "group", "", al_model, admin_group)
+	instantiate_link(core, "owner", "", al_model, admin_user)
+
 	// Add the core formalism already
 	core_formalism_model = instantiate_node(core, "Model", "")
 	instantiate_attribute(core, core_formalism_model, "name", "CoreFormalism")
@@ -146,6 +163,7 @@ Element function get_full_model(model_id : String):
 	Element m
 	Element all_links
 	String choice
+	log("Getting full model!")
 
 	choice = get_instanceOf_link(model_id)
 
@@ -159,6 +177,7 @@ Element function get_full_model(model_id : String):
 	else:
 		dict_add(m, "metamodel", get_full_model(readAssociationDestination(core, choice)))
 
+	log("Finished!")
 	return m!
 
 Integer function get_relation_to_model(user_id : String, model_id : String):
@@ -349,7 +368,7 @@ Void function model_create(model : Element, name : String, user_id : String, typ
 	String model_id
 	String instance_of
 
-	location = "/models/" + cast_id2s(model)
+	location = "models/" + cast_id2s(model)
 	export_node(location, model["model"])
 
 	// Manage meta-info
@@ -368,7 +387,7 @@ Void function model_overwrite(model : Element, model_id : String):
 	String location
 	String instanceOf_link
 
-	location = "/models/" + cast_id2s(model)
+	location = "models/" + cast_id2s(model)
 	export_node(location, model["model"])
 
 	// Change location in meta-data
@@ -567,7 +586,6 @@ Void function user_function_skip_init(user_id : String):
 
 							schedule_model = get_full_model(transformation_id)
 
-							// Need to fall back to the default approach, which is way slower
 							// 1) Create empty instance of merged metamodel
 
 							ramified_metamodel_id = set_pop(followAssociation(core, transformation_id, "instanceOf"))
@@ -619,7 +637,54 @@ Void function user_function_skip_init(user_id : String):
 							else:
 								output("Could not resolve intermediate merged metamodel")
 						elif (exact_type == "ActionLanguage"):
-							output("Not Implemented yet!")
+							Element dictionary
+							Element new_inputs
+							Element input_keys
+							Element output_keys
+							Element result
+							String key
+							Element func
+
+							log("Action Language execution starts!")
+							log("Getting full model for transformation")
+							log("Got model: " + cast_e2s(read_attribute(core, transformation_id, "location")))
+
+							// 1) Group source models in dictionary
+							//  --> This is just the "inputs" variable, but resolve all references
+							log("Create inputs")
+							new_inputs = create_node()
+							input_keys = dict_keys(inputs)
+							while (read_nr_out(input_keys) > 0):
+								key = set_pop(input_keys)
+								log("Resolving " + cast_e2s(key))
+								log("  --> " + cast_e2s(inputs[key]))
+								log("  ID " + cast_e2s(get_model_id(inputs[key])))
+								log("  full m " + cast_e2s(get_full_model(get_model_id(inputs[key]))))
+								dict_add(new_inputs, key, get_full_model(get_model_id(inputs[key])))
+							inputs = new_inputs
+
+							// 2) Execute action language model
+							func = get_func_AL_model(get_full_model(transformation_id))
+							log("Ready to execute: " + cast_e2s(func))
+							result = func(inputs)
+							log("Result: " + cast_e2s(result))
+
+							// 3) Split output dictionary back to seperate models
+							output_keys = dict_keys(outputs)
+							while (read_nr_out(output_keys) > 0):
+								key = set_pop(output_keys)
+								log("Splitting " + key)
+
+								// Check if the destination model already exists
+								if (get_model_id(outputs[key]) == ""):
+									// New model
+									model_create(result[key], outputs[key], user_id, get_model_id(key), "Model")
+								else:
+									// Model exists, so we overwrite
+									model_overwrite(result[key], get_model_id(outputs[key]))
+
+							log("Finished")
+
 						else:
 							output("Did not know how to interpret model of type " + exact_type)
 					else:
@@ -828,6 +893,82 @@ Void function user_function_skip_init(user_id : String):
 			else:
 				output("No such model")
 
+		elif (cmd == "transformation_add_AL"):
+			// Add an action language transformation model
+			output("Which metamodels do you want to use as source for the action code (empty string to finish)?")
+			String model_id
+			Element models
+			Element source
+			Element target
+			String name
+
+			name = input()
+			source = create_node()
+			target = create_node()
+
+			while (name != ""):
+				model_id = get_model_id(name)
+				if (model_id != ""):
+					if (bool_not(set_in(source, model_id))):
+						set_add(source, model_id)
+						output("Model added as source")
+					else:
+						output("Model already selected as source")
+				else:
+					output("No such model; try again")
+				
+				name = input()
+
+			output("Which metamodels do you want to use as target for the action code (empty string to finish)?")
+			name = input()
+			while (name != ""):
+				model_id = get_model_id(name)
+				if (model_id != ""):
+					if (bool_not(set_in(target, model_id))):
+						set_add(target, model_id)
+						output("Model added as target")
+					else:
+						output("Model already selected as target")
+				else:
+					output("No such model; try again")
+				
+				name = input()
+
+			output("Name of Action Language model?")
+			name = input()
+
+			log("Add AL is fine!")
+			if (get_model_id(name) == ""):
+				// Finished with all information, now create the model itself!
+				output("Waiting for model constructors...")
+				log("AL model: " + cast_e2s(get_model_id("ActionLanguage")))
+				log("Location: " + cast_e2s(read_attribute(core, get_model_id("ActionLanguage"), "location")))
+				log("Imported: " + cast_e2s(import_node(read_attribute(core, get_model_id("ActionLanguage"), "location"))))
+				add_code_model(get_full_model(get_model_id("ActionLanguage")), "AL/" + name, construct_function())
+				log("Exported to " + cast_e2s(import_node("AL/" + name)))
+				model_create(import_node("AL/" + name), name, user_id, get_model_id("ActionLanguage"), "ActionLanguage")
+				model_id = get_model_id(name)
+
+				// Extend metadata with info on source and target
+				String link
+				String dst
+
+				log("Adding inputs")
+				while (read_nr_out(source) > 0):
+					dst = set_pop(source)
+					log(" for " + dst)
+					link = instantiate_link(core, "transformInput", "", model_id, dst)
+					instantiate_attribute(core, link, "name", read_attribute(core, dst, "name"))
+
+				log("Adding outputs")
+				while (read_nr_out(target) > 0):
+					dst = set_pop(target)
+					log(" for " + dst)
+					link = instantiate_link(core, "transformOutput", "", model_id, dst)
+					instantiate_attribute(core, link, "name", read_attribute(core, dst, "name"))
+			else:
+				output("Model already exists")
+
 		elif (cmd == "transformation_add_MT"):
 			// Add a model transformation model
 			// Just a usual model instantiation, but need to add the source and target links based on user info

+ 88 - 0
integration/code/pn_simulate.alc

@@ -0,0 +1,88 @@
+include "primitives.alh"
+include "modelling.alh"
+include "random.alh"
+include "model_management.alh"
+include "object_operations.alh"
+include "modelling.alh"
+
+Element function simulate(inputs : Element):
+	log("Start PN step!")
+	Element outputs
+	outputs = create_node()
+
+	log("Inputs: " + dict_to_string(inputs))
+	log("PN input: " + cast_e2s(inputs["PetriNets_Runtime"]))
+	log("Outgoing: " + set_to_string(dict_keys(inputs["PetriNets_Runtime"])))
+
+	// Copy over the model to the output dictionary
+	dict_add(outputs, "PetriNets_Runtime", model_copy(inputs["PetriNets_Runtime"]))
+
+	log("Copy OK!")
+
+	// Do a single simulation step
+	Element model
+	model = outputs["PetriNets_Runtime"]
+
+	// Find enabled transitions
+	Element all_transitions
+	Element enabled_transitions
+	String under_study
+	Boolean enabled
+	Element in_arcs
+	String arc_under_study
+
+	all_transitions = allInstances(model, "Transition")
+	enabled_transitions = create_node()
+
+	while (0 < read_nr_out(all_transitions)):
+		under_study = set_pop(all_transitions)
+		enabled = True
+
+		// Find all incoming transitions
+		in_arcs = allIncomingAssociationInstances(model, under_study, "P2T")
+
+		while (0 < read_nr_out(in_arcs)):
+			arc_under_study = set_pop(in_arcs)
+
+			Integer present_tokens
+			Integer required_tokens
+			required_tokens = read_attribute(model, arc_under_study, "weight")
+			log("Weight: " + cast_i2s(required_tokens))
+			present_tokens = read_attribute(model, reverseKeyLookup(model["model"], read_edge_src(model["model"][arc_under_study])), "tokens")
+			log("Tokens: " + cast_i2s(present_tokens))
+			if (present_tokens < required_tokens):
+				// Less tokens than required, so disable the transition completely
+				enabled = False
+
+		if (enabled):
+			set_add(enabled_transitions, under_study)
+
+	// Pick random enabled transition
+	String transition
+
+	transition = random_choice(enabled_transitions)
+
+	// Consume tokens
+	Element workset
+	String working_arc
+	String working_place
+	Integer new_value
+
+	workset = allIncomingAssociationInstances(model, transition, "P2T")
+	while (0 < read_nr_out(workset)):
+		working_arc = set_pop(workset)
+		working_place = reverseKeyLookup(model["model"], read_edge_src(model["model"][working_arc]))
+		new_value = integer_subtraction(read_attribute(model, working_place, "tokens"), read_attribute(model, working_arc, "weight"))
+		instantiate_attribute(model, working_place, "tokens", new_value)
+
+	// Add tokens
+	workset = allOutgoingAssociationInstances(model, transition, "T2P")
+	while (0 < read_nr_out(workset)):
+		working_arc = set_pop(workset)
+		working_place = reverseKeyLookup(model["model"], read_edge_dst(model["model"][working_arc]))
+		new_value = integer_addition(read_attribute(model, working_place, "tokens"), read_attribute(model, working_arc, "weight"))
+		instantiate_attribute(model, working_place, "tokens", new_value)
+
+	// Finish up
+	log("Finished PN Step!")
+	return outputs!

+ 326 - 0
integration/test_mvc.py

@@ -40,6 +40,7 @@ class TestModelverseCore(unittest.TestCase):
                 "Ready for command...",
                 set(["  SimpleClassDiagrams : SimpleClassDiagrams",
                      "  CoreFormalism : SimpleClassDiagrams",
+                     "  ActionLanguage : SimpleClassDiagrams",
                      "  core : CoreFormalism"]),
             ],
             mode))
@@ -61,6 +62,7 @@ class TestModelverseCore(unittest.TestCase):
                 "Ready for command...",
                 set(["  221  root admin   SimpleClassDiagrams : SimpleClassDiagrams",
                      "  221  root admin   CoreFormalism : SimpleClassDiagrams",
+                     "  221  root admin   ActionLanguage : SimpleClassDiagrams",
                      "  200  root admin   core : CoreFormalism"]),
             ],
             mode))
@@ -93,12 +95,14 @@ class TestModelverseCore(unittest.TestCase):
                 "Ready for command...",
                 set(["  SimpleClassDiagrams : SimpleClassDiagrams",
                      "  CoreFormalism : SimpleClassDiagrams",
+                     "  ActionLanguage : SimpleClassDiagrams",
                      "  Empty : SimpleClassDiagrams",
                      "  core : CoreFormalism"]),
                 "Ready for command...",
                 set(["  221  root admin   SimpleClassDiagrams : SimpleClassDiagrams",
                      "  221  root admin   CoreFormalism : SimpleClassDiagrams",
                      "  200  root nobody   Empty : SimpleClassDiagrams",
+                     "  221  root admin   ActionLanguage : SimpleClassDiagrams",
                      "  200  root admin   core : CoreFormalism"]),
             ],
             mode))
@@ -139,11 +143,13 @@ class TestModelverseCore(unittest.TestCase):
                 set(["  SimpleClassDiagrams : SimpleClassDiagrams",
                      "  CoreFormalism : SimpleClassDiagrams",
                      "  Empty : SimpleClassDiagrams",
+                     "  ActionLanguage : SimpleClassDiagrams",
                      "  core : CoreFormalism"]),
                 "Ready for command...",
                 set(["  221  root admin   SimpleClassDiagrams : SimpleClassDiagrams",
                      "  221  root admin   CoreFormalism : SimpleClassDiagrams",
                      "  200  root nobody   Empty : SimpleClassDiagrams",
+                     "  221  root admin   ActionLanguage : SimpleClassDiagrams",
                      "  200  root admin   core : CoreFormalism"]),
                 "Ready for command...",
                 "Which model do you want to modify?",
@@ -157,6 +163,7 @@ class TestModelverseCore(unittest.TestCase):
                 "Ready for command...",
                 set(["  221  root admin   SimpleClassDiagrams : SimpleClassDiagrams",
                      "  221  root admin   CoreFormalism : SimpleClassDiagrams",
+                     "  221  root admin   ActionLanguage : SimpleClassDiagrams",
                      "  200  root nobody   Empty : SimpleClassDiagrams",
                      "  200  root admin   core : CoreFormalism"]),
                 "Ready for command...",
@@ -214,6 +221,7 @@ class TestModelverseCore(unittest.TestCase):
                 set(["  221  root admin   SimpleClassDiagrams : SimpleClassDiagrams",
                      "  221  root admin   CoreFormalism : SimpleClassDiagrams",
                      "  200  root nobody   Empty : SimpleClassDiagrams",
+                     "  221  root admin   ActionLanguage : SimpleClassDiagrams",
                      "  200  root admin   core : CoreFormalism"]),
                 "Ready for command...",
                 "Which model do you want to modify?",
@@ -227,6 +235,7 @@ class TestModelverseCore(unittest.TestCase):
                 "Ready for command...",
                 set(["  221  root admin   SimpleClassDiagrams : SimpleClassDiagrams",
                      "  221  root admin   CoreFormalism : SimpleClassDiagrams",
+                     "  221  root admin   ActionLanguage : SimpleClassDiagrams",
                      "  200  root nobody   Empty : SimpleClassDiagrams",
                      "  200  root admin   core : CoreFormalism"]),
                 "Ready for command...",
@@ -236,6 +245,7 @@ class TestModelverseCore(unittest.TestCase):
                 "Ready for command...",
                 set(["  221  root admin   SimpleClassDiagrams : SimpleClassDiagrams",
                      "  221  root admin   CoreFormalism : SimpleClassDiagrams",
+                     "  221  root admin   ActionLanguage : SimpleClassDiagrams",
                      "  200  root nobody   Empty : SimpleClassDiagrams",
                      "  200  root admin   core : CoreFormalism"]),
                 "Ready for command...",
@@ -284,6 +294,7 @@ class TestModelverseCore(unittest.TestCase):
                 set(["  221  root admin   SimpleClassDiagrams : SimpleClassDiagrams",
                      "  221  root admin   CoreFormalism : SimpleClassDiagrams",
                      "  200  root nobody   PetriNets : SimpleClassDiagrams",
+                     "  221  root admin   ActionLanguage : SimpleClassDiagrams",
                      "  200  root admin   core : CoreFormalism"]),
                 "Ready for command...",
                 "Formalisms to include (terminate with empty string)?",
@@ -294,6 +305,7 @@ class TestModelverseCore(unittest.TestCase):
                      "  200  root nobody   PetriNets : SimpleClassDiagrams",
                      "  200  root nobody   __merged_PetriNets_RAM : SimpleClassDiagrams",
                      "  200  root nobody   PetriNets_RAM : SimpleClassDiagrams",
+                     "  221  root admin   ActionLanguage : SimpleClassDiagrams",
                      "  200  root admin   core : CoreFormalism"]),
                 "Ready for command...",
             ],
@@ -341,6 +353,7 @@ class TestModelverseCore(unittest.TestCase):
                 "Ready for command...",
                 set(["  221  root admin   SimpleClassDiagrams : SimpleClassDiagrams",
                      "  221  root admin   CoreFormalism : SimpleClassDiagrams",
+                     "  221  root admin   ActionLanguage : SimpleClassDiagrams",
                      "  200  root nobody   PetriNets : SimpleClassDiagrams",
                      "  200  root admin   core : CoreFormalism"]),
                 "Ready for command...",
@@ -349,6 +362,7 @@ class TestModelverseCore(unittest.TestCase):
                 "Ready for command...",
                 set(["  221  root admin   SimpleClassDiagrams : SimpleClassDiagrams",
                      "  221  root admin   CoreFormalism : SimpleClassDiagrams",
+                     "  221  root admin   ActionLanguage : SimpleClassDiagrams",
                      "  200  root nobody   PetriNets : SimpleClassDiagrams",
                      "  200  root nobody   __merged_PetriNets_RAM : SimpleClassDiagrams",
                      "  200  root nobody   PetriNets_RAM : SimpleClassDiagrams",
@@ -370,6 +384,7 @@ class TestModelverseCore(unittest.TestCase):
                      "  200  root nobody   PetriNets : SimpleClassDiagrams",
                      "  200  root nobody   __merged_PetriNets_RAM : SimpleClassDiagrams",
                      "  200  root nobody   PetriNets_RAM : SimpleClassDiagrams",
+                     "  221  root admin   ActionLanguage : SimpleClassDiagrams",
                      "  200  root nobody   PetriNets_Print : PetriNets_RAM",
                      "  200  root admin   core : CoreFormalism"]),
                 "Ready for command...",
@@ -422,6 +437,7 @@ class TestModelverseCore(unittest.TestCase):
                 "Ready for command...",
                 set(["  221  root admin   SimpleClassDiagrams : SimpleClassDiagrams",
                      "  221  root admin   CoreFormalism : SimpleClassDiagrams",
+                     "  221  root admin   ActionLanguage : SimpleClassDiagrams",
                      "  200  root nobody   PetriNets : SimpleClassDiagrams",
                      "  200  root admin   core : CoreFormalism"]),
                 "Ready for command...",
@@ -431,6 +447,7 @@ class TestModelverseCore(unittest.TestCase):
                 set(["  221  root admin   SimpleClassDiagrams : SimpleClassDiagrams",
                      "  221  root admin   CoreFormalism : SimpleClassDiagrams",
                      "  200  root nobody   PetriNets : SimpleClassDiagrams",
+                     "  221  root admin   ActionLanguage : SimpleClassDiagrams",
                      "  200  root nobody   __merged_PetriNets_RAM : SimpleClassDiagrams",
                      "  200  root nobody   PetriNets_RAM : SimpleClassDiagrams",
                      "  200  root admin   core : CoreFormalism"]),
@@ -506,6 +523,7 @@ class TestModelverseCore(unittest.TestCase):
                 "Ready for command...",
                 set(["  221  root admin   SimpleClassDiagrams : SimpleClassDiagrams",
                      "  221  root admin   CoreFormalism : SimpleClassDiagrams",
+                     "  221  root admin   ActionLanguage : SimpleClassDiagrams",
                      "  200  root nobody   PetriNets : SimpleClassDiagrams",
                      "  200  root nobody   my_pn : PetriNets",
                      "  200  root admin   core : CoreFormalism"]),
@@ -514,6 +532,7 @@ class TestModelverseCore(unittest.TestCase):
                 "Name of the RAMified transformation metamodel?",
                 "Ready for command...",
                 set(["  221  root admin   SimpleClassDiagrams : SimpleClassDiagrams",
+                     "  221  root admin   ActionLanguage : SimpleClassDiagrams",
                      "  221  root admin   CoreFormalism : SimpleClassDiagrams",
                      "  200  root nobody   PetriNets : SimpleClassDiagrams",
                      "  200  root nobody   __merged_PetriNets_RAM : SimpleClassDiagrams",
@@ -680,6 +699,7 @@ class TestModelverseCore(unittest.TestCase):
                 "Ready for command...",
                 # model_list
                 set(["  SimpleClassDiagrams : SimpleClassDiagrams",
+                     "  ActionLanguage : SimpleClassDiagrams",
                      "  CoreFormalism : SimpleClassDiagrams",
                      "  PetriNets : SimpleClassDiagrams",
                      "  my_pn : PetriNets",
@@ -692,6 +712,7 @@ class TestModelverseCore(unittest.TestCase):
                 "Ready for command...",
                 # model_list
                 set(["  SimpleClassDiagrams : SimpleClassDiagrams",
+                     "  ActionLanguage : SimpleClassDiagrams",
                      "  CoreFormalism : SimpleClassDiagrams",
                      "  PetriNets_Runtime : SimpleClassDiagrams",
                      "  PetriNets : SimpleClassDiagrams",
@@ -805,6 +826,7 @@ class TestModelverseCore(unittest.TestCase):
                      "  __merged_PetriNets_RAM : SimpleClassDiagrams",
                      "  PetriNets_RAM : SimpleClassDiagrams",
                      "  my_pn : PetriNets",
+                     "  ActionLanguage : SimpleClassDiagrams",
                      "  core : CoreFormalism"]),
                 "Ready for command...",
                 # transformation_list
@@ -1015,6 +1037,7 @@ class TestModelverseCore(unittest.TestCase):
                      "  CoreFormalism : SimpleClassDiagrams",
                      "  PetriNets : SimpleClassDiagrams",
                      "  my_pn : PetriNets",
+                     "  ActionLanguage : SimpleClassDiagrams",
                      "  PetriNets_Runtime : SimpleClassDiagrams",
                      "  core : CoreFormalism"]),
                 "Ready for command...",
@@ -1027,6 +1050,7 @@ class TestModelverseCore(unittest.TestCase):
                      "  CoreFormalism : SimpleClassDiagrams",
                      "  PetriNets_Runtime : SimpleClassDiagrams",
                      "  PetriNets : SimpleClassDiagrams",
+                     "  ActionLanguage : SimpleClassDiagrams",
                      "  __merged_PetriNets_RAM : SimpleClassDiagrams",
                      "  PetriNets_RAM : SimpleClassDiagrams",
                      "  my_pn : PetriNets",
@@ -1130,6 +1154,7 @@ class TestModelverseCore(unittest.TestCase):
                      "  CoreFormalism : SimpleClassDiagrams",
                      "  PetriNets_Runtime : SimpleClassDiagrams",
                      "  PetriNets : SimpleClassDiagrams",
+                     "  ActionLanguage : SimpleClassDiagrams",
                      "  pn_print : PetriNets_RAM",
                      "  pn_design_to_runtime : PetriNets_RAM",
                      "  pn_runtime_to_design : PetriNets_RAM",
@@ -1164,3 +1189,304 @@ class TestModelverseCore(unittest.TestCase):
                     step_and_print() * 10 +
                 [],
             mode))
+
+    def test_po_transform_add_AL_pn_simulate(self):
+        self.transform_add_AL_pn_simulate("PO")
+
+    def transform_add_AL_pn_simulate(self, mode):
+        self.assertTrue(run_file(all_files,
+            [ "root", "root", "root", 
+                "model_add",
+                    "SimpleClassDiagrams",
+                    "PetriNets",
+                    ] + get_model_constructor(open("integration/code/pn_design.mvc", "r").read()) + [
+                "model_add",
+                    "SimpleClassDiagrams",
+                    "PetriNets_Runtime",
+                    ] + get_model_constructor(open("integration/code/pn_runtime.mvc", "r").read()) + [
+                "model_add",
+                    "PetriNets",
+                    "my_pn",
+                    ] + get_model_constructor(open("integration/code/pn_design_model.mvc", "r").read()) + [
+                "model_list",
+                "transformation_add_MT_language",
+                    "PetriNets_Runtime",
+                    "PetriNets",
+                    "",
+                    "PetriNets_RAM",
+                "model_list",
+                "model_modify",
+                    "__merged_PetriNets_RAM",
+                        "instantiate",
+                            "Association",
+                            "D2R_PlaceLink",
+                            "PetriNets/Place",
+                            "PetriNets_Runtime/Place",
+                        "instantiate",
+                            "Association",
+                            "D2R_TransitionLink",
+                            "PetriNets/Transition",
+                            "PetriNets_Runtime/Transition",
+                        "instantiate",
+                            "Association",
+                            "R2D_PlaceLink",
+                            "PetriNets_Runtime/Place",
+                            "PetriNets/Place",
+                        "instantiate",
+                            "Association",
+                            "R2D_TransitionLink",
+                            "PetriNets_Runtime/Transition",
+                            "PetriNets/Transition",
+                        "exit",
+                "transformation_RAMify",
+                    "__merged_PetriNets_RAM",
+                    "PetriNets_RAM",
+                "transformation_add_MT",
+                    "PetriNets_RAM",
+                    "PetriNets",
+                    "",
+                    "PetriNets_Runtime",
+                    "",
+                    "pn_design_to_runtime",
+                    ] + get_model_constructor(open("integration/code/pn_design_to_runtime.mvc", "r").read()) + [
+                "transformation_add_MT",
+                    "PetriNets_RAM",
+                    "PetriNets_Runtime",
+                    "",
+                    "PetriNets",
+                    "",
+                    "pn_runtime_to_design",
+                    ] + get_model_constructor(open("integration/code/pn_runtime_to_design.mvc", "r").read()) + [
+                "transformation_add_AL",
+                    "PetriNets_Runtime",
+                    "",
+                    "PetriNets_Runtime",
+                    "",
+                    "pn_step",
+                    ] + get_constructor(open("integration/code/pn_simulate.alc", "r").read()) + [
+                "transformation_add_MT",
+                    "PetriNets_RAM",
+                    "PetriNets",
+                    "",
+                    "",
+                    "pn_print",
+                    ] + get_model_constructor(open("integration/code/pn_print.mvc", "r").read()) + [
+                "model_list",
+                "transformation_list",
+                "transformation_execute",
+                "pn_print",
+                "my_pn",
+                "transformation_execute",
+                "pn_design_to_runtime",
+                "my_pn",
+                "my_pn_runtime",
+                "transformation_execute",
+                "pn_step",
+                "my_pn_runtime",
+                "my_pn_runtime",
+                "transformation_execute",
+                "pn_runtime_to_design",
+                "my_pn_runtime",
+                "my_pn",
+                "transformation_execute",
+                "pn_print",
+                "my_pn",
+            ],
+            [   # bootup phase
+                "Desired username for admin user?",
+                "Desired password for admin user?",
+                "Please repeat the password",
+                "Passwords match!",
+                "Welcome to the Model Management Interface v2.0!",
+                "Use the 'help' command for a list of possible commands",
+                "Ready for command...",
+                # model_add
+                "Creating new model!",
+                "Model type?",
+                "Model name?",
+                "Waiting for model constructors...",
+                "Model upload success!",
+                "Ready for command...",
+                # model_add
+                "Creating new model!",
+                "Model type?",
+                "Model name?",
+                "Waiting for model constructors...",
+                "Model upload success!",
+                "Ready for command...",
+                # model_add
+                "Creating new model!",
+                "Model type?",
+                "Model name?",
+                "Waiting for model constructors...",
+                "Model upload success!",
+                "Ready for command...",
+                # model_list
+                set(["  SimpleClassDiagrams : SimpleClassDiagrams",
+                     "  ActionLanguage : SimpleClassDiagrams",
+                     "  CoreFormalism : SimpleClassDiagrams",
+                     "  PetriNets : SimpleClassDiagrams",
+                     "  my_pn : PetriNets",
+                     "  PetriNets_Runtime : SimpleClassDiagrams",
+                     "  core : CoreFormalism"]),
+                "Ready for command...",
+                # transformation_add_MT_language
+                "Formalisms to include (terminate with empty string)?",
+                "Name of the RAMified transformation metamodel?",
+                "Ready for command...",
+                # model_list
+                set(["  SimpleClassDiagrams : SimpleClassDiagrams",
+                     "  ActionLanguage : SimpleClassDiagrams",
+                     "  CoreFormalism : SimpleClassDiagrams",
+                     "  PetriNets_Runtime : SimpleClassDiagrams",
+                     "  PetriNets : SimpleClassDiagrams",
+                     "  __merged_PetriNets_RAM : SimpleClassDiagrams",
+                     "  PetriNets_RAM : SimpleClassDiagrams",
+                     "  my_pn : PetriNets",
+                     "  core : CoreFormalism"]),
+                "Ready for command...",
+                # model_modify
+                "Which model do you want to modify?",
+                "Model loaded, ready for commands!",
+                "Use 'help' command for a list of possible commands",
+                "Please give your command.",
+                # instantiate 1
+                "Type to instantiate?",
+                "Name of new element?",
+                "Source name?",
+                "Destination name?",
+                "Instantiation successful!",
+                "Please give your command.",
+                # instantiate 2
+                "Type to instantiate?",
+                "Name of new element?",
+                "Source name?",
+                "Destination name?",
+                "Instantiation successful!",
+                "Please give your command.",
+                # instantiate 3
+                "Type to instantiate?",
+                "Name of new element?",
+                "Source name?",
+                "Destination name?",
+                "Instantiation successful!",
+                "Please give your command.",
+                # instantiate 4
+                "Type to instantiate?",
+                "Name of new element?",
+                "Source name?",
+                "Destination name?",
+                "Instantiation successful!",
+                "Please give your command.",
+                "Ready for command...",
+                # transformation_RAMify
+                "Which metamodel do you want to RAMify?",
+                "Where do you want to store the RAMified metamodel?",
+                "Ready for command...",
+                # transformation_add_MT
+                "RAMified metamodel to use?",
+                "Supported metamodels:",
+                set(["  PetriNets",
+                     "  PetriNets_Runtime",
+                    ]),
+                "",
+                "Which ones do you want to use as source (empty string to finish)?",
+                "Model added as source",
+                "Which ones do you want to use as target (empty string to finish)?",
+                "Model added as target",
+                "Name of new transformation?",
+                "Waiting for model constructors...",
+                "Ready for command...",
+                # transformation_add_MT
+                "RAMified metamodel to use?",
+                "Supported metamodels:",
+                set(["  PetriNets",
+                     "  PetriNets_Runtime",
+                    ]),
+                "",
+                "Which ones do you want to use as source (empty string to finish)?",
+                "Model added as source",
+                "Which ones do you want to use as target (empty string to finish)?",
+                "Model added as target",
+                "Name of new transformation?",
+                "Waiting for model constructors...",
+                "Ready for command...",
+                # transformation_add_AL
+                "Which metamodels do you want to use as source for the action code (empty string to finish)?",
+                "Model added as source",
+                "Which metamodels do you want to use as target for the action code (empty string to finish)?",
+                "Model added as target",
+                "Name of Action Language model?",
+                "Waiting for model constructors...",
+                "Ready for command...",
+                # transformation_add_MT
+                "RAMified metamodel to use?",
+                "Supported metamodels:",
+                set(["  PetriNets",
+                     "  PetriNets_Runtime",
+                    ]),
+                "",
+                "Which ones do you want to use as source (empty string to finish)?",
+                "Model added as source",
+                "Which ones do you want to use as target (empty string to finish)?",
+                "Name of new transformation?",
+                "Waiting for model constructors...",
+                "Ready for command...",
+                # model_list
+                set(["  SimpleClassDiagrams : SimpleClassDiagrams",
+                     "  CoreFormalism : SimpleClassDiagrams",
+                     "  PetriNets_Runtime : SimpleClassDiagrams",
+                     "  PetriNets : SimpleClassDiagrams",
+                     "  pn_print : PetriNets_RAM",
+                     "  pn_design_to_runtime : PetriNets_RAM",
+                     "  pn_runtime_to_design : PetriNets_RAM",
+                     "  pn_step : ActionLanguage",
+                     "  __merged_PetriNets_RAM : SimpleClassDiagrams",
+                     "  PetriNets_RAM : SimpleClassDiagrams",
+                     "  my_pn : PetriNets",
+                     "  ActionLanguage : SimpleClassDiagrams",
+                     "  core : CoreFormalism"]),
+                "Ready for command...",
+                # transformation_list
+                set(["[ModelTransformation] pn_print : PetriNets_RAM",
+                     "[ModelTransformation] pn_design_to_runtime : PetriNets_RAM",
+                     "[ModelTransformation] pn_runtime_to_design : PetriNets_RAM",
+                     "[ActionLanguage] pn_step : ActionLanguage"]),
+                "Ready for command...",
+                # transformation_execute (pn_print)
+                "Which transformation do you want to execute?",
+                "Which model to bind for source element PetriNets",
+                set(['"p1" --> 1',
+                     '"p2" --> 2',
+                     '"p3" --> 3',
+                    ]),
+                "Transformation executed with result: True",
+                "Ready for command...",
+                # transformation_execute (pn_design_to_runtime)
+                "Which transformation do you want to execute?",
+                "Which model to bind for source element PetriNets",
+                "Which model to create for target element PetriNets_Runtime",
+                "Transformation executed with result: True",
+                "Ready for command...",
+                # transformation_execute (pn_step)
+                "Which transformation do you want to execute?",
+                "Which model to bind for source element PetriNets_Runtime",
+                "Which model to create for target element PetriNets_Runtime",
+                "Ready for command...",
+                # transformation_execute (pn_runtime_to_design)
+                "Which transformation do you want to execute?",
+                "Which model to bind for source element PetriNets_Runtime",
+                "Which model to create for target element PetriNets",
+                "Transformation executed with result: True",
+                "Ready for command...",
+                # transformation_execute (pn_print)
+                "Which transformation do you want to execute?",
+                "Which model to bind for source element PetriNets",
+                set(['"p1" --> 0',
+                     '"p2" --> 1',
+                     '"p3" --> 5',
+                    ]),
+                "Transformation executed with result: True",
+                "Ready for command...",
+            ],
+            mode))

+ 2 - 1
interface/HUTN/includes/modelling.alh

@@ -21,4 +21,5 @@ Element function read_attribute(model : Element, elem : String, name : String)
 Void function model_delete_element(model : Element, name : String)
 String function model_define_attribute(model : Element, elem : String, name : String, optional : Boolean, type : String)
 Element function construct_model_raw(metamodel : Element)
-Element function get_func_AL_model(model_location : String)
+Element function get_func_AL_model(model : Element)
+Void function add_code_model(model : Element, export_name : String, code : Element)