设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 5931|回复: 3

[求助] 关于CarryDrop model的一个问题

  [复制链接]
发表于 2012-3-4 17:00:49 | 显示全部楼层 |阅读模式
在CarryDrop model中那个spreadmoney方法里,哪一句是用来随机撒钱的啊?程序代码如下,我看到了随机选取坐标,并将该坐标对应的空间格内的值转换为数值,关键在于这个值貌似始终为0,不知道怎么把它修改掉的?哪一句是生成不为0的值的?
/ Y0 O; t- O& v5 H# ^        public void spreadmoney(int m){
7 o2 e. D, u$ I  p7 V                for(int i=0;i<m;i++){
: F. y$ U: Q2 @8 b" q& h& M" }4 A                        int x = (int)(Math.random()*(moneyspace.getSizeX()));0 N3 H. n4 x1 m5 C' U
                        int y = (int)(Math.random()*(moneyspace.getSizeY()));+ G. n" `) J2 n1 j0 w" W

+ [4 n& _4 H0 A                        int I;
; F$ P( [$ Z) x& W                        if(moneyspace.getObjectAt(x,y)!=null                                I = ((Integer)moneyspace.getObjectAt(x,y)).intValue();
  P9 \; \+ u- ~- X- h$ S                        }* R( C3 D- ?2 o# P. K( ?. {
                        else{
/ w0 z1 k, h! c, ?2 n                                I = 0;/ [* w2 h7 n6 ~: a
                        }' t, h# `* ]' W2 E
                        moneyspace.putObjectAt(x, y, new Integer(I+1));                              }
" K' |5 ?* G/ K  K- Q1 f$ Y3 _2 `        }
 楼主| 发表于 2012-3-6 09:15:08 | 显示全部楼层
代码帖的有点乱,怎么都没人能帮忙看看呢?      
+ n' m; v3 j' |4 u       public void spreadmoney(int m){) O  A/ j' \; U+ y! }) X
                for(int i=0;i<m;i++){
. r4 K& w: e2 s* a6 T                        int x = (int)(Math.random()*(moneyspace.getSizeX()));
  T; o* n  C- m) e& x$ \. ]1 K% V3 R                        int y = (int)(Math.random()*(moneyspace.getSizeY()));
4 o4 g, i7 }8 ^+ t  ~2 E) s1 K0 I* z: c: m+ f
                        int I;/ D4 d) b  M( ], h5 N& h
                        if(moneyspace.getObjectAt(x,y)!=null                                
; ]. I7 g) b. I8 _9 Q5 R1 v' m* x# Q7 l                        I = ((Integer)moneyspace.getObjectAt(x,y)).intValue();
& q2 c4 u7 @# q# u: e                        }
6 D4 K: v4 l7 e$ u/ H5 i                        else{
7 \1 ?0 L5 J& A, W                                I = 0;
, T. W( h9 G3 ~& P2 `) \8 G                        }
( E0 @6 }7 _7 G& ?8 ]                        moneyspace.putObjectAt(x, y, new Integer(I+1));                              }* }9 F  P' ]3 x: `9 k8 S0 @  X1 Y9 ^
        }
 楼主| 发表于 2012-3-6 11:25:15 | 显示全部楼层
还有,当两个agent碰到一起了,到底是谁抢走了谁的钱呢?从程序上真的没看明白
 楼主| 发表于 2012-3-10 15:35:24 | 显示全部楼层
至今没人解答,这个论坛太失败了,还是我自己找出答案吧,不知道对不对。6 t$ F: k! D/ t$ L# Y  d
第一个问题的钱其实是随机在40*40的格子中选择了1000个格子,每个格子里假设有1块钱,只要agent经过这个格子,如果没人来过,就认为拣了1块钱。: j/ x( V/ w$ H1 Y' |- K: P6 ^
第二个问题的答案来自于schedule的execute方法中有个shuffle方法,重新随机调整了每一轮agent的执行次序,根据执行次序的不同而判断是谁先进入了这个格子,从而得知后来的就要交钱了。

点评

e, 没人回答你不代表论坛失败。。。做这块的本来人就少,而且刚好看过捡钱这个例子的人也不多。  发表于 2012-3-15 17:29
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-8-11 01:52 , Processed in 0.013423 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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