2024年电工杯B题(大学生食谱)助攻论文&支撑材料.doc

本博客下载链接包含修改的word版本, 可免费下载阅览学习, 也可作为数学建模相关课程作业修改上交:

链接:https://pan.baidu.com/s/1HxzDk3q0p6y2xpuJyxPgvw?pwd=qtnc

提取码:qtnc

        大学生作为社会活跃的知识群体,其饮食习惯对健康和发展具有深远影响。然而,不合理的饮食结构和营养知识缺乏导致许多大学生面临营养不均衡的问题。针对这一现状,本研究旨在通过科学的方法优化膳食结构,促进大学生健康饮食。

        针对问题一, 对大学生的一日食谱进行全面的营养分析评价。本研究基于营养学原理,对男女大学生各一份的一日食谱进行了详细的定量分析,以评估其营养均衡性。通过计算各类营养素的摄入量与推荐标准进行比较,揭示了食谱中存在的营养不平衡问题。针对发现的问题,本文提出了具体的调整建议,目的在于改善膳食结构,确保营养素的充足摄入,促进健康饮食习惯的形成。

        针对问题二, 旨在建立一个优化模型,以设计出蛋白质氨基酸评分最大化的大学生日平衡膳食食谱。研究首先定义了决策变量和约束条件,构建了目标函数以反映食谱的营养价值。鉴于问题求解的复杂性,本研究采用了模拟退火算法进行求解,该算法能够有效地搜索解空间,寻找全局最优解。通过算法的参数调整和优化,最终得到了满足营养和成本约束的日食谱,为大学生提供了科学合理的膳食选择。

        问题三在问题二的基础上进一步扩展,目标是设计男生和女生一周的平衡膳食食谱。本研究考虑了一周内每日的食谱设计,增加了决策变量的数目,并对模型进行了相应的扩展。通过模拟退火算法的应用,本研究不仅考虑了每日的营养需求,还考虑了一周内食物多样性的需求,以确保食谱的均衡性和可持续性。研究结果提供了一周内每日三餐的详细食谱,满足了营养均衡、成本效益和食物多样性的要求。

        问题四着眼于撰写一份针对大学生饮食结构及习惯的健康饮食、平衡膳食的倡议书。本研究基于前三问的研究结果,分析了当前大学生饮食习惯中普遍存在的问题,并提出了一系列具体的建议和措施。倡议书旨在提升大学生对健康饮食重要性的认识,引导他们采取行动改善饮食习惯。通过教育和宣传活动,本研究期望能够促进校园内健康饮食文化的建立。

关键词: 平衡膳食, 营养评估, 健康行为改变, 膳食模式, 营养优化模型

问题分析

2.1总体问题把握

        我们的研究将从对两名大学生现有一日食谱的营养分析评价入手,识别其营养摄入中的不足,并提出相应的改进建议。接下来,我们将利用高校食堂提供的食物信息,通过数学建模和优化算法,设计出既满足营养需求又经济实惠的日食谱和周食谱。在设计过程中,我们特别关注蛋白质氨基酸评分的最大化、用餐费用的最经济化,以及两者之间的平衡。此外,我们还将撰写一份健康饮食倡议书,旨在提升大学生对健康饮食重要性的认识,并鼓励他们采取行动改善自己的饮食习惯。

2.2第一小问问题分析

        (1)要求我们对两份食谱做出全面的膳食营养评价,B站up: 全糖奶茶屋那我们基于附件四给出“全面”的评价,也就是我们要把附件四所给的指标全部加入考虑,分别有平衡膳食标准;每日摄入能量;主要营养定量(包含营养能量、供能占比、非产能能量摄入、氨基酸评分)等, 接着参考附件4的第二节: 膳食食谱营养评价过程进行相关评价.

        (2)要求我们进行较少的改进,那我们就需要基于(1)中的结果进行评判,B站up: 全糖奶茶屋对比较不足的评价标准进行补足,同样的我们需要讲附件三的数据全部进行统一的整理, 增加(1)评价结果不足部分的菜品, 减少(1)评价结果超过部分的菜品.

