{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# FTG generation from a PM\n",
"In this example notebook, we show how to generate an FTG out of a PM."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Initialization\n",
"As usual, we start with the initialization of the Modelverse and the definition of the *view* operation for SVG."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import sys\n",
"sys.path.append(\"../wrappers\")\n",
"from modelverse import *\n",
"\n",
"init()\n",
"login(None, None)\n",
"\n",
"from IPython.display import SVG, display\n",
"\n",
"def view(model_name):\n",
" svg = SVG()\n",
" svg.data = show(model_name)\n",
" display(svg)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Add models\n",
"We add the models that we will be using: the process model that we want to fetch the FTG of, and we also load the FTG formalism."
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"model_add(\"~/models/pm_powerwindow\", \"formalisms/ProcessModel\", open(\"../models/PowerWindow/PM_analyze.mvc\", 'r').read())\n",
"model_add(\"~/formalisms/FormalismTransformationGraph\", \"formalisms/SimpleClassDiagrams\", open(\"../models/FTGPM/metamodels/FTG_MM.mvc\", 'r').read())"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Add transformation\n",
"We now add the transformation that will generate the FTG part."
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"def add_traceability(model):\n",
" instantiate(model, \"Association\", edge=(\"PM/Exec\", \"FTG/Activity\"), ID=\"activity_link\")\n",
" instantiate(model, \"Association\", edge=(\"PM/Data\", \"FTG/Formalism\"), ID=\"formalism_link\")\n",
"\n",
"transformation_add_AL({\"PM\": \"formalisms/ProcessModel\"}, {\"FTG\": \"~/formalisms/FormalismTransformationGraph\"}, \"~/models/generate_FTG\", open(\"../models/FTGPM/transformations/PM_to_FTG.alc\", 'r').read(), add_traceability)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Execute transformation\n",
"Finally we execute the transformation, thereby generating the FTG.\n",
"The FTG model is subsequently visualized."
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"transformation_execute_AL(\"~/models/generate_FTG\", {\"PM\": \"~/models/pm_powerwindow\"}, {\"FTG\": \"~/models/ftg_powerwindow\"})\n",
"view(\"~/models/ftg_powerwindow\")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.5"
}
},
"nbformat": 4,
"nbformat_minor": 2
}