Browse Source

current version

Simon Van Mierlo 8 years ago
parent
commit
a4cad58764

+ 3 - 3
integration/code/pdevs_client.alc

@@ -18,7 +18,7 @@ Boolean function main(model : Element):
     
     while (True):
         if (comm_hasInput(port)):
-            log(cast_v2s(has_input()))
+            log(cast_value(has_input()))
             the_input = comm_get(port)
             log("(PDEVS) Got input from simulator!")
             log("(PDEVS) " + the_input)
@@ -26,9 +26,9 @@ Boolean function main(model : Element):
         if (has_input()):
             the_input = input()
             log("(PDEVS) Got input from console/ps simulator!")
-            log("(PDEVS) " + cast_v2s(the_input))
+            log("(PDEVS) " + cast_value(the_input))
             if (is_physical_string(the_input)):
                 comm_set(port, the_input)
             else:
-                comm_set(port, cast_v2s(the_input))
+                comm_set(port, cast_value(the_input))
         sleep(0.05)

+ 335 - 88
integration/code/ps_simulator.alc

@@ -4,6 +4,7 @@ include "modelling.alh"
 include "object_operations.alh"
 include "io.alh"
 include "json.alh"
+include "conformance_scd.alh"
 
 Boolean function main(model : Element):
 	String pdevs_client_taskname
@@ -34,32 +35,63 @@ Boolean function main(model : Element):
     Element temp_dict
     Boolean item_found
     String devs_name
+    Element devs_to_ps
+    Element ps_to_devs
+    Element memory
+    Element convbelt_instances
+    Element ass_instances
+    Element curr_ass
     
     pdevs_client_taskname = input()
     log("(PS) Got task name from console!")
     log("(PS) " + pdevs_client_taskname)
     
     simulation_state = "paused"
+    memory = dict_create()
+    
+    dict_add_fast(memory, "detect_initialize", dict_create())
+    dict_add_fast(memory, "detect_convbelt_new_item", dict_create())
+    dict_add_fast(memory, "detect_convbelt_deleted_item", dict_create())
+    
+    log("(PS) building DEVS to PS dictionary...")    
+    devs_to_ps = dict_create()
+    ps_to_devs = dict_create()
+    
+    devs_instances = allInstances(model, 'ParallelDEVS/DEVSInstance')
+    while (read_nr_out(devs_instances) > 0):
+        curr_devs_instance = set_pop(devs_instances)
+        dict_add_fast(devs_to_ps, cast_string(read_attribute(model, curr_devs_instance, "name")), set_pop(allAssociationOrigins(model, curr_devs_instance, "PS2DEVS_instancelink")))
+        
+    convbelt_instances = allInstances(model, 'ProductionSystemRuntime/ConveyorBelt')
+    while (read_nr_out(convbelt_instances) > 0):
+        curr_convbelt = set_pop(convbelt_instances)
+        dict_add_fast(ps_to_devs, curr_convbelt, allAssociationDestinations(model, curr_convbelt, "PS2DEVS_instancelink"))
+    ass_instances = allInstances(model, 'ProductionSystemRuntime/ConveyorBelt')
+    while (read_nr_out(ass_instances) > 0):
+        curr_ass = set_pop(ass_instances)
+        dict_add_fast(ps_to_devs, curr_ass, allAssociationDestinations(model, curr_ass, "PS2DEVS_instancelink"))
+    log("(PS) ps_to_devs = " + dict_to_string(ps_to_devs))
     
     while (True):
         if (has_input()):
             the_input = input()
             log("(PS) Got input from console!")
-            log("(PS) " + cast_v2s(the_input))
+            log("(PS) " + cast_value(the_input))
             if (bool_not(is_physical_string(the_input))):
-                the_input = cast_v2s(the_input)
+                the_input = cast_value(the_input)
             parsed_value = json_deserialize(the_input)
             log("(PS) Parsed input!")
             log("(PS) " + list_to_string(parsed_value))
