设为首页收藏本站

最大的系统仿真与系统优化公益交流社区

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8893|回复: 3

[求助] Repast建模时,怎么在一个网格里面放多个对象?

  [复制链接]
发表于 2008-11-28 09:26:19 | 显示全部楼层 |阅读模式
5仿真币
最近做流行病模型,需要在一个网格里面放多个Agent,我查了一下API,使用OrderedMultiGrid类来构造,里面提供了一些putObjectAt(int, int, index);之类的东西。似乎可以用。但是当我编程调试的时候发现在同一位置只能获取一个对象。这是很令人纳闷的事情。我想问一下Repast有提供什么好方法处理吗,不仅要能存进去,还要能方便的拿出来。
9 H) V& h/ |* c/ g0 | private boolean findPotentialPartner(){
/ Q9 w7 @6 r) l4 m( {3 M; E7 R  boolean value = false;' u0 v9 e/ H0 C" E( r
  
$ o5 T- C! x: ~. O; Q8 z1 D- l  OrderedMulti2DGrid grid = space.getCurrentAgentSpace();* f4 t/ I5 ~% f: z" K1 J
  Iterator iterator = grid.getIteratorAt(x, y);1 X; T! `8 Z7 G, D6 k
  SexAgent ag1 = null;  ) S9 E  q& @- w' z$ {
  SexAgent [] potenAgent = new SexAgent[20];
* d* V( D, ?$ r/ c  int goodNumber = 0;
' R4 Q9 Q) b' K8 O1 [  while(iterator.hasNext()){
; ]- j" Y( G# C   System.out.println("XXXXXXXXXXXXXXXXXXXXX");. N" V# w' g, {& K; X6 j' l
   ag1 = (SexAgent)iterator.next();! e4 R7 a$ V' ~' G
   if((ag1.sex == FEMALE)
8 b# O+ A1 M# F7 H" e, `; O0 ^     &&(!ag1.isCoupled())){
: }6 ]6 m) _7 c- u7 }+ U: n5 E    System.out.println("YYYYYYYYYYYYYYYYYYYY");( ^0 L/ j+ V  r. g
    potenAgent[goodNumber] = ag1;% C, Q. ]- P) K0 z
    goodNumber ++;- L. e3 J9 P3 i% s8 B
   }
6 x& H6 |* m5 {7 M0 B# E0 R* s  }2 E/ l( R6 U  C% Q! `
  
+ X+ M7 A8 Z5 K: x4 ?/ l  if(goodNumber >0){
. l0 s$ w7 p1 C& W! ~2 a( }( {+ ?# s     System.out.println("ZZZZZZZZZZZZZZZZZZZZZZZZZZZZ");
; R* N  V6 D" k; }" R     Random rd1 = new Random();% I7 G* I: V* d, D* m( w
     int select = rd1.nextInt(goodNumber);) W! I" e5 J: Y3 k
     potentialParterner = potenAgent[select];
- L/ N$ J; u: [% U# P     value = true;" [7 ^. F: a! V" f& W  F
  }
5 N# M6 f+ B* F  s    return value;; ^% f) F& f: d" A
}
8 Y# F" P, _9 w* N. I' f: l1 p始终只能打印出XXXXXXXXXXXXXXXXXXXX,请各位帮帮忙。

发表于 2008-11-28 17:44:57 | 显示全部楼层
我想问下你这个打印的XXXXXX打印了几遍,还有你是否已经把agent添加进去了
发表于 2010-7-8 18:15:38 | 显示全部楼层
囧。。。这么久都没人回
发表于 2012-4-14 14:56:01 | 显示全部楼层
08年提出的问题到现在都没有人解决啊,真是够可以的
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|Archiver|手机版|SimulWay 道于仿真   

GMT+8, 2025-11-25 22:16 , Processed in 0.014787 second(s), 12 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表