Browse Source

current version

Simon Van Mierlo 9 years ago
parent
commit
779bf2bf68
4 changed files with 115 additions and 38 deletions
  1. 3 0
      bootstrap/core_algorithm.alc
  2. 105 38
      integration/code/ps_simulator.alc
  3. 6 0
      interface/PDEVS/console.py
  4. 1 0
      models/ps_to_devs.mvc

+ 3 - 0
bootstrap/core_algorithm.alc

@@ -1239,12 +1239,15 @@ String function cmd_transformation_execute(transformation_name : String, source_
 					// Check if exists
 					if (get_entry_id(tracability_name) == ""):
 						// No, so create
+                        log("Tracability model being created...")
 						tracability_model = instantiate_model(get_full_model(get_entry_id("formalisms/Tracability"), get_entry_id("formalisms/SimpleClassDiagrams")))
 						model_create(tracability_model, tracability_name, get_entry_id("formalisms/Tracability"), "Model")
 					else:
+                        log("Tracability model being created.lready exists...")
 						// Yes, so read out
 						tracability_model = get_full_model(get_entry_id(tracability_name), get_entry_id("formalisms/Tracability"))
 				else:
+                    log("No tracability...")
 					tracability_model = read_root()
 
 				result = execute_operation(transformation_id, inputs, tracability_model)

+ 105 - 38
integration/code/ps_simulator.alc

@@ -19,6 +19,21 @@ Boolean function main(model : Element):
     Element constructed_output
     Element to_output
     Element new_items
+    Element curr_param
+    Element keys
+    Element curr_key
+    Element devs_instances
+    Element curr_devs_instance
+    Element generators
+    Element curr_convbelt
+    Element splitted_key
+    Element connected_items
+    Element curr_item
+    Element curr_value
+    String curr_id
+    Element temp_dict
+    Boolean item_found
+    String devs_name
     
     pdevs_client_taskname = input()
     log("(PS) Got task name from console!")
@@ -51,10 +66,58 @@ Boolean function main(model : Element):
             log("(PS) " + the_output)
             parsed_value = json_deserialize(the_output)
             log("(PS) Parsed output!")
-            log("(PS) " + dict_to_string(parsed_value))
-            if (cast_v2s(parsed_value['name']) == 'new_states'):
-                constructed_output = list_create()
-                curr_output = detect_convbelt_new_item(parsed_value, model)
+            // log("(PS) " + dict_to_string(parsed_value))
+            constructed_output = list_create()
+            if (bool_or((cast_i2s(parsed_value['name']) == 'new_states'), (cast_i2s(parsed_value['name']) == 'all_states'))):
+                // curr_output = detect_convbelt_new_item(parsed_value, model)
+                
+                log("(PS) ENTER detect_convbelt_new_item")
+                    
+                params = parsed_value['params']
+                curr_output = dict_create()
+                keys = dict_keys(params[1])
+                while (read_nr_out(keys) > 0):
+                    curr_key = set_pop(keys)
+                    log("(PS) curr_key = " + cast_i2s(curr_key))
+                    if (cast_i2s(parsed_value['name']) == 'new_states'):
+                        curr_value = params[1][curr_key]
+                    else:
+                        curr_value = params[1][curr_key][1]
+                    log("(PS) curr_value = " + dict_to_string(curr_value))
+                    log(cast_v2s(dict_in(curr_value, 'product')))
+                    if (bool_and(dict_in(curr_value, 'product'), bool_not(is_physical_none(curr_value['product'])))):
+                        devs_instances = allInstances(model, 'ParallelDEVS/DEVSInstance')
+                        while (read_nr_out(devs_instances) > 0):
+                            curr_devs_instance = set_pop(devs_instances)
+                            splitted_key = string_split(curr_key, ".")
+                            log("(PS) checking key = " + cast_i2s(list_read(splitted_key, list_len(splitted_key) - 1)))
+                            log("(PS) checking name = " + cast_i2s(read_attribute(model, curr_devs_instance, "name")))
+                            if (cast_i2s(list_read(splitted_key, list_len(splitted_key) - 1)) == cast_i2s(read_attribute(model, curr_devs_instance, "name"))):
+                                break!
+                            if (read_nr_out(devs_instances) == 0):
+                                log("(PS) We shouldn't reach this point..")
+                        log("(PS) found: " + cast_i2s(curr_devs_instance))
+                        curr_convbelt = set_pop(allAssociationOrigins(model, curr_devs_instance, "PS2DEVS_instancelink"))
+                        if (read_type(model, curr_convbelt) == "ProductionSystemRuntime/ConveyorBelt"):
+                            connected_items = allAssociationDestinations(model, curr_convbelt, "ProductionSystemRuntime/Conv_To_I")
+                            curr_id = cast_i2s(curr_value['product']['id'])
+                            item_found = False
+                            while (read_nr_out(connected_items) > 0):
+                                if (cast_v2s(set_pop(connected_items)) == curr_id):
+                                    item_found = True
+                                    log("(PS) Item " + curr_id + " found...")
+                                    break!
+                            if (bool_not(item_found)):
+                                log("(PS) Item not found, creating...")
+                                instantiate_node(model, ("ProductionSystemRuntime/" + cast_i2s(curr_value['product']['type'])), curr_id)
+                                instantiate_attribute(model, curr_id, "broken", curr_value['product']['broken'])
+                                instantiate_link(model, "ProductionSystemRuntime/Conv_To_I", "", curr_convbelt, curr_id)
+                                temp_dict = dict_create()
+                                dict_add_fast(temp_dict, 'type', ("ProductionSystemRuntime/" + cast_i2s(curr_value['product']['type'])))
+                                dict_add_fast(temp_dict, 'name', curr_id)
+                                dict_add_fast(temp_dict, 'broken', curr_value['product']['broken'])
+                                dict_add_fast(curr_output, curr_convbelt, temp_dict)
+                                
                 if (read_nr_out(dict_keys(curr_output)) > 0):
                     new_items = dict_create()
                     dict_add_fast(new_items, "new_items", curr_output)
@@ -70,6 +133,8 @@ Boolean function main(model : Element):
         sleep(0.05)
         
 Element function detect_convbelt_new_item(state_update: Element, model: Element):
+    log("(PS) ENTER detect_convbelt_new_item")
+
     Element params
     Element curr_param
     Element keys
@@ -88,42 +153,44 @@ Element function detect_convbelt_new_item(state_update: Element, model: Element)
     Boolean item_found
     String devs_name
         
-    params = state_update['parameters']
+    params = state_update['params']
     to_output = dict_create()
-    while (list_len(params) > 0):
-        curr_param = list_pop(params, 0)
-        keys = dict_keys(curr_param)
-        while (read_nr_out(keys) > 0):
-            curr_key = set_pop(keys)
-            curr_value = curr_param[curr_key]
-            if (dict_in(curr_value, 'product')):
-                devs_instances = allInstances(model, 'ParallelDEVS/DEVSInstance')
-                while (read_nr_out(devs_instances) > 0):
-                    curr_devs_instance = set_pop(devs_instances)
-                    splitted_key = string_split(curr_key, ".")
-                    if (list_read(splitted_key, list_len(splitted_key) - 1) == read_attribute(model, curr_devs_instance, "name")):
+    keys = dict_keys(params[1])
+    while (read_nr_out(keys) > 0):
+        curr_key = set_pop(keys)
+        log("(PS) curr_key = " + cast_i2s(curr_key))
+        curr_value = curr_param[curr_key]
+        if (dict_in(curr_value, 'product')):
+            devs_instances = allInstances(model, 'ParallelDEVS/DEVSInstance')
+            while (read_nr_out(devs_instances) > 0):
+                curr_devs_instance = set_pop(devs_instances)
+                splitted_key = string_split(curr_key, ".")
+                log("(PS) checking key = " + cast_i2s(list_read(splitted_key, list_len(splitted_key) - 1)))
+                log("(PS) checking name = " + cast_i2s(read_attribute(model, curr_devs_instance, "name")))
+                if (cast_i2s(list_read(splitted_key, list_len(splitted_key) - 1)) == cast_i2s(read_attribute(model, curr_devs_instance, "name"))):
+                    break!
+                if (read_nr_out(devs_instances) == 0):
+                    log("(PS) We shouldn't reach this point..")
+            curr_convbelt = set_pop(allAssociationOrigins(model, curr_devs_instance, "PS2DEVS_instancelink"))
+            if (read_type(model, curr_convbelt) == "ProductionSystemRuntime/ConveyorBelt"):
+                connected_items = allAssociationDestinations(model, curr_convbelt, "ProductionSystemRuntime/Conv_To_I")
+                curr_id = cast_i2s(curr_value['product']['id'])
+                item_found = False
+                while (read_nr_out(connected_items) > 0):
+                    if (cast_v2s(set_pop(connected_items)) == curr_id):
+                        item_found = True
+                        log("(PS) Item " + curr_id + " found...")
                         break!
-                    log("(PS) We shouldn't reach this point...")
-                curr_convbelt = set_pop(allAssociationOrigins(model, curr_devs_instance, "PS2DEVS_instancelink"))
-                if (read_type(model, curr_convbelt) == "ProductionSystemRuntime/ConveyorBelt"):
-                    connected_items = allAssociationDestinations(model, curr_convbelt, "ProductionSystemRuntime/Conv_To_I")
-                    curr_id = cast_i2s(curr_value['product']['id'])
-                    item_found = False
-                    while (read_nr_out(connected_items) > 0):
-                        if (cast_v2s(set_pop(connected_items)) == curr_id):
-                            item_found = True
-                            log("(PS) Item " + curr_id + " found...")
-                            break!
-                    if (bool_not(item_found)):
-                        log("(PS) Item not found, creating...")
-                        instantiate_node(model, ("ProductionSystemRuntime/" + cast_i2s(curr_value['product']['type'])), curr_id)
-                        instantiate_attribute(model, curr_id, "broken", curr_value['product']['broken'])
-                        instantiate_link(model, "ProductionSystemRuntime/Conv_To_I", "", curr_convbelt, curr_id)
-                        temp_dict = dict_create()
-                        dict_add_fast(temp_dict, 'type', ("ProductionSystemRuntime/" + cast_i2s(curr_value['product']['type'])))
-                        dict_add_fast(temp_dict, 'name', curr_id)
-                        dict_add_fast(temp_dict, 'broken', curr_value['product']['broken'])
-                        dict_add_fast(to_output, curr_convbelt, temp_dict)
+                if (bool_not(item_found)):
+                    log("(PS) Item not found, creating...")
+                    instantiate_node(model, ("ProductionSystemRuntime/" + cast_i2s(curr_value['product']['type'])), curr_id)
+                    instantiate_attribute(model, curr_id, "broken", curr_value['product']['broken'])
+                    instantiate_link(model, "ProductionSystemRuntime/Conv_To_I", "", curr_convbelt, curr_id)
+                    temp_dict = dict_create()
+                    dict_add_fast(temp_dict, 'type', ("ProductionSystemRuntime/" + cast_i2s(curr_value['product']['type'])))
+                    dict_add_fast(temp_dict, 'name', curr_id)
+                    dict_add_fast(temp_dict, 'broken', curr_value['product']['broken'])
+                    dict_add_fast(to_output, curr_convbelt, temp_dict)
     return to_output!
         
 Boolean function is_big_step_done(state_update: Element):

+ 6 - 0
interface/PDEVS/console.py

@@ -160,6 +160,12 @@ if __name__ == '__main__':
             model_delete("models/ps_to_devs")
         except ModelverseException:
             pass
+            
+        print("Remove tracability model")
+        try:
+            model_delete("models/PS_DEVS_traceability")
+        except ModelverseException:
+            pass
 
         print("Add PS->DEVS transformation model")
         transformation_add_MT({"ProductionSystem": "formalisms/ProductionSystem"}, {"ParallelDEVS": "formalisms/ParallelDEVS"}, "models/ps_to_devs", open("../../models/ps_to_devs.mvc", 'r').read(), traceability_PS2DEVS)

+ 1 - 0
models/ps_to_devs.mvc

@@ -1507,6 +1507,7 @@ Composite schedule {
             action = $ 
                 Void function action(host_model: Element, mapping: Element):
                     //log(pretty_print(host_model))
+                    log("nr of traceability links: " + cast_i2s(read_nr_out(allInstances(host_model, "PS2DEVS_instancelink"))))
                     return!
             $
         }