<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Movine Odhiambo on Medium]]></title>
        <description><![CDATA[Stories by Movine Odhiambo on Medium]]></description>
        <link>https://medium.com/@movineee?source=rss-1baa9aa26903------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*05nImPBKhIGNvQgyRupQcA.jpeg</url>
            <title>Stories by Movine Odhiambo on Medium</title>
            <link>https://medium.com/@movineee?source=rss-1baa9aa26903------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 16:47:53 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@movineee/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Engineering a Nomadic Migration Engine (Part 3): Debugging Repast, GeoTools, and GIS Until the…]]></title>
            <link>https://medium.com/@movineee/engineering-a-nomadic-migration-engine-part-3-debugging-repast-geotools-and-gis-until-the-4438b78c5a0d?source=rss-1baa9aa26903------2</link>
            <guid isPermaLink="false">https://medium.com/p/4438b78c5a0d</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[gis]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[agent-based-modeling]]></category>
            <category><![CDATA[simulation]]></category>
            <dc:creator><![CDATA[Movine Odhiambo]]></dc:creator>
            <pubDate>Tue, 10 Mar 2026 17:13:58 GMT</pubDate>
            <atom:updated>2026-03-10T17:13:58.733Z</atom:updated>
            <content:encoded><![CDATA[<h3>Engineering a Nomadic Migration Engine (Part 3): Debugging Repast, GeoTools, and GIS Until the Model Finally Ran</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FAeCFmZ3sbySKiUZiP_3GA.png" /></figure><h3>Series: Engineering a Nomadic Migration Engine</h3><p>This article is <strong>Part 3</strong> of an ongoing series documenting the engineering process behind building a spatial agent-based simulation.</p><p><strong>Part 1 —</strong><a href="https://medium.com/@movineee/engineering-a-nomadic-migration-engine-from-naive-prototype-to-high-performance-simulation-52833c48f282"><strong> The Concept and the Configuration Nightmare</strong></a><br><strong>Part 2 — </strong><a href="https://medium.com/@movineee/part-2-the-display-and-data-crisis-37eacc09d074"><strong>The Display and Data Crisis</strong></a><br><strong>Part 3 — From XML Hell to a Working Simulation (this article)</strong></p><p>In the first two parts, we explored the early design and the painful configuration issues that come with building simulations in <strong>Repast Simphony</strong>.</p><p>Part 1 focused on the <strong>architecture and configuration battles</strong>.<br>Part 2 tackled the <strong>visualization and data pipeline problems</strong>.</p><p>In this third installment, we finally reached the stage where the <strong>simulation should have worked</strong>.</p><p>Instead, we encountered a new wave of problems:</p><ul><li>GeoTools method ambiguity</li><li>missing environmental datasets</li><li>Repast XML configuration traps</li><li>scheduler conflicts</li><li>GIS visualization failures</li></ul><p>Each of these issues stopped the model from running correctly.</p><p>This article walks through the <strong>exact problems and solutions</strong> that ultimately allowed the simulation to run successfully.</p><h3>The Simulation We Were Building</h3><p>The goal was to simulate <strong>nomadic households moving across a basin </strong>with livestock.</p><p>Each household behaves as an <strong>agent</strong> that decides whether to move based on environmental conditions.</p><p>The simulation integrates <strong>GIS spatial data</strong>, including shapefiles and raster layers.</p><h3>Core Behavioral Rules</h3><p>Agents must:</p><ul><li>Start at <strong>random locations inside a drainage basin</strong></li><li>Avoid <strong>sedentary settlement zones</strong></li><li>Stay within <strong>rangeland areas</strong></li><li>Evaluate movement <strong>once per month</strong></li><li>Score nearby locations based on environmental conditions</li><li>Prefer moving with <strong>members of the same clan</strong></li><li>Remember previously visited locations (<strong>Agent Memory)</strong></li></ul><p>The environmental model was supposed to incorporate several datasets:</p><ul><li>vegetation index (SAVI)</li><li>rainfall</li><li>proximity to water</li><li>slope</li><li>topographic wetness index</li><li>conflict risk</li><li>rangeland suitability</li></ul><p>However, when the project started, <strong>only one environmental layer existed</strong>.</p><pre>rangelands.tif</pre><p>That limitation created the next engineering challenge.</p><h3>Hurdle 1 — The Demo Code Was the Wrong Foundation</h3><p>Repast provides a GIS demonstration project that includes two main classes:</p><ul><li>GisAgent</li><li>ContextCreator</li></ul><p>These are designed for <strong>simple random-walk agents</strong>, not complex decision-making households.</p><p>The demo system assumed:</p><ul><li>agents move randomly</li><li>no environmental scoring</li><li>no movement rules</li><li>no clan structure</li><li>no monthly decision process</li></ul><p>In short, the architecture did not match the problem.</p><h3>The Solution</h3><p>Instead of modifying the demo code piece by piece, we <strong>rebuilt the core classes</strong>.</p><h3>The NomadicHousehold Agent</h3><pre>public class NomadicHousehold {<br><br>private String clanId;<br>    private double travelSpeed;<br>    private int monthsInCurrentLocation;<br>    private double currentLocationScore;<br>    private Coordinate targetLocation;<br>    @ScheduledMethod(start = 1, interval = 1)<br>    public void monthlyEvaluation() {<br>        monthsInCurrentLocation++;<br>        evaluateMove();<br>        if (targetLocation != null) {<br>            moveToTarget();<br>        }<br>    }<br>}</pre><p>Each household now evaluates its movement decision every simulated month.</p><h3>Updated ContextCreator Responsibilities</h3><p>The ContextCreator class now handles:</p><ul><li>loading GIS layers</li><li>creating agents</li><li>generating valid starting positions</li><li>scheduling simulation events</li></ul><p>This structure allowed the simulation logic to remain <strong>clean and modular</strong>.</p><h3>Lesson</h3><p>When base code conflicts with the design of your system, <strong>rewriting early often saves more time than incremental fixes</strong>.</p><h3>Hurdle 2 — GeoTools Method Ambiguity</h3><p>Repast relies heavily on <strong>GeoTools</strong> for raster and GIS operations.</p><p>GeoTools contains many <strong>overloaded methods</strong>, which sometimes confuses the Java compiler.</p><p>We encountered errors like this:</p><pre>The method evaluate(DirectPosition, double[]) is ambiguous</pre><p>And:</p><pre>method contains(DirectPosition) is ambiguous</pre><p>The compiler could not determine which method version should be used.</p><h3>The Solution</h3><p>We created <strong>wrapper methods</strong> to remove ambiguity.</p><pre>private double convertRasterResultToDouble(Object result) {<br><br>if (result instanceof double[]) return ((double[]) result)[0];<br>    if (result instanceof int[]) return ((int[]) result)[0];<br>    if (result instanceof float[]) return ((float[]) result)[0];<br>    if (result instanceof Number) return ((Number) result).doubleValue();<br>    return 0.0;<br>}</pre><p>Raster evaluation then became:</p><pre>Object result = coverage.evaluate(position);<br>double value = convertRasterResultToDouble(result);</pre><h3>Lesson</h3><p>When using large libraries with heavy method overloading, create <strong>utility wrappers</strong> that make your intent explicit.</p><p>This also improves long-term maintainability.</p><h3>Hurdle 3 — Missing Environmental Data</h3><p>The movement model originally depended on <strong>seven environmental variables</strong>.</p><p>But only one raster layer was available.</p><p>Without environmental variation, agents would behave unrealistically.</p><h3>The Solution</h3><p>We introduced <strong>controlled randomness</strong> to simulate the missing environmental influences.</p><pre>private double calculateSuitabilityScore(Coordinate coord, boolean isCurrentCell) {<br><br>double rangelandScore = getRasterValue(&quot;rangelands&quot;, coord);<br>    double randomness = RandomHelper.nextDoubleFromTo(-0.2, 0.2);<br>    double totalScore = rangelandScore + randomness;<br>    if (isCurrentCell) {<br>        totalScore += 0.5;<br>    }<br>    return totalScore;<br>}</pre><p>This ensured the model still produced <strong>dynamic behavior</strong> while waiting for additional datasets.</p><h3>Lesson</h3><p>Real-world projects rarely begin with complete datasets.</p><p>A robust model should <strong>remain functional even when some inputs are missing</strong>.</p><h3>Hurdle 4 — Repast Style Constants That Don’t Exist</h3><p>When creating agent visualization styles, we attempted to use shapes like:</p><pre>PatternFactory.PATTERN_STAR<br>PatternFactory.PATTERN_TRIANGLE</pre><p>These constants do not exist.</p><p>Repast only provides a limited set of built-in shapes.</p><h3>The Solution</h3><p>We generated shapes manually using <strong>Java2D graphics</strong>.</p><p>Example triangle creation:</p><pre>Path2D triangle = new Path2D.Double();<br>triangle.moveTo(width / 2, 0);<br>triangle.lineTo(width, height);<br>triangle.lineTo(0, height);<br>triangle.closePath();</pre><p>This allowed us to create <strong>custom agent symbols</strong> for visualization.</p><h3>Lesson</h3><p>When visualization libraries lack the shapes you need, generating them programmatically often provides <strong>greater flexibility</strong>.</p><h3>Hurdle 5 — Repast XML Configuration Hell</h3><p>Repast simulations rely on XML files for:</p><ul><li>displays</li><li>charts</li><li>data collection</li><li>batch runs</li></ul><p>Unfortunately, the XML parser is <strong>extremely strict</strong>.</p><p>Common errors included:</p><pre>CannotResolveClassException: display</pre><p>and</p><pre>CannotResolveClassException: object-actions</pre><p>These errors gave very little useful information.</p><h3>The Breakthrough</h3><p>The key solution was to <strong>generate XML through Repast’s GUI first</strong>.</p><p>A valid configuration looked like this:</p><pre>&lt;object-actions xmlns=&quot;http://repast.org/scenario/display&quot;<br>xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;&gt;</pre><p>Two details proved critical:</p><ul><li>use type=&quot;...&quot; rather than xsi:type</li><li>keep elements inside the default namespace</li></ul><h3>Lesson</h3><p>When dealing with complex configuration files, <strong>generate a working version through the GUI and reverse engineer it</strong>.</p><h3>Hurdle 6 — Phantom Library Paths</h3><p>The model produced warnings like:</p><pre>Empty or non-existent path ... geotools</pre><p>The configuration referenced library directories that did not exist.</p><h3>The Fix</h3><p>We removed unnecessary library references.</p><p>Repast already bundles:</p><ul><li>GeoTools</li><li>JTS</li><li>OpenGIS</li></ul><p>The classpath only needed the project binaries.</p><h3>Lesson</h3><p>Avoid adding library paths unless absolutely necessary.</p><p>Many frameworks already include their dependencies.</p><h3>Hurdle 7 — Scheduler Conflicts</h3><p>The next issue appeared during runtime scheduling.</p><pre>Unable to find match for ScheduleMethod</pre><p>The problem came from scheduling an <strong>anonymous Runnable</strong>.</p><p>Repast’s scheduler uses reflection and works best with <strong>named methods</strong>.</p><h3>The Solution</h3><p>We replaced the anonymous class with a named method.</p><pre>schedule.schedule(params, this, &quot;processMonthlyEvaluation&quot;);</pre><pre>public void processMonthlyEvaluation() {<br><br>for (Object obj : context.getObjects(NomadicHousehold.class)) {<br>        NomadicHousehold agent = (NomadicHousehold) obj;<br>        agent.monthlyEvaluation();<br>    }<br>}</pre><h3>Lesson</h3><p>Repast scheduling works reliably when you use <strong>named methods on registered objects</strong>.</p><p>Avoid anonymous tasks.</p><h3>Hurdle 8 — The Invisible Simulation</h3><p>After fixing every error, the simulation ran.</p><p>But nothing appeared on screen.</p><p>The console only printed:</p><pre>Monthly evaluation scheduled</pre><p>No map.<br>No agents.</p><h3>The Cause</h3><p>The visualization files existed but were not referenced inside scenario.xml.</p><h3>The Fix</h3><p>Add display references explicitly.</p><pre>&lt;Scenario simphonyVersion=&quot;2.8.0&quot;&gt;<br>&lt;repast.simphony.action.display file=&quot;gis_display.xml&quot;/&gt;<br>&lt;repast.simphony.action.display file=&quot;charts_display.xml&quot;/&gt;<br>&lt;repast.simphony.action.display file=&quot;display_2d.xml&quot;/&gt;<br>&lt;/Scenario&gt;</pre><p>Once connected, the system finally produced a <strong>visible simulation</strong>.</p><h3>The Final Working System</h3><p>After resolving these issues, the model successfully produced:</p><h3>Agent Behavior</h3><p>✔ random starting locations<br>✔ avoidance of settlement zones<br>✔ rangeland constraints<br>✔ monthly movement evaluation<br>✔ environmental suitability scoring<br>✔ clan identity tracking</p><h3>Visualization</h3><p>✔ GIS map layers<br>✔ animated agent movement<br>✔ time-series charts<br>✔ CSV data export</p><h3>Key Lessons from the Project</h3><p><strong>1. Build systems incrementally</strong></p><p>Start with minimal features and expand gradually.</p><p><strong>2. Wrap confusing APIs</strong></p><p>Utility methods simplify complex libraries.</p><p><strong>3. Use GUI-generated configuration</strong></p><p>It prevents subtle XML errors.</p><p><strong>4. Avoid anonymous scheduling code</strong></p><p>Named methods work better with Repast.</p><p><strong>5. Validate every file path</strong></p><p>Incorrect paths are a frequent source of runtime failures.</p><p><strong>6. Design models to tolerate missing data</strong></p><p>Stochastic elements can simulate unavailable environmental variables.</p><p><strong>7. Visualization is essential</strong></p><p>A simulation that runs without visual feedback is almost impossible to debug.</p><h3>Conclusion</h3><p>Building spatial agent-based simulations is rarely a linear engineering process.</p><p>Integrating GIS data, environmental models, Repast scheduling, and visualization systems introduces layers of complexity that are difficult to anticipate at the start.</p><p>But once the architecture stabilizes, the result is powerful.</p><p>The system now simulates <strong>how nomadic households adapt their movement patterns based on environmental conditions and spatial constraints</strong>.</p><p>Even though several environmental datasets are still pending, the framework is now stable enough to integrate them easily.</p><p>The next stage will focus on <strong>scaling the simulation and improving performance</strong> as the number of agents increases.</p><h3>Building Simulation Systems?</h3><p>If you’re working on:</p><ul><li>agent-based simulations</li><li>GIS-driven modeling systems</li><li>decision-support simulations</li><li>computational social science models</li></ul><p>I occasionally collaborate with research groups, NGOs, and startups to design <strong>large-scale simulation engines</strong> like this one.</p><p>More articles in this series are coming soon, including:</p><p>If you’d like to follow the series or discuss similar projects, feel free to reach out here on Medium.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4438b78c5a0d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Part 2: The Display and Data Crisis]]></title>
            <link>https://medium.com/@movineee/part-2-the-display-and-data-crisis-37eacc09d074?source=rss-1baa9aa26903------2</link>
            <guid isPermaLink="false">https://medium.com/p/37eacc09d074</guid>
            <category><![CDATA[gis-visualization]]></category>
            <category><![CDATA[debugging]]></category>
            <category><![CDATA[xml-parsing-error]]></category>
            <category><![CDATA[repast-simphony]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[Movine Odhiambo]]></dc:creator>
            <pubDate>Tue, 24 Feb 2026 14:55:28 GMT</pubDate>
            <atom:updated>2026-02-24T14:55:28.793Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to Fix the “Content is not allowed in prolog” Error in Repast Simphony GIS</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_JmWy4ovCq3rkC3A-eGq7Q.png" /></figure><p>When building an agent-based model with GIS visualization in Repast Simphony, you might eventually encounter a frustrating error that prevents the display from loading — even though your agents and context initialize perfectly.</p><p>This write‑up walks through a real‑world debugging session that uncovered the root cause: a corrupted or missing <strong>SLD</strong> (Styled Layer Descriptor) file referenced in a hidden GIS display descriptor.</p><p>Here is how to identify the issue, fix the XML, and get your visualization back on track.</p><h3>The Symptoms</h3><p>You launch your Repast model, the simulation starts, but the visualizer crashes and outputs something like this in the console:</p><pre>Successfully created 50 out of 50 agents<br>=== NomadABM Initialization Complete ===<br>[Fatal Error] :1:1: Content is not allowed in prolog.<br>ERROR … DisplayProducer — Error creating display for GIS<br>java.lang.RuntimeException: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; Content is not allowed in prolog.</pre><p>The model logic works — your agents exist in the memory space — but the GIS display crashes with an XML parsing error. The stack trace usually points to SLDParser.readXML(), which is the ultimate clue: the problem lies in reading an SLD style file.</p><h3>The Investigation</h3><h3>1. Check the obvious configuration files</h3><p>The first instinct is to examine layers.xml, context.xml, and the Java style classes (e.g., EnergyBasedNomadStyle, DrainageBasinStyle). In this specific project, all were correctly formed and compiled without errors.</p><p>The layers.xml referenced a shapefile (./data/basin.shp) but did <strong>not</strong> include any &lt;style&gt; tag that would point to an external SLD. The context.xml correctly used a Java style class:</p><pre>&lt;style class=&quot;geography.agents.NomadAgent&quot; <br>       style-class=&quot;geography.styles.EnergyBasedNomadStyle&quot; /&gt;</pre><p>So, if the code isn’t pointing to an SLD file, why was Repast still trying to parse one?</p><h3>2. Look for hidden display descriptors</h3><p>Repast Simphony stores display configurations in hidden XML files under the scenario directory, typically located at scenario/YourModel.rs/display/. These files describe the display name, type, projections, and <strong>styles</strong> associated with specific agents and layers.</p><p>In this project, three such files existed:</p><ul><li>GIS (NomadABM).xml</li><li>GIS (NomadABM 3D).xml</li><li>GIS (NomadABM Edited).xml</li></ul><p>Opening the third file revealed the culprit:</p><pre>&lt;editedStyles&gt;<br>  &lt;entry&gt;<br>    &lt;string&gt;geography.agents.NomadAgent&lt;/string&gt;<br>    &lt;string&gt;geography.agents.NomadAgent.style_0.xml&lt;/string&gt; &lt;/entry&gt;<br>&lt;/editedStyles&gt;</pre><h3>3. Confirm the issue</h3><p>A quick workspace search confirmed that no such file actually existed in the project. The display descriptor was leftover “ghost code” from an earlier experiment where styles were edited directly through the Repast GUI.</p><p>GUI edits generate temporary style files. If they are not cleaned up properly when you switch back to Java classes, Repast looks for a file that isn’t there, or reads a malformed invisible file. When the XML parser hits this, it throws the fatal “<strong>Content is not allowed in prolog</strong>” error.</p><h3>The Solutions</h3><p>You have three ways to fix this, depending on your project needs:</p><h3>Option 1: Remove or fix the problematic SLD file</h3><p>If you actually <em>want</em> to use the SLD file, ensure it exists and is not corrupt. Open it and ensure the very first line starts exactly with &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt; with no hidden spaces, UTF-8 BOM characters, or line breaks before it.</p><h3>Option 2: Edit the display descriptor to use Java styles instead</h3><p>Open the offending display descriptor XML in your text editor and change the editedStyles entry. Set it to &lt;null/&gt; to force Repast to ignore it:</p><pre>&lt;editedStyles&gt;<br>  &lt;entry&gt;<br>    &lt;string&gt;geography.agents.NomadAgent&lt;/string&gt;<br>    &lt;null/&gt;<br>  &lt;/entry&gt;<br>&lt;/editedStyles&gt;</pre><h3>Option 3: Delete the entire display descriptor</h3><p>If you have multiple display descriptors (like a 2D and 3D version), simply delete the XML file that contains the broken reference. Repast will safely default to the remaining valid ones.</p><h3>Prevention and Best Practices</h3><ul><li><strong>Avoid editing styles through the GUI if using Java classes:</strong> Mixing GUI style edits with hardcoded Java style classes creates hidden temporary files that easily desync.</li><li><strong>Audit your </strong><strong>display/ folder:</strong> Regularly check this directory for orphaned style files, especially if you frequently switch between different display configurations.</li><li><strong>Prefer Java style classes:</strong> For agent styling, Java classes (.java) are compiled alongside your code and are significantly less prone to silent XML parsing errors than external SLD files.</li></ul><h3>Conclusion</h3><p>The “<strong><em>Content is not allowed in prolog</em></strong>” error in Repast Simphony GIS displays is almost always caused by a missing, orphaned, or corrupted SLD file referenced deep inside a display descriptor. By checking the hidden scenario/ directory, you can quickly identify the problematic reference, delete it, and restore your visualizer.</p><p>Happy modeling!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=37eacc09d074" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Engineering a Nomadic Migration Engine: From Naive Prototype to High-Performance Simulation]]></title>
            <link>https://medium.com/@movineee/engineering-a-nomadic-migration-engine-from-naive-prototype-to-high-performance-simulation-52833c48f282?source=rss-1baa9aa26903------2</link>
            <guid isPermaLink="false">https://medium.com/p/52833c48f282</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[agent-based-modeling]]></category>
            <category><![CDATA[simulation]]></category>
            <dc:creator><![CDATA[Movine Odhiambo]]></dc:creator>
            <pubDate>Tue, 17 Feb 2026 08:28:49 GMT</pubDate>
            <atom:updated>2026-02-17T08:28:49.665Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1007/1*RzS6MEL6PkrFA9R99ssDoA.png" /></figure><h3>Part 1: The Concept and the Configuration Nightmare</h3><p><strong>By Movine Odhiambo</strong></p><blockquote>“In theory, there is no difference between theory and practice. In practice, there is.” — Yogi Berra</blockquote><p>Every complex system starts as a blank canvas, or in the case of <a href="https://www.anylogic.com/use-of-simulation/agent-based-modeling/"><strong>Agent-Based Modeling</strong></a><strong> </strong>(ABM) in Java, a blank context.xml file that refuses to load.</p><p>This series documents the engineering journey of building a large-scale simulation of 8,000+ nomadic households. Before we could optimize for 1.3 billion pixels of environmental data, we first had to survive: simply getting a single agent to exist on a map without crashing the <a href="https://medium.com/@ByteOfJava/understanding-the-jvm-what-it-is-and-how-it-works-5c647eb5a659"><strong>JVM</strong></a>.</p><p>This is the story of how we went from NullPointerExceptions to a working proof-of-concept.</p><h3>The System Vision (Version 1)</h3><p>The goal for Version 1 was architectural feasibility. We needed to prove that we could:</p><ol><li><strong>Initialize Agents:</strong> Place 50 nomadic households in a specific drainage basin.</li><li><strong>Enforce Constraints:</strong> Ensure agents only spawned in valid “Rangelands” (Raster Value = 1).</li><li><strong>Visualize:</strong> Render these agents on a GIS display moving in real-time.</li></ol><p>It sounded simple. But as any engineer knows, the “Hello World” of a complex framework like <strong>Repast Simphony</strong> is rarely simple.</p><h3>The Software Reality: Battling the Framework</h3><p>We encountered three distinct categories of failure during this phase.</p><h4>1. The Dependency Injection Nightmare</h4><p>Our first major blocker was a catastrophic crash on launch:</p><pre>java.lang.NullPointerException: Cannot invoke &quot;Object.getClass()&quot; because &quot;context&quot; is null</pre><p><strong>The Engineering Diagnosis:</strong></p><p>Repast relies on a rigid dependency injection container. Our scenario.xml was present but misconfigured, meaning the internal scheduler couldn&#39;t &quot;find&quot; our ContextCreator. The system was trying to run a simulation in a void.</p><p><strong>The Fix:</strong></p><p>We had to strictly define the lifecycle. We abandoned our custom configuration and rebuilt the XML foundation using the standard Geography example as a template. This enforced a strict loading order: Context — &gt;Projections → Agents.</p><h4>2. The “Schrödinger’s Agent” (The Lifecycle Trap)</h4><p>Once the context loaded, we hit a subtle logic error. We were trying to give agents “spatial awareness” too early.</p><p><strong>The Error:</strong></p><p>Inside the Agent’s constructor, we called ContextUtils.getContext(this) to determine where the agent was.</p><pre>// CRASH: The agent doesn&#39;t &quot;exist&quot; in the context yet!<br>context.getProjection(&quot;Geography&quot;);</pre><p><strong>The Engineering Diagnosis:</strong></p><p>This was a classic <strong>Object Lifecycle</strong> violation. We were asking the agent to query the world before the agent had been fully registered <em>in</em> the world.</p><p><strong>The Fix:</strong></p><p>We decoupled the agent’s logic from the simulation engine. Instead of the agent asking “Where am I?”, the ContextCreator now explicitly tells the agent: &quot;You are here.&quot;</p><ul><li><strong>Old Way:</strong> Agent pulls data from Context (Unsafe).</li><li><strong>New Way:</strong> Context pushes data to Agent via setCurrentLocation(Point) (Safe).</li></ul><h4>3. The “Silent Failure” of GIS Data</h4><p>Our logs showed a confusing state:</p><pre>Loaded 1 drainage basin.<br>Successfully created 0 out of 50 agents.</pre><p>The simulation was running, but the world was empty.</p><p><strong>The Engineering Diagnosis:</strong></p><p>This was a data pipeline failure. Our validity check (isRangeland()) was failing silently because the underlying raster file was missing from the target directory. The code didn&#39;t crash; it just logically rejected every single attempt to spawn an agent because &quot;Nothing is a rangeland if there is no map.&quot;</p><p><strong>The Fix:</strong></p><p>We implemented <strong>Defensive Programming</strong>.</p><ol><li>We added strict validation on startup: If basin.shp or rangeland.tif is missing, throw a hard error immediately.</li><li>We implemented a “<em>Fallback Mode</em>” for debugging: If the raster is missing during dev testing, default to true (allow movement everywhere) so we can at least test the agent logic.</li></ol><h3>The Product Outcome: A Visual Proof of Concept</h3><p>After resolving these architectural hurdles, Version 1 went live.</p><p><strong>The Results:</strong></p><ul><li><strong>Stability:</strong> 50 Agents successfully initialized within the complex polygon of the Drainage Basin.</li><li><strong>Visualization:</strong> We implemented a Style class to color-code agents by energy levels (Green → Red), giving us immediate visual feedback on their state.</li><li><strong>Performance:</strong> Acceptable for 50 agents, but the geometry checks (O(n) <strong><em>attempts to find a valid point</em></strong>) hinted at the scaling problems we would face in Version 2.</li></ul><h3>Key Engineering Takeaways</h3><ol><li><strong>Start with a Working Reference:</strong> Never bootstrap a complex framework from zero. Adapting the Geography prototype saved us days of XML debugging.</li><li><strong>Decouple Logic from Frameworks:</strong> Agents should be <a href="https://medium.com/@noble_frost_lion_664/pojos-plain-old-java-objects-7017030254cf"><strong>Plain Old Java Objects (POJOs) </strong></a>where possible. Relying on framework static calls (ContextUtils) inside domain logic creates fragile dependencies.</li><li><strong>Fail Loudly:</strong> Silent failures (like missing shapefiles resulting in 0 agents) are harder to debug than crashes. We learned to assert our data preconditions early.</li></ol><p><strong>Stay tuned</strong>, Next Up: Part 2 — The Display and Data Crisis</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=52833c48f282" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>