Problem
A grizzly bear stands in the shallows of a river during salmon spawning season. Precisely once every hour, a fish swims within its reach. The bear can either catch the fish and eat it, or let it swim past to safety. This grizzly is, as many grizzlies are, persnickety. Itβll only eat fish that are at least as big as every fish it ate before.
Each fish weighs some amount, randomly and uniformly distributed between 0 and 1 kilogram. (Each fishβs weight is independent of the others, and the skilled bear can tell how much each weighs just by looking at it.) The bear wants to maximize its intake of salmon, as measured in kilograms. Suppose the bearβs fishing expedition is two hours long. Under what circumstances should it eat the first fish within its reach? What if the expedition is three hours long?
Solution
Let be the random variable denoting the weight of fish seen each hour where .
We have for .
Greedy Strategy
By following the Greedy Strategy, the bear eats as much salmon as it can starting with the first salmon in the first hour.
Let be the weight of the fish consumed in the hour using the greedy strategy.
We have the following equations for the greedy strategy:
The distribution function and the density function of a random variable are given by
where and .
From the above, we have
The expectation of can be calculated as follows
From the above, we have
Two hour expedition
To get the average total weight of salmon consumed by bear in hours under the greedy strategy we need to calculate .
Three hour expedition
To get the average total weight of salmon consumed by bear in hours under the greedy strategy we need to calculate .
Monte Carlo Simulation
from random import random
runs = 100000
total_weight = 0
for _ in range(runs):
r1, r2 = random(), random()
total_weight += r1
if r2 > r1:
total_weight += r2
print("Avg weight of fish consumed in 2 hrs :", total_weight/runs)
total_weight = 0
for _ in range(runs):
r1, r2, r3 = random(), random(), random()
total_weight += r1
if r2 > r1:
total_weight += r2
if r3 > r2:
total_weight += r3
elif r3 > r1:
total_weight += r3
print("Avg weight of fish consumed in 3 hrs :", total_weight/runs)