How to control the number of iterations
回答済みHi
I'm a newbie with Python and I try to follow this MOOC : https://www.coursera.org/learn/operations-research-algorithms/home/welcome
After, installing python and Gurobi on my computer (an old computer with Windows 10), I tried to launch these lines.
from gurobipy import *
eg1= Model("eg1")
x1= eg1.addVar(lb = 0, vtype=GRB.CONTINUOUS, name="x1")
x2= eg1.addVar(lb = 0, vtype=GRB.CONTINUOUS, name="x2")
eg1.setObjective(700*x1+900*x2,GRB.MAXIMIZE)
eg1.addConstr(3*x1+5*x2 <= 3600, "resource_wood")
eg1.addConstr(x1+2*x2 <= 1600, "resource_labor")
eg1.addConstr(50*x1+20*x2 <= 4800, "resource_machine")
eg1.optimize()
This is the result (with Jupyter Lab and with VSCode :
Gurobi Optimizer version 11.0.3 build v11.0.3rc0 (win64 - Windows 10.0 (19045.2)) CPU model: Intel(R) Core(TM) i5-6400 CPU @ 2.70GHz, instruction set [SSE2|AVX|AVX2] Thread count: 4 physical cores, 4 logical processors, using up to 4 threads Optimize a model with 3 rows, 2 columns and 6 nonzeros Model fingerprint: 0xeaf3d20c Coefficient statistics: Matrix range [1e+00, 5e+01] Objective range [7e+02, 9e+02] Bounds range [0e+00, 0e+00] RHS range [2e+03, 5e+03] Presolve removed 3 rows and 2 columns Presolve time: 0.01s Presolve: All rows and columns removed Iteration Objective Primal Inf. Dual Inf. Time 0 2.1600000e+05 0.000000e+00 0.000000e+00 0s Solved in 0 iterations and 0.01 seconds (0.00 work units) Optimal objective 2.160000000e+05
The optimal objective should be 789473.68.
What is the problem ? From my computer ? From the code (because it's a old MOOC and something change with the new versions of Gurobi ?) ?
For your information, I launched the code from https://www.gurobi.com/documentation/current/examples/diet_py.html and the result is :
Set parameter Username Gurobi Optimizer version 11.0.3 build v11.0.3rc0 (win64 - Windows 10.0 (19045.2)) CPU model: Intel(R) Core(TM) i5-6400 CPU @ 2.70GHz, instruction set [SSE2|AVX|AVX2] Thread count: 4 physical cores, 4 logical processors, using up to 4 threads Optimize a model with 4 rows, 12 columns and 39 nonzeros Model fingerprint: 0x33ddb849 Coefficient statistics: Matrix range [1e+00, 2e+03] Objective range [9e-01, 3e+00] Bounds range [7e+01, 2e+03] RHS range [7e+01, 2e+03] Presolve removed 0 rows and 2 columns Presolve time: 0.10s Presolved: 4 rows, 10 columns, 37 nonzeros Iteration Objective Primal Inf. Dual Inf. Time 0 0.0000000e+00 1.472500e+02 0.000000e+00 0s 4 1.1828861e+01 0.000000e+00 0.000000e+00 0s Solved in 4 iterations and 0.18 seconds (0.00 work units) Optimal objective 1.182886111e+01 Cost: 11.8289 Buy: hamburger 0.604514 milk 6.97014 ice cream 2.59132 Adding constraint: at most 6 servings of dairy Gurobi Optimizer version 11.0.3 build v11.0.3rc0 (win64 - Windows 10.0 (19045.2)) CPU model: Intel(R) Core(TM) i5-6400 CPU @ 2.70GHz, instruction set [SSE2|AVX|AVX2] Thread count: 4 physical cores, 4 logical processors, using up to 4 threads Optimize a model with 5 rows, 12 columns and 41 nonzeros Coefficient statistics: Matrix range [1e+00, 2e+03] Objective range [9e-01, 3e+00] Bounds range [7e+01, 2e+03] RHS range [6e+00, 2e+03] LP warm-start: use basis Iteration Objective Primal Inf. Dual Inf. Time 0 1.1828861e+01 5.698333e+01 0.000000e+00 0s Solved in 0 iterations and 0.02 seconds (0.00 work units) Infeasible model No solution
Regards
0
-
Hi Frederic,
You have a typo in your code:
eg1.addConstr(50*x1+20*x2 <= 4800, "resource_machine")
should be
eg1.addConstr(50*x1+20*x2 <= 48000, "resource_machine")
The output of diet.py looks normal.
- Riley
0
サインインしてコメントを残してください。
コメント
1件のコメント