酒吧博弈模拟
一、实验目的:
学习用计算机模拟博弈问题。
二、实验要求:
编程实现对酒吧博弈的模拟。
小镇居民的决策行为通过编写随机函数或实现简单的智能体来模拟。
输出图表,展示模拟效果(一年内去酒吧人数,居民的平均幸福度等)。
分析结果,得出结论。
import random
import matplotlib.pyplot as plt
import numpy as np
import scipy.signal
YEAR=365
happinessindex=0.5
def bar_problem(num_people, capacity):
Numberpeople=[]
Happinessindex=[]
num_at_bar = 0
for m in range(YEAR):
for i in range(num_people):
Serviceattitude=random.random()
if num_at_bar + 1 <= capacity:
num_at_bar += 1
if happinessindex < Serviceattitude and m==0:
num_people-=1
Happinessindex.append(Serviceattitude)
elif happinessindex >= Serviceattitude and m == 0:
Happinessindex.append(Serviceattitude)
if random.random() &l