铛铛!小秘籍来咯!
小秘籍希望大家都能轻松建模呀,华数杯也会持续给大家放送思路滴~
抓紧小秘籍,我们出发吧~
2024年MCM问题A:资源可用性和性别比例
在自然界,有些动物物种存在除了常见的雄性和雌性之外的性别,但大多数物种主要是雄性或雌性。尽管许多物种在出生时表现出1:1的性别比例,但其他物种会偏离均等的性别比例,这被称为适应性性别比例变异。例如,美国鳄鱼的巢穴温度会影响出生时的性别比例。
对于七鳃鳗的角色是复杂的。在一些湖泊栖息地中,它们被视为对生态系统产生重要影响的寄生虫,而在世界一些地区,如斯堪的纳维亚、波罗的海地区以及北美太平洋西北部的一些土著民族中,七鳃鳗也是一种食物来源。
七鳃鳗的性别比例可以根据外部环境而变化。七鳃鳗在幼虫阶段的生长速度决定其性别,而这些幼虫的生长速度受食物可用性的影响。在食物可用性较低的环境中,生长速度较慢,雄性的比例可能达到人口的约78%。而在食物更充足的环境中,雄性的比例观察到约为人口的56%。
我们关注七鳃鳗的性别比例及其对当地条件的依赖性,具体是湖泊或海洋栖息地的七鳃鳗。七鳃鳗生活在湖泊或海洋栖息地,并沿河上迁移产卵。任务是研究一个物种能够根据资源可用性改变其性别比例时,对生态系统中相互作用的影响。
要探讨的问题包括:
你的PDF解决方案总页数不得超过25页,包括:
在报告中,需明确使用的AI工具,包括模型和目的,并在文中引用和在参考文献中列出所有使用的AI工具。如果使用AI工具,请在报告结束后添加一个名为“AI使用报告”的新部分,无页数限制,不计入总页数限制。
当鳗鱼种群能够改变其性别比例时,对更大的生态系统有何影响?
基于代理的建模详细分析:
1. 代理属性定义:
2. 代理行为规则定义:
3. 影响性别比例的因素:
4. 代理交互规则定义:
5. 可能的公式:
Agent-Based Modeling (ABM) 简介:
ABM是一种建模方法,通过模拟个体代理的行为和相互作用,以理解整体系统的行为。在这个场景中,每个鳗鱼个体都是代理,其行为受到模型中定义的规则和环境条件的影响。
ABM的核心思想是将系统建模为一组具有独特属性和行为规则的个体,这些个体根据模拟的时间步骤进行交互。通过观察个体之间的相互作用,可以了解整体系统是如何演变的。
在我们的模型中,代理(鳗鱼个体)的行为受到食物可用性、年龄、性别和竞争等因素的影响。通过迭代模拟这些代理的行为,我们可以观察到整个鳗鱼种群中性别比例的变化,并探讨这种变化对生态系统的影响。
ABM提供了一种灵活的方法,可以模拟复杂系统中个体之间的相互作用,从而更好地理解整个系统的动态。
import random
import matplotlib.pyplot as plt
class EelAgent:
def __init__(self, gender, age, growth_rate):
self.gender = gender
self.age = age
self.growth_rate = growth_rate
def calculate_competition_factor():
# Placeholder for competition factor calculation
return random.uniform(0.2, 0.8)
def calculate_age_factor(eel):
# Placeholder for age factor calculation
return 0.8 if eel.age < 5 else 0.2
#省略部分见完整版
def visualize_population(eel_population, timestep):
# Simple bar chart to visualize gender distribution
genders = [eel.gender for eel in eel_population]
plt.figure()
plt.title(f"Population Distribution at Timestep {timestep}")
plt.hist(genders, bins=['Male', 'Female', 'Unknown'], color=['blue', 'pink', 'gray'])
plt.show()
# Simulation parameters
population_size = 100
food_availability = 0.8
simulation_duration = 10
# Initialize a population of EelAgents
eel_population = [EelAgent(random.choice(['Male', 'Female']), 0, 1.0) for _ in range(population_size)]
# Simulation loop
for timestep in range(simulation_duration):
for eel in eel_population:
# Eel's behavior: Acquire food based on food availability and competition
eel.growth_rate = food_availability * (1 - calculate_competition_factor())
# Eel's behavior: Reproduce based on age, gender, and competition
new_eel = eel.reproduce(calculate_age_factor(eel), calculate_gender_factor(eel), calculate_competition_factor())
if new_eel:
eel_population.append(new_eel)
# Visualize the population at each timestep
visualize_population(eel_population, timestep)
在上述Python示例中,我们使用了Matplotlib库来创建简单的直方图,以可视化鳗鱼种群的性别分布。下面是如何更详细地可视化:
进化过程的可视化: 可以通过绘制种群中每个鳗鱼个体的属性随时间的演变来了解整个进化过程。例如,可以在每个时间步骤结束后记录种群中鳗鱼个体的年龄、性别、生长速率等,并使用折线图或散点图来表示这些属性的变化。
生长速率分布: 可以绘制种群中鳗鱼个体的生长速率分布,以了解生长速率在整个种群中的分布情况。这可以通过直方图或核密度估计图来实现。
种群大小随时间的变化: 可以通过追踪每个时间步骤后的种群大小,并绘制种群大小随时间的变化曲线。这有助于了解模拟过程中种群的增长或减小趋势。
import random
import matplotlib.pyplot as plt
class EelAgent:
def __init__(self, gender, age, growth_rate):
self.gender = gender
self.age = age
self.growth_rate = growth_rate
def calculate_competition_factor():
return random.uniform(0.2, 0.8)
def calculate_age_factor(eel):
return 0.8 if eel.age < 5 else 0.2
def calculate_gender_factor(eel):
return 0.7 if eel.gender == 'Female' else 0.3
def visualize_population(eel_population, timestep):
# Simple bar chart to visualize gender distribution
genders = [eel.gender for eel in eel_population]
plt.figure(figsize=(10, 5))
plt.subplot(1, 2, 1)
plt.title(f"Population Distribution at Timestep {timestep}")
plt.hist(genders, bins=['Male', 'Female', 'Unknown'], color=['blue', 'pink', 'gray'])
# Evolution process visualization
ages = [eel.age for eel in eel_population]
growth_rates = [eel.growth_rate for eel in eel_population]
plt.subplot(1, 2, 2)
plt.title("Evolution Process")
plt.plot(ages, label='Age')
plt.plot(growth_rates, label='Growth Rate')
plt.legend()
plt.show()
def visualize_growth_rate_distribution(eel_population):
growth_rates = [eel.growth_rate for eel in eel_population]
plt.figure(figsize=(8, 5))
plt.title("Growth Rate Distribution")
plt.hist(growth_rates, bins=20, color='green', alpha=0.7)
plt.xlabel("Growth Rate")
plt.ylabel("Frequency")
plt.show()
# Simulation parameters
population_size = 100
food_availability = 0.8
simulation_duration = 10
# Initialize a population of EelAgents
eel_population = [EelAgent(random.choice(['Male', 'Female']), 0, 1.0) for _ in range(population_size)]
# Simulation loop
for timestep in range(simulation_duration):
for eel in eel_population:
eel.growth_rate = food_availability * (1 - calculate_competition_factor())
new_eel = eel.reproduce(calculate_age_factor(eel), calculate_gender_factor(eel), calculate_competition_factor())
if new_eel:
eel_population.append(new_eel)
# Visualize the population at each timestep
visualize_population(eel_population, timestep)
# Visualize growth rate distribution at the end of simulation
visualize_growth_rate_distribution(eel_population)
我们添加了一个新的函数 visualize_growth_rate_distribution
来绘制种群中鳗鱼个体生长速率的分布情况。同时, visualize_population
函数现在包括了演化过程的可视化。
鳗鱼种群的优势和劣势是什么?
使用Agent-Based Modeling (ABM) 解决问题二的建模思路(使用字母表示的具体公式):
在建模过程中,我们使用字母来表示不同的变量和参数,以提高模型的可读性和通用性。以下是建模思路中的公式,使用字母表示:
1. 代理属性定义:
import numpy as np
import matplotlib.pyplot as plt
class EelAgent:
def __init__(self, gender, age, reproduction_state, resource_need):
self.gender = gender
self.age = age
self.reproduction_state = reproduction_state
self.resource_need = resource_need
def acquire_resource(self, environment_availability, competition_factor, neighbors_resource):
acquired_resource = self.resource_need * environment_availability - competition_factor * np.sum(neighbors_resource)
return acquired_resource
def reproduce(self, reproduction_competition_factor, acquired_resource):
reproduction_success_rate = reproduction_competition_factor * acquired_resource
return np.random.rand() < reproduction_success_rate
def adjust_gender_ratio(self, gender_adjust_factor, environment_availability, base_threshold):
new_male_ratio = gender_adjust_factor * (environment_availability - base_threshold)
return new_male_ratio
#部分省略见完整版
def simulate_step(self):
environment_availability = np.random.rand() # Placeholder for environmental changes
competition_factor = np.random.rand() # Placeholder for competition changes
neighbors_resource = [agent.resource_need for agent in self.agents]
for agent in self.agents:
acquired_resource = agent.acquire_resource(environment_availability, competition_factor, neighbors_resource)
if agent.reproduce(self.reproduction_competition_factor, acquired_resource):
self.agents.append(EelAgent(gender=np.random.choice(['Male', 'Female']),
age=0,
reproduction_state=False,
resource_need=np.random.rand()))
new_male_ratio = agent.adjust_gender_ratio(self.gender_adjust_factor, environment_availability, self.base_threshold)
# Adjust gender ratio (not implemented in this simplified example)
# Parameters
population_size = 100
time_steps = 100
base_resource_rate = 0.5
base_reproduction_rate = 0.2
base_male_ratio = 0.5
reproduction_competition_factor = 0.3
gender_adjust_factor = 0.1
base_threshold = 0.3
# Initialize population
eel_population = EelPopulation(size=population_size,
base_resource_rate=base_resource_rate,
base_reproduction_rate=base_reproduction_rate,
base_male_ratio=base_male_ratio,
reproduction_competition_factor=reproduction_competition_factor,
gender_adjust_factor=gender_adjust_factor,
base_threshold=base_threshold)
# Simulation loop
for step in range(time_steps):
eel_population.simulate_step()
# Data collection and visualization (not shown in this simplified example)
在这个模型中,可视化可以帮助理解模拟过程中鳗鱼种群的变化。以下是一个可视化代码,展示种群大小和性别比例随时间的变化。
import matplotlib.pyplot as plt
class EelPopulation:
# ... (之前的代码保持不变)
def visualize(self, step):
male_count = sum(1 for agent in self.agents if agent.gender == 'Male')
female_count = sum(1 for agent in self.agents if agent.gender == 'Female')
plt.figure(figsize=(10, 5))
plt.subplot(1, 2, 1)
plt.plot(range(step + 1), [len(self.agents)] * (step + 1), label='Total Population')
plt.title('Total Population over Time')
plt.xlabel('Time Steps')
plt.ylabel('Population Size')
plt.legend()
plt.subplot(1, 2, 2)
plt.plot(range(step + 1), [male_count / len(self.agents)] * (step + 1), label='Male Ratio')
plt.plot(range(step + 1), [female_count / len(self.agents)] * (step + 1), label='Female Ratio')
plt.title('Gender Ratio over Time')
plt.xlabel('Time Steps')
plt.ylabel('Gender Ratio')
plt.legend()
plt.tight_layout()
plt.show()
# Parameters (保持不变)
# Initialize population
eel_population = EelPopulation(size=population_size,
base_resource_rate=base_resource_rate,
base_reproduction_rate=base_reproduction_rate,
base_male_ratio=base_male_ratio,
reproduction_competition_factor=reproduction_competition_factor,
gender_adjust_factor=gender_adjust_factor,
base_threshold=base_threshold)
# Simulation loop
for step in range(time_steps):
eel_population.simulate_step()
eel_population.visualize(step)
这段代码中,我添加了一个 visualize
方法,该方法绘制了两个子图,一个显示总体种群大小随时间的变化,另一个显示雄性和雌性比例随时间的变化。在每个时间步骤结束时,都会调用 visualize
方法进行可视化。
解决问题三涉及评估鳗鱼性别比例变化对生态系统稳定性的影响。这可以通过Agent-Based Modeling (ABM)的模拟和对模拟结果的分析来实现。以下是一种可能的建模思路:
R a = N × E − C × ∑ i = 1 N R n i R_a = N \times E - C \times \sum_{i=1}^{N} R_{n_i} Ra=N×E−C×i=1∑NRni
R s = R r × R c × R a R_s = R_r \times R_c \times R_a Rs=Rr×Rc×Ra
R e p r o d u c e = random ( 0 , 1 ) < R s Reproduce = \text{random}(0, 1) < R_s Reproduce=random(0,1)<Rs
N e w _ M R = B M R + G A R × ( E − B T ) New\_MR = BMR + GAR \times (E - BT) New_MR=BMR+GAR×(E−BT)
初始化:
时间步骤循环:
数据收集:
性别比例的影响:
生态系统稳定性的评估:
灵敏度分析:
Agent-Based Modeling (ABM):
数学模型:
import random
class Lamprey:
def __init__(self, gender, age, reproduction_status, resource_need):
self.gender = gender
self.age = age
self.reproduction_status = reproduction_status
self.resource_need = resource_need
def initialize_population(population_size):
population = []
for _ in range(population_size):
gender = random.choice(['M', 'F'])
age = random.randint(1, 5)
reproduction_status = random.choice([True, False])
resource_need = random.uniform(0.5, 1.5)
lamprey = Lamprey(gender, age, reproduction_status, resource_need)
population.append(lamprey)
return population
def calculate_resource_acquisition(agent, environment_availability, competition_factor):
neighbor_resources = [random.uniform(0, 2) for _ in range(5)] # Example: 5 neighbors
acquired_resource = agent.resource_need * environment_availability - competition_factor * sum(neighbor_resources)
return acquired_resource
def calculate_reproduction_success(agent, base_reproduction_rate, reproduction_competition_factor, acquired_resource):
reproduction_success_rate = base_reproduction_rate * reproduction_competition_factor * acquired_resource
return random.random() < reproduction_success_rate
def adjust_gender_ratio(base_male_ratio, gender_adjust_factor, environment_availability, base_threshold):
new_male_ratio = base_male_ratio + gender_adjust_factor * (environment_availability - base_threshold)
return max(0, min(1, new_male_ratio)) # Ensure the ratio is between 0 and 1
def simulate_one_time_step(population, environment_availability, competition_factor,
base_reproduction_rate, reproduction_competition_factor,
base_male_ratio, gender_adjust_factor, base_threshold):
for agent in population:
acquired_resource = calculate_resource_acquisition(agent, environment_availability, competition_factor)
if agent.reproduction_status:
reproduction_success = calculate_reproduction_success(agent, base_reproduction_rate,
#省略部分见完整版
# Adjust gender of existing population based on the new ratio
for agent in population:
if agent.gender == 'M' and random.random() > new_male_ratio:
agent.gender = 'F'
elif agent.gender == 'F' and random.random() > (1 - new_male_ratio):
agent.gender = 'M'
return population
# Example simulation parameters
initial_population_size = 100
environment_availability = 1.0
competition_factor = 0.2
base_reproduction_rate = 0.1
reproduction_competition_factor = 0.5
base_male_ratio = 0.5
gender_adjust_factor = 0.1
base_threshold = 0.8
# Initialize population
population = initialize_population(initial_population_size)
# Run simulation for multiple time steps
for _ in range(10):
population = simulate_one_time_step(population, environment_availability, competition_factor,
base_reproduction_rate, reproduction_competition_factor,
base_male_ratio, gender_adjust_factor, base_threshold)
# Print final population
for agent in population:
print(f"Gender: {agent.gender}, Age: {agent.age}, Reproduction Status: {agent.reproduction_status}")
在 Python 中,你可以使用 matplotlib
或 seaborn
等库进行数据可视化。
import matplotlib.pyplot as plt
def plot_gender_ratio_over_time(gender_ratios):
time_steps = range(len(gender_ratios))
plt.plot(time_steps, gender_ratios, label='Male Ratio')
plt.xlabel('Time Steps')
plt.ylabel('Male Ratio')
plt.title('Male Ratio Over Time')
plt.legend()
plt.show()
# Example simulation parameters
initial_population_size = 100
environment_availability = 1.0
competition_factor = 0.2
base_reproduction_rate = 0.1
reproduction_competition_factor = 0.5
base_male_ratio = 0.5
gender_adjust_factor = 0.1
base_threshold = 0.8
# Initialize population
population = initialize_population(initial_population_size)
# Run simulation for multiple time steps
male_ratios_over_time = []
for _ in range(10):
population = simulate_one_time_step(population, environment_availability, competition_factor,
base_reproduction_rate, reproduction_competition_factor,
base_male_ratio, gender_adjust_factor, base_threshold)
# Calculate and store male ratio at each time step
male_ratio = sum(1 for agent in population if agent.gender == 'M') / len(population)
male_ratios_over_time.append(male_ratio)
# Visualize the results
plot_gender_ratio_over_time(male_ratios_over_time)
除了折线图,还可以考虑使用其他类型的可视化工具。
import matplotlib.pyplot as plt
ages = [agent.age for agent in population]
reproduction_success_rates = [calculate_reproduction_success(agent, base_reproduction_rate, reproduction_competition_factor,
calculate_resource_acquisition(agent, environment_availability, competition_factor)) for agent in population]
plt.scatter(ages, reproduction_success_rates, alpha=0.5)
plt.xlabel('Age')
plt.ylabel('Reproduction Success Rate')
plt.title('Scatter Plot of Age vs. Reproduction Success Rate')
plt.show()
import matplotlib.pyplot as plt
resource_needs = [agent.resource_need for agent in population]
plt.hist(resource_needs, bins=20, alpha=0.5)
plt.xlabel('Resource Needs')
plt.ylabel('Frequency')
plt.title('Histogram of Resource Needs')
plt.show()
import matplotlib.pyplot as plt
male_ages = [agent.age for agent in population if agent.gender == 'M']
female_ages = [agent.age for agent in population if agent.gender == 'F']
plt.boxplot([male_ages, female_ages], labels=['Male', 'Female'])
plt.ylabel('Age')
plt.title('Boxplot of Age by Gender')
plt.show()
代理属性定义:
代理属性定义:
代理属性定义:
寄生虫代理属性定义:
import random
class Lamprey:
def __init__(self, resource_need, reproduction_rate, reproduction_competition, gender_ratio_adjustment, gender_threshold):
self.resource_need = resource_need
self.reproduction_rate = reproduction_rate
self.reproduction_competition = reproduction_competition
self.gender_ratio_adjustment = gender_ratio_adjustment
self.gender_threshold = gender_threshold
self.gender = random.choice(['M', 'F'])
self.reproduction_status = False # Initially not in reproductive state
def initialize_population(population_size):
return [Lamprey(random.uniform(0.5, 1.5), random.uniform(0.1, 0.5), random.uniform(0.1, 0.5), random.uniform(0.01, 0.1), random.uniform(0.5, 1.5)) for _ in range(population_size)]
def calculate_resource_acquisition(agent, environment_availability, competition_factor, neighbor_resources):
acquired_resource = agent.resource_need * environment_availability - competition_factor * sum(neighbor_resources)
return max(0, acquired_resource)
def calculate_reproduction_success(agent, acquired_resource):
reproduction_success_rate = agent.reproduction_rate * agent.reproduction_competition * acquired_resource
return random.random() < reproduction_success_rate
def adjust_gender_ratio(base_male_ratio, gender_adjust_factor, environment_availability, base_threshold):
new_male_ratio = base_male_ratio + gender_adjust_factor * (environment_availability - base_threshold)
return max(0, min(1, new_male_ratio))
#省略部分见完整版
for agent in population:
if agent.gender == 'M' and random.random() > new_male_ratio:
agent.gender = 'F'
elif agent.gender == 'F' and random.random() > (1 - new_male_ratio):
agent.gender = 'M'
return population, new_male_ratio
# Example simulation parameters
initial_population_size = 100
environment_availability = 1.0
competition_factor = 0.2
base_male_ratio = 0.5
gender_adjust_factor = 0.1
base_threshold = 0.8
# Initialize population
population = initialize_population(initial_population_size)
# Run simulation for multiple time steps
male_ratios_over_time = []
for _ in range(10):
population, male_ratio = simulate_one_time_step(population, environment_availability, competition_factor, base_male_ratio, gender_adjust_factor, base_threshold)
male_ratios_over_time.append(male_ratio)
# Print final population
for agent in population:
print(f"Gender: {agent.gender}, Reproduction Status: {agent.reproduction_status}")
# Print male ratio over time
print("Male Ratios Over Time:", male_ratios_over_time)
可视化:
def plot_resource_vs_reproduction(population):
resource_acquisitions = [calculate_resource_acquisition(agent, environment_availability, competition_factor, [random.uniform(0, 2) for _ in range(5)]) for agent in population]
reproduction_success_rates = [calculate_reproduction_success(agent, resource_acquisition) for agent in population]
plt.scatter(resource_acquisitions, reproduction_success_rates, alpha=0.5)
plt.xlabel('Resource Acquisition')
plt.ylabel('Reproduction Success Rate')
plt.title('Scatter Plot of Resource Acquisition vs. Reproduction Success Rate')
plt.show()
# 在每个时间步骤后调用
plot_resource_vs_reproduction(population)
def plot_resource_distribution(population):
resource_acquisitions = [calculate_resource_acquisition(agent, environment_availability, competition_factor, [random.uniform(0, 2) for _ in range(5)]) for agent in population]
plt.hist(resource_acquisitions, bins=20, alpha=0.5)
plt.xlabel('Resource Acquisition')
plt.ylabel('Frequency')
plt.title('Histogram of Resource Acquisition')
plt.show()
# 在每个时间步骤后调用
plot_resource_distribution(population)
def plot_age_distribution_by_gender(population):
male_ages = [agent.age for agent in population if agent.gender == 'M']
female_ages = [agent.age for agent in population if agent.gender == 'F']
plt.boxplot([male_ages, female_ages], labels=['Male', 'Female'])
plt.ylabel('Age')
plt.title('Boxplot of Age by Gender')
plt.show()
# 在每个时间步骤后调用
plot_age_distribution_by_gender(population)
美赛跟紧小秘籍冲冲冲!!更多内容可以点击下方名片详细了解!
记得关注 数学建模小秘籍打开你的数学建模夺奖之旅!