{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import sys\n",
    "sys.path.append(\"wrappers\")\n",
    "from modelverse import *\n",
    "\n",
    "import uuid\n",
    "\n",
    "init()\n",
    "username = str(uuid.uuid4())\n",
    "password = str(uuid.uuid4())\n",
    "login(username, password)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "model_add(\"~/formalisms/PetriNets\", \"formalisms/SimpleClassDiagrams\", \"\"\"\n",
    "    include \"primitives.alh\"\n",
    "    \n",
    "    SimpleAttribute Natural {\n",
    "        name = \"Natural\"\n",
    "        constraint = $\n",
    "            String function constraint(value : Element):\n",
    "                if (is_physical_int(value)):\n",
    "                    if (integer_gt(value, 0)):\n",
    "                        return \"OK\"!\n",
    "                    else:\n",
    "                        return \"Natural must be non-negative\"!\n",
    "                else:\n",
    "                    return \"Natural is not an integer value\"!\n",
    "            $\n",
    "    }\n",
    "    SimpleAttribute String{\n",
    "        name = \"String\"\n",
    "    }\n",
    "    \n",
    "    Class Place {\n",
    "        name = \"MYPLACE\"\n",
    "        name : String\n",
    "        tokens : Natural\n",
    "    }\n",
    "    \n",
    "    Class Transition {\n",
    "        name = \"Transition\"\n",
    "        name : String\n",
    "    }\n",
    "    \n",
    "    Association P2T (Place, Transition) {\n",
    "        name = \"P2T\"\n",
    "        weight : Natural\n",
    "    }\n",
    "    \n",
    "    Association T2P (Transition, Place) {\n",
    "        name = \"T2P\"\n",
    "        weight : Natural\n",
    "    }\n",
    "    \"\"\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<svg height=\"186\" width=\"998\"><marker id=\"triangle\" orient=\"auto\" refX=\"0.0\" refY=\"0.0\" style=\"overflow:visible;\"><path d=\"M 0.0,0.0 L 5.0,-5.0 L -12.5,0.0 L 5.0,5.0 L 0.0,0.0 z \" id=\"path941\" style=\"fill-rule:evenodd;stroke:#000000;stroke-width:1pt;stroke-opacity:1;fill:#000000;fill-opacity:1\" transform=\"scale(0.8) rotate(180) translate(12.5,0)\"/></marker><line stroke=\"black\" style=\"marker-end:url(#triangle)\" x1=\"653\" x2=\"763.5\" y1=\"33\" y2=\"33.0\"/><line stroke=\"black\" x1=\"763.5\" x2=\"874\" y1=\"33.0\" y2=\"33\"/><line stroke=\"black\" style=\"marker-end:url(#triangle)\" x1=\"874\" x2=\"763.5\" y1=\"33\" y2=\"33.0\"/><line stroke=\"black\" x1=\"763.5\" x2=\"653\" y1=\"33.0\" y2=\"33\"/><rect fill=\"white\" height=\"90\" stroke=\"black\" width=\"244\" x=\"3\" y=\"3\"/><rect fill=\"white\" height=\"90\" stroke=\"black\" width=\"226\" x=\"287\" y=\"3\"/><rect fill=\"white\" height=\"180\" stroke=\"black\" width=\"181\" x=\"553\" y=\"3\"/><rect fill=\"white\" height=\"165\" stroke=\"black\" width=\"181\" x=\"774\" y=\"3\"/><line stroke=\"black\" x1=\"3\" x2=\"247\" y1=\"33\" y2=\"33\"/><line stroke=\"black\" x1=\"3\" x2=\"247\" y1=\"23\" y2=\"23\"/><line stroke=\"black\" x1=\"287\" x2=\"513\" y1=\"33\" y2=\"33\"/><line stroke=\"black\" x1=\"287\" x2=\"513\" y1=\"23\" y2=\"23\"/><line stroke=\"black\" x1=\"553\" x2=\"734\" y1=\"78\" y2=\"78\"/><line stroke=\"black\" x1=\"553\" x2=\"734\" y1=\"23\" y2=\"23\"/><line stroke=\"black\" x1=\"774\" x2=\"955\" y1=\"63\" y2=\"63\"/><line stroke=\"black\" x1=\"774\" x2=\"955\" y1=\"23\" y2=\"23\"/><text fill=\"black\" x=\"13\" y=\"18\">Natural : SimpleAttribute</text><text fill=\"black\" x=\"13\" y=\"55.5\">name = &quot;Natural&quot;</text><text fill=\"black\" x=\"13\" y=\"70.5\">constraint = ^code/1171120</text><text fill=\"black\" x=\"297\" y=\"18\">String : SimpleAttribute</text><text fill=\"black\" x=\"297\" y=\"55.5\">name = &quot;String&quot;</text><text fill=\"black\" x=\"297\" y=\"70.5\">(constraint)</text><text fill=\"black\" x=\"563\" y=\"18\">Place : Class</text><text fill=\"black\" x=\"563\" y=\"36.75\">name : String</text><text fill=\"black\" x=\"563\" y=\"51.75\">tokens : Natural</text><text fill=\"black\" x=\"563\" y=\"100.5\">(lower_cardinality)</text><text fill=\"black\" x=\"563\" y=\"115.5\">(upper_cardinality)</text><text fill=\"black\" x=\"563\" y=\"130.5\">name = &quot;Place&quot;</text><text fill=\"black\" x=\"563\" y=\"145.5\">(abstract)</text><text fill=\"black\" x=\"563\" y=\"160.5\">(constraint)</text><text fill=\"black\" x=\"784\" y=\"18\">Transition : Class</text><text fill=\"black\" x=\"784\" y=\"36.75\">name : String</text><text fill=\"black\" x=\"784\" y=\"85.5\">(lower_cardinality)</text><text fill=\"black\" x=\"784\" y=\"100.5\">(upper_cardinality)</text><text fill=\"black\" x=\"784\" y=\"115.5\">name = &quot;Transition&quot;</text><text fill=\"black\" x=\"784\" y=\"130.5\">(abstract)</text><text fill=\"black\" x=\"784\" y=\"145.5\">(constraint)</text></svg>"
      ],
      "text/plain": [
       "<IPython.core.display.SVG object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "from IPython.display import SVG, display\n",
    "svg = SVG()\n",
    "svg.data = show(\"~/formalisms/PetriNets\")\n",
    "display(svg)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "attr_assign(\"~/formalisms/PetriNets\", \"Place\", \"name\", \"Place\")\n",
    "attr_assign(\"~/formalisms/PetriNets\", \"Natural\", \"name\", \"Natural\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "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
}
