import sys
sys.path.append("wrappers/")

from modelverse import *

init()
login("admin", "admin")

model_add("formalisms/DEVS/DEVS_MM", "formalisms/SimpleClassDiagrams", open("models/ClassicDEVS/metamodels/DEVS.mvc", 'r').read())
model_add("formalisms/PM/PM_Extended_MM", "formalisms/SimpleClassDiagrams", open("models/FTGPM/metamodels/control_patterns.mvc", 'r').read())
model_add("formalisms/Experiment/Experiment_MM", "formalisms/SimpleClassDiagrams", open("models/PythonPDEVS_Experiment/metamodels/experiment.mvc", 'r').read())

model_add("models/PM/to_DEVS", "formalisms/ProcessModel", open("models/FTGPM/PM_patterns_simulation.mvc").read())

model_add("models/DEVS/PM_library", "formalisms/DEVS/DEVS_MM", open("models/ClassicDEVS/models/process_patterns_library.mvc", 'r').read())
model_add("models/PM/example_PM", "formalisms/PM/PM_Extended_MM", open("models/FTGPM/models/example_patterns.mvc", 'r').read())
model_add("models/Experiment/example_experiment", "formalisms/Experiment/Experiment_MM", open("models/PythonPDEVS_Experiment/models/optimize_PM_resources.mvc", 'r').read())

def traceability_pm_devs(model):
    instantiate(model, "Association", ("PM/ProcessNode", "DEVS/DEVSInstance"), ID="Trace")

transformation_add_MT({"PM": "formalisms/PM/PM_Extended_MM"}, {"DEVS": "formalisms/DEVS/DEVS_MM"}, "formalisms/PM/to_DEVS", open("models/FTGPM/transformations/patterns_to_DEVS.mvc", 'r').read(), traceability_pm_devs)

transformation_add_AL({"model1": "formalisms/DEVS/DEVS_MM", "model2": "formalisms/DEVS/DEVS_MM"}, {"result": "formalisms/DEVS/DEVS_MM"}, "formalisms/DEVS/merge", open("models/ClassicDEVS/transformations/merge.alc", 'r').read())
transformation_add_AL({"DEVS": "formalisms/DEVS/DEVS_MM", "Experiment": "formalisms/Experiment/Experiment_MM"}, {}, "formalisms/DEVS/simulate", open("models/ClassicDEVS/transformations/simulate.alc", 'r').read())

process_execute("models/PM/to_DEVS", {"PM": "models/PM/example_PM", "DEVS library": "models/DEVS/PM_library", "Experiment": "models/Experiment/example_experiment"}, {})
