Matlab离散优化: Mixed-Integer Linear Programming Basics: Problem-Based

Mixed-Integer Linear Programming Basics: Problem-Based

全文翻译自Matlab官方教程:Mixed-Integer Linear Programming Basics: Problem-Based

这个例子展示了如何解决一个混合整数线性问题。虽然不复杂,但示例显示了使用基于问题的方法来构造问题的典型步骤。有关显示此示例的视频,请参见 Mixed-Integer Linear Programming Basics: Sovler-Based

Problem Description

你想把不同化学成分的钢混合起来,得到25吨具有特定化学成分的钢。结果应含有5%的碳和5%的钼(按重量计),即25吨*5%=1.25吨碳和1.25吨钼。其目的是尽量降低钢的混合成本。

这个问题摘自Carl Henrik Westerberg,Bengt Bjorklund和Eskil Hultman,“瑞典钢铁厂混合整数规划的应用”,接口1977年2月第7卷,第2期,第39-43页,摘要见https://doi.org/10.1287/inte.7.2.39。

有四块钢锭可供购买,每个钢锭只有一个可用。

在这里插入图片描述
可购买三级合金钢和一级废钢,合金钢和废钢可以少量购买。

在这里插入图片描述

Formulate Problem

要解决这个问题,首先要确定控制变量。取变量ingot(1)=1ingot(1)=1表示购买锭1,ingot(1)=0ingot(1)=0表示不购买锭1。类似地,变量ingot(2)ingot(2)ingot(4)ingot(4)是指示您是否购买锭2到锭4的二进制变量。

变量alloys(1)alloys(1)到合金alloys(3)alloys(3)是以吨为单位购买的合金1、2和3的数量。scrapscrap是您购买的废钢数量。

steelprob = optimproblem;
ingots = optimvar('ingots',4,'Type','integer','LowerBound',0,'UpperBound',1);
alloys = optimvar('alloys',3,'LowerBound',0);
scrap = optimvar('scrap','LowerBound',0);

创建cost的函数。

weightIngots = [5,3,4,6];
costIngots = weightIngots.*[350,330,310,280];
costAlloys = [500,450,400];
costScrap = 100;
cost = costIngots*ingots + costAlloys*alloys + costScrap*scrap;

把cost作为目标函数包含在问题中。

steelprob.Objective = cost;

这个问题有三个等式约束。第一个限制是总重量是25吨,计算钢的重量:

totalWeight = weightIngots*ingots + sum(alloys) + scrap;

第二个限制是碳的重量是25吨的5%,即1.25吨。计算钢中碳的重量:

carbonIngots = [5,4,5,3]/100;
carbonAlloys = [8,7,6]/100;
carbonScrap = 3/100;
totalCarbon = (weightIngots.*carbonIngots)*ingots + carbonAlloys*alloys + carbonScrap*scrap;

第三个限制是钼的重量是1.25吨。计算钢中钼的重量:

molybIngots = [3,3,4,4]/100;
molybAlloys = [6,7,8]/100;
molybScrap = 9/100;
totalMolyb = (weightIngots.*molybIngots)*ingots + molybAlloys*alloys + molybScrap*scrap;

在问题中包含约束:

steelprob.Constraints.conswt = totalWeight == 25;
steelprob.Constraints.conscarb = totalCarbon == 1.25;
steelprob.Constraints.consmolyb = totalMolyb == 1.25;

Solve Problem

调用求解器:

[sol,fval] = solve(steelprob);

输出:

Solving problem using intlinprog.
LP:                Optimal objective value is 8125.600000.                                          

Cut Generation:    Applied 3 mir cuts.                                                              
                   Lower bound is 8495.000000.                                                      
                   Relative gap is 0.00%.                                                          


Optimal solution found.

Intlinprog stopped at the root node because the objective value is within a gap
tolerance of the optimal value, options.AbsoluteGapTolerance = 0 (the default
value). The intcon variables are integer within tolerance,
options.IntegerTolerance = 1e-05 (the default value).

查看结果:

sol.ingots
ans = 4×1

    1.0000
    1.0000
         0
    1.0000
sol.alloys
ans = 3×1

    7.2500
         0
    0.2500
sol.scrap
sol.fval
ans = 3.5000
fval = 8.4950e+03

最佳购买价格为8495美元。购买1号、2号和4号钢锭,但不要购买3号钢锭,购买7.25吨合金1、0.25吨合金3和3.5吨废钢。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章