2023 The Ninth Dimensional Cup Question D Modeling Analysis, Senior Xiaolu Leads the Team to Guide Full Code Articles and Ideas

I am senior Xiaolu, studying at Shanghai Jiao Tong University. So far, I have helped more than 200 people complete modeling and idea building~

This time I will take you to experience Question D of the 9th Digital Dimension Cup!

Insert image description here

Question 1: Best cleaning method

In question one we want to consider what is the best way to clean given the amount of dirt and the amount of water available, by choosing an appropriate solubility (a_k).

First, we can build a mathematical model to describe the change process of dirt:

C k = ( 1 − a k ) C k − 1 C_k = (1 - a_k)C_{k-1} Ck=(1ak)Ck1

In that, C k C_k Ck is the first k k The amount of dirt after k cleaning times, C k − 1 C_{k-1} Ck1 is the first k − 1 k-1 k1Amount of scum after washing, a k a_k ak is the first k k Dirt solubility during k cleanings.

The goal is to minimize the total amount of dirt:

C total = ∑ k = 1 n C k C_{\text{total}} = \sum_{k=1}^{n} C_k Ctotal=k=1nCk

Considering the limit of available water, we can introduce a water limit condition:

∑ k = 1 n V k ≤ V total \sum_{k=1}^{n} V_k \leq V_{\text{total}} k=1nINkINtotal

In that, V k V_k INk is the first k k k Amount of water used for next cleaning, V total V_{\text{total}} INtotalis the total amount of water available.

Now, we can use mathematical optimization methods (such as linear programming or nonlinear programming) to solve this problem and find the minimum total dirt amount a k a_k aksum V k V_k INkThe combination.

关于 a k ak ak, initial scale amount C 0 C_0 C0 Total available water V total V_{\text{total}} INtotalThe impact on the target can be discussed by performing a sensitivity analysis on the model. Conduct simulations or numerical experiments under different parameter values ​​to observe how the optimal solution changes as these parameters change, thereby drawing conclusions about their impact on the objectives.

Further discussion about a k a_k ak, initial dirt amount C 0 C_0 C0 Total available water V total V_{\text{total}} INtotalImpact on the optimal solution

  1. effect a k a_k akthe elements of:

    • 初值 a 1 a_1 a1 Target selection: Yuyu a k = 0.5 a k − 1 a_k = 0.5a_{k-1} ak=0.5ak1,初值 a 1 a_1 a1The choice of will have an important impact on the entire cleaning process. if a 1 a_1 a1Larger values ​​may result in poorer cleaning results because solubility decreases with increasing number of cleanings.
    • Solubility Decrease Rate 0.5 0.5 0.5 0.5 0.5 The choice of 0.5 affects the rapid decrease in solubility. A smaller ramp-down rate will result in a slower decrease in solubility and may require more cleaning cycles to achieve desired cleaning results.
  2. Influence the initial dirt amount C 0 C_0 C0the elements of:

    • Initial dirt amount C 0 C_0 C0Size of : Greater initial dirt volume may require more washes to achieve the same cleaning effect. Where water is limited, a larger volume of water may be required to handle a larger initial volume of dirt.
  3. Available water volume V total V_{\text{total}} INtotalthe elements of:

    • Water limit V total V_{\text{total}} INtotal Size: Smaller water restrictions may result in less than ideal cleaning results. Where water is limited, higher solubility may be required a k a_k akor less initial dirt volume to accommodate water volume limitations.
import numpy as np
from scipy.optimize import minimize

def objective_function(variables):
    # 定义目标函数,即总污垢量
    ak_values = variables[:n]
    Vk_values = variables[n:]
    
    Ck_values = [C0]
    for k in range(1, n+1):
        Ck_values.append((1 - ak_values[k-1]) * Ck_values[k-1])
    
    return np.sum(Ck_values)

def constraint(variables):
    # 定义约束条件,即水量限制
    Vk_values = variables[n:]
    return V_total - np.sum(Vk_values)

# 初始参数
n = 10  # 清洗次数
C0 = 100  # 初始污垢量
V_total = 500  # 可用水量

