2024 美国大学生数学建模竞赛(B题)寻找潜水艇问题 | 建模秘籍&文章代码思路大全

铛铛!小秘籍来咯!

深海探险新篇章!小秘籍团队创造性解决MCMS深海搜救挑战。利用卡尔曼滤波、蚁群、遗传算法等创新手段,打造高效搜救模型。准确定位、智能设备部署、多目标协同,一网打尽。小秘籍团队,为深海探险保驾护航,开创深蓝新领域!

美赛B题,抓紧小秘籍,我们出发吧~

完整内容可以在文章末尾领取!
在这里插入图片描述

问题重述

问题 B:寻找潜水艇

Maritime Cruises Mini-Submarines(MCMS)是一家希腊公司,专门制造能够携带人类深入海洋最深处的潜水艇。这些潜水艇可以从母船处脱离,无需连接线进行操作。MCMS现在计划利用他们的潜水艇带游客探险爱奥尼亚海底寻找沉船残骸。然而,在此之前,他们需要赢得监管机构的批准,以制定在与母船失去通信和可能的机械故障(包括潜水艇推进失效)情况下的安全程序。特别是,他们希望你开发一个模型来预测潜水艇随时间的位置。与在陆地或海面进行典型搜救不同,有问题的潜水艇可能会位于海底或水中某个中性浮力点。其位置可能受到洋流、海水不同密度以及海底地理的影响。您的任务包括:

  • 定位 - 制定一个或多个模型,以预测潜水艇随时间的位置。

    • 针对这些预测,有哪些不确定性?
    • 在事故发生之前,潜水艇可以周期性地向母船发送什么信息,以减小这些不确定性?潜水艇需要什么样的设备来实现这一点?
  • 准备 - 如果需要,您将建议公司携带什么样的额外搜索设备并在主船上进行部署?

    • 您可能会考虑不同类型的设备,但也必须考虑与可用性、维护、准备和使用这些设备相关的成本。救援船需要携带什么额外的设备以在必要时提供帮助?
  • 搜索 - 制定一个模型,该模型将使用您的位置模型信息,为设备的初始部署点和搜索模式推荐,以最小化寻找失去的潜水艇所需的时间。确定随时间和累积搜索结果的条件下找到潜水艇的概率。

  • 推演 - 如何扩展您的模型以考虑其他旅游目的地,如加勒比海?您的模型将如何调整以考虑在相同区域移动的多个潜水艇?

请准备一份不超过25页的报告,详细介绍您的计划。包括一份两页的备忘录,地址写给希腊政府,以帮助赢得批准。

问题一

我们用卡尔曼滤波器来解决这一题。

卡尔曼滤波器是一种递归的状态估计算法,广泛应用于动态系统中,特别适用于线性系统。在潜水艇位置预测问题中,使用卡尔曼滤波器有以下优势:

  1. 融合传感器数据: 卡尔曼滤波器能够有效地融合多传感器数据,如潜水艇上的GPS、水深传感器等,以提高对状态的估计准确性。这对于在海洋环境中的潜水艇而言尤为重要,因为海洋环境可能会引入多种不确定性。

  2. 实时更新: 卡尔曼滤波器是一种递归算法,能够在不断接收新的观测数据时实时更新状态估计。这对于潜水艇来说尤为关键,因为海洋环境可能随时发生变化,需要实时适应。

  3. 优化预测: 卡尔曼滤波器通过考虑系统的动态模型和观测数据,优化状态的预测。对于潜水艇而言,这意味着更准确地预测未来位置,有助于规划行动和避免潜在的危险。

  4. 处理不确定性: 卡尔曼滤波器能够有效处理状态估计的不确定性。在潜水艇运动的情况下,由于海洋环境的复杂性,存在各种不确定性,卡尔曼滤波器通过动态地调整状态的不确定性协方差矩阵来适应这些不确定性。

  5. 计算效率: 卡尔曼滤波器的计算相对较轻量,适用于嵌入式系统或有计算资源限制的环境。这使得它成为在实际潜水艇设备上部署的一种合适的算法。

总体而言,卡尔曼滤波器在对状态进行估计和预测方面具有较强的性能,特别适用于需要实时更新和融合多传感器数据的动态系统。

建模思路:

问题一:定位 - 制定一个或多个模型,以预测潜水艇随时间的位置。

在解决潜水艇位置预测问题上,我们选择使用卡尔曼滤波器,这是一种适用于动态系统的强大算法,特别适用于潜水艇在海洋环境中的运动。以下是我们的建模思路:

1. 状态定义:

我们定义潜水艇的状态为一个包含位置和速度的状态向量,表示为 X t = [ x t , v t ] T X_t = [x_t, v_t]^T Xt=[xt,vt]T,其中 x t x_t xt 是位置, v t v_t vt 是速度。

