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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章