多主体(Multi-Agent)仿真平台RePast基础教程1-3
合集下载
相关主题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
The SimModel Object—Schedule
• Schedule manages the execution of BasicAction according to the simulation clock. • Each tick is completed at the end of all BasicAction executions. • Actions scheduled on a Schedule will be executed in random order.
• getName() replaces ‘RePast’ with the name of the project on the control toolbar.
import uchicago.src.sim.engine.SimModelImpl; public class MyFirstRePastModel extends SimModelImpl {
The SimModel Object--numAgents
• First, lets insert the variable into our code.
import uchicago.src.sim.engine.SimModelImpl; import uchicago.src.sim.engine.Schedule; public class MyFirstRePastModel extends SimModelImpl { private Schedule schedule; private int numAgents; public String getName(){ return “My First Repast Model”; } […]
• RePast models traditionally have a consistent ‘map’ to their model classes. • We will divide the begin() method into three other methods. • Thus, we will add the following code.
The CarryDrop Model--Introduction
We want to create a model with the following characteristics.
• Agents move around a gridded landscape • Each cell may contain money. • Agents always move in a straight line in one of the eight neighborhood directions. • When an agents moves into another agent’s square, the moving agent gives money to the other. • Agents have a different lifespan between max. and min. values. When it dies, the money is spread randomly and is replaced.
public String getName(){ return “My First RePast Model”; }
}
The SimModel Object—begin()
• begin() initializes the model.
import uchicago.src.sim.engine.SimModelImpl;
public class MyFirstRePastModel extends SimModelImpl {
public String getName(){ return “My First RePast Model”; } public void begin(){ } }
The SimModel Object—tradition
public void begin(){ buildModel(); buildSchedule(); buildDisplay(); }
public void buildModel(){ } public void buildSchedule(){ } public void buildDisplay(){ }
private Schedule schedule;
public String getName(){ return “My First RePast Model”; }
public void begin(){ buildModel(); buildSche源自文库ule(); buildDisplay(); } public void buildModel(){ } public void buildSchedule(){ } public void buildDisplay(){ }
The SimModel Object—current code
import uchicago.src.sim.engine.SimModelImpl; public class MyFirstRePastModel extends SimModelImpl { public String getName(){ return “My First RePast Model”; } public void begin(){ buildModel(); buildSchedule(); buildDisplay(); } public void buildModel(){ } public void buildSchedule(){ } public void buildDisplay(){ } }
The SimObject Model--Schedule
import uchicago.src.sim.engine.SimModelImpl; import uchicago.src.sim.engine.Schedule;
public class MyFirstRePastModel extends SimModelImpl {
The SimModel Object--numAgents
• Next, RePast structure requires us to provide ‘get’ and ‘set’.
public Schedule getSchedule(){ return schedule; }
public String[] getInitParam(){ String[] initParams = {“NumAgents”}; return initParams; } public int getNumAgents(){ return numAgents; }
The CarryDrop model
To accomplish this, we will need three files
• The class that instantiates the SimModel object
• CarryDropModel
• A class specifying the agents
The SimModel Object--numAgents
• Next, RePast structure requires us to provide ‘get’ and ‘set’.
public Schedule getSchedule(){ return schedule; }
public int getNumAgents(){ return numAgents; } public void setNumAgents (int na){ numAgents=na; } }
The SimModel Object—setup()
• The setup() function returns the model to the initial condition.
public class MyFirstRePastModel extends SimModelImpl { public String getName(){ return “My First RePast Model”; } public void setup(){ } public void begin(){ […]
The (Sim)Model Object
• Model object will extend RePast’s SimModelImpl object. • It will react to the RePast control toolbar.
The SimModel Object—getName()
public Schedule getSchedule(){ return schedule; } }
The SimModel Object--getInitParam
• getInitParam returns an array of String variables (e.g., N agents) • This will change Ns by using the ‘setup’ and ‘initialize’ buttons. • Two important factors:
• CarryDropAgent
• A class describing the space
• CarryDropSpace
[To be continues at http://www.u.arizona.edu/~jtmurphy/H2R/HowTo03.htm]
Creating a RePast Model
Introduction, (Sim)Model Object, CarryDrop
Elements of a RePast Model
1. Model Object—acts as the model itself
2. Space Object—controls the environment 3. Agent Object
• You must supply RePast with a list of the parameters you want to vary, in this case ‘NumAgents.’ • You must create ‘get’ and ‘set’ methods for each parameter in the list.