{"data":{"markdownRemark":{"html":"<p>The model's schema is used to describe the model's data output. It is important to initialise models correctly to ensure that a models schema remains the same while the simulation is being run.</p>\n<p>The <code class=\"language-text\">model#init()</code> method is used to used to initialise and register all model components that might be output, and so therefore need to be present in the schema. The schema should be fixed after the model#init call. All updates to the schema after this call will trigger an error. </p>\n<h2 id=\"accumulators\"><a href=\"#accumulators\" 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>Accumulators</h2>\n<p>Accumulators should be created before or during the <code class=\"language-text\">model#init()</code> call. Attempted creation of new accumulators after this will throw an exception.\nTo learn more about accumulators creation and use, refer to the <a href=\":version/reference/data_management/outputting_data\">Outputting Data</a> section. You can create accumulators during <code class=\"language-text\">model#init</code>.</p>\n<p class=\"code-header\">Creating Accumulators</p>\n<div class=\"gatsby-highlight\" data-language=\"java\"><pre class=\"language-java\"><code class=\"language-java\"><span class=\"token annotation punctuation\">@Override</span>\n<span class=\"token keyword\">public</span> <span class=\"token keyword\">void</span> <span class=\"token function\">init</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token function\">createDoubleAccumulator</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"AccumulatorA\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token function\">createLongAccumulator</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"AccumulatorB\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>As of v2.5 you can also specify an initial value for accumulators. This can be useful especially for view output of accumulators where the inital value of 0 or NaN would be incorrect.</p>\n<p class=\"code-header\">Creating Accumulators with Initial Value</p>\n<div class=\"gatsby-highlight\" data-language=\"java\"><pre class=\"language-java\"><code class=\"language-java\"><span class=\"token annotation punctuation\">@Override</span>\n<span class=\"token keyword\">public</span> <span class=\"token keyword\">void</span> <span class=\"token function\">init</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token function\">createDoubleAccumulator</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"AccumulatorA\"</span><span class=\"token punctuation\">,</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token function\">createLongAccumulator</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"AccumulatorB\"</span><span class=\"token punctuation\">,</span> variableA<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h2 id=\"agents\"><a href=\"#agents\" 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>Agents</h2>\n<p>Agents must be registered during <code class=\"language-text\">model#init</code>. If you try to generate groups of agents or spawn unregistered agents, then this will throw an exception. The best place to register <code class=\"language-text\">Agent</code> types is in the init method. Simply call <code class=\"language-text\">AgentBasedModel#registerAgentTypes</code> and pass your agent types. This method takes a variable number of arguments so you can pass in as many <code class=\"language-text\">Agents</code> as you need.</p>\n<p class=\"code-header\">Registering Agents</p>\n<div class=\"gatsby-highlight\" data-language=\"java\"><pre class=\"language-java\"><code class=\"language-java\"><span class=\"token annotation punctuation\">@Override</span>\n<span class=\"token keyword\">public</span> <span class=\"token keyword\">void</span> <span class=\"token function\">init</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\t<span class=\"token function\">registerAgentTypes</span><span class=\"token punctuation\">(</span>AgentA<span class=\"token punctuation\">.</span><span class=\"token keyword\">class</span><span class=\"token punctuation\">,</span> AgentB<span class=\"token punctuation\">.</span><span class=\"token keyword\">class</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h2 id=\"links\"><a href=\"#links\" 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>Links</h2>\n<p>Links again must be registered during <code class=\"language-text\">model#init</code>. If you try to generate a group with a link that is not registered or add a link to an agent during a step that has not been registered this will throw an exception. Simply call <code class=\"language-text\">AgentBasedModel#registerLinkTypes</code> passing in the link types your model uses.</p>\n<p class=\"code-header\">Registering Links</p>\n<div class=\"gatsby-highlight\" data-language=\"java\"><pre class=\"language-java\"><code class=\"language-java\"><span class=\"token annotation punctuation\">@Override</span>\n<span class=\"token keyword\">public</span> <span class=\"token keyword\">void</span> <span class=\"token function\">init</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\t<span class=\"token function\">registerLinkTypes</span><span class=\"token punctuation\">(</span>LinkA<span class=\"token punctuation\">.</span><span class=\"token keyword\">class</span><span class=\"token punctuation\">,</span> LinkB<span class=\"token punctuation\">.</span><span class=\"token keyword\">class</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>","headings":[{"value":"Accumulators","depth":2},{"value":"Agents","depth":2},{"value":"Links","depth":2}],"frontmatter":{"title":"Model Initialisation","toc":null,"experimental":null}},"site":{"siteMetadata":{"title":"Simudyne Docs","latestVersion":"2.6"}}},"pageContext":{"absolutePath":"/home/vsts/work/1/s/content/2.6/reference/modelling/model-initialisation.md","versioned":false,"version":"2.6","kind":"reference","pagePath":"/reference/modelling/model-initialisation","chronology":{"prev":{"name":"Model Interface","path":"/reference/modelling/model-interface"},"next":{"name":"Annotations","path":"/reference/modelling/annotations"}},"lastUpdated":"2026-04-21T13:56:54.869Z"}}