# 混合整数线性规划基础：基于求解器

### 问题描述

`$\begin{array}{ccccc}Ingot& Weight\phantom{\rule{0.2777777777777778em}{0ex}}in\phantom{\rule{0.2777777777777778em}{0ex}}Tons& %\phantom{\rule{0.2777777777777778em}{0ex}}Carbon& %\phantom{\rule{0.2777777777777778em}{0ex}}Molybdenum& \frac{Cost}{Ton}\\ 1& 5& 5& 3& 350\\ 2& 3& 4& 3& 330\\ 3& 4& 5& 4& 310\\ 4& 6& 3& 4& 280\end{array}$`

`$\begin{array}{cccc}Alloy& %\phantom{\rule{0.2777777777777778em}{0ex}}Carbon& %\phantom{\rule{0.2777777777777778em}{0ex}}Molybdenum& \frac{Cost}{Ton}\\ 1& 8& 6& 500\\ 2& 7& 7& 450\\ 3& 6& 8& 400\\ Scrap& 3& 9& 100\end{array}$`

### MATLAB® 表示

`[x,fval] = intlinprog(f,intcon,A,b,Aeq,beq,lb,ub)`

`intlinprog` 创建输入，从第一个 (`f`) 到最后一个 (`ub`) 都包含在内。

`f` 是由成本系数组成的向量。表示钢锭成本的系数是钢锭重量与其每吨成本之积。

`f = [350*5,330*3,310*4,280*6,500,450,400,100];`

`intcon = 1:4;`

```A = []; b = [];```

`5*x(1) + 3*x(2) + 4*x(3) + 6*x(4) + x(5) + x(6) + x(7) + x(8) = 25`

`5*0.05*x(1) + 3*0.04*x(2) + 4*0.05*x(3) + 6*0.03*x(4)`

` + 0.08*x(5) + 0.07*x(6) + 0.06*x(7) + 0.03*x(8) = 1.25`

`5*0.03*x(1) + 3*0.03*x(2) + 4*0.04*x(3) + 6*0.04*x(4)`

` + 0.06*x(5) + 0.07*x(6) + 0.08*x(7) + 0.09*x(8) = 1.25`

```Aeq = [5,3,4,6,1,1,1,1; 5*0.05,3*0.04,4*0.05,6*0.03,0.08,0.07,0.06,0.03; 5*0.03,3*0.03,4*0.04,6*0.04,0.06,0.07,0.08,0.09]; beq = [25;1.25;1.25];```

```lb = zeros(8,1); ub = ones(8,1); ub(5:end) = Inf; % No upper bound on noninteger variables```

### 求解问题

`[x,fval] = intlinprog(f,intcon,A,b,Aeq,beq,lb,ub);`
```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 intcon variables are integer within tolerance, options.IntegerTolerance = 1e-05. ```

`x,fval`
```x = 8×1 1.0000 1.0000 0 1.0000 7.0000 0.5000 0 3.5000 ```
```fval = 8495 ```