-
Notifications
You must be signed in to change notification settings - Fork 2
/
updateDwellingState.m
executable file
·26 lines (22 loc) · 1.06 KB
/
updateDwellingState.m
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
function dwellLogInd = updateDwellingState(dwellLogInd,k_dwell,k_undwell,dkdN_dwell,dkdN_undwell,num_nbr_per_node,dT)
% updates movement state of worm based on specified rates of
% entering/leaving the dwelling state
% fast worms start dwelling with rate k_dwell + dkdN_dwell*num_nbr_per_node
if any(~dwellLogInd)
speeders = find(~dwellLogInd);
dwellrate = k_dwell + dkdN_dwell.*num_nbr_per_node;
starters = logical(poissrnd(dwellrate(speeders)*dT,numel(speeders),1));
dwellLogInd(speeders(starters)) = true;
end
% dwelling worms stop dwelling with rate k_undwell, decreasing
% exponentially with more neighbours
% NOTE: thsi current implentation allows worms that just stopped to speed
% up again. you may not want this, but it's currently kept for backwards
% compatibility (consistency with previous results)
if any(dwellLogInd)
dwellers = find(dwellLogInd);
undwellrate = k_undwell*exp(-dkdN_undwell.*num_nbr_per_node);
stoppers = logical(poissrnd(undwellrate(dwellers)*dT,numel(dwellers),1));
dwellLogInd(dwellers(stoppers)) = false;
end
end