第一问数据处理代码:
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'name': '小米粥', 'ingredients': {15101: 15}},\n",
       " {'name': '油条', 'ingredients': {'011201x': 50}},\n",
       " {'name': nan, 'ingredients': {192004: 20, 192017: 2, nan: nan}},\n",
       " {'name': '煎鸡蛋', 'ingredients': {'111101x': 50}},\n",
       " {'name': '拌海带丝', 'ingredients': {52004: 100}}]"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "\n",
    "def safe_float_conversion(value):\n",
    "    try:\n",
    "        return float(value)\n",
    "    except ValueError:\n",
    "        return None\n",
    "\n",
    "\n",
    "# Function to merge dishes with the same name and update idx2ingredient\n",
    "def create_merged_meals(meal_data):\n",
    "    meals_dict = {}\n",
    "    for index, row in meal_data.iterrows():\n",
    "        dish_name = row['食物名称']\n",
    "        price = row['价格\\n(元/份)']\n",
    "        half_portion = row['是否\\n可半份'] == '是'\n",
    "        ingredient_idx = row['食物编码']\n",
    "        amount = safe_float_conversion(row['可食部\\n(克/份)'])\n",
    "\n",
    "        if dish_name not in meals_dict:\n",
    "            meals_dict[dish_name] = {\n",
    "                'name': dish_name,\n",
    "                'price': price,\n",
    "                'half_portion': half_portion,\n",
    "                'ingredients': {ingredient_idx: amount}\n",
    "            }\n",
    "        else:\n",
    "            # Merge ingredients\n",
    "            meals_dict[dish_name]['ingredients'][ingredient_idx] = amount\n",
    "\n",
    "    return list(meals_dict.values())\n",
    "\n",
    "\n",
    "def load_recipe(file_path= 'data/recipe.xlsx'):\n",
    "    # Load and prepare the data\n",
    "    data_dishes = pd.read_excel(file_path, header=None)\n",
    "    data_dishes = data_dishes.ffill(axis=0)\n",
    "\n",
    "    # Set header and remove header row data from processing\n",
    "    header_row = data_dishes[data_dishes.iloc[:, 0] == '序号'].index[0]\n",
    "    data_dishes.columns = data_dishes.iloc[header_row]\n",
    "    data_dishes = data_dishes.iloc[header_row+1:].reset_index(drop=True)\n",
    "\n",
    "    # Find indices for meals\n",
    "    meal_indices = data_dishes[data_dishes['序号'].isin(['早餐', '午餐', '晚餐'])].index\n",
    "\n",
    "    # Define and process meals\n",
    "    breakfast = create_merged_meals(data_dishes.iloc[:meal_indices[0]])\n",
    "    lunch = create_merged_meals(data_dishes.iloc[meal_indices[0]+2:meal_indices[1]])\n",
    "    dinner = create_merged_meals(data_dishes.iloc[meal_indices[1]+2:])\n",
    "    return breakfast, lunch, dinner\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'name': '小米粥', 'ingredients': {15101: 15}, 'multiple': 1},\n",
       " {'name': '油条', 'ingredients': {'011201x': 50, 192004: 10}, 'multiple': 2},\n",
       " {'name': '煎鸡蛋', 'ingredients': {'111101x': 50, 192004: 10}, 'multiple': 1},\n",
       " {'name': '拌海带丝', 'ingredients': {52004: 100, 192017: 4}, 'multiple': 1}]"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def create_merged_meals(meal_df):\n",
    "    # Create a dictionary to store meals and their attributes\n",
    "    meals_dict = {}\n",
    "    for index, row in meal_df.iterrows():\n",
    "        dish_name = row['食物名称']\n",
    "        ingredient_idx = row['食物编码']\n",
    "        amount = row['可食部(克/份)']\n",
    "        multiple = row['食用份数']\n",
    "\n",
    "        if dish_name not in meals_dict:\n",
    "            meals_dict[dish_name] = {\n",
    "                'name': dish_name,\n",
    "                'ingredients': {ingredient_idx: amount},\n",
    "                'multiple': multiple\n",
    "            }\n",
    "        else:\n",
    "            if ingredient_idx in meals_dict[dish_name]['ingredients']:\n",
    "                # Sum the amounts if the ingredient is already listed under the dish\n",
    "                meals_dict[dish_name]['ingredients'][ingredient_idx] += amount\n",
    "            else:\n",
    "                meals_dict[dish_name]['ingredients'][ingredient_idx] = amount\n",
    "\n",
    "    # Convert the dictionary to a list of dictionaries for each dish\n",
    "    return list(meals_dict.values())\n",
    "\n",
    "def load_and_process_diet(file_path):\n",
    "    # Load the Excel file\n",
    "    data = pd.read_excel(file_path, header=None)\n",
    "    data = data.ffill(axis=0)\n",
    "    \n",
    "    # Detect meals and process them with aggregation\n",
    "    meals = [\"早餐\", \"午餐\", \"晚餐\"]\n",
    "    meal_data = {}\n",
    "    current_meal = None\n",
    "    meal_indices = {}\n",
    "    \n",
    "    # Find indices for each meal\n",
    "    for index, row in data.iterrows():\n",
    "        if row[0] in meals:\n",
    "            current_meal = row[0]\n",
    "            meal_indices[current_meal] = index\n",
    "\n",
    "    # Process and aggregate each meal\n",
    "    for meal in meals:\n",
    "        start = meal_indices[meal] + 2  # Skip meal name and headers\n",
    "        end = meal_indices.get(meals[meals.index(meal) + 1], None) if meals.index(meal) + 1 < len(meals) else len(data)\n",
    "        meal_df = data.iloc[start:end].reset_index(drop=True)\n",
    "        meal_df.columns = ['食物名称', '主要成分', '食物编码', '可食部(克/份)', '食用份数']\n",
    "        meal_data[meal] = create_merged_meals(meal_df)\n",
    "    \n",
    "    return meal_data['早餐'], meal_data['午餐'], meal_data['晚餐']\n",
    "\n",
    "# Load and process the diet data\n",
    "breakfast_aggregated, lunch_aggregated, dinner_aggregated = load_and_process_diet(\"data/male_diat.xlsx\")\n",
    "\n",
    "# Display a sample from the aggregated breakfast data\n",
    "breakfast_aggregated[:5]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "base",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}

