设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9694|回复: 2

[求助] 代碼的问题需要求助..

[复制链接]
发表于 2008-6-3 17:42:03 | 显示全部楼层 |阅读模式
10仿真币
我想请问各位大大高手帮我解决我的问题" R* P$ F2 D$ |* n0 {
我先简述一下我所要做的模型,我的模型里,整体有两种人,政府与民众。 1 S6 }( `" n3 R/ o, o; Z
那政府里又分为四种策略的人faithfuls ,trigger-punishments ,trigger-punishments , mixeds 8 C5 b! N, Q, c3 I
那政府要与民众互动,选择合作与不合作,政府合作和民众合作可得分(energy) ' V' y: p" H2 {
,相对的不合作也有得分但当我要开始写规则的时候,却发现程式无法照我的意思去跑,想请问各位高手能帮我看看是哪里出问题了吗?% o7 H: J* H7 `
breed [peoples people]  O# C% S; k8 U  c0 W0 j. B
breed [faithfuls faithful]
1 l; [( m' |% D. {" v- m" Sbreed [trigger-punishments trigger-punishment]
( A% a2 c5 ^1 O; S) b! l/ Fbreed [tit-for-tats tit-for-tat]- z4 U. m! ?# C4 c: K" K7 \4 P
breed [mixeds mixed]   
  r, D) R- M/ w. _* Fturtles-own [cooperate?  energy]2 N  P( j5 x5 g9 `1 b
5 {7 ^' _" _! ^4 ~, y- B, X
to setup
4 H* n1 I' R: [4 Aset-default-shape turtles "person"! C! d, E# |. @. X* e
  clear-all               ( v. Y4 I0 E. k3 Q
  setup-peoples  
& K% v& Q+ o: G% P4 D- D* W7 [  setup-goverments3 N: e8 H$ a% {4 L* `
ask faithfuls  [ set energy 0 ]
/ g$ F% M/ z1 ?  Y* V: r! O2 mask trigger-punishments  [set energy 0 ]/ j/ ?" w: E+ A2 m; \! ~% @. f
ask tit-for-tats  [set energy 0 ]" s( I- v. |/ T/ Y
ask mixeds  [set energy 0 ]0 k- q) @2 h$ h1 _" p  O5 h
ask peoples  [set energy 0 ]
2 ?  Y% E; ]; t* V. cend: k6 C6 C: A0 Y+ ^. u) T- {
' p0 h' O& Z2 p& ]
to setup-peoples
  L4 p: E0 z3 G4 \* l4 _) `7 b5 `: D
ask patches with [-1 < pxcor and pxcor < 20 and pycor = 0]  E+ e4 ~, l1 f, M
[sprout-peoples 1 [ set color blue set heading 0 ]
, |' i7 |4 G. a. y' b9 w- W2 s
. y5 q2 ]/ V( a]2 |8 _7 N- k2 x9 q# A2 Z
end' a! S$ O  J1 p; l% S2 W
" l) ?0 j. _1 d, N: z
to  setup-goverments' a2 ?8 h; e  i! a6 L( [. S
create-faithfuls  5 [set color red set heading 180]
- `) V& f$ g6 M; A* Mcreate-trigger-punishments  5 [set color green set heading 180]
; j6 \6 k- o9 z& T/ tcreate-tit-for-tats  5 [set color white set heading 180]
" ]3 A% l5 ^% J5 j$ G# R' [create-mixeds  5 [set color pink set heading 180]1 j2 o2 u8 q6 h, r
ask turtles with [ color != blue ] [while [any? other turtles-here] [setxy random 20 1]
; d" `8 C% l0 W' J- X]: _5 d: ^- _! n6 O  B/ b
end( P  Y/ \5 G, i2 A8 P0 k  O

% ?: ?9 q: t) Vto go1 x& x+ m3 s3 J. V
ask  peoples [ set cooperate? random 2]
' y8 |$ \3 m8 e9 G) |9 y9 A! `  ask  faithfuls [  set cooperate? random 2]
1 I8 ~" }  r( j) ?0 y% Q. p  ask  trigger-punishments [ set cooperate? random 2]
% _2 e( W5 I+ w! S! _/ R; ?6 U  ask  tit-for-tats [ set cooperate? random 2]
% t: n/ V6 ~$ @2 ~  ask  mixeds [ set cooperate? random 2]& e4 O; E- P/ O4 Q) N
  6 T3 Z* Q& f0 E9 x9 G
  ask faithfuls [ 6 i6 _; e) j$ l, V4 L
  if ( cooperate? = [cooperate?] of peoples-on patch-ahead 1 ) 9 p# C' Y7 Z9 n# k/ r9 Y$ M; R/ r4 r1 o
   [  set energy  energy + 8 & _& H# s8 C6 @4 Q: y  N: F3 N4 {
      ask peoples-on patch-ahead 1 [ set energy  energy + 2] ]
. u1 h' }$ q, [      ]         就是这里出问题了无法照我的意思去跑
3 Z& l( `* a! p" o* y  ifelse (show-energy?)
, t; R) z, K- T0 W    [ ask turtles [ set label (energy) ] ]+ L& ]1 z6 ^* k
    [ ask turtles [ set label "" ] ]( F; C  A( d: s' s' x( ~+ B
  end& p% Z3 X$ V5 G. Y
希望大家能帮我解决一下不然我没办法继续写下去
/ X" @. }7 m) Z* V
* _: e: @( C8 f$ x5 ^* T0 Y* w4 C[ 本帖最后由 h64914110 于 2008-6-4 10:51 编辑 ]

最佳答案

查看完整内容

为什么不考虑用patches设定政府,假设政府不能够移动,民众可以通过用脚投票选择政府。这样也许可以解决你说的问题。
发表于 2008-6-3 17:42:04 | 显示全部楼层
为什么不考虑用patches设定政府,假设政府不能够移动,民众可以通过用脚投票选择政府。这样也许可以解决你说的问题。
 楼主| 发表于 2008-6-4 11:57:22 | 显示全部楼层
简单点说好了模型固定分为上下两排,上为政府下为民众
  {; k, `. H; C/ H. @3 D9 a- f% t每一个政府类的人对应一个民众; q9 @( s, ^% U' V  ~5 j# K
上下两两对应  但我现在问题就是  我不知道turtles是否有互相对应到" ~% X4 Q8 Q: a2 a5 }& P  w
那如果没对应到    要让turtles互相对应的语法又该怎么写?
0 s9 d0 f/ j) Z  G$ W* d2 y; G0 c我是新手  麻烦大家帮帮忙  传短讯给我也可以  谢谢. @/ R9 u) k, S& S

# x4 w! Z: R% U! `  W[ 本帖最后由 h64914110 于 2008-6-4 11:58 编辑 ]
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-8-1 07:38 , Processed in 0.017029 second(s), 14 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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