Python调用Gurobi求解器日志解析

python 复制代码
Set parameter Username
Set parameter LicenseID to value 2675318
Academic license - for non-commercial use only - expires 2026-06-05
Gurobi Optimizer version 12.0.2 build v12.0.2rc0 (mac64[arm] - Darwin 24.5.0 24F74)

CPU model: Apple M4
Thread count: 10 physical cores, 10 logical processors, using up to 10 threads

Optimize a model with 280 rows, 545 columns and 973 nonzeros
Model fingerprint: 0x7d4ec560
Variable types: 0 continuous, 545 integer (0 binary)
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [5e+00, 4e+03]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+00, 5e+02]
Found heuristic solution: objective 6668451.0000
Presolve removed 240 rows and 289 columns
Presolve time: 0.00s
Presolved: 40 rows, 256 columns, 469 nonzeros
Found heuristic solution: objective 6665347.0000
Variable types: 0 continuous, 256 integer (0 binary)

Root relaxation: objective 5.810983e+06, 104 iterations, 0.00 seconds (0.00 work units)

    Nodes    |    Current Node    |     Objective Bounds      |     Work
 Expl Unexpl |  Obj  Depth IntInf | Incumbent    BestBd   Gap | It/Node Time

*    0     0               0    5810983.0000 5810983.00  0.00%     -    0s

Explored 1 nodes (104 simplex iterations) in 0.00 seconds (0.00 work units)
Thread count was 10 (of 10 available processors)

Solution count 3: 5.81098e+06 6.66535e+06 6.66845e+06 

Optimal solution found (tolerance 1.00e-04)
Best objective 5.810983000000e+06, best bound 5.810983000000e+06, gap 0.0000%
Set parameter MIPGap to value 0
Traceback (most recent call last):
  File "src/gurobipy/_util.pyx", line 33, in gurobipy._util._bytestostring
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x88 in position 26: invalid start byte
Exception ignored in: 'gurobipy._core.logcallbackstub'
Traceback (most recent call last):
  File "src/gurobipy/_util.pyx", line 33, in gurobipy._util._bytestostring
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x88 in position 26: invalid start byte
Warning: to let Gurobi read it back, use rlp format
Optimal solution found with objective value: 5810983.0

以下进行逐行分析:

1. Gurobi许可证初始化

python 复制代码
Set parameter Username
Set parameter LicenseID to value 2675318
Academic license - for non-commercial use only - expires 2026-06-05
  • 使用学术许可证(仅限非商业用途),有效期至2026年。

2. 求解器环境信息

python 复制代码
Gurobi Optimizer version 12.0.2 build v12.0.2rc0 (mac64[arm] - Darwin 24.5.0 24F74)
CPU model: Apple M4
Thread count: 10 physical cores, 10 logical processors, using up to 10 threads
  • Gurobi版本为12.0.2,运行在Apple M4芯片的MacOS上,使用10线程。

3. 模型统计信息

python 复制代码
Optimize a model with 280 rows, 545 columns and 973 nonzeros
Model fingerprint: 0x7d4ec560
Variable types: 0 continuous, 545 integer (0 binary)
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]  # 约束矩阵系数均为1
  Objective range  [5e+00, 4e+03]   # 目标函数系数范围
  Bounds range     [0e+00, 0e+00]   # 变量无边界限制
  RHS range        [2e+00, 5e+02]   # 约束右侧值范围
  • 模型规模:280个约束,545个整数变量(无连续或二进制变量)。
  • 目标函数涉及的成本范围较大(5到4000),可能与运输距离或租箱成本相关。

4. 启发式求解与预处理

python 复制代码
Found heuristic solution: objective 6668451.0000  # 初始启发式解
Presolve removed 240 rows and 289 columns       # 预处理简化模型
Presolve time: 0.00s
Presolved: 40 rows, 256 columns, 469 nonzeros
Found heuristic solution: objective 6665347.0000  # 简化后的启发式解
  • 预处理大幅减少了问题规模(从280行到40行),加速求解。
  • 启发式算法提供了两个初始解(目标值约666万),但非最优。

5. 松弛问题求解

python 复制代码
Root relaxation: objective 5.810983e+06, 104 iterations, 0.00 seconds (0.00 work units)
  • 线性松弛(忽略整数约束)的解为5,810,983,提供了问题的下界(最优解不会低于此值)。

6. 分支定界过程

python 复制代码
Nodes | Current Node | Objective Bounds | Work
Expl Unexpl | Obj Depth IntInf | Incumbent BestBd Gap | It/Node Time
* 0 0 0 5810983.0000 5810983.00 0.00% - 0s
  • 在根节点(Nodes=0)即找到整数最优解,目标值与松弛解一致(5,810,983),Gap为0%。
  • 关键结论:模型求解非常高效(0秒内完成),且解为全局最优。

7. 求解结果汇总

python 复制代码
Solution count 3: 5.81098e+06 6.66535e+06 6.66845e+06 
Optimal solution found (tolerance 1.00e-04)
Best objective 5.810983000000e+06, best bound 5.810983000000e+06, gap 0.0000%
  • 共找到3个解,最优解为5,810,983(与松弛解一致,验证了最优性)。

8. 编码错误警告

python 复制代码
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x88 in position 26
Warning: to let Gurobi read it back, use rlp format
  • 日志输出时出现编码问题(可能是中文字符处理异常),但未影响求解结果。
  • 建议检查输出文件的编码格式或使用rlp格式保存模型。