2. 系统动态模型:

建立潜水艇的运动方程,采用简单的匀速直线运动模型:
X t + 1 = F ⋅ X t + B ⋅ U t + ϵ t X_{t+1} = F \cdot X_t + B \cdot U_t + \epsilon_t Xt+1=FXt+BUt+ϵt
其中, F F F 是状态转移矩阵, B B B 是控制输入矩阵, U t U_t Ut 是外部控制输入, ϵ t \epsilon_t ϵt 是过程噪声。

3. 观测模型:

定义观测方程,表示如何通过传感器观测潜水艇的状态:
Z t = H ⋅ X t + δ t Z_t = H \cdot X_t + \delta_t Zt=HXt+δt
其中, H H H 是观测矩阵, Z t Z_t Zt 是观测值, δ t \delta_t δt 是观测噪声。

4. 初始状态和协方差矩阵:

定义初始状态估计 X 0 X_0 X0 和初始协方差矩阵 P 0 P_0 P0,即对潜水艇状态的初始不确定性的估计。

5. 卡尔曼增益计算:

利用系统动态模型和观测模型计算卡尔曼增益 K t K_t Kt
K t = P t ⋅ H T ⋅ ( H ⋅ P t ⋅ H T + R ) − 1 K_t = P_t \cdot H^T \cdot (H \cdot P_t \cdot H^T + R)^{-1} Kt=PtHT(HPtHT+R)1
其中, P t P_t Pt 是状态协方差矩阵, R R R 是观测噪声协方差矩阵。

6. 状态更新:

利用观测值和卡尔曼增益来更新状态估计和协方差矩阵:
X t = X t + K t ⋅ ( Z t − H ⋅ X t ) X_{t} = X_{t} + K_t \cdot (Z_{t} - H \cdot X_{t}) Xt=Xt+Kt(ZtHXt)
P t = ( I − K t ⋅ H ) ⋅ P t P_{t} = (I - K_t \cdot H) \cdot P_{t} Pt=(IKtH)Pt
其中, I I I 是单位矩阵。

7. 预测下一时刻状态:

利用系统动态模型进行状态的预测:
X t + 1 = F ⋅ X t + B ⋅ U t X_{t+1} = F \cdot X_t + B \cdot U_t Xt+1=FXt+BUt
P t + 1 = F ⋅ P t ⋅ F T + Q P_{t+1} = F \cdot P_t \cdot F^T + Q Pt+1=FPtFT+Q
其中, Q Q Q 是过程噪声的协方差矩阵。

通过递归地应用上述步骤,卡尔曼滤波器能够实时预测潜水艇的位置,并有效地处理不同传感器数据的不确定性,提高位置预测的准确性。

import numpy as np
import matplotlib.pyplot as plt

def kalman_filter(observation_sequence, initial_state, initial_covariance, F, B, H, R, Q):
    num_states = len(initial_state)
    num_observations = len(observation_sequence)

    # Initialization
    state_estimate = initial_state
    covariance_estimate = initial_covariance

    # Lists to store results for plotting
    all_estimates = []

    for t in range(num_observations):
        # Prediction Step
        state_predict = F @ state_estimate
        covariance_predict = F @ covariance_estimate @ F.T + Q

        # Update Step
        kalman_gain = covariance_predict @ H.T @ np.linalg.inv(H @ covariance_predict @ H.T + R)
        state_estimate = state_predict + kalman_gain @ (observation_sequence[t] - H @ state_predict)
        covariance_estimate = (np.eye(num_states) - kalman_gain @ H) @ covariance_predict

        # Save the estimate for plotting
        all_estimates.append(state_estimate)

    return np.array(all_estimates)

# Example usage
np.random.seed(42)

# Generate synthetic data
true_position = 0.5
true_velocity = 0.02
observation_noise = 0.1

time_steps = np.arange(0, 10, 0.1)
true_states = np.column_stack([true_position + true_velocity * time_steps, true_velocity * np.ones_like(time_steps)])
observations = true_states[:, 0] + np.random.normal(0, observation_noise, len(time_steps))

# 省略部分见完整版

# No control input in this example
B = np.zeros((2, 1))

# Measurement matrix, only observing position
H = np.array([[1, 0]])

# Measurement noise covariance
R = np.array([[observation_noise**2]])

# Process noise covariance
Q = np.array([[0.01, 0], [0, 0.01]])

# Apply Kalman filter
estimated_states = kalman_filter(observations, initial_state_guess, initial_covariance_guess, F, B, H, R, Q)

