| from core import networkdata as nd |
| from core.parsing.jsonparser import JSONParser |
| from core.parsing.jsonencoder import JSONEncoder |
| from cytoapp.cytoscapeapp import CytoscapeApp |
| from roverdatahandler import RoverDataHandler |
| import itertools |
| import copy |
| import webbrowser |
| from core.visualization.tikzstandard import StandardTikzVisualizer as s |
| from core.visualization.tikzlayer import LayeredTikzVisualizer as l |
| |
|
|
| ''' The folder containing the JSON data. |
| ''' |
| directory: str = "data/" |
|
|
| ''' The JSON files in the given folder |
| ''' |
| data_sets: list[str] = [ |
| "robot_example", |
| ] |
|
|
| |
| class UserData: |
| def __init__(self, QOS=1000000): |
| self.QOS = QOS |
|
|
| |
| def custom_user_parse(user_data): |
| ''' The default behavior for parsing user data. These types of |
| functions recieve the data tied to the "UserData" entries in |
| JSON files and return what user_data within the network model |
| elements should be set to. |
| ''' |
|
|
| QOS = user_data["QOS"] |
| |
| if QOS != "": |
| user_data = UserData(float(QOS)) |
| else: |
| user_data = UserData(1000000) |
|
|
| return user_data |
|
|
| ''' Store the parsed network models in a dictionary. |
| ''' |
| data_dict: dict[str, nd.NetworkModel] = {} |
| for name in data_sets: |
| data_dict[name] = JSONParser.parse(directory + name + ".json", e_user_data_func = custom_user_parse) |
|
|
| |
| main_net = data_dict["robot_example"] |
|
|
| |
| operator: nd.Agent = nd.Agent("Operator") |
| rover: nd.Agent = nd.Agent("Robot") |
|
|
| operator.add_action(main_net.get_node("LAA"), operator.allocation_types.Authority) |
| operator.add_action(main_net.get_node("OLL"), operator.allocation_types.Authority) |
| operator.add_action(main_net.get_node("CAM"), operator.allocation_types.Authority) |
| operator.add_action(main_net.get_node("REV"), operator.allocation_types.Authority) |
| |
|
|
| rover.add_action(main_net.get_node("BLM"), rover.allocation_types.Authority) |
| rover.add_action(main_net.get_node("TMP"), rover.allocation_types.Authority) |
| rover.add_action(main_net.get_node("RPP"), rover.allocation_types.Authority) |
| rover.add_action(main_net.get_node("NWS"), rover.allocation_types.Authority) |
| rover.add_action(main_net.get_node("IC"), rover.allocation_types.Authority) |
| rover.add_action(main_net.get_node("RM"), rover.allocation_types.Authority) |
|
|
| |
| operator.add_action(main_net.get_node("BLM"), operator.allocation_types.Responsibility) |
| operator.add_action(main_net.get_node("TMP"), operator.allocation_types.Responsibility) |
| operator.add_action(main_net.get_node("RPP"), operator.allocation_types.Responsibility) |
| operator.add_action(main_net.get_node("NWS"), operator.allocation_types.Responsibility) |
| operator.add_action(main_net.get_node("IC"), operator.allocation_types.Responsibility) |
| operator.add_action(main_net.get_node("RM"), operator.allocation_types.Responsibility) |
|
|
|
|
| |
| |
|
|
| |
| shared_resources = [] |
|
|
| |
| for node_id in main_net.get_graph().nodes(): |
| |
| node = main_net.get_node(node_id) |
| |
| |
| if issubclass (node.__class__, nd.BaseEnvironmentResource): |
|
|
| |
| functions_that_set = main_net.get_graph().predecessors(node_id) |
| functions_that_get = main_net.get_graph().successors(node_id) |
|
|
| |
| interdependent_functions = list(itertools.product(functions_that_get,functions_that_set)) |
|
|
| |
| for pair in interdependent_functions: |
| agent_setting = main_net.get_node(pair[0]).get_authorized_agent() |
| agent_getting = main_net.get_node(pair[1]).get_authorized_agent() |
|
|
| if agent_setting.id != agent_getting.id: |
| shared_resources.append((node_id,pair)) |
|
|
| |
| |
| |
| |
| |
| functions_w_auth_resp_mismatch = [] |
|
|
| |
| for node_id in main_net.get_graph().nodes(): |
| |
| node = main_net.get_node(node_id) |
| |
| |
| if issubclass (node.__class__, nd.DistributedWorkFunction): |
|
|
| |
| authorized_agent = node.get_authorized_agent() |
| |
|
|
| |
| if authorized_agent != operator: |
| functions_w_auth_resp_mismatch.append(node_id) |
|
|
| |
| |
| |
| for node_id in functions_w_auth_resp_mismatch: |
|
|
| if node_id == "RM": |
| continue |
|
|
| |
| soc_org_node = main_net.add_node(nd.CoordinationGroundingResource("Confirmation-"+node_id)) |
| main_net.get_node("Confirmation-"+node_id).user_data = "Confirmation-"+node_id |
| teamwork_node = main_net.add_node(nd.SynchronyFunction("Confirming-"+node_id)) |
| main_net.get_node("Confirming-"+node_id).user_data = "Confirming-"+node_id |
|
|
| |
| main_net.add_edge("Confirming-"+node_id,"Confirmation-"+node_id) |
| main_net.get_edge("Confirming-"+node_id,"Confirmation-"+node_id).user_data = UserData(100000) |
|
|
| |
| main_net.add_edge("Confirmation-"+node_id,node_id) |
|
|
| |
| for wd_resource in main_net.get_graph().successors(node_id): |
| main_net.add_edge(wd_resource,"Confirming-"+node_id) |
| |
| |
| main_net.get_edge(wd_resource,"Confirming-"+node_id).user_data = UserData(1000000) |
|
|
| |
| operator.add_action(main_net.get_node("Confirming-"+node_id), operator.allocation_types.Authority) |
| operator.add_action(main_net.get_node("Confirming-"+node_id), operator.allocation_types.Responsibility) |
|
|
| |
| main_net.get_edge("Confirmation-"+node_id,node_id).user_data = UserData(0) |
|
|
|
|
| |
| |
| def custom_user_encode(user_data): |
|
|
| user_data = { |
| "QOS": user_data.QOS, |
| } |
| |
| return user_data |
|
|
|
|
| |
| |
|
|
| ''' Alter networks after they have been read |
| from JSON. |
| ''' |
| |
| app = CytoscapeApp(data_dict, RoverDataHandler) |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| app.run() |