>> x = optimvar('x', 6, 1); % 生产量 t = optimvar('t', 6, 1); % 加班时间 % 定义目标函数 r = [1700, 1540, 1510, 1600, 1640, 1450]; % 工资标准 d = [192, 192, 192, 192, 192, 192]; % 正常工作时间 Q = 0; % 总运输成本,需要根据具体数据计算 z = sum(r.* (d + 1.3 * d.* t / 192)'); % 注意这里添加了转置操作 obj = z + Q; % 定义约束条件 b = Xql; % 各城市的月需求量 a = D; % 各工厂到各城市的距离 y = optimvar('y', 6, 18, 'Type', 'Binary'); % 表示工厂提供城市产品的二进制变量 con1 = [sum(b.* y(1, :)) <= x(1); sum(b.* y(2, :)) <= x(2); sum(b.* y(3, :)) <= x(3); sum(b.* y(4, :)) <= x(4); sum(b.* y(5, :)) <= x(5); sum(b.* y(6, :)) <= x(6)]; con2 = [sum(y(:, 1)) == 1; sum(y(:, 2)) == 1; sum(y(:, 3)) == 1; sum(y(:, 4)) == 1; sum(y(:, 5)) == 1; sum(y(:, 6)) == 1; sum(y(:, 7)) == 1; sum(y(:, 8)) == 1; sum(y(:, 9)) == 1; sum(y(:, 10)) == 1; sum(y(:, 11)) == 1; sum(y(:, 12)) == 1; sum(y(:, 13)) == 1; sum(y(:, 14)) == 1; sum(y(:, 15)) == 1; sum(y(:, 16)) == 1; sum(y(:, 17)) == 1; sum(y(:, 18)) == 1]; % 定义线性规划问题 prob = optimproblem('Objective', obj, 'Variables', {x, t, y}, 'Constraints', {con1, con2}); % 求解线性规划问题 sol = solve(prob); % 输出结果 disp('生产量:'); disp(sol.x); disp('加班时间:'); disp(sol.t); 错误使用 optim.internal.problemdef.ElementwiseOperator/checkIsValid Argument dimensions 1-by-6 and 6-by-1 must agree. 出错 optim.internal.problemdef.Times/checkIsValid 出错 optim.internal.problemdef.Times.getTimesOperator 出错 .*
理解问题>> x = optimvar('x', 6, 1); % 生产量 t = optimvar('t', 6, 1); % 加班时间 % 定义目标函数 r = [1700, 1540, 1510, 1600, 1640, 1450]; % 工资标准 d = [192, 192, 192, 192, 192, 192]; % 正常工作时间 Q = 0; % 总运输成本,需要根据具体数据计算 z = sum(r.* (d + 1.3 * d.* t / 192)'); % 注意这里添加了转置操作 obj = z + Q; % 定义约束条件 b = Xql; % 各城市的月需求量 a = D; % 各工厂到各城市的距离 y = optimvar('y', 6, 18, 'Type', 'Binary'); % 表示工厂提供城市产品的二进制变量 con1 = [sum(b.* y(1, :)) <= x(1); sum(b.* y(2, :)) <= x(2); sum(b.* y(3, :)) <= x(3); sum(b.* y(4, :)) <= x(4); sum(b.* y(5, :)) <= x(5); sum(b.* y(6, :)) <= x(6)]; con2 = [sum(y(:, 1)) == 1; sum(y(:, 2)) == 1; sum(y(:, 3)) == 1; sum(y(:, 4)) == 1; sum(y(:, 5)) == 1; sum(y(:, 6)) == 1; sum(y(:, 7)) == 1; sum(y(:, 8)) == 1; sum(y(:, 9)) == 1; sum(y(:, 10)) == 1; sum(y(:, 11)) == 1; sum(y(:, 12)) == 1; sum(y(:, 13)) == 1; sum(y(:, 14)) == 1; sum(y(:, 15)) == 1; sum(y(:, 16)) == 1; sum(y(:, 17)) == 1; sum(y(:, 18)) == 1]; % 定义线性规划问题 prob = optimproblem('Objective', obj, 'Variables', {x, t, y}, 'Constraints', {con1, con2}); % 求解线性规划问题 sol = solve(prob); % 输出结果 disp('生产量:'); disp(sol.x); disp('加班时间:'); disp(sol.t); 错误使用 optim.internal.problemdef.ElementwiseOperator/checkIsValid Argument dimensions 1-by-6 and 6-by-1 must agree. 出错 optim.internal.problemdef.Times/checkIsValid 出错 optim.internal.problemdef.Times.getTimesOperator 出错 .*
已完成理解「>> x = optimvar('x', 6, 1); % 生产量 t = optimvar('t', 6, 1); % 加班时间 % 定义目标函数 r = [1700, 1540, 1510, 1600, 1640, 1450]; % 工资标准 d = [192, 192, 192, 192, 192, 192]; % 正常工作时间 Q = 0; % 总运输成本,需要根据具体数据计算 z = sum(r.* (d + 1.3 * d.* t / 192)'); % 注意这里添加了转置操作 obj = z + Q; % 定义约束条件 b = Xql; % 各城市的月需求量 a = D; % 各工厂到各城市的距离 y = optimvar('y', 6, 18, 'Type', 'Binary'); % 表示工厂提供城市产品的二进制变量 con1 = [sum(b.* y(1, :)) <= x(1); sum(b.* y(2, :)) <= x(2); sum(b.* y(3, :)) <= x(3); sum(b.* y(4, :)) <= x(4); sum(b.* y(5, :)) <= x(5); sum(b.* y(6, :)) <= x(6)]; con2 = [sum(y(:, 1)) == 1; sum(y(:, 2)) == 1; sum(y(:, 3)) == 1; sum(y(:, 4)) == 1; sum(y(:, 5)) == 1; sum(y(:, 6)) == 1; sum(y(:, 7)) == 1; sum(y(:, 8)) == 1; sum(y(:, 9)) == 1; sum(y(:, 10)) == 1; sum(y(:, 11)) == 1; sum(y(:, 12)) == 1; sum(y(:, 13)) == 1; sum(y(:, 14)) == 1; sum(y(:, 15)) == 1; sum(y(:, 16)) == 1; sum(y(:, 17)) == 1; sum(y(:, 18)) == 1]; % 定义线性规划问题 prob = optimproblem('Objective', obj, 'Variables', {x, t, y}, 'Constraints', {con1, con2}); % 求解线性规划问题 sol = solve(prob); % 输出结果 disp('生产量:'); disp(sol.x); disp('加班时间:'); disp(sol.t); 错误使用 optim.internal.problemdef.ElementwiseOperator/checkIsValid Argument dimensions 1-by-6 and 6-by-1 must agree. 出错 optim.internal.problemdef.Times/checkIsValid 出错 optim.internal.problemdef.Times.getTimesOperator 出错 .*」
展开阅读网页