# Plot the results
plt.figure(figsize=(10, 6))
plt.plot(time_steps, observations, label='Observations', marker='o', linestyle='None')
plt.plot(time_steps, true_states[:, 0], label='True Position', linestyle='--')
plt.plot(time_steps, estimated_states[:, 0], label='Estimated Position', linestyle='-', color='orange')
plt.xlabel('Time')
plt.ylabel('Position')
plt.legend()
plt.show()

可视化方法:

  1. 速度估计对比: 如果潜水艇状态包括速度信息,你可以绘制真实速度、观测速度(如果有的话)和卡尔曼滤波器估计的速度随时间的变化。

  2. 误差曲线: 绘制估计位置与真实位置之间的误差曲线,以便了解卡尔曼滤波器的准确性。可以使用均方根误差(Root Mean Squared Error,RMSE)等指标来量化估计的准确性。

  3. 卡尔曼增益随时间的变化: 绘制卡尔曼增益随时间的变化,以了解在不同时间点系统对观测的权重有多大。这可以提供有关滤波器对系统动态和观测噪声的适应性的信息。

  4. 协方差矩阵的变化: 绘制协方差矩阵元素随时间的变化,这可以反映系统状态不确定性的演化。

  5. 滤波器响应: 尝试改变滤波器的参数(例如过程噪声、观测噪声的方差),观察滤波器对系统动态和观测噪声的不同响应。
    代码:
    请注意,这些代码需要与之前给出的卡尔曼滤波器代码一起运行,因为它们使用相同的数据和模型。

import numpy as np
import matplotlib.pyplot as plt

# ...(之前的卡尔曼滤波器实现)

# Plotting additional graphs

# Plot velocity estimates
estimated_velocities = estimated_states[:, 1]
true_velocities = true_states[:, 1]

plt.figure(figsize=(10, 6))
plt.plot(time_steps, true_velocities, label='True Velocity', linestyle='--')
plt.plot(time_steps, estimated_velocities, label='Estimated Velocity', linestyle='-', color='orange')
plt.xlabel('Time')
plt.ylabel('Velocity')
plt.legend()
plt.title('True and Estimated Velocities over Time')
plt.show()

# Plot error curve
position_errors = true_states[:, 0] - estimated_states[:, 0]

plt.figure(figsize=(10, 6))
plt.plot(time_steps, position_errors, label='Position Error', linestyle='-', color='red')
plt.xlabel('Time')
plt.ylabel('Position Error')
plt.legend()
plt.title('Position Error between True and Estimated Positions')
plt.show()

# Plot Kalman gain
kalman_gains = []

for t in range(len(time_steps)):
    state_predict = F @ estimated_states[t]
    covariance_predict = F @ covariance_estimate @ F.T + Q
    kalman_gain = covariance_predict @ H.T @ np.linalg.inv(H @ covariance_predict @ H.T + R)
    kalman_gains.append(np.linalg.norm(kalman_gain))

plt.figure(figsize=(10, 6))
plt.plot(time_steps, kalman_gains, label='Kalman Gain')
plt.xlabel('Time')
plt.ylabel('Kalman Gain Magnitude')
plt.legend()
plt.title('Magnitude of Kalman Gain over Time')
plt.show()

# Plot covariance matrix elements
covariance_elements = np.array([covariance_estimate[0, 0], covariance_estimate[1, 1]])

plt.figure(figsize=(10, 6))
plt.plot(time_steps, covariance_elements, label='Covariance Elements')
plt.xlabel('Time')
plt.ylabel('Covariance Elements')
plt.legend()
plt.title('Covariance Matrix Elements over Time')
plt.show()

在这里插入图片描述

问题二:

  • 准备 - 如果需要,您将建议公司携带什么样的额外搜索设备并在主船上进行部署?
    • 您可能会考虑不同类型的设备,但也必须考虑与可用性、维护、准备和使用这些设备相关的成本。救援船需要携带什么额外的设备以在必要时提供帮助?

问题二建模思路:基于蚁群算法的搜救模型

蚁群算法是一种启发式算法,灵感来自蚂蚁在寻找食物时的行为。蚁群算法具有以下优势:

分布式计算: 模拟蚂蚁群体的协作行为,可以应对复杂的搜索和优化问题,特别是在分布式环境中。

适应性: 蚁群算法适用于动态和不确定的环境,具有良好的自适应性。

全局搜索: 通过模拟蚂蚁在解空间中的随机搜索和信息素沉积,蚁群算法可以在全局范围内寻找潜在的优秀解。

在问题二的背景下,使用蚁群算法可以模拟搜索设备在水域中的部署和寻找失联潜水艇的过程,充分利用其全局搜索和分布式计算的特性。

1. 设备准备和搜索路径规划:
  • 设备准备:定义每个搜索设备的性能和特性,包括搜索范围、搜索深度、设备工作时间等。
  • 搜索路径规划:使用蚁群算法模拟搜索设备在水域中的部署和移动。设备的位置可以在水平和垂直方向上进行变化。
