set the initial values of variables to warmstart
AnsweredI use set_start_value function in Gurobi's Julia interface to set initial values for variables before solving the model. I did not see any change in the iteration behavior. To be more specific, I am solving an LP problem. I set the initial value as the optimal solution to this problem, but the number of iterations did not change.
-
Hi Jiaze,
We may need specifics on how you are using the solver, as we do not provide a Julia interface. It may be that your question will be better answered by the maintainers of the API you are using.
- Riley
0 -
Hi Riley,
Thanks much for getting back to me!
I have developed a simple supply chain model that uses linear programming. To solve this problem, I specified the use of primal simplex. After obtaining the initial solution, I attempted to solve the problem again by setting a new initial value using the "set_start_value" function in Julia. Unfortunately, despite this modification, the number of iterations required to solve the problem remained the same. Below, I provide the relevant code and a log of the results:
Code:
using JuMP
using Gurobi
######################################################################
m = Model(Gurobi.Optimizer)
set_optimizer_attribute(m, "Method", 0) #primal simplex
@variable(m, f[i in NODES,j in NODES, pr in PRODS]>= 0);
# demand and supply
@variable(m, dem[DEMS] >= 0);
@variable(m, sup[SUPS] >= 0);
# cost
@constraint(m, swf == -opcost -capcost -supcost - transcost + demrevn);
@objective(m, Max, swf)
optimize!(m)
# get the solution
dem_sol = JuMP.value.(dem)
sup_sol = JuMP.value.(sup)
#sovling the same problem again with predefined values of variables.
m0 = Model(Gurobi.Optimizer)
set_optimizer_attribute(m0, "Method", 0) #primal simplex
# demand and supply
@variable(m0, dem[DEMS] >= 0);
@variable(m0, sup[SUPS] >= 0);
# cost
@constraint(m0, swf == -opcost -capcost -supcost - transcost + demrevn);
@objective(m0, Max, swf)
#Warmstart
set_start_value.(dem, dem_sol)
set_start_value.(sup, sup_sol)
optimize!(m0)
#
Gurobi Optimizer version 9.0.0 build v9.0.0rc2 (mac64)
Optimize a model with 1462 rows, 1408 columns and 5117 nonzeros
Model fingerprint: 0x9f60bc55
Coefficient statistics:
Matrix range [1e-01, 1e+03]
Objective range [1e+00, 1e+00]
Bounds range [1e+00, 1e+00]
RHS range [1e+03, 1e+04]
Presolve removed 1402 rows and 192 columns
Presolve time: 0.00s
Presolved: 60 rows, 1216 columns, 2362 nonzeros
Ordering time: 0.00s
Barrier statistics:
AA' NZ : 5.760e+02
Factor NZ : 7.500e+02 (roughly 1 MByte of memory)
Factor Ops : 1.153e+04 (less than 1 second per iteration)
Threads : 1
Objective Residual
Iter Primal Dual Primal Dual Compl Time
0 -9.32439111e+05 1.52625978e+09 8.30e+02 3.38e-13 1.10e+06 0s
1 -9.37179500e+06 2.60348353e+08 1.14e+02 6.23e-13 1.26e+05 0s
2 -9.49054256e+06 9.93698298e+06 1.30e+01 9.09e-13 8.37e+03 0s
3 -1.22452355e+05 1.70611853e+06 1.43e-02 1.07e-12 7.52e+02 0s
4 8.02354831e+05 1.13814577e+06 2.30e-03 4.55e-13 1.38e+02 0s
5 9.33501591e+05 1.12270711e+06 4.27e-04 4.55e-13 7.78e+01 0s
6 9.58072171e+05 1.04166018e+06 2.23e-04 4.55e-13 3.44e+01 0s
7 9.78180397e+05 1.00879293e+06 5.52e-05 2.42e-13 1.26e+01 0s
8 9.80858081e+05 9.98581038e+05 3.56e-05 2.84e-13 7.29e+00 0s
9 9.83856564e+05 9.94064545e+05 1.77e-05 4.55e-13 4.20e+00 0s
10 9.86259161e+05 9.90760740e+05 3.84e-06 3.98e-13 1.85e+00 0s
11 9.86607327e+05 9.88726114e+05 2.26e-06 2.27e-13 8.71e-01 0s
12 9.87180760e+05 9.87638832e+05 2.14e-08 4.55e-13 1.88e-01 0s
13 9.87216449e+05 9.87254808e+05 8.34e-09 4.55e-13 1.58e-02 0s
14 9.87242841e+05 9.87244416e+05 2.33e-11 2.27e-13 6.47e-04 0s
15 9.87243401e+05 9.87243425e+05 7.89e-11 4.55e-13 1.00e-05 0s
16 9.87243409e+05 9.87243409e+05 3.12e-10 3.98e-13 1.01e-08 0s
17 9.87243409e+05 9.87243409e+05 5.63e-11 4.55e-13 1.01e-14 0s
Barrier solved model in 17 iterations and 0.01 seconds
Optimal objective 9.87243409e+05
Crossover log...
42 DPushes remaining with DInf 0.0000000e+00 0s
0 DPushes remaining with DInf 5.6843419e-14 0s
0 PPushes remaining with PInf 0.0000000e+00 0s
Push phase complete: Pinf 0.0000000e+00, Dinf 5.6843419e-14 0s
Extra 18 simplex iterations after uncrush
Iteration Objective Primal Inf. Dual Inf. Time
63 9.8724341e+05 0.000000e+00 0.000000e+00 0s
Solved in 63 iterations and 0.01 seconds
Optimal objective 9.872434088e+05
User-callback calls 155, time in user-callback 0.00 sec0 -
Hi Jiaze,
When Gurobi uses a MIP start you will see it reflected in the log, for example
User MIP start produced solution with objective 1.18884e+06 (1.56s)
Loaded user MIP start with objective 1.18884e+06
Processed MIP start in 1.55 seconds (0.79 work units)The fact that lines like these are not shown in your log means Gurobi is never given the initial solution you provide to JuMP. You could try using the start solution when the variables are created, instead of using set_start_solution, but perhaps this will fail also - the problem is not Gurobi though. My suggestion would be to ask the JuMP community for assistance.
EDIT: A colleague noticed that your model is a LP and so my comments regarding MIP start are not relevant in your case. It looks like JuMP uses the same set_start_value function for both MIP start and warm starting a LP. I think this thread in the JuMP Discourse will be useful for you. Noting that you are using Gurobi 9, please make sure you consult the documentation for PStart and DStart corresponding to this version, since it has changed in later versions.
- Riley
0
Please sign in to leave a comment.
Comments
3 comments