# 设置初始猜测值
initial_guess = np.ones(2 * n)  # [a1, a2, ..., an, V1, V2, ..., Vn]

# 设置约束条件
constraint_definition = {'type': 'ineq', 'fun': constraint}

# 优化器
result = minimize(objective_function, initial_guess, constraints=constraint_definition)

# 提取最优解
optimal_ak_values = result.x[:n]
optimal_Vk_values = result.x[n:]

# 输出结果
print("最优清洁方法:")
print("最优的ak值:", optimal_ak_values)
print("最优的Vk值:", optimal_Vk_values)
print("最小总污垢量:", result.fun)

Question two:

Question 2: The most time-saving cleaning plan

In question two, we assume that each cleaning takes the same amount of time and that there is no limit on the available water. The optimization goal is to find the most time-saving cleaning plan to ensure that the final dirt residue does not exceed one thousandth of the initial dirt amount.

First, we can build a mathematical model to describe the change process of dirt:

C k = ( 1 − a k ) C k − 1 C_k = (1 - a_k)C_{k-1}Ck=(1ak)Ck1

In that, C k C_k Ck is the first k k The amount of dirt after k cleaning, C k − 1 C_{k-1} Ck1 is the first k − 1 k-1 k1 Amount of scum after washing in the next clearing, a k a_k ak is the first k k Dirt solubility in k washes.

Since each cleaning takes the same amount of time, we can use the same time unit. Assume the time required for each cleaning is T T T, Cleaning order n n n

The optimization goal is to minimize the total cleaning time:

T total = n ⋅ T T_{\text{total}} = n \cdot T Ttotal=nT

At the same time, it is necessary that the final amount of dirt residue does not exceed one thousandth of the initial amount of dirt:

C n ≤ C 0 1000 C_n \leq \frac{C_0}{1000} Cn1000C0

Now, we can use mathematical optimization methods such as linear programming or nonlinear programming to solve this problem and find the combination of (a_k) and (n) that minimizes the total cleaning time.

effect a k a_k ak and initial dirt amount C 0 C_0 C0the elements of:

  1. a k a_kak Target effect: Further a k a_k akMay cause faster dissolution of dirt, resulting in fewer washes and shorter overall wash time.
  2. Initial dirt amount C 0 C_0 C0Effect of : Larger initial dirt volumes may require more cleaning cycles to achieve final requirements, thereby increasing the total cleaning time.

Use the optimizer from the SciPy library:

import numpy as np
from scipy.optimize import minimize

def objective_function(variables):
    # 定义目标函数,即总清洗时间
    ak_values = variables[:n]
    Ck_values = [C0]
    
    for k in range(1, n+1):
        Ck_values.append((1 - ak_values[k-1]) * Ck_values[k-1])
    
    return n * T

def constraint(variables):
    # 定义约束条件,即最终的污垢残留量不超过初始污垢量的千分之一
    ak_values = variables[:n]
    Ck_values = [C0]
    
    for k in range(1, n+1):
        Ck_values.append((1 - ak_values[k-1]) * Ck_values[k-1])
    
    return Ck_values[-1] - C0 / 1000

# 初始参数
n = 10  # 清洗次数
C0 = 100  # 初始污垢量
T = 1  # 每次清洗所需时间

# 设置初始猜测值
initial_guess = np.ones(n)  # [a1, a2, ..., an]

# 设置约束条件
constraint_definition = {
    
    'type': 'ineq', 'fun': constraint}

# 优化器
result = minimize(objective_function, initial_guess, constraints=constraint_definition)

# 提取最优解
optimal_ak_values = result.x

# 输出结果
print("最省时的清洗计划:")
print("最优的ak值:", optimal_ak_values)
print("最小总清洗时间:", result.fun)

Question 3: Cost-saving and effective cleaning solution

In this question, we need to consider the price, solubility, and water costs of different detergents to find a solution that is both cost-effective and effective in cleaning. We can model this problem using linear programming.