-            // TODO: look at simulation state: figure out what to send to simulator (either nothing or big_step). Also save the end condition probably.
-            command = list_read(parsed_value, 0)
-            if (command == "big_step"):
-                if (simulation_state == "paused"):
-                    simulation_state = "big_step"
-                    input_for_devs_sim = list_create()
-                    list_append(input_for_devs_sim, "big_step")
-                    list_append(input_for_devs_sim, list_read(parsed_value, 1))
-            give_input_to_other(pdevs_client_taskname, json_serialize(input_for_devs_sim))
+            if (list_len(parsed_value) > 0):
+                // TODO: look at simulation state: figure out what to send to simulator (either nothing or big_step). Also save the end condition probably.
+                command = list_read(parsed_value, 0)
+                if (command == "big_step"):
+                    if (simulation_state == "paused"):
+                        simulation_state = "big_step"
+                        input_for_devs_sim = list_create()
+                        list_append(input_for_devs_sim, "big_step")
+                        list_append(input_for_devs_sim, list_read(parsed_value, 1))
+                give_input_to_other(pdevs_client_taskname, json_serialize(input_for_devs_sim))
         if (other_has_output(pdevs_client_taskname)):
             the_output = get_output_from_other(pdevs_client_taskname)
             log("(PS) Got output from pdevs simulator!")
@@ -68,71 +100,55 @@ Boolean function main(model : Element):
             log("(PS) Parsed output!")
             // 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)
-                    list_append(constructed_output, new_items)
+            if (bool_or((cast_string(parsed_value['name']) == 'new_states'), (cast_string(parsed_value['name']) == 'all_states'))):
+                detect_initialize_SESSION(parsed_value, model, constructed_output, devs_to_ps, ps_to_devs, memory['detect_initialize'])
+                detect_convbelt_new_item_SESSION(parsed_value, model, constructed_output, devs_to_ps, ps_to_devs, memory['detect_convbelt_new_item'])
+                detect_convbelt_deleted_item_SESSION(parsed_value, model, constructed_output, devs_to_ps, ps_to_devs, memory['detect_convbelt_deleted_item'])
+                detect_ass_new_item_SESSION(parsed_value, model, constructed_output, devs_to_ps, ps_to_devs, memory['detect_convbelt_new_item'])
+                detect_ass_deleted_item_SESSION(parsed_value, model, constructed_output, devs_to_ps, ps_to_devs, memory['detect_convbelt_deleted_item'])
             if (list_len(constructed_output) > 0):
                 to_output = dict_create()
                 dict_add_fast(to_output, 'name', 'state_update')
-                dict_add_fast(to_output, 'parameters', constructed_output)
+                dict_add_fast(to_output, 'params', constructed_output)
                 output(json_serialize(to_output))
             else:
                 // TODO temporary
                 output(the_output)
         sleep(0.05)
         
-Element function detect_convbelt_new_item(state_update: Element, model: Element):
+Void function detect_initialize_SESSION(state_update: Element, model: Element, output_list: Element, devs_to_ps: Element, ps_to_devs: Element, memory: Element):
+    log("(PS) ENTER detect_initialize")
+    
+    Element params
+    Element keys
+    Element curr_key
+    Element splitted_key
+    Element curr_element
+    Element to_output
+    Element state_updates
+    
+    to_output = dict_create()
+    if (cast_string(state_update['name']) == 'all_states'):
+        params = state_update['params']
+        if (bool_and((cast_float(params[0][0]) == 0.0), (cast_integer(params[0][1]) == 0))):
+            log("(PS) initializing...")
+            
+            keys = dict_keys(params[1])
+            while (read_nr_out(keys) > 0):
+                curr_key = set_pop(keys)
+                splitted_key = string_split(curr_key, ".")
+                curr_element = devs_to_ps[cast_string(list_read(splitted_key, list_len(splitted_key) - 1))]
+                if (is_nominal_instance(model, curr_element, "ProductionSystemRuntime/Machine")):
+                    log("(PS) found a machine " + cast_string(curr_element))
+                    instantiate_attribute(model, curr_element, "state", cast_string(params[1][curr_key][1]['name']))
+                    dict_add_fast(to_output, curr_element, cast_string(params[1][curr_key][1]['name']))
+    if (read_nr_out(dict_keys(to_output)) > 0):
+        state_updates = dict_create()
+        dict_add_fast(state_updates, "new_states", to_output)
+        list_append(output_list, state_updates)
+    return!
+        
+Void function detect_convbelt_new_item_SESSION(state_update: Element, model: Element, output_list: Element, devs_to_ps: Element, ps_to_devs: Element, memory: Element):
     log("(PS) ENTER detect_convbelt_new_item")
 
     Element params
@@ -145,11 +161,12 @@ Element function detect_convbelt_new_item(state_update: Element, model: Element)
     Element curr_convbelt
     Element splitted_key
     Element connected_items
-    Element curr_item
+    String curr_item
     Element curr_value
     String curr_id
     Element to_output
     Element temp_dict
