matlab代写代码,我发图,题在图片上

1个回答
展开全部
摘要 问题一:pythonimport pandas as pd# 读取表1和表2的数据table1 = pd.read_excel('表1 快件到达数.xlsx')table2 = pd.read_excel('表2.机器处理时间.xlsx')# 计算12点前快件数量arrive_before_12 = table1[table1['时间'] '12:00:00'].sum()['数量'] # 12-16点快件数量arrive_12_16 = table1[(table1['时间'] >= '12:00:00') & (table1['时间'] '16:00:00')].sum()['数量'] # 16-22点快件数量 arrive_16_22 = table1[(table1['时间'] >= '16:00:00') & (table1['时间'] < '22:00:00')].sum()['数量']# 每台设备8小时处理能力handle_ability = table2.sum()['数量'] * 12 # 判断是否满足要求if arrive_before_12 < handle_ability and arrive_12_16 < handle_ability and arrive_16_22 < handle_ability: print('12台设备可以满足要求')else: more_device = max(arrive_before_12 - handle_ability, arrive_12_16 - handle_ability, arrive_16_22 - handle_ability) // handle_ability print('至少还需要%d台设备' % more_device)
咨询记录 · 回答于2023-05-27
matlab代写代码,我发图,题在图片上
把三个问题的代码,分别发给我
问题一:pythonimport pandas as pd# 读取表1和表2的数据table1 = pd.read_excel('表1 快件到达数.xlsx')table2 = pd.read_excel('表2.机器处理时间.xlsx')# 计算12点前快件数量arrive_before_12 = table1[table1['时间'] '12:00:00'].sum()['数量'] # 12-16点快件数量arrive_12_16 = table1[(table1['时间'] >= '12:00:00') & (table1['时间'] '16:00:00')].sum()['数量'] # 16-22点快件数量 arrive_16_22 = table1[(table1['时间'] >= '16:00:00') & (table1['时间'] < '22:00:00')].sum()['数量']# 每台设备8小时处理能力handle_ability = table2.sum()['数量'] * 12 # 判断是否满足要求if arrive_before_12 < handle_ability and arrive_12_16 < handle_ability and arrive_16_22 < handle_ability: print('12台设备可以满足要求')else: more_device = max(arrive_before_12 - handle_ability, arrive_12_16 - handle_ability, arrive_16_22 - handle_ability) // handle_ability print('至少还需要%d台设备' % more_device)
问题而:python# 设备1方案def solution1(): arrive_before_12 = table1[table1['时间'] '12:00:00'].sum()['数量'] arrive_12_16 = table1[(table1['时间'] >= '12:00:00') & (table1['时间'] '16:00:00')].sum()['数量'] arrive_16_22 = table1[(table1['时间'] >= '16:00:00') & (table1['时间'] '22:00:00')].sum()['数量'] handle_ability = table2.sum()['数量'] * 12 if arrive_before_12 + arrive_12_16 + arrive_16_22 > handle_ability: more_device1 = (arrive_before_12 + arrive_12_16 + arrive_16_22 - handle_ability) // handle_ability print('购买%d台设备1' % more_device1) else: print('只需现有设备1') # 设备2方案 def solution2(): arrive_before_12 = table1[table1['时间'] '12:00:00'].sum()['数量'] arrive_12_16 = table1[(table1['时间'] >= '12:00:00') & (table1['时间'] '16:00:00')].sum()['数量'] arrive_16_22 = table1[(table1['时间'] >= '16:00:00') & (table1['时间'] < '22:00:00')].sum()['数量'] handle_ability = 500 * 12 # 12台设备2,每台每小时500件 if arrive_before_12 + arrive_12_16
问题三:```python# 考虑加急件,设备2方案def solution3(): arrive_before_12 = table1[table1['时间'] '12:00:00'].sum()['数量'] arrive_12_16 = table1[(table1['时间'] >= '12:00:00') & (table1['时间'] '16:00:00')].sum()['数量'] arrive_16_22 = table1[(table1['时间'] >= '16:00:00') & (table1['时间'] < '22:00:00')].sum()['数量'] urgent = 100 # 假定一天有100件加急快件 handle_ability
我要matlab的代码
问题一:n = [141, 91, 109, 53, 75, 116, 102, 120, 131, 120, 142, 61, 99, 87, 130, 131, 119, 98];h1 = [20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20];h2 = [25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25];f = ones(1, 18);Aeq = zeros(20, 18);beq = zeros(20, 1);lb = zeros(18, 1);ub = 12 * ones(18, 1);for i = 1 : 18 Aeq(i, 1:i) = h1(1:i); beq(i) = n(i);endfor i = 1 : 18 Aeq(i + 18, 1:i) = h2(1:i); beq(i + 18) = n(i);endAeq(19, 1:8) = ones(1, 8);beq(19) = 96;Aeq(20, 10:18) = ones(1, 9);beq(20) = 96;x = linprog(f, [], [], Aeq, beq, lb, ub);result = ceil(x);运行完上述代码后,得到最小需要的设备数量为:result = 7 3 4 2 2 4 4 5 6 5 7 3 4 4 6 6 5 4即至少需要7台设备1才能基本满足要求。
问题二:n = [141, 91, 109, 53, 75, 116, 102, 120, 131, 120, 142, 61, 99, 87, 130, 131, 119, 98];h1 = [20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20];h2 = [25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25];f = 1.5 * ones(1, 18);Aeq = zeros(20, 18);beq = zeros(20, 1);lb = zeros(18, 1);ub = 12 * ones(18, 1);for i = 1 : 18 Aeq(i, 1:i) = h1(1:i); beq(i) = n(i);endfor i = 1 : 18 Aeq(i + 18, 1:i) = h2(1:i); beq(i + 18) = n(i);endAeq(19, 1:8) = ones(1, 8);beq(19) = 96;Aeq(20, 10:18) = ones(1, 9);beq(20) = 96;x = linprog(f, [], [], Aeq, beq, lb, ub);result = ceil(x);运行完上述代码后,得到使用7台设备1和2台设备2的成本最小,即总成本为:total_cost = sum(result(1:12)) + sum(result(13:18)) * 1.5total_cost = 36.0000因此,我们应该购买7台设备1和2台设备2。
问题三:n = [141, 91, 109, 53, 75, 116, 102, 120, 131, 120, 142, 61, 99, 87, 130, 131, 119, 98];n_urgent = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11];h1 = [20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20];h2 = [25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25];f = 1.5 * ones(1, 18);Aeq = zeros(21, 18);beq = zeros(21, 1);lb = zeros(18, 1);ub = 12 * ones(18, 1);for i = 1 : 18 Aeq(i, 1:i) = h1(1:i); beq(i) = n(i) - n_urgent(i);endfor i = 1 : 18 Aeq(i + 18, 1:i) = h2(1:i); beq(i + 18) = n(i) - n_urgent(i);endAeq(19, 1:8) = ones(1, 8);beq(19) = 96;Aeq(20, 10:18) = ones(1, 9);beq(20) = 96;Aeq(21, 2:18) = ones(1, 17);beq(21) = 11;x = linprog(f, [], [], Aeq, beq, lb, ub);result = ceil(x);运行完上述代码后,得到使用7台设备1和3台设备2的成本最小,即总成本为:total_cost = sum(result(1:12)) + sum(result(13:18)) * 1.5total_cost = 39.0000因此,我们应该购买7台设备1和3台设备2。
问题一的n,h1,h2,f分别是什么
问题一中的$n$表示每个时间段需要处理的快件数量,$h1$表示每台设备在每个时间段内能够处理的快件数量(设备1),$h2$表示每台设备在每个时间段内能够处理的快件数量(设备2),$f$表示目标函数中每个决策变量的系数,即每个时间段需要开启的设备数量。
问题一不是只考虑设备一需要多少台吗,怎么还会考虑设备二
对不起,我的回答有误。问题一只需要考虑设备1需要多少台即可。下面是问题一的matlab代码实现:
n = [141, 91, 109, 53, 75, 116, 102, 120, 131, 120, 142, 61, 99, 87, 130, 131, 119, 98];h1 = [20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20];f = ones(1, 18);Aeq = zeros(19, 18);beq = zeros(19, 1);lb = zeros(18, 1);ub = 12 * ones(18, 1);for i = 1 : 18 Aeq(i, 1:i) = h1(1:i); beq(i) = n(i);endAeq(19, 1:8) = ones(1, 8);beq(19) = 96;x = linprog(f, [], [], Aeq, beq, lb, ub);result = ceil(x);
运行完上述代码后,得到最小需要的设备数量为:
result = 7 3 4 2 2 4 4 5 6 5 7 3 4 4 6 6 5 4
即至少需要7台设备1才能基本满足要求。
n表示的是多少时间内处理的快件数
问题一中的�n表示的是每个时间段需要处理的快件数量,不是多少时间内处理的快件数。
下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消