|
@@ -1,5 +1,6 @@
|
|
|
import sys
|
|
|
import time
|
|
|
+import uuid
|
|
|
sys.path.append("kernel/")
|
|
|
sys.path.append("state/")
|
|
|
sys.path.append("interface/HUTN")
|
|
@@ -338,7 +339,7 @@ class ModelverseKernel(AtomicDEVS):
|
|
|
outputs[self.to_mvs] = [self.state.commands]
|
|
|
|
|
|
if self.state.mvk and self.state.mvk.returnvalue is not None:
|
|
|
- outputs[self.to_mvi] = [self.state.mvk.returnvalue]
|
|
|
+ outputs[self.to_mvi] = [(self.state.current_task, self.state.mvk.returnvalue)]
|
|
|
|
|
|
return outputs
|
|
|
|
|
@@ -355,16 +356,24 @@ class ModelverseKernel(AtomicDEVS):
|
|
|
class MvIState():
|
|
|
def __init__(self):
|
|
|
self.operations = []
|
|
|
- self.output = []
|
|
|
- self.processing = []
|
|
|
- self.init = True
|
|
|
+ self.additional_operations = []
|
|
|
+ self.keyed_operations = {}
|
|
|
+ self.output = {}
|
|
|
+ self.allow_progress = True
|
|
|
+ self.blocked = True
|
|
|
self.finished = False
|
|
|
+ self.send_operations = []
|
|
|
|
|
|
class ModelverseInterface(AtomicDEVS):
|
|
|
- def __init__(self, taskname, operations, finish_on):
|
|
|
+ def __init__(self, taskname, operations, finish_on, additional_operations=[], keyed_operations={}):
|
|
|
AtomicDEVS.__init__(self, "MvI_%s" % taskname)
|
|
|
self.state = MvIState()
|
|
|
+ if taskname == "task_manager":
|
|
|
+ self.state.blocked = False
|
|
|
self.state.operations = operations
|
|
|
+ self.state.additional_operations = additional_operations
|
|
|
+ self.state.keyed_operations = keyed_operations
|
|
|
+ self.state.create_additional_task = False
|
|
|
self.taskname = taskname
|
|
|
self.finish_on = finish_on
|
|
|
|
|
@@ -372,31 +381,90 @@ class ModelverseInterface(AtomicDEVS):
|
|
|
self.from_mvk = self.addInPort("from_MvK")
|
|
|
|
|
|
def intTransition(self):
|
|
|
- self.state.init = False
|
|
|
- self.state.operations = []
|
|
|
+ self.state.create_additional_task = False
|
|
|
+ if self.state.allow_progress:
|
|
|
+ self.state.operations.pop(0)
|
|
|
+ elif not self.state.allow_progress:
|
|
|
+ self.state.send_operations.pop(0)
|
|
|
+
|
|
|
+ self.state.blocked = True
|
|
|
return self.state
|
|
|
|
|
|
def extTransition(self, inputs):
|
|
|
for inp in inputs[self.from_mvk]:
|
|
|
- self.state.output.append(inp)
|
|
|
- if inp == self.finish_on:
|
|
|
+ print("Got input: " + str(inp))
|
|
|
+ self.state.blocked = False
|
|
|
+
|
|
|
+ self.state.output.setdefault(inp[0], []).append(inp[1])
|
|
|
+ if inp[0] == self.taskname and inp[1] == self.finish_on:
|
|
|
self.state.finished = True
|
|
|
- print("Event history: " + str(self.state.output))
|
|
|
+ elif inp[0] == self.taskname and self.state.operations[0] is None:
|
|
|
+ # We have to block for now, and modify a model first...
|
|
|
+ print("Blocking for now...")
|
|
|
+ self.state.allow_progress = False
|
|
|
+ prev_output = self.state.output[inp[0]][-1]
|
|
|
+ if prev_output.startswith("Please edit this model before sending next input: "):
|
|
|
+ _, model_name = prev_output.split("Please edit this model before sending next input: ", 1)
|
|
|
+ self.state.do_additional_operations = True
|
|
|
+ self.state.send_operations = [[], ["admin"], ["admin"], [], ["model_modify"], [model_name], ["formalisms/SimpleClassDiagrams"]] + self.state.additional_operations[0] + [["exit"]]
|
|
|
+ self.state.additional_taskname = str(uuid.uuid4())
|
|
|
+ print("Modifying model " + str(model_name))
|
|
|
+ print("On taskname " + str(self.state.additional_taskname))
|
|
|
+ self.state.create_additional_task = True
|
|
|
+ self.state.had_key = None
|
|
|
+ elif prev_output.startswith("Spawned activity on task: "):
|
|
|
+ print("Spawned activity")
|
|
|
+ _, task_name = prev_output.split("Spawned activity on task: ", 1)
|
|
|
+ self.state.blocked = True
|
|
|
+
|
|
|
+ elif inp[0] != self.taskname:
|
|
|
+ # Got some output on another task
|
|
|
+ if self.state.send_operations == []:
|
|
|
+ # At the end of these operations, so finish up!
|
|
|
+ if self.state.had_key is not None:
|
|
|
+ self.state.keyed_operations.pop(self.state.had_key)
|
|
|
+ self.state.additional_taskname = self.state.had_key
|
|
|
+ self.state.additional_operations.insert(0, [])
|
|
|
+ self.state.send_operations = ["__continue__"]
|
|
|
+ self.state.had_key = None
|
|
|
+ else:
|
|
|
+ self.state.additional_operations.pop(0)
|
|
|
+ self.state.do_additional_operations = False
|
|
|
+ self.state.allow_progress = True
|
|
|
+ self.state.send_operations = None
|
|
|
+ self.state.operations[0] = []
|
|
|
+ print("Clear up to the normal task!")
|
|
|
+ elif inp[1].startswith("Please edit this model before sending next input: "):
|
|
|
+ _, model_name = inp[1].split("Please edit this model before sending next input: ", 1)
|
|
|
+ self.state.do_additional_operations = True
|
|
|
+ self.state.send_operations = [[], ["admin"], ["admin"], [], ["model_modify"], [model_name], ["formalisms/SimpleClassDiagrams"]] + self.state.keyed_operations[inp[0]] + [["exit"]]
|
|
|
+ self.state.additional_taskname = str(uuid.uuid4())
|
|
|
+ print("Modifying model " + str(model_name))
|
|
|
+ print("On taskname " + str(self.state.additional_taskname))
|
|
|
+ self.state.create_additional_task = True
|
|
|
+ self.state.had_key = inp[0]
|
|
|
+
|
|
|
return self.state
|
|
|
|
|
|
def outputFnc(self):
|
|
|
- if self.state.operations:
|
|
|
- return {self.to_mvk: [(self.taskname, self.state.operations)]}
|
|
|
+ if self.state.allow_progress and self.state.operations:
|
|
|
+ print("REQUEST: " + str(self.state.operations[0]))
|
|
|
+ return {self.to_mvk: [(self.taskname, self.state.operations[0])]}
|
|
|
+ elif not self.state.allow_progress and self.state.send_operations:
|
|
|
+ outp = []
|
|
|
+ if self.state.create_additional_task:
|
|
|
+ outp.append(('task_manager', [self.state.additional_taskname]))
|
|
|
+ outp.append((self.state.additional_taskname, self.state.send_operations[0]))
|
|
|
+ print("REQUEST special: " + str(outp))
|
|
|
+ return {self.to_mvk: outp}
|
|
|
else:
|
|
|
return {}
|
|
|
|
|
|
def timeAdvance(self):
|
|
|
- if self.state.init:
|
|
|
- return 0
|
|
|
- elif self.state.processing:
|
|
|
- return 0
|
|
|
- else:
|
|
|
+ if self.state.blocked:
|
|
|
return float("inf")
|
|
|
+ else:
|
|
|
+ return 0.0
|
|
|
|
|
|
class NetworkState(object):
|
|
|
def __init__(self):
|
|
@@ -444,6 +512,8 @@ class System(CoupledDEVS):
|
|
|
def __init__(self,
|
|
|
taskname,
|
|
|
operations,
|
|
|
+ mvi_additional,
|
|
|
+ mvi_keyed,
|
|
|
finish_on,
|
|
|
rule_generation,
|
|
|
time_per_phase,
|
|
@@ -476,13 +546,15 @@ class System(CoupledDEVS):
|
|
|
|
|
|
self.mvi_manager = self.addSubModel(ModelverseInterface(\
|
|
|
taskname = "task_manager",
|
|
|
- operations = [taskname],
|
|
|
+ operations = [[taskname]],
|
|
|
finish_on = None,
|
|
|
))
|
|
|
self.mvi = self.addSubModel(ModelverseInterface(\
|
|
|
taskname = taskname,
|
|
|
operations = operations,
|
|
|
finish_on = finish_on,
|
|
|
+ additional_operations = mvi_additional,
|
|
|
+ keyed_operations = mvi_keyed,
|
|
|
))
|
|
|
self.mvk = self.addSubModel(ModelverseKernel(\
|
|
|
time_per_phase = time_per_phase,
|
|
@@ -540,13 +612,31 @@ class System(CoupledDEVS):
|
|
|
|
|
|
taskname = "test_task"
|
|
|
|
|
|
-operations = ["admin", "admin", "model_add", "formalisms/SimpleClassDiagrams", "formalisms/PN"] + compile_model("models/petrinets.mvc") + ["model_list", "formalisms", "echo", "FINISHED"]
|
|
|
+operations = json.loads(open("model/operations", 'r').read())
|
|
|
+additional_operations = [[], # revise_req
|
|
|
+ [], # revise_environment
|
|
|
+ [], # revise_plant
|
|
|
+ [], # revise_control
|
|
|
+ [], # revise_query
|
|
|
+ [], # revise_architecture
|
|
|
+ [], # make_initial_models
|
|
|
+ [["instantiate_edge", "Association", "PLANT2EPN_link", "PW_Plant/State", "Encapsulated_PetriNet/Place"], ["instantiate_edge", "Association", "PLANT2EPN_tlink", "PW_Plant/Transition", "Encapsulated_PetriNet/Transition"]], # plant_to_EPN
|
|
|
+ [["instantiate_edge", "Association", "CTRL2EPN_link", "PW_Control/State", "Encapsulated_PetriNet/Place"], ["instantiate_edge", "Association", "CTRL2EPN_tlink", "PW_Control/Transition", "Encapsulated_PetriNet/Transition"]], # control_to_EPN
|
|
|
+ [["instantiate_edge", "Association", "ENV2EPN_link", "PW_Environment/Event", "Encapsulated_PetriNet/Place"]], # environment_to_EPN
|
|
|
+ [["instantiate_edge", "Association", "EPN2PN_place_link", "Encapsulated_PetriNet/Place", "PetriNet/Place"], ["instantiate_edge", "Association", "EPN2PN_transition_link", "Encapsulated_PetriNet/Transition", "PetriNet/Transition"]], # EPN_to_PN
|
|
|
+ [], # reachability
|
|
|
+ [], # bfs
|
|
|
+ [], # merge
|
|
|
+ ]
|
|
|
+keyed_operations = {}
|
|
|
finish_on = "FINISHED"
|
|
|
|
|
|
args = {
|
|
|
"taskname": taskname,
|
|
|
"operations": operations,
|
|
|
"finish_on": finish_on,
|
|
|
+ "mvi_additional": additional_operations,
|
|
|
+ "mvi_keyed": keyed_operations,
|
|
|
"mvi2mvk_latency": 0.0000001,
|
|
|
"mvi2mvk_bandwidth": 50000000000,
|
|
|
"mvk2mvs_latency": 0.0000001,
|