{ "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": [ "__3123484 : Activityname = "models/revise_req"__3123553 : Activityname = "models/make_initial_models"__3123622 : Activityname = "models/revise_plant"__3123691 : Activityname = "models/revise_environment"__3123760 : Activityname = "models/revise_control"__3123829 : Activityname = "models/revise_query"__3123898 : Activityname = "models/revise_architecture"__3123967 : Activityname = "models/plant_to_EPN"__3124036 : Activityname = "models/environment_to_EPN"__3124105 : Activityname = "models/control_to_EPN"__3124174 : Activityname = "models/merge_EPN"__3124243 : Activityname = "models/combine_EPN"__3124312 : Activityname = "models/EPN_to_PN"__3124381 : Activityname = "models/reachability"__3124450 : Activityname = "models/match"__3124519 : Activityname = "models/bfs"__3124683 : Formalismname = "formalisms/Requirements"__3124752 : Formalismname = "formalisms/PW_Plant"__3124821 : Formalismname = "formalisms/PW_Environment"__3124890 : Formalismname = "formalisms/PW_Control"__3124959 : Formalismname = "formalisms/Encapsulated_PetriNet"__3125032 : Formalismname = "formalisms/PetriNet"__3125101 : Formalismname = "formalisms/ReachabilityGraph"__3125170 : Formalismname = "formalisms/Query"__3125239 : Formalismname = "formalisms/Architecture"" ], "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 }