GUROBI如何使用50个效率最低的提供者来运行优化

2024-05-17 11:59:02 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用Python和Gurobi solver。我正在解决一个混合整数优化问题,我试图得到一个优化结果与50个最低效率的供应商。但我得到了47个供应商的结果,而不是50预期。 如何运行此优化以实现相同的效果?你知道吗

代码片段,我试图优化至少50低效率的供应商。你知道吗

model.addConstr(quicksum(df_Eff_Spend_p['Tier_Status']), GRB.GREATER_EQUAL, 50)
model.update()     
Efficiency  = df_Eff_Spend_p['Efficiency Score'] * df_Eff_Spend_p['Tier_Status']
model.setObjective( Efficiency.sum(), GRB.MINIMIZE)
model.optimize()

Gurobi解决方案的输出如下-

Optimize a model with 1 rows, 1121 columns and 1112 nonzeros
Variable types: 0 continuous, 1121 integer (1121 binary)
Coefficient statistics:
  Matrix range     [1e+00, 2e+02]
  Objective range  [1e-01, 5e+02]
  Bounds range     [1e+00, 1e+00]
  RHS range        [5e+01, 5e+01]
Found heuristic solution: objective 128.2053191
Presolve removed 0 rows and 160 columns
Presolve time: 0.01s
Presolved: 1 rows, 961 columns, 961 nonzeros
Variable types: 0 continuous, 961 integer (819 binary)

Root relaxation: objective 1.978018e+01, 1 iterations, 0.00 seconds

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

     0     0   19.78018    0    1  128.20532   19.78018  84.6%     -    0s
H    0     0                      19.7952723   19.78018  0.08%     -    0s
H    0     0                      19.7823530   19.78018  0.01%     -    0s
     0     0 infeasible    0        19.78235   19.78235  0.00%     -    0s

Explored 1 nodes (1 simplex iterations) in 0.06 seconds
Thread count was 4 (of 4 available processors)

Solution count 3: 19.7824 19.7953 128.205 

Optimal solution found (tolerance 1.00e-04)
Best objective 1.978235301932e+01, best bound 1.978235301932e+01, gap 0.0000%
---**--- Model Details ---**---

Number of Variables       : 1121
Number of Constraints     : 1


---**--- Optimum network ---**---

Total Efficiency          : 19.782


Runtime                   : 0

检查网络中有多少人的代码-

count_network = 0
count_all = 0
for v in model.getVars ():
    count_network = count_network + v.x
    count_all = count_all + 1
print("The total number of selected providers in the network= ", count_network )
print("The total number of providers in the network= ", count_all )  

网络中所选提供商的总数=47.0

网络中的提供商总数=1121


Tags: columnsofindfmodelcountrangenetwork