【数学建模】【matlab & lingo】模糊规划和非线性规划

您所在的位置:网站首页 lingo是干什么用的 【数学建模】【matlab & lingo】模糊规划和非线性规划

【数学建模】【matlab & lingo】模糊规划和非线性规划

2024-03-04 00:06| 来源: 网络整理| 查看: 265

因为敲符号实在是太麻烦了,所以我把约束条件写在了注释里面。 我也是在学习过程中,这不是标答,都是我自己写的,所以大家辨证看待我写的内容。 欢迎大家批评指正,别骂的太凶我都能接受的(捂脸)。 问题一

在这里插入图片描述

计算已知距离

利用matlab软件计算两个临时料场到建筑工地的距离

function NJUCM_2() function Distance = cal_length(a_1, b_1, a_2, b_2) %% 定义一个计算距离的函数; temp_1 = (a_1 - a_2) ^ 2; temp_2 = (b_1 - b_2) ^ 2; Distance = (temp_1 + temp_2) ^ 0.5; end %% 数据的输入与预定义; Construction_site_location = [[1.25, 1.25]; [8.75, 0.75]; [0.5, 4.75]; [5.75, 5]; [3, 6.5]; [7.25, 1.75]]; Yard_temp_location = [[5, 1]; [2, 7]]; Distance_construction_yard = zeros(2, 6); %% 分别计算两个料场到建筑工地的距离; for i = 1 : 2 for j = 1 : 6 Distance_construction_yard(i, j) = cal_length(Construction_site_location(j, 1), Construction_site_location(j, 2), Yard_temp_location(i, 1), Yard_temp_location(i, 2)); end end disp(Distance_construction_yard) end

得到如下结果(i 行 j 列代表第 i 个料场到第 j 个工地的距离) 在这里插入图片描述

规划约束

我最开始是这样写的,但是它告诉我这不是最优解,我尝试把它理解为一个局部最优解(?)

model: title NJUCM 3_1; sets: Temp_yard/1..2/:Temp_yard_reserves; ! 临时料场的储量; Construction_site/1..6/:Construction_site_requirement; ! 工地的需求量; link_1(Temp_yard, Temp_yard):Yard_location, Yard_temp_distance, Goods_quantity_1, Temp_yard_location; ! 新料场的位置; link_2(Temp_yard, Construction_site):Distance_yard_site, Goods_quantity_2; ! 临时料场到工地的距离; endsets data: Temp_yard_reserves = 20, 20; Construction_site_requirement = 3 5 4 7 6 11; Distance_yard_site = 3.7583 3.7583 5.8577 4.0697 5.8523 2.3717 5.7987 9.1992 2.7042 4.2500 1.1180 7.4246; Temp_yard_location = 5 1 2 7; enddata min = @sum(link_1(i, j) : Goods_quantity_1(i, j) * Yard_temp_distance(i, j)) + @sum(link_2(i, j) : Goods_quantity_2(i, j) * Distance_yard_site(i, j)); ! 给新料场与临时料场的距离赋值; @for(link_1(i, j) : Yard_temp_distance(i, j) = ((Yard_location(i, 1) - Temp_yard_location(j, 1))^2 + (Yard_location(i, 2) - Temp_yard_location(j, 2))^2) ^ 0.5); ! 从料场运到临时料场的数量 > 临时料场运到建筑工地的数量; @for(Temp_yard(i) : @sum(link_1(i, j) : Goods_quantity_1(i, j)) > @sum(link_2(i, j) : Goods_quantity_2(i, j))); ! 从料场运送到临时料场的货物数量 Construction_site_requirement(j)); end

这句话就是告诉我,这可能不是一个最优解 在这里插入图片描述

老师的做法

老师用到一个新的定义:

! 初始段:对集合属性定义初值(迭代算法的迭代初值);

好像使用 init 来定义的,查询资料后可知知道,就是把这两个变量定义一个初值,设置一个迭代(计算)的起点,这样可以大幅度提高计算效率,也可以尽量向全局最优解靠近。

但我在这边还是有点不理解,再学习一下吧

问题二

在这里插入图片描述

普通线性规划 ! 2022/03/09; ! 略小(大)于 范围均限制在 2; ! 需要原料 约为 范围限制在 正负2; ! 原料总数 约为 范围限制在 正负200; model: title NJUCM第三次作业; sets: Medicine/1..2/:Profits_medicine, Number_production; Material/1..2/:Total_material; link(Medicine, Material):Consuption; endsets data: Profits_medicine = 3 4; Total_material = 4600 4800; Consuption = 4 12 20 6.4; enddata max = @sum(Medicine(i) : Number_production(i) * Profits_medicine(i)); @for(Material(j) : @sum(Medicine(i) : Number_production(i) * Consuption(i, j))


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3