-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScienceInstrument.nlogo
More file actions
470 lines (443 loc) · 13.2 KB
/
Copy pathScienceInstrument.nlogo
File metadata and controls
470 lines (443 loc) · 13.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
;
; Science Instrument Key Development Resource Reallocation Agent-based
Model, Version 1
;
;
; Define Science Instruments as Agents
;
Breed [Instruments Instrument]
;
; Define Instrument Properties
;
Instruments-own [initialCost cost initialMass mass initialPower power mass-cost?
cost-mass? mass-power? power-mass? cost-power? power-cost? deltaCost
deltaMass deltaPower ID]
;
; Define Global Variables
;
Globals [tickcount maxTime costGrowth massGrowth powerGrowth
totalMassCostBilateralBarters totalCostPowerBilateralBarters
totalMassPowerBilateralBarters totalMultilateralBarters numberEligible
totalCost totalInitialCost totalMass totalInitialMass totalPower totalInitialPower]
;
; Setup the Simulation
;
to setup
clear-all
set tickcount 0
set costGrowth 0
set massGrowth 0
set powerGrowth 0
set totalMassCostBilateralBarters 0
set totalCostPowerBilateralBarters 0
set totalMassPowerBilateralBarters 0
set totalMultilateralBarters 0
set maxTime 1461 ; equates to a 4 year development
;
; Create the Number of Instruments as Provided by the Input Slider
;
create-Instruments NUMBERINSTRUMENTS [instrumentSetup]
;
; Set the Instrument ID Values
;
;Let i 1
;ask instruments [
; set ID i
; set i (i + 1)
; ]
end
to instrumentSetup
;
; Set the Initial Instrument Resource Allocations and Utilization Rates
; The Initial Resource Values Are Set to a Uniform Random Value Between 0 and the Value Indicated
; The Resource Utilization Rates are Set to a Random Normal Value, With Mean and Standard Deviation Indicated
;
set initialCost (random 50) + 50
set initialMass (random 50) + 50
set initialPower (random 50) + 50
set deltaCost random-normal 0 60
set deltaMass random-normal 0 46
set deltaPower random-normal 0 47
end
;
; Main Procedure
;
to step
if (tickcount = maxTime) [
displayResults
stop
]
currentResourceValues
doBarter
set tickcount tickcount + 1
end
;
; The Go Procedure
;
to go
step
end
;
; Calculate Final Results.
; Use Monitors to Display Final Cost Growth, Mass Growth, Power Growth
; Use Monitor to Display Final Number of Multi-lateral Barters
; Use Monitors to Display Final Number of Cost-Mass, Mass-Power, Power-Cost Bi-lateral Barters
;
to displayResults
set totalCost 0
set totalInitialCost 0
set totalMass 0
set totalInitialMass 0
set totalPower 0
set totalInitialPower 0
set totalCost sum [cost] of Instruments ; Sum Final Cost of All Instruments
set totalInitialCost sum [initialCost] of Instruments ; Sum Initial Cost of All Instruments
set totalMass sum [mass] of Instruments ; Sum Final Mass of All Instruments
set totalInitialMass sum [initialMass] of Instruments ; Sum Initial Mass of All Instruments
set totalPower sum [power] of Instruments ; Sum Final Power of All Instruments
set totalInitialPower sum [initialPower] of Instruments ; Sum Initial Power of All Instruments
set costGrowth ((totalCost - totalInitialCost) / totalInitialCost) * 100
set massGrowth ((totalMass - totalInitialMass) / totalInitialMass) * 100
set powerGrowth ((totalPower - totalInitialPower) / totalInitialPower) * 100
end
;
; Procedure to Get Current Instrument Cost, Mass and Power Values
;
to currentResourceValues
;
; Calculate Current Cost, Mass and Power Values
; Resource Values Start at the Initial Resource Value at Time = 0, Then Change Linearly
; Between 0 < Time < 0.75 Max Time, Then Stay Constant Until Max Time Is Reached
;
ask Instruments [
let co initialCost
let dc ((deltaCost / 100) * initialCost) / (0.75 * maxTime)
ifelse (tickcount = 0) [
set cost co]
[ ifelse (tickcount > 0.75 * maxTime) [
set cost cost]
[set cost cost + dc]
]
let mo initialMass
let dm ((deltaMass / 100) * initialMass) / (0.75 * maxTime)
ifelse (tickcount = 0) [
set mass mo]
[ifelse (tickcount > 0.75 * maxTime) [
set mass mass]
[set mass mass + dm]
]
let po initialPower
let dp ((deltaPower / 100) * initialPower) / (0.75 * maxTime)
ifelse (tickcount = 0) [
set power po]
[ifelse (tickcount > 0.75 * maxTime) [
set power power]
[set power power + dp]
]
]
end
;
; Main Barter Procedure
;
to doBarter
; Define & Initialize Some Local Variables
let tradeFlag 0
let costHigh 0
let costLow 0
let massHigh 0
let massLow 0
let powerHigh 0
let powerLow 0
let barterMass 0
let barterCost 0
let barterPower 0
;
; Determine Instrument Barter Eligibility
;
ask Instruments [
set mass-cost? false
set cost-mass? false
set mass-power? false
set power-mass? false
set cost-power? false
set power-cost? false
]
ask Instruments [
if (mass > initialMass + (initialMass * THRESHOLD)) and (cost < initialCost - (initialCost * THRESHOLD))
[set mass-cost? true]
if (mass < initialMass - (initialMass * THRESHOLD)) and (cost > initialCost + (initialCost * THRESHOLD))
[set cost-mass? true]
if (mass > initialMass + (initialMass * THRESHOLD)) and (power < initialPower - (initialPower * THRESHOLD))
[set mass-power? true]
if (mass < initialMass - (initialMass * THRESHOLD)) and (power >
initialPower + (initialPower * THRESHOLD))
[set power-mass? true]
if (cost > initialCost + (initialCost * THRESHOLD)) and (power < initialPower - (initialPower * THRESHOLD))
[set cost-power? true]
if (cost < initialCost - (initialCost * THRESHOLD)) and (power > initialPower + (initialPower * THRESHOLD))
[set power-cost? true]
]
;
; Count Up the Number of Instruments Eligible for Barter
;
Set numberEligible ((count Instruments with [mass-cost? = true]) + (count Instruments with [cost-mass? = true]) +
(count Instruments with [mass-power? = true]) + (count Instruments with [power-mass? = true])
+ (count Instruments with [cost-power? = true]) + (count Instruments with [power-cost? = true]))
;
; Conduct M?P? with P?C? with C?M? Multi-lateral Barter
;
if (tradeFlag = 0) [
let candidates nobody
let candidatesList []
set candidates Instruments with [mass-power? = true or power-cost? = true or cost-mass? = true]
set candidatesList (sort candidates)
; Iterate Over Each Instrument Eligible for Mass Power, Power Cost, and Cost Mass Barter
; For Each Pair of Eligible Instruments
; Calculate Mass, Cost and Power Over and Under Utilizations
; Exchange The Average of the Mass, Cost and Power Over and Under Utilizations
; Increment the total number of Multi-lateral Barters
; If no Trade Occurs, Move on to the Next Trade Type
; If a Trade Occurs, Start the doBarter Procedure All Over Again
foreach candidatesList [
let x ?
foreach candidatesList [
let y ?
foreach candidatesList [
let z ?
if (x != y) or (y != z) or (x != z) [
if ([mass-power?] of x = true) and ([power-cost?] of y = true) and ([costmass?] of z = true) [
ask x [
set massHigh mass - initialMass
set powerLow power - initialPower]
ask y [
set powerHigh power - initialPower
set costLow cost - initialCost]
ask z [
set costHigh cost - initialCost
set massLow mass - initialMass]
set barterMass ((massHigh - massLow) / 2)
set barterPower ((powerHigh - powerLow) / 2)
set barterCost ((costHigh - costLow) / 2)
ask x [
set mass mass - barterMass
set power power + barterPower]
ask y [
set power power - barterPower
set cost cost + barterCost]
ask z [
set cost cost - barterCost
set mass mass + barterMass]
;ask x [set mass-power? false]
;ask y [set power-cost? false]
;ask z [set cost-mass? false]
set totalMultilateralBarters totalMultilateralBarters + 1
set tradeFlag 1
]
]
]
]
]
]
if (tradeFlag = 1) [
doBarter
]
;
; Conduct M?P? with P?C? with C?M? Multi-lateral Barter
;
if (tradeFlag = 0) [
let candidates nobody
let candidatesList []
set candidates Instruments with [power-mass? = true or cost-power? = true or mass-cost? = true]
set candidatesList (sort candidates)
; Iterate Over Each Instrument Eligible for Power Mass, Cost Power, and Mass Cost Barter
; For Each Pair of Eligible Instruments
; Calculate Mass, Cost and Power Over and Under Utilizations
; Exchange The Average of the Mass, Cost and Power Over and Under Utilizations
; Increment the total number of Multi-lateral Barters
; If no Trade Occurs, Move on to the Next Trade Type
; If a Trade Occurs, Start the doBarter Procedure All Over Again
foreach candidatesList [
let x ?
foreach candidatesList [
let y ?
foreach candidatesList [
let z ?
if (x != y) or (y != z) or (x != z) [
if ([power-mass?] of x = true) and ([cost-power?] of y = true) and ([masscost?] of z = true) [
ask x [
set massLow mass - initialMass
set powerHigh power - initialPower]
ask y [
set powerLow power - initialPower
set costHigh cost - initialCost]
ask z [
set costLow cost - initialCost
set massHigh mass - initialMass]
set barterMass ((massHigh - massLow) / 2)
set barterPower ((powerHigh - powerLow) / 2)
set barterCost ((costHigh - costLow) / 2)
ask x [
set mass mass + barterMass
set power power - barterPower]
ask y [
set power power + barterPower
set cost cost - barterCost]
ask z [
set cost cost + barterCost
set mass mass - barterMass]
;ask x [set power-mass? false]
;ask y [set cost-power? false]
;ask z [set mass-cost?false]
set totalMultilateralBarters totalMultilateralBarters + 1
set tradeFlag 1
]
]
]
]
]
]
if (tradeFlag = 1) [
doBarter
]
;
; Conduct Mass Cost Bilateral Barter
;
if (tradeFlag = 0) [
let candidates nobody
let candidatesList []
set candidates Instruments with [mass-cost? = true or cost-mass? = true]
set candidatesList (sort candidates)
; Iterate Over Each Instrument Eligible for Mass Cost Barter
; For Each Pair of Mass-Cost and Cost-Mass Eligible Instruments:
; Calculate Mass and Cost Over and Under Utilizations
; Exchange The Average of the Mass and Cost Over and Under Utilizations
; Increment the total number of Cost Mass Bilateral Barters
; If no Trade Occurs, Move on to the Next Trade Type
; If a Trade Occurs, Start the doBarter Procedure All Over Again
foreach candidatesList [
let x ?
foreach candidatesList [
let y ?
if (x != y) [
if ([mass-cost?] of x = true) and ([cost-mass?] of y = true) [
ask x [
set massHigh mass - initialMass
set costLow cost - initialCost]
ask y [
set massLow mass - initialMass
set costHigh cost - initialCost]
set barterMass ((massHigh - massLow) / 2)
set barterCost ((costHigh - costLow) / 2)
ask x [
set mass mass - barterMass
set cost cost + barterCost]
ask y [
set mass mass + barterMass
set cost cost - barterCost]
;ask x [set mass-cost? false]
;ask y [set cost-mass? false]
set totalMassCostBilateralBarters totalMassCostBilateralBarters + 1
set tradeFlag 1
]
]
]
]
]
if (tradeFlag = 1) [
doBarter
]
;
; Conduct Mass Power Bilateral Barter
;
if (tradeFlag = 0) [
let candidates nobody
let candidatesList []
set candidates Instruments with [mass-power? = true or power-mass? = true]
set candidatesList (sort candidates)
; Iterate Over Each Instrument Eligible for Mass Power Barter
; For Each Pair of Mass-Power and Power-Mass Eligible Instruments:
; Calculate Mass and Power Over and Under Utilizations
; Exchange The Average of the Mass and Power Over and Under Utilizations
; Increment the total number of Mass Power Bilateral Barters
; If no Trade Occurs, Move on to the Next Trade Type
; If a Trade Occurs, Start the doBarter Procedure All Over Again
foreach candidatesList [
let x ?
foreach candidatesList [
let y ?
if (x != y) [
if ([mass-power?] of x = true) and ([power-mass?] of y = true) [
ask x [
set massHigh mass - initialMass
set powerLow power - initialPower]
ask y [
set massLow mass - initialMass
set powerHigh power - initialPower]
set barterMass ((massHigh - massLow) / 2)
set barterPower ((powerHigh - powerLow) / 2)
ask x [
set mass mass - barterMass
set power power + barterPower]
ask y [
set mass mass + barterMass
set power power - barterPower]
;ask x [set mass-power? false]
;ask y [set power-mass? false]
set totalMassPowerBilateralBarters totalMassPowerBilateralBarters + 1
set tradeFlag 1
]
]
]
]
]
if (tradeFlag = 1) [
doBarter
]
;
; Conduct Cost Power Bilateral Barter
;
if (tradeFlag = 0) [
let candidates nobody
let candidatesList []
set candidates Instruments with [cost-power? = true or power-cost? = true]
set candidatesList (sort candidates)
; Iterate Over Each Instrument Eligible for Power Cost Barter
; For Each Pair of Power-Cost and Cost-Power Eligible Instruments:
; Calculate Power and Cost Over and Under Utilizations
; Exchange The Average of the Power and Cost Over and Under Utilizations
; Increment the total number of Cost Power Bilateral Barters
; If no Trade Occurs, Exit the doBarter Procedure and Increment Time in the Step Procedure
; If a Trade Occurs, Start the doBarter Procedure All Over Again
foreach candidatesList [
let x ?
foreach candidatesList [
let y ?
if (x != y) [
if ([cost-power?] of x = true) and ([power-cost?] of y = true) [
ask x [
set costHigh cost - initialCost
set powerLow power - initialPower]
ask y [
set costLow cost - initialCost
set powerHigh power - initialPower]
set barterCost ((costHigh - costLow) / 2)
set barterPower ((powerHigh - powerLow) / 2)
ask x [
set cost cost - barterCost
set power power + barterPower]
ask y [
set cost cost + barterCost
set power power - barterPower]
;ask x [set cost-power? false]
;ask y [set power-cost? false]
set totalCostPowerBilateralBarters totalCostPowerBilateralBarters + 1
set tradeFlag 1
]
]
]
]
]
if (tradeFlag = 1) [
doBarter
]
end