+    Element new_items
     Boolean item_found
     String devs_name
         
@@ -158,40 +175,270 @@ Element function detect_convbelt_new_item(state_update: Element, model: Element)
     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"))
+        log("(PS) curr_key = " + cast_string(curr_key))
+        if (cast_string(state_update['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_value(dict_in(curr_value, 'product')))
+        if (bool_and(dict_in(curr_value, 'product'), bool_not(is_physical_none(curr_value['product'])))):
+            splitted_key = string_split(curr_key, ".")
+            curr_convbelt = devs_to_ps[cast_string(list_read(splitted_key, list_len(splitted_key) - 1))]
             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'])
+                curr_id = cast_string(curr_value['product']['id'])
                 item_found = False
                 while (read_nr_out(connected_items) > 0):
-                    if (cast_v2s(set_pop(connected_items)) == curr_id):
+                    curr_item = cast_string(set_pop(connected_items))
+                    if (curr_item == 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)
+                    log("(PS) Item " + curr_id + " not found, creating...")
+                    instantiate_node(model, ("ProductionSystemRuntime/" + cast_string(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, 'type', (cast_string(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!
+    if (read_nr_out(dict_keys(to_output)) > 0):
+        new_items = dict_create()
+        dict_add_fast(new_items, "new_items", to_output)
+        list_append(output_list, new_items)
+    return!
+    
+Void function detect_convbelt_deleted_item_SESSION(state_update: Element, model: Element, output_list: Element, devs_to_ps: Element, ps_to_devs: Element, memory: Element):
+    log("(PS) ENTER detect_convbelt_deleted_item")
+
+    Element params
+    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 to_output
+    Element temp_dict
+    Element removed_items
+    String curr_instance
+    Boolean item_found
+    String devs_name
+    Element items
+    Element prev_items
+    Element new_memory
+    Element conveyorbelts
+    Element items_keys
+    Element prev_items_keys
+    
+    new_memory = dict_copy(memory)
+        
+    params = state_update['params']
+    to_output = dict_create()
+    keys = dict_keys(params[1])
+    while (read_nr_out(keys) > 0):
+        curr_key = set_pop(keys)
+        if (cast_string(state_update['name']) == 'new_states'):
+            curr_value = params[1][curr_key]
+        else:
+            curr_value = params[1][curr_key][1]
+                
+        if (dict_in(curr_value, 'product')):        
+            splitted_key = string_split(curr_key, ".")
+            if (bool_and(dict_in(new_memory, cast_string(list_read(splitted_key, list_len(splitted_key) - 1))), is_physical_none(curr_value['product']))):
+                dict_delete(new_memory, cast_string(list_read(splitted_key, list_len(splitted_key) - 1)))
+            elif (bool_not(is_physical_none(curr_value['product']))):
+                dict_overwrite(new_memory, cast_string(list_read(splitted_key, list_len(splitted_key) - 1)), curr_value['product'])
+                        
+    conveyorbelts = allInstances(model, "ProductionSystemRuntime/ConveyorBelt")
+    while (read_nr_out(conveyorbelts) > 0):
+        curr_convbelt = set_pop(conveyorbelts)
+        devs_instances = set_copy(ps_to_devs[curr_convbelt])
+        prev_items = dict_create()
+        items = dict_create()
+        while (read_nr_out(devs_instances) > 0):            
+            curr_instance = cast_string(read_attribute(model, set_pop(devs_instances), "name"))
+            if (bool_and(dict_in(memory, curr_instance), bool_not(is_physical_none(memory[curr_instance])))):
+                dict_add_fast(prev_items, cast_string(memory[curr_instance]['id']), memory[curr_instance])            
+            if (bool_and(dict_in(new_memory, curr_instance), bool_not(is_physical_none(new_memory[curr_instance])))):
+                dict_add_fast(items, cast_string(new_memory[curr_instance]['id']), new_memory[curr_instance])
+        prev_items_keys = dict_keys(prev_items)
+        items_keys = dict_keys(items)
+        while(read_nr_out(prev_items_keys) > 0):
+            curr_item = set_pop(prev_items_keys)
+            if (bool_not(set_in(items_keys, curr_item))):
+                log("(PS) item " + cast_string(curr_item) + " removed")
+                temp_dict = dict_create()
+                dict_add_fast(temp_dict, 'name', curr_item)
+                dict_add_fast(to_output, curr_convbelt, temp_dict)
+                model_delete_element(model, curr_item)
+            else:
+                log("(PS) item " + cast_string(curr_item) + " NOT removed")
+    keys = dict_keys(new_memory)
+    while (read_nr_out(keys) > 0):
+        curr_key = set_pop(keys)
+        dict_overwrite(memory, curr_key, new_memory[curr_key])
+    if (read_nr_out(dict_keys(to_output)) > 0):
+        removed_items = dict_create()
+        dict_add_fast(removed_items, "removed_items", to_output)
+        list_append(output_list, removed_items)
+    return!
+    
+Void function detect_ass_new_item_SESSION(state_update: Element, model: Element, output_list: Element, devs_to_ps: Element, ps_to_devs: Element, memory: Element):
+    log("(PS) ENTER detect_ass_new_item")
+
+    Element params
+    Element curr_param
+    Element keys
+    Element curr_key
+    Element devs_instances
+    Element curr_devs_instance
+    Element generators
+    Element curr_ass
+    Element splitted_key
+    Element connected_items
+    String curr_item
+    Element curr_value
+    String curr_id
+    Element to_output
+    Element temp_dict
+    Element new_items
+    Boolean item_found
+    String devs_name
+    Element queue
+        
+    params = state_update['params']
+    to_output = dict_create()
+    keys = dict_keys(params[1])
+    while (read_nr_out(keys) > 0):
+        curr_key = set_pop(keys)
+        log("(PS) curr_key = " + cast_string(curr_key))
+        if (cast_string(state_update['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_value(dict_in(curr_value, 'queue')))
+        if (dict_in(curr_value, 'queue')):
+            if (list_len(curr_value['queue']) > 0):
+                queue = curr_value['queue']
+                splitted_key = string_split(curr_key, ".")
+                curr_ass = devs_to_ps[cast_string(list_read(splitted_key, list_len(splitted_key) - 1))]
+                if (read_type(model, curr_ass) == "ProductionSystemRuntime/Assembler"):
+                    connected_items = allAssociationDestinations(model, curr_ass, "ProductionSystemRuntime/Proc_To_I")
+                    while (read_nr_out(queue) > 0):
+                        curr_id = cast_string(dict_read(list_pop_final(queue), 'id'))
+                        item_found = False
+                        while (read_nr_out(connected_items) > 0):
+                            curr_item = cast_string(set_pop(connected_items))
+                            if (curr_item == curr_id):
+                                item_found = True
+                                log("(PS) Item " + curr_id + " found...")
+                                break!
+                        if (bool_not(item_found)):
+                            log("(PS) Item " + curr_id + " not found, creating...")
+                            instantiate_node(model, ("ProductionSystemRuntime/" + cast_string(curr_value['product']['type'])), curr_id)
+                            instantiate_attribute(model, curr_id, "broken", curr_value['product']['broken'])
+                            instantiate_link(model, "ProductionSystemRuntime/P_To_I", "", curr_ass, curr_id)
+                            temp_dict = dict_create()
+                            dict_add_fast(temp_dict, 'type', (cast_string(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_ass, temp_dict)
+    if (read_nr_out(dict_keys(to_output)) > 0):
+        new_items = dict_create()
+        dict_add_fast(new_items, "new_items", to_output)
+        list_append(output_list, new_items)
+    return!
+    
+Void function detect_ass_deleted_item_SESSION(state_update: Element, model: Element, output_list: Element, devs_to_ps: Element, ps_to_devs: Element, memory: Element):
+    log("(PS) ENTER detect_ass_deleted_item")
+
+    Element params
+    Element curr_param
+    Element keys
+    Element curr_key
+    Element devs_instances
+    Element curr_devs_instance
+    Element generators
+    Element curr_ass
+    Element splitted_key
+    Element connected_items
+    String curr_item
+    Element curr_value
+    String curr_id
+    Element to_output
+    Element temp_dict
+    Element removed_items
+    String curr_instance
+    Boolean item_found
+    String devs_name
+    Element curr_queue
+    Element curr_queue_keys
+    Element prev_queue
+    Element new_memory
+    Element assemblers
+    Element items_keys
+    Element prev_items_keys
+    Element to_remove
+    
+    new_memory = dict_copy(memory)
+        
+    params = state_update['params']
+    to_output = dict_create()
+    keys = dict_keys(params[1])
+    while (read_nr_out(keys) > 0):
+        curr_key = set_pop(keys)
+        if (cast_string(state_update['name']) == 'new_states'):
+            curr_value = params[1][curr_key]
+        else:
+            curr_value = params[1][curr_key][1]
+                
+        if (dict_in(curr_value, 'queue')):
+            splitted_key = string_split(curr_key, ".")
+            dict_overwrite(new_memory, cast_string(list_read(splitted_key, list_len(splitted_key) - 1)), curr_value['queue'])
+                        
+    assemblers = allInstances(model, "ProductionSystemRuntime/Assembler")
+    while (read_nr_out(assemblers) > 0):
+        curr_ass = set_pop(assemblers)
+        to_remove = list_create()
+        curr_devs_instance = ps_to_devs[curr_ass]
+        if (dict_in(memory, curr_devs_instance)):
+            prev_queue = list_copy(memory[curr_devs_instance])
+            curr_queue_keys = set_create()
+            curr_queue = list_copy(new_memory[curr_devs_instance])
+            while (read_nr_out(curr_queue) > 0):
+                set_add(curr_queue_keys, cast_string(dict_read(list_pop_final(curr_queue), 'id')))
+            while(read_nr_out(prev_queue) > 0):
+                curr_item = cast_string(curr_item['id'])
+                if (bool_not(set_in(curr_queue_keys, curr_item))):
+                    log("(PS) item " + curr_item + " removed")
+                    temp_dict = dict_create()
+                    dict_add_fast(temp_dict, 'name', curr_item)
+                    list_append(to_remove, temp_dict)
+                    model_delete_element(model, curr_item)
+                else:
+                    log("(PS) item " + curr_item + " NOT removed")
+            if (read_nr_out(to_remove) > 0):
+                dict_add_fast(to_output, curr_ass, to_remove)
+    keys = dict_keys(new_memory)
+    while (read_nr_out(keys) > 0):
+        curr_key = set_pop(keys)
+        dict_overwrite(memory, curr_key, new_memory[curr_key])
+    if (read_nr_out(dict_keys(to_output)) > 0):
+        removed_items = dict_create()
+        dict_add_fast(removed_items, "removed_items", to_output)
+        list_append(output_list, removed_items)
+    return!
         
 Boolean function is_big_step_done(state_update: Element):
     return True!

+ 2 - 2
interface/PDEVS/console.py

@@ -1,6 +1,6 @@
 import sys
 from modelverse import *
-import random, re, json
+import random, re, json, uuid
 from interface import Controller
 from pprint import pprint
 from multiprocessing import Process, Pipe, freeze_support
@@ -234,7 +234,7 @@ if __name__ == '__main__':
             instantiate(None, "Association", ("ProductionSystemRuntime/Machine", "ParallelDEVS/BaseDEVSBlock"), ID="PS2DEVS_typelink")
             instantiate(None, "Association", ("ProductionSystemRuntime/Machine", "ParallelDEVS/DEVSInstance"), ID="PS2DEVS_instancelink")
 
-        transformation_add_AL({"ProductionSystemRuntime": "formalisms/ProductionSystemRuntime", "ParallelDEVS": "formalisms/ParallelDEVS"}, {}, "models/ps_simulator", open("../../integration/code/ps_simulator.alc", "r").read(), traceability_PS2DEVS_runtime)
+        transformation_add_AL({"ProductionSystemRuntime": "formalisms/ProductionSystemRuntime", "ParallelDEVS": "formalisms/ParallelDEVS"}, {}, "models/ps_simulator", open("../../integration/code/ps_simulator.alc", "r").read().replace("SESSION", str(uuid.uuid4()).replace("-", "")), traceability_PS2DEVS_runtime)
     except ModelExists:
         pass
     

+ 14 - 4
interface/PDEVS/helpers.py

@@ -1,19 +1,29 @@
 def canRiotAPC(queue):
-    return queue.count('Wheel') >= 4 and queue.count('Body') >= 1 and queue.count('WaterCannon') >= 1
+    t_q = [i['type'] for i in queue]
+    return t_q.count('Wheel') >= 4 and t_q.count('Body') >= 1 and t_q.count('WaterCannon') >= 1
 
 def isRiotAPC(queue):
     if canRiotAPC(queue):
         toremove = ['Wheel','Wheel','Wheel','Wheel','Body','WaterCannon']
         while toremove:
-            queue.remove(toremove.pop())            
+            tofind = toremove.pop()
+            for idx, it in enumerate(queue):
+                if (it['type'] == tofind):
+                    break
+            del queue[idx]
         return True
 
 def canWarAPC(queue):
-    return queue.count('Tracks') >= 2 and queue.count('Body') >= 1 and queue.count('MachineGun') >= 1
+    t_q = [i['type'] for i in queue]
+    return t_q.count('Tracks') >= 2 and t_q.count('Body') >= 1 and t_q.count('MachineGun') >= 1
         
 def isWarAPC(queue):
     if canWarAPC(queue):
         toremove = ['Tracks','Tracks','Body','MachineGun']
         while toremove:
-            queue.remove(toremove.pop())
+            tofind = toremove.pop()
+            for idx, it in enumerate(queue):
+                if (it['type'] == tofind):
+                    break
+            del queue[idx]
         return True

+ 14 - 4
interface/PDEVS/pypdevs/examples/helpers.py

@@ -1,19 +1,29 @@
 def canRiotAPC(queue):
-    return queue.count('Wheel') >= 4 and queue.count('Body') >= 1 and queue.count('WaterCannon') >= 1
+    t_q = [i['type'] for i in queue]
+    return t_q.count('Wheel') >= 4 and t_q.count('Body') >= 1 and t_q.count('WaterCannon') >= 1
 
 def isRiotAPC(queue):
     if canRiotAPC(queue):
         toremove = ['Wheel','Wheel','Wheel','Wheel','Body','WaterCannon']
         while toremove:
-            queue.remove(toremove.pop())            
+            tofind = toremove.pop()
+            for idx, it in enumerate(queue):
+                if (it['type'] == tofind):
+                    break
+            del queue[idx]
         return True
 
 def canWarAPC(queue):
-    return queue.count('Tracks') >= 2 and queue.count('Body') >= 1 and queue.count('MachineGun') >= 1
+    t_q = [i['type'] for i in queue]
+    return t_q.count('Tracks') >= 2 and t_q.count('Body') >= 1 and t_q.count('MachineGun') >= 1
         
 def isWarAPC(queue):
     if canWarAPC(queue):
         toremove = ['Tracks','Tracks','Body','MachineGun']
         while toremove:
-            queue.remove(toremove.pop())
+            tofind = toremove.pop()
+            for idx, it in enumerate(queue):
+                if (it['type'] == tofind):
+                    break
+            del queue[idx]
         return True

+ 1 - 1
interface/PDEVS/pypdevs/examples/ps_model.py

@@ -237,7 +237,7 @@ class assembler(AtomicDEVS):
 
                 import helpers, random
                 if self.my_ports['ass_in'] in my_inputs:
-                        self.state['queue'].extend([i['type'] for i in my_inputs[self.my_ports['ass_in']]])
+                        self.state['queue'].extend(my_inputs[self.my_ports['ass_in']])
                         if (self.state['name'] == 'waiting' and (helpers.canWarAPC(self.state['queue']) or helpers.canRiotAPC(self.state['queue']))):
                                 self.state['name'] = 'looking_for_op'
                 if self.state['name'] == 'looking_for_op' and self.my_ports['ass_op_in'] in my_inputs:

+ 19 - 19
models/devs_to_string.alc

@@ -30,15 +30,15 @@ Boolean function devs_to_string(model: Element):
     all_atomics = allInstances(model, "ParallelDEVS/AtomicDEVSBlock")
     while (read_nr_out(all_atomics) > 0):
         curr_atomic = set_pop(all_atomics)
-        model_rep = ((model_rep + "class ") + cast_i2s(read_attribute(model, curr_atomic, "name"))) + "(AtomicDEVS):\n"
-        model_rep = ((model_rep + "\tdef __init__(self, name=") + cast_v2s(read_attribute(model, curr_atomic, "name"))) + "):\n"
+        model_rep = ((model_rep + "class ") + cast_string(read_attribute(model, curr_atomic, "name"))) + "(AtomicDEVS):\n"
+        model_rep = ((model_rep + "\tdef __init__(self, name=") + cast_value(read_attribute(model, curr_atomic, "name"))) + "):\n"
         model_rep = model_rep + "\t\tAtomicDEVS.__init__(self, name)\n"
         model_rep = model_rep + "\t\tself.state = self.initialState()\n"
         model_rep = model_rep + "\t\tself.my_ports = {"
         all_ports = allAssociationDestinations(model, curr_atomic, "ParallelDEVS/DEVSBlockToPort")
         while (read_nr_out(all_ports) > 0):
             curr_port = set_pop(all_ports)
-            curr_port_name = cast_v2s(read_attribute(model, curr_port, "name"))
+            curr_port_name = cast_value(read_attribute(model, curr_port, "name"))
             curr_port_type = read_type(model, curr_port)
             if (curr_port_type == "ParallelDEVS/InputPort"):                
                 model_rep = (((model_rep + curr_port_name) + ": self.addInPort(") + curr_port_name) + ")"
@@ -47,24 +47,24 @@ Boolean function devs_to_string(model: Element):
             if (read_nr_out(all_ports) > 0):
                 model_rep = model_rep + ", "
         model_rep = model_rep + "}\n"
-        model_rep = model_rep + "\tdef initialState(self):\n" + cast_i2s(read_attribute(model, curr_atomic, "initialState")) + "\n"
-        model_rep = ((model_rep + "\tdef timeAdvance(self):\n") + cast_i2s(read_attribute(model, curr_atomic, "timeAdvance"))) + "\n"
-        model_rep = ((model_rep + "\tdef outputFnc(self):\n") + cast_i2s(read_attribute(model, curr_atomic, "outputFnc"))) + "\n"
-        model_rep = ((model_rep + "\tdef intTransition(self):\n") + cast_i2s(read_attribute(model, curr_atomic, "intTransition"))) + "\n"
-        model_rep = ((model_rep + "\tdef extTransition(self, my_inputs):\n") + cast_i2s(read_attribute(model, curr_atomic, "extTransition"))) + "\n"
-        model_rep = ((model_rep + "\tdef confTransition(self, my_inputs):\n") + cast_i2s(read_attribute(model, curr_atomic, "confTransition"))) + "\n"
+        model_rep = model_rep + "\tdef initialState(self):\n" + cast_string(read_attribute(model, curr_atomic, "initialState")) + "\n"
+        model_rep = ((model_rep + "\tdef timeAdvance(self):\n") + cast_string(read_attribute(model, curr_atomic, "timeAdvance"))) + "\n"
+        model_rep = ((model_rep + "\tdef outputFnc(self):\n") + cast_string(read_attribute(model, curr_atomic, "outputFnc"))) + "\n"
+        model_rep = ((model_rep + "\tdef intTransition(self):\n") + cast_string(read_attribute(model, curr_atomic, "intTransition"))) + "\n"
+        model_rep = ((model_rep + "\tdef extTransition(self, my_inputs):\n") + cast_string(read_attribute(model, curr_atomic, "extTransition"))) + "\n"
+        model_rep = ((model_rep + "\tdef confTransition(self, my_inputs):\n") + cast_string(read_attribute(model, curr_atomic, "confTransition"))) + "\n"
         
     all_coupleds = allInstances(model, "ParallelDEVS/CoupledDEVSBlock")
     while (read_nr_out(all_coupleds) > 0):
         curr_coupled = set_pop(all_coupleds)
-        model_rep = ((model_rep + "class ") + cast_i2s(read_attribute(model, curr_coupled, "name"))) + "(CoupledDEVS):\n"
-        model_rep = ((model_rep + "\tdef __init__(self, name=") + cast_v2s(read_attribute(model, curr_coupled, "name"))) + "):\n"
+        model_rep = ((model_rep + "class ") + cast_string(read_attribute(model, curr_coupled, "name"))) + "(CoupledDEVS):\n"
+        model_rep = ((model_rep + "\tdef __init__(self, name=") + cast_value(read_attribute(model, curr_coupled, "name"))) + "):\n"
         model_rep = model_rep + "\t\tCoupledDEVS.__init__(self, name)\n"
         model_rep = model_rep + "\t\tself.my_ports = {"
         all_ports = allAssociationDestinations(model, curr_coupled, "ParallelDEVS/DEVSBlockToPort")
         while (read_nr_out(all_ports) > 0):
             curr_port = set_pop(all_ports)
-            curr_port_name = cast_v2s(read_attribute(model, curr_port, "name"))
+            curr_port_name = cast_value(read_attribute(model, curr_port, "name"))
             curr_port_type = read_type(model, curr_port)
             log(curr_port_type)
             if (curr_port_type == "ParallelDEVS/InputPort"):                
@@ -78,8 +78,8 @@ Boolean function devs_to_string(model: Element):
         all_submodels = allAssociationDestinations(model, curr_coupled, "ParallelDEVS/SubModel")
         while (read_nr_out(all_submodels) > 0):
             curr_submodel = set_pop(all_submodels)
-            curr_submodel_name = cast_v2s(read_attribute(model, curr_submodel, "name"))
-            curr_submodel_type = cast_i2s(read_attribute(model, curr_submodel, "type"))
+            curr_submodel_name = cast_value(read_attribute(model, curr_submodel, "name"))
+            curr_submodel_type = cast_string(read_attribute(model, curr_submodel, "type"))
             model_rep = ((((((model_rep + curr_submodel_name) + ": self.addSubModel(") + curr_submodel_type) + "(name=") + curr_submodel_name) + ")") + ")"
             if (read_nr_out(all_submodels) > 0):
                 model_rep = model_rep + ", "
@@ -91,25 +91,25 @@ Boolean function devs_to_string(model: Element):
             while (read_nr_out(out_channels) > 0):
                 curr_channel = set_pop(out_channels)
                 parent = set_pop(allAssociationOrigins(model, curr_channel, "ParallelDEVS/DEVSInstanceToPort"))
-                model_rep = ((((((model_rep + "\t\tself.connectPorts(self.my_ports[") + cast_v2s(read_attribute(model, curr_port, "name"))) + "], self.submodels[") + cast_v2s(read_attribute(model, parent, "name"))) + "].my_ports[") + cast_v2s(read_attribute(model, curr_channel, "name"))) + "])\n"
+                model_rep = ((((((model_rep + "\t\tself.connectPorts(self.my_ports[") + cast_value(read_attribute(model, curr_port, "name"))) + "], self.submodels[") + cast_value(read_attribute(model, parent, "name"))) + "].my_ports[") + cast_value(read_attribute(model, curr_channel, "name"))) + "])\n"
         all_submodels = allAssociationDestinations(model, curr_coupled, "ParallelDEVS/SubModel")
         while (read_nr_out(all_submodels) > 0):
             curr_submodel = set_pop(all_submodels)
-            curr_submodel_name = cast_v2s(read_attribute(model, curr_submodel, "name"))
+            curr_submodel_name = cast_value(read_attribute(model, curr_submodel, "name"))
             log(curr_submodel_name)
             all_ports = allAssociationDestinations(model, curr_submodel, "ParallelDEVS/DEVSInstanceToPort")
             while (read_nr_out(all_ports) > 0):
                 curr_port = set_pop(all_ports)
                 out_channels = allAssociationDestinations(model, curr_port, "ParallelDEVS/Channel")
-                log(cast_v2s(read_nr_out(out_channels)))
+                log(cast_value(read_nr_out(out_channels)))
                 while (read_nr_out(out_channels) > 0):
                     curr_channel = set_pop(out_channels)
                     possible_parent = allAssociationOrigins(model, curr_channel, "ParallelDEVS/DEVSInstanceToPort")
                     if (read_nr_out(possible_parent) == 0):
-                        model_rep = ((((((model_rep + "\t\tself.connectPorts(self.submodels[") + curr_submodel_name) + "].my_ports[") + cast_v2s(read_attribute(model, curr_port, "name"))) + "], self.my_ports[") + cast_v2s(read_attribute(model, curr_channel, "name"))) + "])\n"
+                        model_rep = ((((((model_rep + "\t\tself.connectPorts(self.submodels[") + curr_submodel_name) + "].my_ports[") + cast_value(read_attribute(model, curr_port, "name"))) + "], self.my_ports[") + cast_value(read_attribute(model, curr_channel, "name"))) + "])\n"
                     else:
                         parent = set_pop(possible_parent)
-                        model_rep = ((((((((model_rep + "\t\tself.connectPorts(self.submodels[") + curr_submodel_name) + "].my_ports[") + cast_v2s(read_attribute(model, curr_port, "name"))) + "], self.submodels[") + cast_v2s(read_attribute(model, parent, "name"))) + "].my_ports[") + cast_v2s(read_attribute(model, curr_channel, "name"))) + "])\n"
+                        model_rep = ((((((((model_rep + "\t\tself.connectPorts(self.submodels[") + curr_submodel_name) + "].my_ports[") + cast_value(read_attribute(model, curr_port, "name"))) + "], self.submodels[") + cast_value(read_attribute(model, parent, "name"))) + "].my_ports[") + cast_value(read_attribute(model, curr_channel, "name"))) + "])\n"
         model_rep = model_rep + "\n"
         
     string_element = instantiate_node(model, "MyString/MyString", "my_string")

File diff suppressed because it is too large
+ 15 - 15
models/ps_to_devs.mvc