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);

 

发布了12 篇原创文章 · 获赞 0 · 访问量 6203
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章