CS计算机代考程序代写 # Data

# Data
psing = .004
pforage = .6
restfood = 3.6
foodpatch = 32

def singfood(i):
return 12 + .002*i

def foragefood(i):
return 8 + .007*i

def SongD(t,x,m):
if x < 0: i = int(x) - 1 else: i = int(x) p = x - i return p*Song(t,i+1,m)[0] + (1-p)*Song(t,i,m)[0] def SongB(t,i,m): return .25*SongD(t,i-6.4,m) + .5*SongD(t,i,m) + .25*SongD(t,i+6.4,m) _Song = {} def Song(t,i,m): if i <= 0: return (0, 'Dead') elif t == 150: if m == 'Y': return (2, 'Mate') else: return (1, 'Lonely') else: if (t,i,m) not in _Song: if t >= 75:
_Song[t,i,m] = (SongD(t+1,i-restfood,m), ‘ZZZ’)
else:
rest = SongD(t+1,i-restfood,m)
sing = psing*SongB(t+1,i-singfood(i),’Y’) + \
(1-psing)*SongB(t+1,i-singfood(i),m)
forage = pforage*SongB(t+1,i-foragefood(i)+foodpatch,m) + \
(1-pforage)*SongB(t+1,i-foragefood(i),m)
_Song[t,i,m] = max((rest,’ZZZ’),(sing,’Sing’),(forage,’Forage’))
return _Song[t,i,m]

def SingThreshold(t):
i = 1
while Song(t,i,’N’)[1] != ‘Sing’:
i += 1
return i

import pylab
thresholds = [SingThreshold(t) for t in range(75)]
pylab.plot(range(75),thresholds)
pylab.xlabel(‘Time period’)
pylab.ylabel(‘Food reserve required to sing’)
pylab.show()