2. 信息素模型:
  • 每个设备在水域中留下信息素,信息素浓度代表设备在该位置的搜索效果。
  • 信息素浓度的更新规则:
    τ i j = ( 1 − ρ ) ⋅ τ i j + Δ τ i j \tau_{ij} = (1 - \rho) \cdot \tau_{ij} + \Delta\tau_{ij} τij=(1ρ)τij+Δτij
    其中, τ i j \tau_{ij} τij 是从位置 i i i 到位置 j j j 的信息素浓度, ρ \rho ρ 是信息素的蒸发率, Δ τ i j \Delta\tau_{ij} Δτij 是蚂蚁在路径上留下的信息素增量。
3. 蚂蚁行为模型:
  • 蚂蚁代表搜索设备,它们在搜索空间中移动。
  • 蚂蚁选择下一个移动的位置的概率:
    P i j = ( τ i j ) α ⋅ ( η i j ) β ∑ k ∈ N i ( τ i k ) α ⋅ ( η i k ) β P_{ij} = \frac{(\tau_{ij})^\alpha \cdot (\eta_{ij})^\beta}{\sum_{k \in N_i} (\tau_{ik})^\alpha \cdot (\eta_{ik})^\beta} Pij=kNi(τik)α(ηik)β(τij)α(ηij)β
    其中, P i j P_{ij} Pij 是从位置 i i i 移动到位置 j j j 的概率, α \alpha α β \beta β 是调节信息素和启发因子的参数, η i j \eta_{ij} ηij 是启发因子,表示从位置 i i i 移动到位置 j j j 的启发信息。
4. 搜索路径更新:
  • 蚂蚁的搜索路径由多个位置组成,每个位置表示设备的当前部署点。
  • 搜救设备按照蚂蚁的行为更新搜索路径。
5. 搜救概率模型:
  • 对于每个时间步,计算设备的搜救概率:
    搜救概率 = 覆盖区域内信息素浓度总和 覆盖区域面积 \text{搜救概率} = \frac{\text{覆盖区域内信息素浓度总和}}{\text{覆盖区域面积}} 搜救概率=覆盖区域面积覆盖区域内信息素浓度总和
  • 考虑信息素浓度和其他相关因素。
6. 多潜水艇和多设备情况:
  • 考虑多艘潜水艇失联的情况,适当扩展模型以适应多潜水艇的搜索和救援。
  • 每个潜水艇有一个对应的蚂蚁群体,它们独立进行搜索和搜救。
7. 多次迭代和最优路径选择:
  • 迭代多次,通过信息素的更新和搜索设备路径的调整,逐步找到最优的搜索路径。
  • 最终选择搜救概率最高的路径作为最优路径。

公式总结:

  1. 信息素更新公式:
    τ i j = ( 1 − ρ ) ⋅ τ i j + Δ τ i j \tau_{ij} = (1 - \rho) \cdot \tau_{ij} + \Delta\tau_{ij} τij=(1ρ)τij+Δτij

  2. 蚂蚁选择下一个位置的概率:
    P i j = ( τ i j ) α ⋅ ( η i j ) β ∑ k ∈ N i ( τ i k ) α ⋅ ( η i k ) β P_{ij} = \frac{(\tau_{ij})^\alpha \cdot (\eta_{ij})^\beta}{\sum_{k \in N_i} (\tau_{ik})^\alpha \cdot (\eta_{ik})^\beta} Pij=kNi(τik)α(ηik)β(τij)α(ηij)β

  3. 搜救概率模型:
    搜救概率 = 覆盖区域内信息素浓度总和 覆盖区域面积 \text{搜救概率} = \frac{\text{覆盖区域内信息素浓度总和}}{\text{覆盖区域面积}} 搜救概率=覆盖区域面积覆盖区域内信息素浓度总和

这样的建模思路和公式考虑了设备的部署、蚂蚁行为、信息素浓度等因素,能够有效模拟搜索和搜救过程。

import numpy as np

class AntColony:
    def __init__(self, num_ants, num_devices, num_iterations, evaporation_rate, alpha=1, beta=2):
        self.num_ants = num_ants
        self.num_devices = num_devices
        self.num_iterations = num_iterations
        self.evaporation_rate = evaporation_rate
        self.alpha = alpha
        self.beta = beta

        # Initialize pheromone matrix
        self.pheromones = np.ones((num_devices, num_devices))

    def run(self):
        for iteration in range(self.num_iterations):
            solutions = []

            # Deploy ants and build solutions
            for ant in range(self.num_ants):
                solution = self.build_solution()
                solutions.append((solution, self.calculate_prob(solution)))

            # Update pheromones
            self.update_pheromones(solutions)

            # Evaporate pheromones
            self.pheromones *= (1 - self.evaporation_rate)

    def build_solution(self):
        # Simplified method to build a solution (path)
        solution = np.zeros(self.num_devices, dtype=int)
        for device in range(self.num_devices - 1):
            # Choose next device based on pheromones and heuristic information
            next_device = self.choose_next_device(solution)
            solution[device + 1] = next_device
        return solution

