modellanguage.html 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  6. <title>Modelling Language &#8212; Modelverse 0.4.0 documentation</title>
  7. <link rel="stylesheet" href="_static/classic.css" type="text/css" />
  8. <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
  9. <script type="text/javascript">
  10. var DOCUMENTATION_OPTIONS = {
  11. URL_ROOT: './',
  12. VERSION: '0.4.0',
  13. COLLAPSE_INDEX: false,
  14. FILE_SUFFIX: '.html',
  15. HAS_SOURCE: true
  16. };
  17. </script>
  18. <script type="text/javascript" src="_static/jquery.js"></script>
  19. <script type="text/javascript" src="_static/underscore.js"></script>
  20. <script type="text/javascript" src="_static/doctools.js"></script>
  21. <link rel="top" title="Modelverse 0.4.0 documentation" href="index.html" />
  22. <link rel="next" title="Examples" href="examples.html" />
  23. <link rel="prev" title="Action Language" href="actionlanguage.html" />
  24. </head>
  25. <body role="document">
  26. <div class="related" role="navigation" aria-label="related navigation">
  27. <h3>Navigation</h3>
  28. <ul>
  29. <li class="right" style="margin-right: 10px">
  30. <a href="genindex.html" title="General Index"
  31. accesskey="I">index</a></li>
  32. <li class="right" >
  33. <a href="examples.html" title="Examples"
  34. accesskey="N">next</a> |</li>
  35. <li class="right" >
  36. <a href="actionlanguage.html" title="Action Language"
  37. accesskey="P">previous</a> |</li>
  38. <li class="nav-item nav-item-0"><a href="index.html">Modelverse 0.4.0 documentation</a> &#187;</li>
  39. </ul>
  40. </div>
  41. <div class="document">
  42. <div class="documentwrapper">
  43. <div class="bodywrapper">
  44. <div class="body" role="main">
  45. <div class="section" id="modelling-language">
  46. <h1>Modelling Language<a class="headerlink" href="#modelling-language" title="Permalink to this headline">¶</a></h1>
  47. <p>Apart from the action language, the Modelverse also has a modelling language.
  48. With this language, models (<em>i.e.</em>, data) can be defined in addition to the algorithms.</p>
  49. <p>This language is still mostly work in progress, but should be decent enough to construct simple metamodels and instantiate them.
  50. All models have the extension *.mvc, indicating that they are models and should be compiled as such.</p>
  51. <div class="section" id="language-description">
  52. <h2>Language description<a class="headerlink" href="#language-description" title="Permalink to this headline">¶</a></h2>
  53. <p>The modelling language defines data structures, which will be formed as models in the Modelverse.</p>
  54. <p>Several constructs are supported.</p>
  55. <div class="section" id="import">
  56. <h3>Import<a class="headerlink" href="#import" title="Permalink to this headline">¶</a></h3>
  57. <p>An import pulls in a model and makes it accessible using a simpler identifier.
  58. The structure is as follows:</p>
  59. <div class="highlight-default"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">path</span><span class="o">/</span><span class="ow">in</span><span class="o">/</span><span class="n">modelverse</span> <span class="k">as</span> <span class="n">my_model</span>
  60. </pre></div>
  61. </div>
  62. <p>After this import, the model that was previously exported to <em>path/in/modelverse</em> becomes available as <em>my_model</em>.</p>
  63. </div>
  64. <div class="section" id="include">
  65. <h3>Include<a class="headerlink" href="#include" title="Permalink to this headline">¶</a></h3>
  66. <p>When combined with action language, the action language might require some includes of header files.
  67. To do this, the includes can be placed at the top of the hierarchy.</p>
  68. </div>
  69. <div class="section" id="model">
  70. <h3>Model<a class="headerlink" href="#model" title="Permalink to this headline">¶</a></h3>
  71. <p>Every model is defined by first specifying the type of model to instantiate, followed by the name of the model to create.
  72. The name of the model can then later on be referenced in other models (as type, or for exporting).
  73. Within the model, all names of the type model can be used as types again.</p>
  74. </div>
  75. <div class="section" id="instance">
  76. <h3>Instance<a class="headerlink" href="#instance" title="Permalink to this headline">¶</a></h3>
  77. <p>A model consists of some instances.
  78. These instances are instances of types specified by the model that is the metaclass of the current model.</p>
  79. </div>
  80. <div class="section" id="attribute">
  81. <h3>Attribute<a class="headerlink" href="#attribute" title="Permalink to this headline">¶</a></h3>
  82. <p>Each model instance can contain attributes.
  83. There are two kinds of attributes: defining attributes, or value attributes.</p>
  84. <p>For defining attributes, the structure is as follows:</p>
  85. <div class="highlight-default"><div class="highlight"><pre><span class="n">Class</span> <span class="n">A</span><span class="p">{</span>
  86. <span class="n">my_parameter</span> <span class="p">:</span> <span class="n">ParameterType</span>
  87. <span class="p">}</span>
  88. </pre></div>
  89. </div>
  90. <p>This defines a parameter called <em>my_parameter</em> which is typed by <em>ParameterType</em>.
  91. <em>ParameterType</em> must always be a type defined in the type that is being instantiated.
  92. Even if this is a primitive, such as <em>Integer</em>, the metamodel must define what it calls an <em>Integer</em>.
  93. While this might seem bothersome, this clearly defines the notion of what a type means, without having to resort to the implementation.</p>
  94. <p>Value attributes are similar, but have a different syntax, and contain an actual value.
  95. Their structure is as follows:</p>
  96. <div class="highlight-default"><div class="highlight"><pre><span class="n">A</span> <span class="n">a</span><span class="p">{</span>
  97. <span class="n">my_parameter</span> <span class="o">=</span> <span class="mi">1</span>
  98. <span class="p">}</span>
  99. </pre></div>
  100. </div>
  101. <p>They assign a value to a previously defined attribute.
  102. In this case, it is important that the value conforms to the type specified in the defining attribute.</p>
  103. </div>
  104. </div>
  105. <div class="section" id="merge-with-action-language">
  106. <h2>Merge with Action Language<a class="headerlink" href="#merge-with-action-language" title="Permalink to this headline">¶</a></h2>
  107. <p>It is of course possible to incorporate action language inside of a model.
  108. A typical use case for this is the definition of constraints or actions.
  109. Action language is surrounded by dollar signs ($), which causes the parser to redirect the text between dollar signs to the action language parser.
  110. All includes necessary for the compilation of the action code, must be provided at the top of the document.</p>
  111. </div>
  112. <div class="section" id="examples">
  113. <h2>Examples<a class="headerlink" href="#examples" title="Permalink to this headline">¶</a></h2>
  114. <p>Some simple examples of models are provided below.
  115. This code only makes the specified models available in code; to do something with these models, an algorithms has to read out the model and operate on it.</p>
  116. <div class="section" id="petri-net-metamodel">
  117. <h3>Petri Net metamodel<a class="headerlink" href="#petri-net-metamodel" title="Permalink to this headline">¶</a></h3>
  118. <p>A simple Petri Net metamodel can be created, based on the SimpleClassDiagrams metamodel.
  119. This looks like this:</p>
  120. <div class="highlight-default"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">models</span><span class="o">/</span><span class="n">SimpleClassDiagrams</span> <span class="k">as</span> <span class="n">SCD</span>
  121. <span class="n">SCD</span> <span class="n">PetriNets</span><span class="p">{</span>
  122. <span class="n">Class</span> <span class="n">Natural</span> <span class="p">{}</span>
  123. <span class="n">Class</span> <span class="n">Place</span><span class="p">{</span>
  124. <span class="n">tokens</span> <span class="p">:</span> <span class="n">Natural</span>
  125. <span class="p">}</span>
  126. <span class="n">Class</span> <span class="n">Transition</span><span class="p">{}</span>
  127. <span class="n">Association</span> <span class="n">P2T</span> <span class="p">(</span><span class="n">Place</span><span class="p">,</span> <span class="n">Transition</span><span class="p">)</span> <span class="p">{</span>
  128. <span class="n">weight</span> <span class="p">:</span> <span class="n">Natural</span>
  129. <span class="p">}</span>
  130. <span class="n">Association</span> <span class="n">T2P</span> <span class="p">(</span><span class="n">Transition</span><span class="p">,</span> <span class="n">Place</span><span class="p">)</span> <span class="p">{</span>
  131. <span class="n">weight</span> <span class="p">:</span> <span class="n">Natural</span>
  132. <span class="p">}</span>
  133. <span class="p">}</span>
  134. <span class="n">export</span> <span class="n">PetriNets</span> <span class="n">to</span> <span class="n">models</span><span class="o">/</span><span class="n">PetriNets</span>
  135. </pre></div>
  136. </div>
  137. <p>Note that in this metamodel, there is no constraint placed on the value of a Natural: it can literaly be anything.
  138. That is why usually, you want to place constraints on the value.
  139. In this case, the value needs to be an integer, and it must be larger than or equal to zero.
  140. Such constraints are written in the action language, surrounded by dollar signs:</p>
  141. <div class="highlight-default"><div class="highlight"><pre>import models/SimpleClassDiagrams as SCD
  142. include &quot;primitives.alh&quot;
  143. SCD PetriNets{
  144. Class Natural {
  145. $
  146. if (bool_not(is_physical_int(self))):
  147. return &quot;Natural has no integer value at &quot; + name!
  148. elif (integer_lt(self, 0)):
  149. return &quot;Natural does not have a positive or zero value at &quot; + name!
  150. else:
  151. return &quot;OK&quot;!
  152. $
  153. }
  154. Class Place{
  155. tokens : Natural {
  156. target_lower_cardinality = 1
  157. target_upper_cardinality = 1
  158. }
  159. }
  160. Class Transition{}
  161. Association P2T (Place, Transition) {
  162. weight : Natural {
  163. target_lower_cardinality = 1
  164. target_upper_cardinality = 1
  165. }
  166. }
  167. Association T2P (Transition, Place) {
  168. weight : Natural {
  169. target_lower_cardinality = 1
  170. target_upper_cardinality = 1
  171. }
  172. }
  173. }
  174. </pre></div>
  175. </div>
  176. </div>
  177. <div class="section" id="petri-net-instance">
  178. <h3>Petri Net instance<a class="headerlink" href="#petri-net-instance" title="Permalink to this headline">¶</a></h3>
  179. <p>The previous metamodel can then be instantiated:</p>
  180. <div class="highlight-default"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">models</span><span class="o">/</span><span class="n">PetriNets</span> <span class="k">as</span> <span class="n">PetriNets</span>
  181. <span class="n">PetriNets</span> <span class="n">my_petrinet</span> <span class="p">{</span>
  182. <span class="n">Place</span> <span class="n">p1</span> <span class="p">{</span>
  183. <span class="n">tokens</span> <span class="o">=</span> <span class="mi">1</span>
  184. <span class="p">}</span>
  185. <span class="n">Place</span> <span class="n">p2</span> <span class="p">{</span>
  186. <span class="n">tokens</span> <span class="o">=</span> <span class="mi">3</span>
  187. <span class="p">}</span>
  188. <span class="n">Transition</span> <span class="n">t1</span> <span class="p">{}</span>
  189. <span class="n">P2T</span> <span class="p">(</span><span class="n">p1</span><span class="p">,</span> <span class="n">t1</span><span class="p">)</span> <span class="p">{</span>
  190. <span class="n">weight</span> <span class="o">=</span> <span class="mi">1</span>
  191. <span class="p">}</span>
  192. <span class="n">T2P</span> <span class="p">(</span><span class="n">t1</span><span class="p">,</span> <span class="n">p2</span><span class="p">)</span> <span class="p">{</span>
  193. <span class="n">weight</span> <span class="o">=</span> <span class="mi">2</span>
  194. <span class="p">}</span>
  195. <span class="p">}</span>
  196. <span class="n">export</span> <span class="n">my_petrinet</span> <span class="n">to</span> <span class="n">models</span><span class="o">/</span><span class="n">my_petrinet</span>
  197. </pre></div>
  198. </div>
  199. </div>
  200. </div>
  201. </div>
  202. </div>
  203. </div>
  204. </div>
  205. <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
  206. <div class="sphinxsidebarwrapper">
  207. <h3><a href="index.html">Table Of Contents</a></h3>
  208. <ul>
  209. <li><a class="reference internal" href="#">Modelling Language</a><ul>
  210. <li><a class="reference internal" href="#language-description">Language description</a><ul>
  211. <li><a class="reference internal" href="#import">Import</a></li>
  212. <li><a class="reference internal" href="#include">Include</a></li>
  213. <li><a class="reference internal" href="#model">Model</a></li>
  214. <li><a class="reference internal" href="#instance">Instance</a></li>
  215. <li><a class="reference internal" href="#attribute">Attribute</a></li>
  216. </ul>
  217. </li>
  218. <li><a class="reference internal" href="#merge-with-action-language">Merge with Action Language</a></li>
  219. <li><a class="reference internal" href="#examples">Examples</a><ul>
  220. <li><a class="reference internal" href="#petri-net-metamodel">Petri Net metamodel</a></li>
  221. <li><a class="reference internal" href="#petri-net-instance">Petri Net instance</a></li>
  222. </ul>
  223. </li>
  224. </ul>
  225. </li>
  226. </ul>
  227. <h4>Previous topic</h4>
  228. <p class="topless"><a href="actionlanguage.html"
  229. title="previous chapter">Action Language</a></p>
  230. <h4>Next topic</h4>
  231. <p class="topless"><a href="examples.html"
  232. title="next chapter">Examples</a></p>
  233. <div role="note" aria-label="source link">
  234. <h3>This Page</h3>
  235. <ul class="this-page-menu">
  236. <li><a href="_sources/modellanguage.txt"
  237. rel="nofollow">Show Source</a></li>
  238. </ul>
  239. </div>
  240. <div id="searchbox" style="display: none" role="search">
  241. <h3>Quick search</h3>
  242. <form class="search" action="search.html" method="get">
  243. <div><input type="text" name="q" /></div>
  244. <div><input type="submit" value="Go" /></div>
  245. <input type="hidden" name="check_keywords" value="yes" />
  246. <input type="hidden" name="area" value="default" />
  247. </form>
  248. </div>
  249. <script type="text/javascript">$('#searchbox').show(0);</script>
  250. </div>
  251. </div>
  252. <div class="clearer"></div>
  253. </div>
  254. <div class="related" role="navigation" aria-label="related navigation">
  255. <h3>Navigation</h3>
  256. <ul>
  257. <li class="right" style="margin-right: 10px">
  258. <a href="genindex.html" title="General Index"
  259. >index</a></li>
  260. <li class="right" >
  261. <a href="examples.html" title="Examples"
  262. >next</a> |</li>
  263. <li class="right" >
  264. <a href="actionlanguage.html" title="Action Language"
  265. >previous</a> |</li>
  266. <li class="nav-item nav-item-0"><a href="index.html">Modelverse 0.4.0 documentation</a> &#187;</li>
  267. </ul>
  268. </div>
  269. <div class="footer" role="contentinfo">
  270. &#169; Copyright 2016, Yentl Van Tendeloo.
  271. Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.4.6.
  272. </div>
  273. </body>
  274. </html>