Browse Source

Updated wrapper with AL execution for Simon

Yentl Van Tendeloo 8 years ago
parent
commit
206efc25ee
6 changed files with 91 additions and 50 deletions
  1. 0 13
      bootstrap/model_management.alc
  2. 6 1
      core/core_algorithm.alc
  3. 14 8
      core/mini_modify.alc
  4. 22 0
      models/petrinets.mvc
  5. 49 12
      wrappers/modelverse.py
  6. 0 16
      wrappers/test.py

+ 0 - 13
bootstrap/model_management.alc

@@ -161,7 +161,6 @@ Element function model_join(models : Element, metamodel : Element, tracability_m
 	while (read_nr_out(models) > 0):
 		tagged_model = set_pop(models)
 		retyping_key = string_join(list_read(tagged_model, 0), "/")
-		log("Retyping key: " + retyping_key)
 		model = list_read(tagged_model, 1)
 
 		// Add all elements from 'model'
@@ -197,7 +196,6 @@ Element function model_join(models : Element, metamodel : Element, tracability_m
 	// Now link in the tracability model
 	// Go over all TracabilityLink elements and connect them in the merged model as well
 
-	log("Searching for tracability links to join")
 	if (element_neq(tracability_model, read_root())):
 		Element tracability_links
 		String tracability_link
@@ -205,29 +203,18 @@ Element function model_join(models : Element, metamodel : Element, tracability_m
 		String new_name_dst
 
 		tracability_links = allInstances(tracability_model, "TracabilityLink")
-		log("Got tracability links to link: " + cast_v2s(read_nr_out(tracability_links)))
 
 		while (read_nr_out(tracability_links) > 0):
 			tracability_link = set_pop(tracability_links)
-			log("Processing link " + cast_e2s(tracability_link))
-			log("In tracability model: " + cast_e2s(tracability_model["model"][tracability_link]))
 
 			// Get necessary information from the tracability link
-			log("Source: " + cast_id2s(read_edge_src(tracability_model["model"][tracability_link])))
-			log("Destination: " + cast_id2s(read_edge_dst(tracability_model["model"][tracability_link])))
-			log("Got elem map: " + set_to_string(dict_keys(elem_map)))
 
 			new_name_src = elem_map[cast_id2s(read_edge_src(tracability_model["model"][tracability_link]))]
 			new_name_dst = elem_map[cast_id2s(read_edge_dst(tracability_model["model"][tracability_link]))]
 			type = read_attribute(tracability_model, tracability_link, "type")
 
-			log("Link element from " + new_name_src)
-			log("Link element fo   " + new_name_dst)
-			log("Of type: " + type)
-
 			// Connect the two with the info we have
 			new_name = instantiate_link(new_model, type, "", new_name_src, new_name_dst)
-			log("New name of link: " + new_name)
 
 			if (new_name == ""):
 				log("ERROR: could not create a tracability link; ignoring")

+ 6 - 1
core/core_algorithm.alc

@@ -1063,6 +1063,11 @@ String function cmd_transformation_execute(user_id : String, transformation_name
 						else:
 							return "Permission denied to model: " + target_model_name!
 
+				if (read_type(core, transformation_id) == "ActionLanguage"):
+					output("Success: ready for AL execution")
+				elif (read_type(core, transformation_id) == "ManualOperation"):
+					output("Success: ready for MANUAL execution")
+
 				result = execute_operation(transformation_id, inputs, dict_keys(outputs), read_root())
 
 				// Now write out the models again
@@ -1366,7 +1371,7 @@ String function transformation_add(user_id : String, source_model_names : Elemen
 
 		elif (operation_type == "actionlanguage"):
 			// Finished with all information, now create the model itself!
-			output("Waiting for model constructors...")
+			output("Waiting for code constructors...")
 			add_code_model(get_full_model(get_model_id("ActionLanguage")), "AL/" + operation_name, construct_function())
 			model_create(import_node("AL/" + operation_name), operation_name, user_id, get_model_id("ActionLanguage"), "ActionLanguage")
 			model_id = get_model_id(operation_name)

+ 14 - 8
core/mini_modify.alc

@@ -390,13 +390,18 @@ Element function set_input(prompt : String):
 	if (verbose):
 		output(prompt)
 		output("-- Set input: empty string to terminate set")
-	set_add(result, input())
 
-	return result!
+	Element inp
+	while (True):
+		inp = input()
+		if (value_eq(inp, "")):
+			return result!
+		else:
+			set_add(result, inp)
 
 Element function dict_input(prompt : String):
 	Element result
-	String key
+	Element key
 	
 	result = create_node()
 
@@ -404,11 +409,12 @@ Element function dict_input(prompt : String):
 		output(prompt)
 		output("-- Dict input: empty key to terminate dict")
 
-	key = input()
-	while (key != ""):
-		dict_add(result, key, input())
-
-	return result!
+	while (True):
+		key = input()
+		if (value_eq(key, "")):
+			return result!
+		else:
+			dict_add(result, key, input())
 
 Void function set_verbose(v : Boolean):
 	verbose = v

+ 22 - 0
models/petrinets.mvc

@@ -0,0 +1,22 @@
+import models/SimpleClassDiagrams as SimpleClassDiagrams
+
+SimpleClassDiagrams PetriNets_Design{
+    SimpleAttribute Natural {}
+    SimpleAttribute String {}
+
+    Class Place {
+        tokens : Natural
+        name : String
+    }
+    Class Transition {
+        name : String
+    }
+    Association P2T (Place, Transition) {
+        weight : Natural
+    }
+    Association T2P (Transition, Place) {
+        weight : Natural
+    }
+}
+
+export PetriNets_Design to models/PetriNets_Design

+ 49 - 12
wrappers/modelverse.py

@@ -125,17 +125,17 @@ def _last_output():
 def _handle_output(requested=None, split=None):
     value = _output()
     if value.startswith("Model exists: "):
-        raise ModelExists()
+        raise ModelExists(value.split(": ", 1)[1])
     elif value.startswith("Permission denied"):
-        raise PermissionDenied()
+        raise PermissionDenied(value.split(": ", 1)[1])
     elif value.startswith("Model not found: "):
-        raise UnknownModel()
+        raise UnknownModel(value.split(": ", 1)[1])
     elif value.startswith("Element not found: "):
-        raise UnknownIdentifier()
+        raise UnknownIdentifier(value.split(": ", 1)[1])
     elif value.startswith("Element exists: "):
-        raise ElementExists()
+        raise ElementExists(value.split(": ", 1)[1])
     elif value.startswith("Attribute not found: "):
-        raise NoSuchAttribute()
+        raise NoSuchAttribute(value.split(": ", 1)[1])
     elif requested is not None and value.startswith(requested):
         if split is None:
             return value
@@ -374,17 +374,54 @@ def transformation_add_MT():
     """Create a new model transformation."""
     raise NotImplementedError()
 
-def transformation_add_AL():
-    """Create a new action language fragment."""
-    raise NotImplementedError()
+def transformation_add_AL(source_metamodels, target_metamodels, operation_name, code):
+    """Create a new action language model, which can be executed."""
+    global mode
+    if mode != 2:
+        raise InvalidMode()
+
+    try:
+        compiled = _compile_AL(code)
+    except Exception as e:
+        raise CompilationError(e)
+
+    _input(["transformation_add_AL"] + source_metamodels + [""] + target_metamodels + [""] + [operation_name])
+    _handle_output("Waiting for code constructors...")
+    _input(compiled)
+    _output("Success")
 
 def transformation_add_MANUAL():
     """Create a new manual model operation."""
     raise NotImplementedError()
 
-def transformation_execute():
+def transformation_execute_AL(operation_name, input_models_dict, output_models_dict, callback=lambda i: None):
     """Execute an existing model operation."""
-    raise NotImplementedError()
+    global mode
+    if mode != 2:
+        raise InvalidMode()
+
+    mv_dict_rep = []
+    for key, value in input_models_dict.items():
+        mv_dict_rep += [key, value]
+    mv_dict_rep += [""]
+    for key, value in output_models_dict.items():
+        mv_dict_rep += [key, value]
+    mv_dict_rep += [""]
+
+    _input(["transformation_execute", operation_name] + mv_dict_rep)
+    _handle_output("Success: ready for AL execution")
+
+    # We are now executing, so everything we get is part of the dialog, except if it is the string for transformation termination
+    while _output() not in ["Success", "Failure"]:
+        reply = callback(_last_output())
+        if reply is not None:
+            _input(reply)
+
+    # Got termination message, so we are done!
+    if _last_output() == "Success":
+        return True
+    else:
+        return False
 
 def transformation_list():
     """List existing model operations."""
@@ -669,7 +706,7 @@ def attr_assign_code(model_name, ID, attr, code):
 
     try:
         _input(["attr_add", ID, attr])
-        output = _handle_output("Waiting for code constructors...")
+        _handle_output("Waiting for code constructors...")
         _input(compiled)
         _output("Success")
     finally:

+ 0 - 16
wrappers/test.py

@@ -1,16 +0,0 @@
-from modelverse import *
-import time
-import sys
-import random
-
-init()
-login(str(random.random()), str(random.random()))
-
-tot = 0.0
-
-for _ in range(10):
-    start = time.time()
-    model_list()
-    tot += (time.time() - start)
-
-print(tot/10.0)