Define variable declaration:

  • D i D_i Di: No. i i Amount of i detergent used (in liters)
  • to a_{ik}aik: No. i i i 种wash涤剂在数 k k k Solubility in dirt during cleaning
  • $P_i):第 i i The unit price of i detergents
  • C water C_{\text{water}} Cwater: Water cost (price per ton of water)
  • V to V_kINk: No. k k k Amount of water used for cleaning

Establish a multivariate analysis mathematical model:

目标函数:
Minimize  Z = ∑ i = 1 10 ( D i ⋅ P i ) + C water ⋅ ∑ k = 1 n V k \text{Minimize } Z = \sum_{i=1}^{10} (D_i \cdot P_i) + C_{\text{water}} \cdot \sum_{k=1}^{n} V_k Minimize Z=i=110(DiPi)+Cwaterk=1nINk

Restrictions:

  1. Scale solubility: C k = ( 1 − ∑ i = 1 10 a i k ⋅ D i ) ⋅ C k − 1 C_k = (1 - \sum_{i=1} ^{10} a_{ik} \cdot D_i) \cdot C_{k-1} Ck=(1i=110aikDi)Ck1
  2. The final residual amount of dirt does not exceed one thousandth of the initial amount of dirt: C n ≤ C 0 1000 C_n \leq \frac{C_0}{1000} Cn1000C0
  3. Water limit: ∑ k = 1 n V k ≤ V total \sum_{k=1}^{n} V_k \leq V_{\text{total}} < /span>k=1nINkINtotal
  4. Washing amount usage penalty: D i ≥ 0 , ​ for i = 1 , 2 , . . . , 10 D_i \geq 0, \text{ for } i = 1,2,...,10Di0, for i=1,2,...,10
  5. Water quantity is non-negative: V k ≥ 0 , for k = 1 , 2 , . . . , n V_k \geq 0, \text{ for } k = 1,2 ,...,n INk0, for k=1,2,...,n

Next, we can use linear programming tools, such as the linprog function in the SciPy library, to solve this problem.

Here is a simplified Python code example:

import numpy as np
from scipy.optimize import linprog

# 初始参数
n = 10  # 清洗次数
C0 = 100  # 初始污垢量
V_total = 500  # 可用水量
C_limit = C0 / 1000  # 最终的污垢残留量不超过初始污垢量的千分之一
Ck_values = [C0]

# 表2中的洗涤剂数据
a_values = np.array([[0.2, 0.3, ..., 0.1],  # 洗涤剂1的溶解度
                     [0.1, 0.2, ..., 0.3],  # 洗涤剂2的溶解度
                     ...
                     [0.4, 0.1, ..., 0.2]])  # 洗涤剂10的溶解度

P_values = np.array([2.5, 1.8, ..., 3.0])  # 洗涤剂的单位价格

# 定义线性规划问题
c = np.concatenate((P_values, np.ones(n)))  # 目标函数系数
A_eq = np.zeros((n+1, 2*n))  # 等式约束矩阵
b_eq = np.zeros(n+1)  # 等式约束右侧

# 设置等式约束矩阵和右侧
for k in range(1, n+1):
    A_eq[k, :n] = -a_values[:, k-1]
    A_eq[k, n+k-1] = C0
    b_eq[k] = Ck_values[-1]

# 设置水量限制
A_ub = np.zeros((1, 2*n))  # 不等式约束矩阵
b_ub = np.array([V_total])  # 不等式约束右侧
A_ub[0, n:] = 1

# 设置边界
bounds = [(0, None) for _ in range(2*n)]

# 使用线性规划求解
result = linprog(c, A_eq=A_eq, b_eq=b_eq, A_ub=A_ub, b_ub=b_ub, bounds=bounds, method='highs')

# 提取最优解
optimal_D_values = result.x[:n]
optimal_V_values = result.x[n:]

# 输出结果
print("最省成本又能够有效清洁的方案:")
print("最优的洗涤剂使用量:", optimal_D_values)
print("最优的水量使用量:", optimal_V_values)
print("最小总成本:", result.fun)

Let’s learn more about it~
Xiaolu Senior Dimensional Cup D Question Full Code Articles and Ideas

Supongo que te gusta

Origin blog.csdn.net/Tech_deer/article/details/134453909
Recomendado
Clasificación