Mahsa soltani
Mahsa soltani

Reputation: 25

how can i find the exact tick in netlogo in which agents take an action?


I have agents that their devices may face failure randomly and based on the probability of failure. (working-devices? false) when the device does not work, I should calculate the summary of waiting-time till now and then update the status of the device (working-devices? true).

My problem is in update part. let assume the waiting-time = 1 and we are in tick = 10 that working-device? become false, and we do our model for 365 days(ticks). In updating, I should let my status became true if tick > 11 ( 10 + 1 ). 11 means (the-tick + waiting time).

My questions is how can I understand in which tick the status became false? and what is the best way to write my update procedure?

;; waiting-time is slider (for example ) 1

breed [ customers customer] 
....

customers-own [device-working? real-waiting-time? ... ]

to setup
....
ask customers [
 set real-waiting-time 0
 set device-working? true
.....
]
end

to go
  if ticks < 365  [
  ask customers [if (device-working? = true)
  [ impose update]
 ]

to impose 
 if random 100 > 95
 [set device-working? false
  set real-waiting-time real-waiting-time + waiting-time ]
end

to update
;; let the-tick when devices of customers faces failure
;; if tick > the-tick + waiting-time-slider and device-working? = false 
;; [set device-working? true]

end

Upvotes: 1

Views: 76

Answers (1)

JenB
JenB

Reputation: 17678

What you need to store is add another attribute for each customer that stores the tick at which it failed or when it is fixed. I have taken the latter approach and called that attribute end-waiting-time (NOT tested).

to impose 
 if random 100 > 95
 [set device-working? false
  set real-waiting-time real-waiting-time + waiting-time
  set end-waiting-time ticks + waiting-time]      ; this is the new line
end

to update
  if device-working? = false tick and ticks = end-waiting-time
  [ set device-working? true ]
end

Upvotes: 2

Related Questions