#省略部分见完整版

    def update_pheromones(self, solutions):
        # Simplified method to update pheromones based on solution quality
        # For each solution
        for solution, prob in solutions:
            for i in range(len(solution) - 1):
                current_device, next_device = solution[i], solution[i + 1]
                # Update pheromones based on the success of the solution
                self.pheromones[current_device, next_device] += prob

# Example Usage
num_ants = 10
num_devices = 20
num_iterations = 100
evaporation_rate = 0.1

ant_colony = AntColony(num_ants, num_devices, num_iterations, evaporation_rate)
ant_colony.run()

# Access the final pheromone matrix
final_pheromones = ant_colony.pheromones
print("Final Pheromones Matrix:")
print(final_pheromones)

在搜救任务中,可视化是理解算法行为和结果的重要手段。以下是一些可视化的方法,根据问题二的情境:

  1. 设备部署可视化: 绘制搜索设备在水域中的部署图,显示每个设备的当前位置。这可以是一个二维图,其中设备用点表示。

  2. 信息素浓度可视化: 将信息素浓度在水域中可视化,以热图或等高线图显示。信息素浓度高的区域表示设备效果好,可能是潜水艇位置。

  3. 蚂蚁行为轨迹: 可视化蚂蚁(搜索设备)的移动轨迹,以了解它们如何在水域中搜索。这可以是轨迹图或动画。

  4. 搜救概率分布: 绘制搜救概率在水域中的分布图,标示搜救概率高的区域。这有助于理解设备在何处集中搜索。

  5. 多次迭代结果对比: 如果进行了多次迭代,可以对比不同迭代中的结果,以了解搜救路径如何演化。

以下是一些示例代码:

import matplotlib.pyplot as plt
import seaborn as sns

# Example for visualization
def visualize_pheromones(pheromones):
    sns.heatmap(pheromones, cmap="YlGnBu", annot=True, fmt=".3f", cbar_kws={'label': 'Pheromone Intensity'})
    plt.title("Pheromone Distribution")
    plt.xlabel("Destination Device")
    plt.ylabel("Current Device")
    plt.show()

# Assuming 'final_pheromones' is the pheromone matrix obtained after running the ant colony algorithm
visualize_pheromones(final_pheromones)

在这里插入图片描述

问题三:

搜索 - 制定一个模型,该模型将使用您的位置模型信息,为设备的初始部署点和搜索模式推荐,以最小化寻找失去的潜水艇所需的时间。确定随时间和累积搜索结果的条件下找到潜水艇的概率。

问题三-遗传算法建模思路详解:

使用遗传算法来解决问题有几个优势,特别是在复杂的搜索和优化问题中:

  1. 全局搜索能力: 遗传算法具有较强的全局搜索能力,能够在搜索空间中寻找较好的解决方案。这对于问题三中的搜索设备的初始部署点和搜索模式参数的优化是至关重要的,因为我们需要考虑多个设备的协同工作。

  2. 并行性: 遗传算法天生具有并行性,每个个体的适应度可以独立计算,从而在计算效率上具有一定优势。这对于大规模搜索设备配置的问题是非常有帮助的。

  3. 多目标优化: 遗传算法适用于多目标优化问题,可以同时考虑多个目标函数。在问题三中,我们要平衡搜救所需时间和搜索范围,这正是遗传算法的优势所在。

  4. 灵活性: 遗传算法可以很容易地扩展和调整,适用于不同类型的问题。通过调整交叉、变异操作和适应度函数,可以灵活地适应问题的特性。

  5. 避免陷入局部最优解: 由于遗传算法的全局搜索性质,相对于一些局部搜索算法,它更不容易陷入局部最优解。这在处理复杂、多峰值函数的问题中是很有价值的。

总的来说,遗传算法是一种通用的、强大的优化算法,适用于问题三中需要考虑多个设备、多个目标的复杂优化场景。

建模思路:

1. 个体表示:
  • 个体表示一个设备的初始部署点和搜索模式。每个设备可以用一个二维向量表示,包括初始坐标和搜索模式参数。
2. 基因编码:
  • 基因编码可以采用实数编码,其中每个维度表示一个搜索设备的初始坐标或搜索模式参数。
