RePast笔记

 


REPAST-Recursive Porous Agent Simulation Toolkit

agent-based modeling
Douglas Samuelson and Charles Macal, "Agent-based Simulation Comes of Age," OR/MS Today, Vol. 33, Number 4, pp. 34-38, Lionheart Publishing, Marietta, GA, USA (August 2006).

agent based modeling and simulation

运行仿真:gui:
java -jar c:\repast\lib\repast.jar
或者:command-line:
java -cp path_to_your_model;c:/repast/lib/repast.jar uchicago.src.sim.engine.SimInit fullyQualifiedModelName
eg:

java -cp c:/repast/demo/bugs/bugs.jar;c:/repast/lib/repast.jar uchicago.src.sim.engine.SimInit uchicago.src.sim.heatBugs.HeatBugsModel
加载参数文件:
java -cp c:/repast/demo/bugs/bugs.jar;c:/repast/lib/repast.jar uchicago.src.sim.engine.SimInit uchicago.src.sim.heatBugs.HeatBugsModel c:\params\bugs.pf

1.parameter必须是getInitParam返回的String[]中的
2.必须有accessor

runs正在batch模式下表示多少次?

multi-keywords:start end incr iterator
single-keywords:set 是numerical
 set_list
 set_boolean
 set_string
 set_boolean_list
 set_boolean_string_list
可以嵌套nested

runs: 1
Food {
 start: 10
 end: 30
 incr: 10
 {
   runs: 10
   MaxAge {
     start: 0
     end: 40
     incr: 1
   }
 }
}

 

list是这样的:
set_list: 1.2 3 10 12 84


simple model:


2步:
1st.setup preparing
2nd.actual running

如果是两个player的囚徒困境。setup阶段就是创建两个player,提供初始状态,比较tit-for-tat,每一次选择依赖与stragtegy和上一个tick。

SimpleModel:extends SimpleModel:

setup(),teardowm()
buildModel()
preStep()->step()->postStep()


  public void step() {
    int size = agentList.size();
    for (int i = 0; i < size; i++) {
      Player p = (Player)agentList.get(i);
      p.play();
    }
  }


step每一步做的事情

投票算法中就要用到preStep和postStep

自动的step机制迭代所有的agent调用他们自身的step方法。agent必须实现Stepable接口,这个接口只有step()方法,更复杂的通过schedule来实现。


When the setup button is clicked, the code in the setup() method is executed. When the initialize button is clicked, the code in buildModel() is executed. When the step button is clicked, the code in buildModel() is executed and the preStep(), step(), and postStep() sequence is executed once. When the start button is clicked, buildModel() is executed, and the preStep(), step(), and postStep() sequence is executed repeatedly until the user clicks the stop or pause button.

 

no knobs to twiddle-using parameters

使用accessor,例如:

public void setP1Strategy(int val) {
    p1Strategy = val;
  }

  public int getP1Strategy() {
    return p1Strategy;
  }

public MyModel() {
    params = new String[] {"P1Strategy"};
  }

是model能够aware到参数。

public MyModel() {
    name = "Example Model";
  }
来命名一个model

 


setStoppingTime(long time) can be used set the time step at which the current simulation run will stop.
setRngSeed(long seed) can be used to set the seed for the default random number generator. Note that the seed defaults to 1.
getNextIntFromTo(int from, int to) returns the next random integer between from and to, inclusive of from and to.
getNextDoubleFromTo(double from, double to) returns the next random double between from and to, exclusive of from and to.
atPause() the body of this method will be executed whenever your simulation is paused. You'll need to override this method.
atEnd() the body of this method will be executed whenever your simulation ends. You'll need to override this method.


build a display?

private DisplaySurface dsurf;

  ...

  private void buildDisplay() {
    ...
  }

  public void buildModel() {
    ...
    buildDisplay();
  }

batch-run:整个过程不需要人为的参与,仿真的过程可以自动的进行。
non-batch-run:人为的参与到整个过程中,中间可以图形化的显示和操作agent的状态。
每种类型至少有两个类,model和agent


Repast provides an abstract class SimModelImpl that partialy implements this interface and it is expected that most if not all models will extend this class.


space:作为agent的容器。


social network:

node,edge

edgeFactory
每个节点都是一个node


BasicAction