2.3第二小问问题分析

        本问是一道约束优化问题,要求我们分别以蛋白质氨基酸评分最大、用餐费用最经济、兼顾蛋白质氨基酸评分和经济性进行优化设计。相关的约束条件为附件4的第三节所提及的相关条件. 最终建立优化模型进行求解.

第二小问代码(部分)
1.clear;
2.clc;
3.
4.global te;
5.global te1;
6.global te2;
7.global T;
8.
9.te=[];
10.te1=[];
11.te2=[];
12.T=[];
13.
14.opts = detectImportOptions('Updated_Dictionary_English.xlsx');
15.opts = setvartype(opts, 'FoodCode', 'string');  % 将 'FoodCode' 设置为 'string' 类型
16.dict = readtable('Updated_Dictionary_English.xlsx', opts);
17.
18.opts = detectImportOptions('Updated_Food_English.xlsx');
19.opts = setvartype(opts, 'FoodCode', 'string');  % 将 'FoodCode' 设置为 'string' 类型
20.food = readtable('Updated_Food_English.xlsx', opts);
21.
22.
23.dataStruct = struct();
24.dataStruct.foodTable = food;  % 将食物表格存储为结构体的一个字段
25.dataStruct.dictTable = dict;  % 将字典表格存储为结构体的另一个字段
26.
27.x_value = linspace(1, 141, 141);
28.x_num = 141;
29.
30.%% 遗传算法
31.objfun2 = @(x)calculate_total_energy(x,dataStruct);
32.confun2 = @(x)constraintFcn(x,dataStruct);
33.options2 = optimoptions("ga", "PlotFcn", "gaplotbestf", "TimeLimit", 30);
34.[solution,objectiveValue] = ga(objfun2,x_num,[],[],[],[],zeros(x_num,1),...
35.    repmat(3,x_num,1),confun2,x_value,options2);
36.
37.%% 结果输出
38.disp('目标函数值')
39.disp(-objectiveValue)
40.
41.disp('各种食物的份数')
42.disp(solution)
43.%%
44.% plot(te)
45.%
46.% plot(te1)
47.%
48.% plot(te2)
49.%% 目标函数,计算其中一种蛋白质的氨基酸评分
50.function total_score = calculate_total_energy(x, a)
51.global T;
52.% 从结构体中提取表格
53.food_table = a.foodTable;
54.dict_table = a.dictTable;
55.
56.total_score = 0;
57.
58.aminoacid = zeros(1, 8);
59.Protein = 0;
60.
61.for i = 1:length(x)
62.    food_code = food_table.FoodCode(i); % 获取食物编码
63.    edible_part_per_serving = food_table.EdiblePartPerServing(i); % 获取每份的可食部分
64.    
65.    % 获取对应食物编码的氨基酸得分
66.    if any(strcmp(dict_table.FoodCode, food_code))
67.        aminoacid(1, 1) = aminoacid(1, 1) + x(i)*dict_table{strcmp(dict_table.FoodCode, food_code), 'AA_1'} * edible_part_per_serving / 100;
68.        aminoacid(1, 2) = aminoacid(1, 2) + x(i)*dict_table{strcmp(dict_table.FoodCode, food_code), 'AA_2'} * edible_part_per_serving / 100;
69.        aminoacid(1, 3) = aminoacid(1, 3) + x(i)*dict_table{strcmp(dict_table.FoodCode, food_code), 'AA_3'} * edible_part_per_serving / 100;
70.        aminoacid(1, 4) = aminoacid(1, 4) + x(i)*dict_table{strcmp(dict_table.FoodCode, food_code), 'AA_4'} * edible_part_per_serving / 100;
71.        aminoacid(1, 5) = aminoacid(1, 5) + x(i)*dict_table{strcmp(dict_table.FoodCode, food_code), 'AA_5'} * edible_part_per_serving / 100;
72.        aminoacid(1, 6) = aminoacid(1, 6) + x(i)*dict_table{strcmp(dict_table.FoodCode, food_code), 'AA_6'} * edible_part_per_serving / 100;
73.        aminoacid(1, 7) = aminoacid(1, 7) + x(i)*dict_table{strcmp(dict_table.FoodCode, food_code), 'AA_7'} * edible_part_per_serving / 100;
74.        aminoacid(1, 8) = aminoacid(1, 8) + x(i)*dict_table{strcmp(dict_table.FoodCode, food_code), 'AA_8'} * edible_part_per_serving / 100;
75.        
76.        Protein = Protein + x(i)*dict_table{strcmp(dict_table.FoodCode, food_code), 'Protein'} * edible_part_per_serving / 100;
77.    else
78.        disp(food_code)
79.    end
80.    
81.end
82.
83.aminoacid = aminoacid / Protein;
84.
85.aminoacid(1, 1) = aminoacid(1, 1) / 40;
86.aminoacid(1, 2) = aminoacid(1, 2) / 70;
87.aminoacid(1, 3) = aminoacid(1, 3) / 55;
88.aminoacid(1, 4) = aminoacid(1, 4) / 35;
89.aminoacid(1, 5) = aminoacid(1, 5) / 60;
90.aminoacid(1, 6) = aminoacid(1, 6) / 40;
91.aminoacid(1, 7) = aminoacid(1, 7) / 10;
92.aminoacid(1, 8) = aminoacid(1, 8) / 50;
93.
94.aminoacid_min = min(aminoacid);
95.
96.total_score = - aminoacid_min * 100;
97.T=total_score;
98.end
99.
100.
101.function [c, ceq] = constraintFcn(x, a)
102.global te;
103.global te1;
104.global te2;
105.
106.% 重置当前计算的变量
107.temp_te = [];
108.temp_te1 = [];
109.temp_te2 = [];
110.
111.food_table = a.foodTable;
112.dict_table = a.dictTable;
113.
114.total_energy = 0;
115.
116.for i = 1:length(x)
117.    food_code = food_table.FoodCode(i);
118.    edible_part_per_serving = food_table.EdiblePartPerServing(i);
119.    temp_te1 = [temp_te1 edible_part_per_serving];
120.    
121.    if any(strcmp(dict_table.FoodCode, food_code))
122.        idx = find(strcmp(dict_table.FoodCode, food_code));
123.        energy_per_gram = dict_table.EnergyPerGram(idx);
124.        temp_te2 = [temp_te2 energy_per_gram];
125.        total_energy = total_energy + x(i) * edible_part_per_serving * energy_per_gram / 100;
126.        temp_te = [temp_te total_energy];
127.    else
128.        disp(['Error: food code not found - ', food_code])
129.    end
130.end
131.
132.% 更新全局变量
133.te = [te temp_te];
134.% 筛选出在范围内的数
135.te  = te (te >= 2400 * 0.9 & te <= 2400 * 1.1);
136.te1 = [te1 temp_te1];
137.te2 = [te2 temp_te2];
138.
139.% 约束条件
140.c(1) = total_energy - 2400 * 1.1;
141.c(2) = 2400 * 0.9 - total_energy;
142.ceq = [];
143.
144.% 检查 te 是否在范围内
145.if total_energy > 2600
146.    c(3) = total_energy - 2600;
147.elseif total_energy < 2400
148.    c(3) = 2400 - total_energy;
149.else
150.    c(3) = 0;
151.end
152.
153.disp(['Total energy: ', num2str(total_energy)])
154.disp(['Length of te: ', num2str(length(te))]);
155.disp(['Length of te1: ', num2str(length(te1))]);
156.disp(['Length of te2: ', num2str(length(te2))]);
157.end
158.

2.4第三小问问题分析

        本问在第二小问的基础上升级, 也是约束优化问题,但是考虑的规模更大,B站up: 全糖奶茶屋并且引入一个新的约束条件:每周摄入食物种类大于25种。同时要保证每天的饮食结构是合理的,所以在这里对算法本身的效率以及编程时数据处理的架构提出了要求,需要高效的求解.

2.5第四小问问题分析

        针对第四小问,我们需要撰写一份倡议书,旨在提升大学生对健康饮食的认识,引导他们形成科学的饮食习惯。倡议书将概述大学生饮食现状,强调平衡膳食的重要性,并提供具体的饮食建议,以促进校园内健康饮食文化的建立。

  • 4
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值