3. 适应度函数:
  • 适应度函数是搜索设备部署的性能度量。考虑两个方面:搜救所需的总时间和覆盖范围。
  • 适应度函数:
    Fitness = w 1 ⋅ Total Time + w 2 ⋅ Coverage \text{Fitness} = w_1 \cdot \text{Total Time} + w_2 \cdot \text{Coverage} Fitness=w1Total Time+w2Coverage
    其中, w 1 w_1 w1 w 2 w_2 w2 是权重,可以根据实际情况调整。
4. 搜索设备的初始部署点:
  • 使用遗传算法,每个个体表示一个设备的初始部署点。通过演化,算法会找到最优的初始部署点配置。
5. 搜索模式参数:
  • 在个体中,搜索模式参数可以影响搜索路径和效率。通过演化,算法会调整搜索模式参数以优化搜救效果。
6. 时间和累积搜索结果的条件下找到潜水艇的概率:
  • 每次搜索迭代后,可以根据累积的搜索结果来评估潜水艇可能的位置。概率可以基于搜索设备的分布和覆盖范围来估算。
  • P ( Submarine Found ) = Number of Devices Covering Submarine Total Number of Devices P(\text{Submarine Found}) = \frac{\text{Number of Devices Covering Submarine}}{\text{Total Number of Devices}} P(Submarine Found)=Total Number of DevicesNumber of Devices Covering Submarine
  • 随着时间的推移,潜水艇被多个设备覆盖的概率应该增加。
7. 多目标优化:
  • 遗传算法可用于多目标优化,以找到平衡搜救时间和搜索范围的解。

公式总结:

  1. 适应度函数:
    Fitness = w 1 ⋅ Total Time + w 2 ⋅ Coverage \text{Fitness} = w_1 \cdot \text{Total Time} + w_2 \cdot \text{Coverage} Fitness=w1Total Time+w2Coverage

  2. 搜索设备的初始部署点:

    • 个体表示每个设备的初始坐标。
  3. 搜索模式参数:

    • 个体中包括搜索设备的搜索模式参数。
  4. 时间和累积搜索结果的条件下找到潜水艇的概率:
    P ( Submarine Found ) = Number of Devices Covering Submarine Total Number of Devices P(\text{Submarine Found}) = \frac{\text{Number of Devices Covering Submarine}}{\text{Total Number of Devices}} P(Submarine Found)=Total Number of DevicesNumber of Devices Covering Submarine

  5. 多目标优化:

    • 考虑搜救时间和搜索范围的权重。

遗传算法 Python 代码示例:

# (前面提供的代码已包含遗传算法的基本框架)

# 适应度函数
def fitness(individual):
    # 提取坐标和参数
    coordinates = individual[:num_devices * 2].reshape((num_devices, 2))
    parameters = individual[num_devices * 2:]

    # 计算总时间和覆盖范围
    total_time = np.sum(parameters)  # 假设 parameters 代表设备搜救时间
    coverage = np.sum(np.sqrt(coordinates[:, 0]**2 + coordinates[:, 1]**2))  # 假设 coordinates 代表设备坐标

    # 计算适应度
    return w1 * total_time + w2 * coverage

