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

### 问题描述

`$\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);`
```Running HiGHS 1.6.0: Copyright (c) 2023 HiGHS under MIT licence terms Presolving model 3 rows, 8 cols, 24 nonzeros 3 rows, 8 cols, 18 nonzeros Solving MIP model with: 3 rows 8 cols (4 binary, 0 integer, 0 implied int., 4 continuous) 18 nonzeros Nodes | B&B Tree | Objective Bounds | Dynamic Constraints | Work Proc. InQueue | Leaves Expl. | BestBound BestSol Gap | Cuts InLp Confl. | LpIters Time 0 0 0 0.00% 0 inf inf 0 0 0 0 0.0s 0 0 0 0.00% 8125.6 inf inf 0 0 0 4 0.0s R 0 0 0 0.00% 8495 8495 0.00% 5 0 0 5 0.0s Solving report Status Optimal Primal bound 8495 Dual bound 8495 Gap 0% (tolerance: 0.01%) Solution status feasible 8495 (objective) 0 (bound viol.) 0 (int. viol.) 0 (row viol.) Timing 0.00 (total) 0.00 (presolve) 0.00 (postsolve) Nodes 1 LP iterations 5 (total) 0 (strong br.) 1 (separation) 0 (heuristics) Optimal solution found. Intlinprog stopped at the root node because the objective value is within a gap tolerance of the optimal value, options.AbsoluteGapTolerance = 1e-06. The intcon variables are integer within tolerance, options.ConstraintTolerance = 1e-06. ```

`x,fval`
```x = 8×1 1.0000 1.0000 0 1.0000 7.2500 0 0.2500 3.5000 ```
```fval = 8495 ```