Scheduling BasicActions for execution is done via the Schedule object. It allows you to schedule actions to occur every tick beginning at some specified tick, once at some specified tick, at intervals, at a pause in the simulation, and at the end of the simulation. (A tick is a single iteration over all the BasicActions scheduled for execution at that time.)

schedule:每一定的间隔就发生,暂停时发生,模拟结束的时候发生。


dataRecoder:record data from a variety of sources and write that data out in tabular format to a file

recorder = new DataRecorder("./data.txt", this, "A Comment");  //header comment~头注释
第二个参数是与他关联的model的引用,这里在model的内部,所以可以用this
recoder会从数据源记录数据当收到record()消息时。

包裹在NumericDataSouce和DataSource中才可以被dataRecoder所接受。


3 kinds of property descriptors:
boolean-checkbox
properties-list
numerical-textbox


A BooleanPropertyDescriptor is typically setup in a model's constructor as follows:

BooleanPropertyDescriptor bd1 = new BooleanPropertyDescriptor("RecordData", false);
descriptors.put("RecordData", bd1);

 

Repast 是一个用于构建基于代理(Agent-Based)模型和仿真的软件框架,广泛应用于社会科学、生态学、经济学、流行病学等多个领域。它提供了一系列工具和库,用于创建、运行和分析复杂的多代理系统(Multi-Agent Systems, MAS)。Repast 支持多种编程语言和开发环境,包括 Java、Python 和 C++。 ### 主要版本和特点 1. **Repast for Java (Repast J)** Repast J 是基于 Java 的仿真框架,适用于构建高性能、可扩展的多代理模型。它提供了丰富的 API,支持多种类型的代理行为、交互规则、网络结构和可视化工具。Repast J 支持与地理信息系统(GIS)集成,适用于空间建模任务。 2. **Repast Simphony** Repast Simphony 是 Repast 系列中较为现代化的框架,支持图形化建模工具和模块化设计。它基于 Eclipse 平台,提供了拖放式的建模界面,并支持与 NetLogo 和 Repast J 的互操作性。Repast Simphony 支持使用 Groovy 和 Java 进行脚本编写,便于快速原型设计和复杂模型开发。 3. **Repast for Python (Repast4Py)** Repast4Py 是面向 Python 开发者的轻量级仿真框架,适合快速构建基于代理的模型。它利用 Python 的简洁语法和丰富的科学计算库(如 NumPy 和 SciPy),使得模型开发更加高效。Repast4Py 也支持分布式计算,适用于大规模仿真。 4. **Repast for C++ (Repast HPC)** Repast HPC 是一个高性能计算版本,适用于需要大规模并行计算的复杂仿真任务。它基于 MPI(Message Passing Interface),支持在超级计算机或集群上运行大规模模型。 ### 主要用途 - **社会科学研究**:Repast 被广泛用于模拟社会行为、经济决策、政策影响评估等。例如,研究城市交通模式、市场行为或社会网络的演化。 - **生态学与环境科学**:Repast 支持构建生态系统模型,用于研究物种交互、气候变化对生物群落的影响等。 - **流行病学**:在流行病传播研究中,Repast 被用来模拟病毒在人群中的传播路径和控制策略的效果。 - **教育与培训**:Repast 提供了教学资源和示例模型,适合用于教学和研究中的仿真训练。 ### 示例代码(Repast4Py) 以下是一个简单的基于 Repast4Py 的代理模型示例,模拟代理的移动和行为: ```python from repast4py import core, schedule, context, space, random class SimpleAgent(core.Agent): def __init__(self, id, type): super().__init__(id, type) self.x = 0 self.y = 0 def move(self): dx = random.randint(-1, 1) dy = random.randint(-1, 1) self.x += dx self.y += dy def step(self): self.move() class Model: def __init__(self, num_agents): self.context = context.SharedContext() self.grid = space.Grid(10, 10) self.schedule = schedule.SharedSchedule() for i in range(num_agents): agent = SimpleAgent(i, 0) self.context.add(agent) self.grid.place_randomly(agent) self.schedule.add(agent) def step(self): self.schedule.step() model = Model(100) for _ in range(10): model.step() ``` ### 开发资源 - **官方文档**:Repast 提供了详细的开发者文档,涵盖安装指南、API 参考和示例模型。 - **社区支持**:Repast 拥有一个活跃的用户社区,用户可以在论坛、邮件列表和 GitHub 仓库中获取帮助和交流经验。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值