{"data":{"markdownRemark":{"html":"<p>The <code class=\"language-text\">Model</code> is the main abstraction in the Simudyne SDK. It incorporates all the elements required to build and run a simulation from setup to teardown.</p>\n<p>The <code class=\"language-text\">Model</code> Interface below outlines three stages. Let's describe them as well as the model flow in more detail.</p>\n<h2 id=\"general-flow\"><a href=\"#general-flow\" aria-hidden=\"true\" class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>General Flow</h2>\n<div class=\"model_flow\">\n<p>\n  <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/model_flow-6d01341fdbcdddc6ed4a8579b9741fcb-3651c.png\"\n    style=\"display: block\"\n    target=\"_blank\"\n    rel=\"noopener\"\n  >\n  \n  <span\n    class=\"gatsby-resp-image-wrapper\"\n    style=\"position: relative; display: block; padding: 20px; max-width: 601px; margin-left: auto; margin-right: auto;\"\n  >\n    <span\n      class=\"gatsby-resp-image-background-image\"\n      style=\"padding-bottom: 106.48137055229425%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAVCAIAAADJt1n/AAAACXBIWXMAAJnKAACZygHjkaQiAAAC2klEQVQ4y3VTTU/VQBTtL2OjOz4SFiZqwkLcuJCVG3+CYUUiiUvjn3AhCsG3ICYioiYICQnCo+17fW2n0/n+aD3zCuWB8WY6uZ2Zc+feM/dEG6/O5uf2nz78NT/3bbBTtG3rXYO5CVM7SvTyvYOV5Z/L9w/WVo/a2xYdH7GdrXxvQD5vF9nY9LDOhPCDbbL7qdz9WO5/odia3Y3wWdvU1MFxroHfDWMaJb2Qpmm1Mco3xjrNOfymxwewlP7sVNS1QwhWTwdztLJYoVReDkdJkqdpHsfjPCda3wY3PlzVJ4M976/K7s6ZGcDdtMGQFB77SBsmhCOlBd77LkpDiDUmHJhaO90KXhQu9qG8Pups7J42pXwS6+RSp4kep7qYWNzUEeakCISFeCEkmLsx70GBqSpNSl0WukLV2jobkozW19cXFxeWlhY2N18zRtM0ieOhEFwpwTlnjEshy5JXlcDi9Qg+pVW0v/9168P2u7fvD78f08pMMp5POBxSaEotrdQkK7KsLEuKssErCkQ6KI5SGklk7NqahmKNdsY4pawQJswcj4dUqyKvCGFKOa29lBbmvQ/guq5RM2NaSoMNrSyqysZKSYsVISwweWaURJkhdIBadwVmaAjXcB6CgZ1A0NSCb7vfQBhjNo3lKJGjVI5TWRaWEBqhbilVRYTW6o5hBQO9SYjIxixNWBKzbAwWpRCaEBIhv7pmrA70ov7ZwYPBARhnpDY4ERYD15xLKcM7owFOT7AM2hpWN5w1gkMqvqr8JBNJMonjDPPFRVrXSKjtezXqxAQZ9JKq8ULEglgMEIYMywKhwSgkhWdqbve2DwLslQAMHrPXBgxqgzasbYNOlQuqvFHVVBLt/62Ljq6+HKrLc4WX0xB400boBDR6MlRFbtBD/8BaKGx4Li/+yHwC7qdJXd8Uvdk4f7x0+OLZ70eLh3uDsrunTxhxV5Z/PH9ytPrg18u1kzuh/wJFn6VOvzPX2wAAAABJRU5ErkJggg=='); background-size: cover; display: block;\"\n    >\n      <picture>\n        <source\n          srcset=\"/static/model_flow-6d01341fdbcdddc6ed4a8579b9741fcb-7d167.webp 173w,\n/static/model_flow-6d01341fdbcdddc6ed4a8579b9741fcb-4c7e6.webp 345w,\n/static/model_flow-6d01341fdbcdddc6ed4a8579b9741fcb-15b94.webp 690w,\n/static/model_flow-6d01341fdbcdddc6ed4a8579b9741fcb-8f7dc.webp 1035w,\n/static/model_flow-6d01341fdbcdddc6ed4a8579b9741fcb-cc64c.webp 1380w,\n/static/model_flow-6d01341fdbcdddc6ed4a8579b9741fcb-2cb6b.webp 2070w,\n/static/model_flow-6d01341fdbcdddc6ed4a8579b9741fcb-a2ec7.webp 8347w\"\n          sizes=\"(max-width: 601px) 100vw, 601px\"\n          type=\"image/webp\"\n        />\n        <source\n          srcset=\"/static/model_flow-6d01341fdbcdddc6ed4a8579b9741fcb-0984e.png 173w,\n/static/model_flow-6d01341fdbcdddc6ed4a8579b9741fcb-ec14e.png 345w,\n/static/model_flow-6d01341fdbcdddc6ed4a8579b9741fcb-cd5eb.png 690w,\n/static/model_flow-6d01341fdbcdddc6ed4a8579b9741fcb-d1003.png 1035w,\n/static/model_flow-6d01341fdbcdddc6ed4a8579b9741fcb-cbf53.png 1380w,\n/static/model_flow-6d01341fdbcdddc6ed4a8579b9741fcb-356c5.png 2070w,\n/static/model_flow-6d01341fdbcdddc6ed4a8579b9741fcb-3651c.png 8347w\"\n          sizes=\"(max-width: 601px) 100vw, 601px\"\n          type=\"image/png\"\n        />\n        <img\n          class=\"gatsby-resp-image-image\"\n          style=\"width: 100%; height: 100%; margin: 0; vertical-align: middle; position: absolute; top: 0; left: 0; box-shadow: inset 0px 0px 0px 400px white;\"\n          src=\"/static/model_flow-6d01341fdbcdddc6ed4a8579b9741fcb-cd5eb.png\"\n          alt=\"model flow\"\n          title=\"\"\n          src=\"/static/model_flow-6d01341fdbcdddc6ed4a8579b9741fcb-cd5eb.png\"\n        />\n      </picture>\n      </span>\n  </span>\n  \n  </a>\n    </p>\n</div>\n<h2 id=\"modelstep-defining-computations-and-operations-at-each-step\"><a href=\"#modelstep-defining-computations-and-operations-at-each-step\" aria-hidden=\"true\" class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Model#step: defining computations and operations at each step</h2>\n<p>One iteration in your simulation involves a set of <code class=\"language-text\">step</code>s. At this stage, you need to specify calculations in your model to form a <code class=\"language-text\">step</code>. These are then run in order to complete one iteration of your simulation.</p>\n <p class=\"code-header\">Defining a step (Java)</p>\n<div class=\"gatsby-highlight\" data-language=\"java\"><pre class=\"language-java\"><code class=\"language-java\"><span class=\"token keyword\">public</span> <span class=\"token keyword\">class</span> <span class=\"token class-name\">MyModel</span> <span class=\"token keyword\">implements</span> <span class=\"token class-name\">Model</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token annotation punctuation\">@Variable</span> <span class=\"token keyword\">int</span> myVariable <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n\n  <span class=\"token annotation punctuation\">@Override</span>\n  <span class=\"token keyword\">public</span> <span class=\"token keyword\">void</span> <span class=\"token function\">step</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    myVariable <span class=\"token operator\">*=</span> <span class=\"token number\">1.1</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h2 id=\"modelsetup-defining-pre-simulation-calculations-and-operations\"><a href=\"#modelsetup-defining-pre-simulation-calculations-and-operations\" aria-hidden=\"true\" class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Model#setup(): defining pre-simulation calculations and operations</h2>\n<p>Each model requires a setup phase. In the Model Interface diagram this occurs at <code class=\"language-text\">setup()</code> between the console and the model.</p>\n<p>Nothing happens in this setup phase by default but you can trigger a specific setup by defining calculations and operations at <code class=\"language-text\">Model#setup()</code>.</p>\n <p class=\"code-header\">Specifying a setup (Java)</p>\n<div class=\"gatsby-highlight\" data-language=\"java\"><pre class=\"language-java\"><code class=\"language-java\"><span class=\"token keyword\">public</span> <span class=\"token keyword\">class</span> <span class=\"token class-name\">MyModel</span> <span class=\"token keyword\">implements</span> <span class=\"token class-name\">Model</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token annotation punctuation\">@Variable</span> <span class=\"token keyword\">int</span> myVariable<span class=\"token punctuation\">;</span>\n\n  <span class=\"token annotation punctuation\">@Override</span>\n  <span class=\"token keyword\">public</span> <span class=\"token keyword\">void</span> <span class=\"token function\">setup</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    SeededRandom ran <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">SeededRandom</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    myVariable <span class=\"token operator\">=</span> ran<span class=\"token punctuation\">.</span><span class=\"token function\">uniform</span><span class=\"token punctuation\">(</span><span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">sample</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n\n  <span class=\"token annotation punctuation\">@Override</span>\n  <span class=\"token keyword\">public</span> <span class=\"token keyword\">void</span> <span class=\"token function\">step</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    myVariable <span class=\"token operator\">*=</span> <span class=\"token number\">1.1</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h2 id=\"modeldispose-specifying-a-tear-down\"><a href=\"#modeldispose-specifying-a-tear-down\" aria-hidden=\"true\" class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Model#dispose(): specifying a tear-down</h2>\n<p>On completion of your simulation, you may want to save results as a file or to perform specific tear-down operations. This can be done by defining <code class=\"language-text\">dispose()</code> in your model.</p>\n<h2 id=\"modelgetconfig-getting-access-to-the-simulation-configuration\"><a href=\"#modelgetconfig-getting-access-to-the-simulation-configuration\" aria-hidden=\"true\" class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Model#getConfig(): getting access to the simulation configuration</h2>\n<p>From the model, you can get access to the <code class=\"language-text\">ModelConfig</code>. This <code class=\"language-text\">ModelConfig</code> contains the set of values for the parameters of the model. These specific settings within your simulation are important especially when it comes to distributing your model.</p>\n<p><a href=\":version/reference/models/model-configuration\">More on Model Config</a></p>\n<h2 id=\"introducing-the-agent-based-flavour\"><a href=\"#introducing-the-agent-based-flavour\" aria-hidden=\"true\" class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Introducing the Agent Based flavour</h2>\n<p>To create Agent Based Models, extend <code class=\"language-text\">AgentBasedModel</code>.</p>\n  <p class=\"code-header\">AgentBasedModels (Java)</p>\n<div class=\"gatsby-highlight\" data-language=\"java\"><pre class=\"language-java\"><code class=\"language-java\"><span class=\"token keyword\">public</span> <span class=\"token keyword\">class</span> <span class=\"token class-name\">MyModel</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">AgentBasedModel</span><span class=\"token generics function\"><span class=\"token punctuation\">&lt;</span>GlobalState<span class=\"token punctuation\">></span></span> <span class=\"token punctuation\">{</span>\n  <span class=\"token annotation punctuation\">@Variable</span> <span class=\"token keyword\">int</span> myVariable<span class=\"token punctuation\">;</span>\n\n  <span class=\"token annotation punctuation\">@Override</span>\n  <span class=\"token keyword\">public</span> <span class=\"token keyword\">void</span> <span class=\"token function\">setup</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    SeededRandom ran <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">SeededRandom</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    myVariable <span class=\"token operator\">=</span> ran<span class=\"token punctuation\">.</span><span class=\"token function\">uniform</span><span class=\"token punctuation\">(</span><span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">sample</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n\n  <span class=\"token annotation punctuation\">@Override</span>\n  <span class=\"token keyword\">public</span> <span class=\"token keyword\">void</span> <span class=\"token function\">step</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    myVariable <span class=\"token operator\">+=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>Several setup operations are required for <code class=\"language-text\">AgentBasedModel</code> at the first stage of building the simulation model. These have to be defined at <code class=\"language-text\">setup()</code>.</p>\n<p><a href=\":version/reference/agents\">More on Agent Based Models</a></p>","headings":[{"value":"General Flow","depth":2},{"value":"Model#step: defining computations and operations at each step","depth":2},{"value":"Model#setup(): defining pre-simulation calculations and operations","depth":2},{"value":"Model#dispose(): specifying a tear-down","depth":2},{"value":"Model#getConfig(): getting access to the simulation configuration","depth":2},{"value":"Introducing the Agent Based flavour","depth":2}],"frontmatter":{"title":"Model Interface","toc":null,"experimental":null}},"site":{"siteMetadata":{"title":"Simudyne Docs","latestVersion":"2.6"}}},"pageContext":{"absolutePath":"/home/vsts/work/1/s/content/2.0/reference/models/model-interface.md","versioned":true,"version":"2.0","kind":"reference","pagePath":"/reference/models/model-interface","chronology":{"prev":{"name":"Models","path":"/reference/models"},"next":{"name":"Annotations","path":"/reference/models/annotations"}},"lastUpdated":"2026-04-21T13:56:54.827Z"}}