datafile-example.nlogo 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531
  1. ;; DataFile Example of R-extension
  2. ;;
  3. ;;
  4. ;; by Jan C. Thiele
  5. ;; University of Goettingen, Germany
  6. ;; Department Ecoinformatics, Biometrics and Forest Growth
  7. ;; Buesgenweg 4
  8. ;; 37077 Goettingen
  9. ;; Germany
  10. ;;
  11. ;; Contact: jthiele@gwdg.de
  12. ;;
  13. ;; Copyright: 2011, J.C. Thiele
  14. extensions [r]
  15. turtles-own [test]
  16. to create-and-write-data
  17. clear-all
  18. crt 30
  19. [
  20. set xcor random-xcor
  21. set ycor random-ycor
  22. ]
  23. (r:putagentdf "ag" turtles "who" "xcor" "ycor")
  24. let evalstring (word "write.table(ag ,file='" path "')")
  25. r:eval evalstring
  26. end
  27. to load-and-show-data
  28. clear-all
  29. let evalstring (word "ag <- read.table(file='" path "')")
  30. r:eval evalstring
  31. let xc r:get "ag$xcor"
  32. let yc r:get "ag$ycor"
  33. let xypos (map [ [?1 ?2] -> list ?1 ?2 ] xc yc)
  34. foreach xypos
  35. [ [?1] ->
  36. crt 1
  37. [
  38. set xcor (item 0 ?1)
  39. set ycor (item 1 ?1)
  40. ]
  41. ]
  42. end
  43. to write-data-with-vector-dataframe
  44. clear-all
  45. crt 30
  46. [
  47. set xcor random-xcor
  48. set ycor random-ycor
  49. set test (list random 10 random 20 random 30)
  50. ]
  51. (r:putagentdf "ag" turtles "who" "xcor" "ycor" "test")
  52. ; mark column test as class "AsIs"
  53. r:eval "ag$test <- I(ag$test)"
  54. let evalstring (word "write.table(ag ,file='" path "')")
  55. r:eval evalstring
  56. end
  57. @#$#@#$#@
  58. GRAPHICS-WINDOW
  59. 254
  60. 10
  61. 691
  62. 448
  63. -1
  64. -1
  65. 13.0
  66. 1
  67. 10
  68. 1
  69. 1
  70. 1
  71. 0
  72. 1
  73. 1
  74. 1
  75. -16
  76. 16
  77. -16
  78. 16
  79. 0
  80. 0
  81. 1
  82. ticks
  83. 30.0
  84. BUTTON
  85. 8
  86. 150
  87. 223
  88. 183
  89. NIL
  90. create-and-write-data
  91. NIL
  92. 1
  93. T
  94. OBSERVER
  95. NIL
  96. NIL
  97. NIL
  98. NIL
  99. 1
  100. INPUTBOX
  101. 5
  102. 55
  103. 221
  104. 115
  105. path
  106. datafile.txt
  107. 1
  108. 0
  109. String
  110. BUTTON
  111. 8
  112. 192
  113. 223
  114. 225
  115. NIL
  116. load-and-show-data
  117. NIL
  118. 1
  119. T
  120. OBSERVER
  121. NIL
  122. NIL
  123. NIL
  124. NIL
  125. 1
  126. BUTTON
  127. 9
  128. 344
  129. 228
  130. 377
  131. NIL
  132. write-data-with-vector-dataframe
  133. NIL
  134. 1
  135. T
  136. OBSERVER
  137. NIL
  138. NIL
  139. NIL
  140. NIL
  141. 1
  142. TEXTBOX
  143. 11
  144. 252
  145. 233
  146. 333
  147. Note: The R-Extension allows you to create a data.frame with a vector in each row of a column. This is not common in data.frames. Therefore, you have to mark this column as class \"AsIs\" by using the I(x) function for this column if you want to use write.table.
  148. 11
  149. 0.0
  150. 1
  151. BUTTON
  152. 5
  153. 14
  154. 220
  155. 47
  156. select path
  157. set path user-new-file
  158. NIL
  159. 1
  160. T
  161. OBSERVER
  162. NIL
  163. NIL
  164. NIL
  165. NIL
  166. 1
  167. @#$#@#$#@
  168. ## WHAT IS IT?
  169. This section could give a general understanding of what the model is trying to show or explain.
  170. ## HOW IT WORKS
  171. This section could explain what rules the agents use to create the overall behavior of the model.
  172. ## HOW TO USE IT
  173. This section could explain how to use the model, including a description of each of the items in the interface tab.
  174. ## THINGS TO NOTICE
  175. This section could give some ideas of things for the user to notice while running the model.
  176. ## THINGS TO TRY
  177. This section could give some ideas of things for the user to try to do (move sliders, switches, etc.) with the model.
  178. ## EXTENDING THE MODEL
  179. This section could give some ideas of things to add or change in the procedures tab to make the model more complicated, detailed, accurate, etc.
  180. ## NETLOGO FEATURES
  181. This section could point out any especially interesting or unusual features of NetLogo that the model makes use of, particularly in the Procedures tab. It might also point out places where workarounds were needed because of missing features.
  182. ## RELATED MODELS
  183. This section could give the names of models in the NetLogo Models Library or elsewhere which are of related interest.
  184. ## CREDITS AND REFERENCES
  185. This section could contain a reference to the model's URL on the web if it has one, as well as any other necessary credits or references.
  186. @#$#@#$#@
  187. default
  188. true
  189. 0
  190. Polygon -7500403 true true 150 5 40 250 150 205 260 250
  191. airplane
  192. true
  193. 0
  194. Polygon -7500403 true true 150 0 135 15 120 60 120 105 15 165 15 195 120 180 135 240 105 270 120 285 150 270 180 285 210 270 165 240 180 180 285 195 285 165 180 105 180 60 165 15
  195. arrow
  196. true
  197. 0
  198. Polygon -7500403 true true 150 0 0 150 105 150 105 293 195 293 195 150 300 150
  199. box
  200. false
  201. 0
  202. Polygon -7500403 true true 150 285 285 225 285 75 150 135
  203. Polygon -7500403 true true 150 135 15 75 150 15 285 75
  204. Polygon -7500403 true true 15 75 15 225 150 285 150 135
  205. Line -16777216 false 150 285 150 135
  206. Line -16777216 false 150 135 15 75
  207. Line -16777216 false 150 135 285 75
  208. bug
  209. true
  210. 0
  211. Circle -7500403 true true 96 182 108
  212. Circle -7500403 true true 110 127 80
  213. Circle -7500403 true true 110 75 80
  214. Line -7500403 true 150 100 80 30
  215. Line -7500403 true 150 100 220 30
  216. butterfly
  217. true
  218. 0
  219. Polygon -7500403 true true 150 165 209 199 225 225 225 255 195 270 165 255 150 240
  220. Polygon -7500403 true true 150 165 89 198 75 225 75 255 105 270 135 255 150 240
  221. Polygon -7500403 true true 139 148 100 105 55 90 25 90 10 105 10 135 25 180 40 195 85 194 139 163
  222. Polygon -7500403 true true 162 150 200 105 245 90 275 90 290 105 290 135 275 180 260 195 215 195 162 165
  223. Polygon -16777216 true false 150 255 135 225 120 150 135 120 150 105 165 120 180 150 165 225
  224. Circle -16777216 true false 135 90 30
  225. Line -16777216 false 150 105 195 60
  226. Line -16777216 false 150 105 105 60
  227. car
  228. false
  229. 0
  230. Polygon -7500403 true true 300 180 279 164 261 144 240 135 226 132 213 106 203 84 185 63 159 50 135 50 75 60 0 150 0 165 0 225 300 225 300 180
  231. Circle -16777216 true false 180 180 90
  232. Circle -16777216 true false 30 180 90
  233. Polygon -16777216 true false 162 80 132 78 134 135 209 135 194 105 189 96 180 89
  234. Circle -7500403 true true 47 195 58
  235. Circle -7500403 true true 195 195 58
  236. circle
  237. false
  238. 0
  239. Circle -7500403 true true 0 0 300
  240. circle 2
  241. false
  242. 0
  243. Circle -7500403 true true 0 0 300
  244. Circle -16777216 true false 30 30 240
  245. cow
  246. false
  247. 0
  248. Polygon -7500403 true true 200 193 197 249 179 249 177 196 166 187 140 189 93 191 78 179 72 211 49 209 48 181 37 149 25 120 25 89 45 72 103 84 179 75 198 76 252 64 272 81 293 103 285 121 255 121 242 118 224 167
  249. Polygon -7500403 true true 73 210 86 251 62 249 48 208
  250. Polygon -7500403 true true 25 114 16 195 9 204 23 213 25 200 39 123
  251. cylinder
  252. false
  253. 0
  254. Circle -7500403 true true 0 0 300
  255. dot
  256. false
  257. 0
  258. Circle -7500403 true true 90 90 120
  259. face happy
  260. false
  261. 0
  262. Circle -7500403 true true 8 8 285
  263. Circle -16777216 true false 60 75 60
  264. Circle -16777216 true false 180 75 60
  265. Polygon -16777216 true false 150 255 90 239 62 213 47 191 67 179 90 203 109 218 150 225 192 218 210 203 227 181 251 194 236 217 212 240
  266. face neutral
  267. false
  268. 0
  269. Circle -7500403 true true 8 7 285
  270. Circle -16777216 true false 60 75 60
  271. Circle -16777216 true false 180 75 60
  272. Rectangle -16777216 true false 60 195 240 225
  273. face sad
  274. false
  275. 0
  276. Circle -7500403 true true 8 8 285
  277. Circle -16777216 true false 60 75 60
  278. Circle -16777216 true false 180 75 60
  279. Polygon -16777216 true false 150 168 90 184 62 210 47 232 67 244 90 220 109 205 150 198 192 205 210 220 227 242 251 229 236 206 212 183
  280. fish
  281. false
  282. 0
  283. Polygon -1 true false 44 131 21 87 15 86 0 120 15 150 0 180 13 214 20 212 45 166
  284. Polygon -1 true false 135 195 119 235 95 218 76 210 46 204 60 165
  285. Polygon -1 true false 75 45 83 77 71 103 86 114 166 78 135 60
  286. Polygon -7500403 true true 30 136 151 77 226 81 280 119 292 146 292 160 287 170 270 195 195 210 151 212 30 166
  287. Circle -16777216 true false 215 106 30
  288. flag
  289. false
  290. 0
  291. Rectangle -7500403 true true 60 15 75 300
  292. Polygon -7500403 true true 90 150 270 90 90 30
  293. Line -7500403 true 75 135 90 135
  294. Line -7500403 true 75 45 90 45
  295. flower
  296. false
  297. 0
  298. Polygon -10899396 true false 135 120 165 165 180 210 180 240 150 300 165 300 195 240 195 195 165 135
  299. Circle -7500403 true true 85 132 38
  300. Circle -7500403 true true 130 147 38
  301. Circle -7500403 true true 192 85 38
  302. Circle -7500403 true true 85 40 38
  303. Circle -7500403 true true 177 40 38
  304. Circle -7500403 true true 177 132 38
  305. Circle -7500403 true true 70 85 38
  306. Circle -7500403 true true 130 25 38
  307. Circle -7500403 true true 96 51 108
  308. Circle -16777216 true false 113 68 74
  309. Polygon -10899396 true false 189 233 219 188 249 173 279 188 234 218
  310. Polygon -10899396 true false 180 255 150 210 105 210 75 240 135 240
  311. house
  312. false
  313. 0
  314. Rectangle -7500403 true true 45 120 255 285
  315. Rectangle -16777216 true false 120 210 180 285
  316. Polygon -7500403 true true 15 120 150 15 285 120
  317. Line -16777216 false 30 120 270 120
  318. leaf
  319. false
  320. 0
  321. Polygon -7500403 true true 150 210 135 195 120 210 60 210 30 195 60 180 60 165 15 135 30 120 15 105 40 104 45 90 60 90 90 105 105 120 120 120 105 60 120 60 135 30 150 15 165 30 180 60 195 60 180 120 195 120 210 105 240 90 255 90 263 104 285 105 270 120 285 135 240 165 240 180 270 195 240 210 180 210 165 195
  322. Polygon -7500403 true true 135 195 135 240 120 255 105 255 105 285 135 285 165 240 165 195
  323. line
  324. true
  325. 0
  326. Line -7500403 true 150 0 150 300
  327. line half
  328. true
  329. 0
  330. Line -7500403 true 150 0 150 150
  331. pentagon
  332. false
  333. 0
  334. Polygon -7500403 true true 150 15 15 120 60 285 240 285 285 120
  335. person
  336. false
  337. 0
  338. Circle -7500403 true true 110 5 80
  339. Polygon -7500403 true true 105 90 120 195 90 285 105 300 135 300 150 225 165 300 195 300 210 285 180 195 195 90
  340. Rectangle -7500403 true true 127 79 172 94
  341. Polygon -7500403 true true 195 90 240 150 225 180 165 105
  342. Polygon -7500403 true true 105 90 60 150 75 180 135 105
  343. plant
  344. false
  345. 0
  346. Rectangle -7500403 true true 135 90 165 300
  347. Polygon -7500403 true true 135 255 90 210 45 195 75 255 135 285
  348. Polygon -7500403 true true 165 255 210 210 255 195 225 255 165 285
  349. Polygon -7500403 true true 135 180 90 135 45 120 75 180 135 210
  350. Polygon -7500403 true true 165 180 165 210 225 180 255 120 210 135
  351. Polygon -7500403 true true 135 105 90 60 45 45 75 105 135 135
  352. Polygon -7500403 true true 165 105 165 135 225 105 255 45 210 60
  353. Polygon -7500403 true true 135 90 120 45 150 15 180 45 165 90
  354. square
  355. false
  356. 0
  357. Rectangle -7500403 true true 30 30 270 270
  358. square 2
  359. false
  360. 0
  361. Rectangle -7500403 true true 30 30 270 270
  362. Rectangle -16777216 true false 60 60 240 240
  363. star
  364. false
  365. 0
  366. Polygon -7500403 true true 151 1 185 108 298 108 207 175 242 282 151 216 59 282 94 175 3 108 116 108
  367. target
  368. false
  369. 0
  370. Circle -7500403 true true 0 0 300
  371. Circle -16777216 true false 30 30 240
  372. Circle -7500403 true true 60 60 180
  373. Circle -16777216 true false 90 90 120
  374. Circle -7500403 true true 120 120 60
  375. tree
  376. false
  377. 0
  378. Circle -7500403 true true 118 3 94
  379. Rectangle -6459832 true false 120 195 180 300
  380. Circle -7500403 true true 65 21 108
  381. Circle -7500403 true true 116 41 127
  382. Circle -7500403 true true 45 90 120
  383. Circle -7500403 true true 104 74 152
  384. triangle
  385. false
  386. 0
  387. Polygon -7500403 true true 150 30 15 255 285 255
  388. triangle 2
  389. false
  390. 0
  391. Polygon -7500403 true true 150 30 15 255 285 255
  392. Polygon -16777216 true false 151 99 225 223 75 224
  393. truck
  394. false
  395. 0
  396. Rectangle -7500403 true true 4 45 195 187
  397. Polygon -7500403 true true 296 193 296 150 259 134 244 104 208 104 207 194
  398. Rectangle -1 true false 195 60 195 105
  399. Polygon -16777216 true false 238 112 252 141 219 141 218 112
  400. Circle -16777216 true false 234 174 42
  401. Rectangle -7500403 true true 181 185 214 194
  402. Circle -16777216 true false 144 174 42
  403. Circle -16777216 true false 24 174 42
  404. Circle -7500403 false true 24 174 42
  405. Circle -7500403 false true 144 174 42
  406. Circle -7500403 false true 234 174 42
  407. turtle
  408. true
  409. 0
  410. Polygon -10899396 true false 215 204 240 233 246 254 228 266 215 252 193 210
  411. Polygon -10899396 true false 195 90 225 75 245 75 260 89 269 108 261 124 240 105 225 105 210 105
  412. Polygon -10899396 true false 105 90 75 75 55 75 40 89 31 108 39 124 60 105 75 105 90 105
  413. Polygon -10899396 true false 132 85 134 64 107 51 108 17 150 2 192 18 192 52 169 65 172 87
  414. Polygon -10899396 true false 85 204 60 233 54 254 72 266 85 252 107 210
  415. Polygon -7500403 true true 119 75 179 75 209 101 224 135 220 225 175 261 128 261 81 224 74 135 88 99
  416. wheel
  417. false
  418. 0
  419. Circle -7500403 true true 3 3 294
  420. Circle -16777216 true false 30 30 240
  421. Line -7500403 true 150 285 150 15
  422. Line -7500403 true 15 150 285 150
  423. Circle -7500403 true true 120 120 60
  424. Line -7500403 true 216 40 79 269
  425. Line -7500403 true 40 84 269 221
  426. Line -7500403 true 40 216 269 79
  427. Line -7500403 true 84 40 221 269
  428. x
  429. false
  430. 0
  431. Polygon -7500403 true true 270 75 225 30 30 225 75 270
  432. Polygon -7500403 true true 30 75 75 30 270 225 225 270
  433. @#$#@#$#@
  434. NetLogo 6.0-BETA2
  435. @#$#@#$#@
  436. @#$#@#$#@
  437. @#$#@#$#@
  438. @#$#@#$#@
  439. @#$#@#$#@
  440. default
  441. 0.0
  442. -0.2 0 0.0 1.0
  443. 0.0 1 1.0 0.0
  444. 0.2 0 0.0 1.0
  445. link direction
  446. true
  447. 0
  448. Line -7500403 true 150 150 90 180
  449. Line -7500403 true 150 150 210 180
  450. @#$#@#$#@
  451. 1
  452. @#$#@#$#@