# 主循环
for generation in range(num_generations):
    # 省略部分见完整版

    # 交叉
    crossover_mask = np.random.rand(int(population_size * crossover_rate)) < crossover_rate
    crossover_pairs = np.array_split(selected_population, len(selected_population) // 2)
    for pair in crossover_pairs:
        if len(pair) == 2:
            crossover_point = np.random.randint(1, num_devices * 2)
            pair[0, :crossover_point], pair[1, :crossover_point] = pair[1, :crossover_point], pair[0, :crossover_point].copy()

    # 变异
    mutation_mask = np.random.rand(selected_population.shape[0], num_devices * 2 + 1) < mutation_rate
    selected_population[mutation_mask] += np.random.normal(0, 0.1, selected_population.shape)[mutation_mask]

    # 替换旧个体
    population[selected_indices] = selected_population

这个代码示例演示了如何通过遗传算法优化设备的初始部署点和搜索模式参数,以最小化搜救所需时间并最大化搜索范围。

可视化是评估算法性能和结果的重要手段。对于问题三,可以使用图表来展示搜索设备的部署情况以及搜救概率随时间的变化。

  1. 搜索设备部署图: 使用散点图展示搜索设备的初始部署点。X、Y轴表示坐标,每个散点代表一个设备。可以通过颜色或形状表示不同的搜索模式参数。
import matplotlib.pyplot as plt

# 提取最佳个体
best_individual = final_population[np.argmin(fitness_values)]

# 提取坐标和参数
best_coordinates = best_individual[:num_devices * 2].reshape((num_devices, 2))
best_parameters = best_individual[num_devices * 2:]

# 绘制散点图
plt.scatter(best_coordinates[:, 0], best_coordinates[:, 1], c=best_parameters, cmap='viridis')
plt.title('Search Devices Deployment')
plt.xlabel('X Coordinate')
plt.ylabel('Y Coordinate')
plt.colorbar(label='Search Mode Parameter')
plt.show()
  1. 搜救概率随时间变化图: 使用折线图展示搜救概率随时间的变化。X轴表示时间步,Y轴表示搜救概率。
# 模拟搜救概率随时间的变化
time_steps = np.arange(num_generations)
probability_found = []

for generation in range(num_generations):
    # 计算搜救概率
    probability = np.sum([1 for ind in population if fitness(ind) == 0]) / population_size
    probability_found.append(probability)

# 绘制折线图
plt.plot(time_steps, probability_found, marker='o')
plt.title('Probability of Finding Submarine over Time')
plt.xlabel('Time Steps')
plt.ylabel('Probability')
plt.show()

这些示例代码可以帮助你开始可视化问题三的结果。你可以根据具体需求和数据的不同调整图表的样式和参数。

在这里插入图片描述

问题四

  • 推演 - 如何扩展您的模型以考虑其他旅游目的地,如加勒比海?您的模型将如何调整以考虑在相同区域移动的多个潜水艇?

多目标协同搜救模型建模详解:

使用多目标协同搜救模型的理由主要基于以下考虑:

  1. 多目标考虑: 通过引入多目标的适应度函数,模型能够综合考虑不同目标地的搜救效果,而不仅仅是单一目标。这使得搜救任务更加全面和多样化。

  2. 多潜水艇协同: 考虑到多潜水艇的搜救任务,协同作战能够更有效地覆盖搜索区域,提高搜索效率。协同搜索模型使潜水艇能够共享信息,优化整体搜索策略。

  3. 动态环境考虑: 引入动态环境模型,考虑海流等因素的影响,使得搜救任务更贴近实际情况。潜水艇可以根据环境变化调整移动策略,提高应对复杂环境的能力。

  4. 多层次搜索策略: 通过多层次搜索策略,模型能够在高层次进行整体规划,例如确定目标地点和区域,同时在低层次对搜救设备进行局部优化,例如确定设备的初始部署点和搜索模式。这提高了搜索过程的灵活性和适应性。

  5. 系统性建模: 这个模型综合考虑了多个方面,从目标设定到搜救设备的优化,从动态环境到潜水艇的协同。这种系统性的建模使得模型更具综合性和实用性。

综合考虑这些因素,多目标协同搜救模型能够更全面、更高效地解决搜救任务,提高了搜救任务的成功率和适应性。这个方法考虑了任务的多样性和复杂性,使得模型更符合实际应用需求。

建模思路:

1. 目标函数设计:

适应度函数可以设计为综合考虑多个目标地的搜索效果,其中每个目标地都有一个适应度贡献。假设有 N N N 个目标地,适应度函数可以定义为:

Fitness = ∑ i = 1 N w i × Fitness D i \text{Fitness} = \sum_{i=1}^{N} w_i \times \text{Fitness}_{D_i} Fitness=i=1Nwi×FitnessDi

其中, Fitness D i \text{Fitness}_{D_i} FitnessDi 表示对目标地 i i i 的搜索效果, w i w_i wi 是相应的权重,满足 ∑ i = 1 N w i = 1 \sum_{i=1}^{N} w_i = 1 i=1Nwi=1

2. 多潜水艇的移动模型:

假设潜水艇的运动是二维的,位置用 $ (x, y) $ 表示。潜水艇在每个时间步上的位置变化可以使用以下运动方程描述:

( x sub , y sub ) new = ( x sub , y sub ) old + ( v sub , v sub ) × Δ t (x_{\text{sub}}, y_{\text{sub}})_{\text{new}} = (x_{\text{sub}}, y_{\text{sub}})_{\text{old}} + (v_{\text{sub}}, v_{\text{sub}}) \times \Delta t (xsub,ysub)new=(xsub,ysub)old+(vsub,vsub)×Δt

这里, v sub v_{\text{sub}} vsub 是潜水艇的速度。

3. 动态环境模型:

引入动态环境因素,如海流影响,可以考虑在潜水艇运动模型中添加环境因素的影响。例如:

( x sub , y sub ) new = ( x sub , y sub ) old + ( v sub , v sub ) × Δ t + ( v sea , v sea ) × Δ t (x_{\text{sub}}, y_{\text{sub}})_{\text{new}} = (x_{\text{sub}}, y_{\text{sub}})_{\text{old}} + (v_{\text{sub}}, v_{\text{sub}}) \times \Delta t + (v_{\text{sea}}, v_{\text{sea}}) \times \Delta t (xsub,ysub)new=(xsub,ysub)old+(vsub,vsub)×Δt+(vsea,vsea)×Δt

这里, v sea v_{\text{sea}} vsea 是海流的速度。

4. 协同搜索模型:

协同搜索可以通过潜水艇之间的信息共享实现。假设每个潜水艇在搜索过程中可以发送和接收信息,影响彼此的搜索策略。一种简单的模型可以是:

Fitness D i = Fitness D i + ∑ j ≠ i Comm_Effect i j \text{Fitness}_{D_i} = \text{Fitness}_{D_i} + \sum_{j \neq i} \text{Comm\_Effect}_{ij} FitnessDi=FitnessDi+j=iComm_Effectij

这里, Comm_Effect i j \text{Comm\_Effect}_{ij} Comm_Effectij 表示潜水艇 i i i 向潜水艇 j j j 发送的通信效果。

5. 多层次搜索策略:

多层次搜索策略可以分为高层次的整体规划和低层次的局部优化。在高层次,我们可以决定搜索的目标地点和区域,而在低层次,我们对搜救设备进行局部优化。这可以通过引入两个层次的适应度函数来实现:

Fitness High_Level = Global_Plan_Effect \text{Fitness}_{\text{High\_Level}} = \text{Global\_Plan\_Effect} FitnessHigh_Level=Global_Plan_Effect
Fitness Low_Level = Local_Opt_Effect \text{Fitness}_{\text{Low\_Level}} = \text{Local\_Opt\_Effect} FitnessLow_Level=Local_Opt_Effect

其中, Global_Plan_Effect \text{Global\_Plan\_Effect} Global_Plan_Effect Local_Opt_Effect \text{Local\_Opt\_Effect} Local_Opt_Effect 分别表示高层次和低层次的适应度效果。

import numpy as np

class Submarine:
    def __init__(self, initial_position, velocity):
        self.position = np.array(initial_position)
        self.velocity = np.array(velocity)

class SearchAndRescueModel:
#省略部分见完整版

    def fitness_function(self, destination_index):
        fitness = 0
        for i, sub in enumerate(self.submarines):
            # Fitness contribution based on distance to the destination
            fitness += np.exp(-self.calculate_distance(sub.position, self.destinations[destination_index]))

            # Communication effect between submarines
            for other_sub in self.submarines[:i] + self.submarines[i+1:]:
                communication_effect = 1 / self.calculate_distance(sub.position, other_sub.position)
                fitness += communication_effect

        return fitness

    def optimize_search(self):
        best_destination = None
        best_fitness = -np.inf

        for i in range(len(self.destinations)):
            fitness = self.fitness_function(i) * self.weights[i]
            if fitness > best_fitness:
                best_fitness = fitness
                best_destination = i

        return best_destination

    def update_submarines(self):
        for sub in self.submarines:
            # Example: Submarine moves in a straight line
            sub.position += sub.velocity

# Example Usage
model = SearchAndRescueModel(num_submarines=3, num_destinations=5, weights=[0.4, 0.3, 0.2, 0.1, 0.0])

# Simulate multiple iterations
for iteration in range(10):
    best_destination = model.optimize_search()
    print(f"Iteration {iteration + 1}: Best Destination - {best_destination}")
    
    # Update submarine positions for the next iteration
    model.update_submarines()

在多目标协同搜救模型中,可视化是理解和分析模型行为的重要工具。以下是一些可视化的代码:

1. 可视化潜水艇的移动轨迹:

import matplotlib.pyplot as plt

def plot_submarine_positions(submarines, iteration):
    positions_x = [sub.position[0] for sub in submarines]
    positions_y = [sub.position[1] for sub in submarines]

    plt.scatter(positions_x, positions_y, label=f'Iteration {iteration}')
    plt.xlabel('X-axis')
    plt.ylabel('Y-axis')
    plt.title('Submarine Positions')
    plt.legend()
    plt.show()

# 在模拟的每次迭代后调用该函数
plot_submarine_positions(model.submarines, iteration)

2. 可视化目标地点和潜水艇选择的目标:

def plot_destinations_and_selection(destinations, best_destination):
    destinations_x = [dest[0] for dest in destinations]
    destinations_y = [dest[1] for dest in destinations]

    plt.scatter(destinations_x, destinations_y, label='Destinations', marker='o')
    plt.scatter(destinations[best_destination][0], destinations[best_destination][1],
                label='Selected Destination', marker='x', color='red')
    
    plt.xlabel('X-axis')
    plt.ylabel('Y-axis')
    plt.title('Destinations and Selected Destination')
    plt.legend()
    plt.show()

# 在模拟的每次迭代后调用该函数
plot_destinations_and_selection(model.destinations, best_destination)

在这里插入图片描述
美赛跟紧小秘籍冲冲冲!!更多内容可以点击下方名片详细了解!
记得关注 数学建模小秘籍打开你的数学建模夺奖之旅!

  • 24
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

数学建模小secret

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值