blob: 9b6e7c6fa3805937273e4c4a31a91b471094d8c3 [file] [log] [blame]
<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>More Information</title>
<link href="book.css" rel="stylesheet" type="text/css">
<meta content="DocBook XSL Stylesheets V1.75.1" name="generator">
<link rel="home" href="index.html" title="Agent Modeling Guide">
<link rel="up" href="Programer_Guide.html" title="Programer Guide">
<link rel="prev" href="Developing_Models.html" title="Developing Models">
<link rel="next" href="Running_Agent_Models.html" title="Running Agent Models">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<h1 xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0">More Information</h1>
<div class="section" title="More Information">
<div class="titlepage">
<div>
<div>
<h2 class="title" style="clear: both">
<a name="More_Information"></a>More Information</h2>
</div>
</div>
</div>
<div class="section" title="Integrating Java and AMF Models">
<div class="titlepage">
<div>
<div>
<h3 class="title">
<a name="Integrating_Java_and_AMF_Models"></a>Integrating Java and AMF Models</h3>
</div>
</div>
</div>
<p>If you're like many Java developers, you might find point-and-click interfaces a bit lame. Personally, I've changed my tune in this, and I now define all of my ABM models from the editor, saving Java for truly specialized tasks. But even without generation of agent behavior, Acore can be a really valuable tool, as the GIS example shows. The way to look at metaABM is as a way to compose your overall model and automate the tedious parts. Apart from Java generated code, the AMF meta-model maintains a number of very useful artifacts. For example, the Repast Simphony target maintains model.score and all of the model.rs component. Generally, AMF should save time and hassle while making your models far more transparent even if you never use the Actions component to define agent behavior.</p>
<div class="section" title="Method Action">
<div class="titlepage">
<div>
<div>
<h4 class="title">
<a name="Method_Action"></a>Method Action</h4>
</div>
</div>
</div>
<p>As explained in the action section, you can simply create a "Method" act with hand-written Java code. This option is nice because all code is contained within the AMF file. But it can be difficult to maintain large blocks of Java code as you aren't using a Java editor to edit the Java code itself. One way to get around this is to create your code in the generated Java method and then copy it into the Method action. Note one imporant issue here -- you'll generally have to fully qualify your Java references as you won't be able to change the imports statements directly. </p>
</div>
<div class="section" title="Protected Code Regions">
<div class="titlepage">
<div>
<div>
<h4 class="title">
<a name="Protected_Code_Regions"></a>Protected Code Regions</h4>
</div>
</div>
</div>
<p>You can mix and match Action behavior with Java and generated code with POJOs. One way to do this is through using protected regions. Select the agent you want to create protected methods for and then select "Generate Protected" from the "Mode" property. Now, create actions just as you have before, or use your existing ones. On code generation, open up the relevant java file and examine the methods that have been created. </p>
<p>
</p>
<div class="mediaobject">
<img src="images/pojo/ProgrammingPojoGenerateProps.png"></div>
<p>
</p>
<p>You can put whatever you want within the PROTECTED REGION comments and those changes will be preserved when the model is regenerated. You can create a schedule, rule or watcher, maintain custom code for the actual implementations, and still have the model adapt to changes in the underlying data structure -- if for example you want to import a modified shape file.</p>
<p>
</p>
<div class="mediaobject">
<img src="images/pojo/ProgrammingPojoGenerateCode.png"></div>
<p>
</p>
</div>
<div class="section" title="Implement Sub-classes">
<div class="titlepage">
<div>
<div>
<h4 class="title">
<a name="Implement_Sub-classes"></a>Implement Sub-classes</h4>
</div>
</div>
</div>
<p>Another approach which can be more robust is to generate the basic model stubs (like an abstract base class except that it isn't abstract) and then override your model with implementations. AMF provides support for generic skeletons and interfaces.</p>
<p>
</p>
<div class="mediaobject">
<img src="images/pojo/ProgrammingPojoGenerate.png"></div>
<p>
</p>
</div>
</div>
<div class="section" title="Converting Existing Ascape models">
<div class="titlepage">
<div>
<div>
<h3 class="title">
<a name="Converting_Existing_Ascape_models"></a>Converting Existing Ascape models</h3>
</div>
</div>
</div>
<p>There are only a few changes should have to make to existing Ascape models or to use existing Ascape documentation to develop Escape models.</p>
<div class="section" title="Model">
<div class="titlepage">
<div>
<div>
<h4 class="title">
<a name="Model"></a>Model</h4>
</div>
</div>
</div>
<p>The core model is completely API compatible. No changes!</p>
</div>
<div class="section" title="View">
<div class="titlepage">
<div>
<div>
<h4 class="title">
<a name="View"></a>View</h4>
</div>
</div>
</div>
<p>Because Escape uses SWT and Ascape uses Swing, there are a few unavoidable incompatibilities. Most of these we avoid by using higher level APIs but here are the key changes that you're likely to have to make:</p>
<div class="section" title="Convert the low-level imports from AWT and Swing to SWT">
<div class="titlepage">
<div>
<div>
<h5 class="title">
<a name="Convert_the_low-level_imports_from_AWT_and_Swing_to_SWT"></a>Convert the low-level imports from AWT and Swing to SWT</h5>
</div>
</div>
</div>
<p>The simplest way to accomplish this is to remove all of the imports and then organize imports. For example:</p>
<div class="literallayout">
<p>java.awt.Color&nbsp;=&gt;&nbsp;org.eclipse.swt.graphics.Color<br>
java.awt.Graphics&nbsp;=&gt;&nbsp;org.eclipse.draw2d.Graphics<br>
</p>
</div>
<p>Then just do a global find for all of the imports and replace them with nothing. This is a great place for a regexp. Try:</p>
<div class="literallayout">
<p>find:&nbsp;import&nbsp;java\.awt\.(.*);<br>
replace:&nbsp;[nothing]<br>
</p>
</div>
<p>You don't have to replace these with the SWT equivalents, just click on the project, right-click and choose "Source:Organize Imports.."
By the way, a great way to avoid having to select the right entries in optimize imports and to alert you when you have missed anything is to prevent the awt and swing classes from being used at all. Right-click on project, choose "Build Path:Configure Build Path", go to Libraries tab, open JRE System Library, choose "Access Rules", edit, and then add entries for java/awt/** and javax/swing/**. The code will regenerate and you'll have error markers for all of the stuff that won't work with Escape and Eclipse.</p>
</div>
<div class="section" title="Convert color features">
<div class="titlepage">
<div>
<div>
<h5 class="title">
<a name="Convert_color_features"></a>Convert color features</h5>
</div>
</div>
</div>
<p>You can't use AWT colors either so you'll need to replace any colors. AMP provides a convenience classes for Colors called ColorFeature and ColorFeatureConcrete. You can use these or any of the other ways to define SWT colors. For example:</p>
<div class="literallayout">
<p>Color.lightGray&nbsp;=&gt;&nbsp;ColorFeature.LIGHT_GRAY<br>
new&nbsp;Color(Math.min(1.0f,&nbsp;(float)&nbsp;(redEnergy&nbsp;+&nbsp;orangeEnergy)),&nbsp;(float)&nbsp;orangeEnergy&nbsp;*&nbsp;.8f,&nbsp;(float)&nbsp;blueEnergy)&nbsp;=&gt;&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;ColorFeatureConcrete.create(Math.min(1.0f,&nbsp;(float)&nbsp;(redEnergy&nbsp;+&nbsp;orangeEnergy)),&nbsp;(float)&nbsp;orangeEnergy&nbsp;*&nbsp;.8f,&nbsp;(float)&nbsp;blueEnergy)<br>
</p>
</div>
</div>
<div class="section" title="Change agent color getters">
<div class="titlepage">
<div>
<div>
<h5 class="title">
<a name="Change_agent_color_getters"></a>Change agent color getters</h5>
</div>
</div>
</div>
<p>If you've defined colors through overriding Agents as in most models, you'll need to change the method signature. You could just do a global replace for this one.</p>
<div class="literallayout">
<p>public&nbsp;Color&nbsp;getColor(&nbsp;=&gt;&nbsp;public&nbsp;Object&nbsp;getPlatformColor(<br>
</p>
</div>
</div>
<div class="section" title="Get rid of image features">
<div class="titlepage">
<div>
<div>
<h5 class="title">
<a name="Get_rid_of_image_features"></a>Get rid of image features</h5>
</div>
</div>
</div>
<p>Escape doesn't support them. In practice they haven't been used a lot. At some point perhaps we'll have nice sprite support instead. :)</p>
<div class="literallayout">
<p>public&nbsp;Image&nbsp;getImage()&nbsp;{**}&nbsp;=&gt;&nbsp;""<br>
</p>
</div>
</div>
<div class="section" title="Modify usages of DrawFeatures">
<div class="titlepage">
<div>
<div>
<h5 class="title">
<a name="Modify_usages_of_DrawFeatures"></a>Modify usages of DrawFeatures</h5>
</div>
</div>
</div>
<p>If you've created any of your own draw features, you'll need to change them slightly to accommodate the differences between the AWT and SWT / Draw2D APIs. This should be pretty straightforwrd. For example:</p>
<div class="literallayout">
<p>g.setColor(...<br>
g.fillOval(..<br>
becomes:<br>
g.setBackgroundColor(<br>
g.fillOval(..<br>
</p>
</div>
<p>That's about it, though it's probable that we've missed something. Please post a message on the amp newsgroup if you run into any other conversion issues.</p>
</div>
</div>
<div class="section" title="Configuration">
<div class="titlepage">
<div>
<div>
<h4 class="title">
<a name="Configuration"></a>Configuration</h4>
</div>
</div>
</div>
<p>Instead of using Ant, Escape has really nice support for parameterizing and testing models. See
<a class="ulink" href="/wiki/Experimenting_and_Testing" target="_new">Experimenting and Testing</a> (todo). If you do want to work with ant you will need to install the plugins from the Sourceforge download site. (These have dependencies that I didn't want to bother with going through the Eclipse IP process to get in. If for some reason you think these should be part of core Escape let Miles know and I'll take care of it.) Ant has not been tested for Escape so it's not even clear it will work.
</p>
</div>
</div>
</div>
</body>
</html>