Look my example to you better underestand. I suggest you execute these commands to see my question.
Consider my original model below (including set data):
using Random,JuMP, CPLEX
rng = MersenneTwister(2020);
###############################################################################
#Data set
m=9;
k=50;
F=4;
L=rand(10:40,k,1);
P=rand(180:200,k,1);
r=[3 3 2 2];
ā = L./sum(L)
Di = round.(50 .+ 20*randn(rng,F,F))
for i in 1:F
Di[i,i] = 0
end
Dist=0.5*(Di+Di')
Dist0 = round.(80 .+ 20*randn(rng,F,1))
Lmax = 150
Ī¦ = 30
H = 1:Ī¦
C = round.(20 .+ 5*randn(rng,Ī¦))
###############################################################################
modelo = Model(CPLEX.Optimizer)
set_optimizer_attribute(modelo,"CPX_PARAM_TILIM",20)
set_optimizer_attribute(modelo,"CPX_PARAM_EPGAP",0.01)
set_optimizer_attribute(modelo,"CPX_PARAM_SCRIND",1)
set_optimizer_attribute(modelo, "CPXPARAM_OptimalityTarget",3)
set_optimizer_attribute(modelo,"CPX_PARAM_QTOLININD",1)
@variable(modelo, x[i in 1:m,j in 1:k], Bin)
@variable(modelo, y[i in 1:m,j in 1:F], Bin)
@variable(modelo, z[i in 1:m,j in 1:k,h in H], Bin)
@variable(modelo, w[i in 1:m,f in 1:F,h in H] >=0)
@variable(modelo, v1[i in 1:m-1,f in 1:F,h in H]>=0)
@variable(modelo, v2[i in 1:m-1,f in 1:F,h in H]>=0)
@variable(modelo, 0 <= e[j in 1:k] <= minimum(C)*Lmax - 100)
#A linear objective
@objective(modelo,Min, sum(y[i,f] for i in 1:m for f in 1:F) )
@constraint(modelo,[i in 1:m,f in 1:F,h in H],
sum(z[i,j,h] for j in sum(r[1:f-1])+1:sum(r[1:f])) == w[i,f,h]
)
@constraint(modelo,[i in 1:m-1, f in 1:F, h in H],
v1[i,f,h] - v2[i,f,h] == w[i+1,f,h] - w[i,f,h]
)
@constraint(modelo,[i in 1:m,h in H],
sum(z[i,j,h] for j in 1:k) <= 1
)
@constraint(modelo,[i in 1:m,h in H,f in 1:F,j in sum(r[1:f-1])+1:sum(r[1:f])],
z[i,j,h] <= y[i,f]
)
@constraint(modelo,[i in 1:m,j in 1:k],
x[i,j] <= sum(z[i,j,h] for h in H)
)
@constraint(modelo,[i in 1:m,j in 1:k],
sum(z[i,j,h] for h in H) <= Ī¦*x[i,j]
)
#As mƔquinas devem fazer a colheita de toda a cana em cada fazenda
@constraint(modelo,[j in 1:k],
sum(Lmax*C[h]*z[i,j,h] for i in 1:m for h in H) - e[j] == P[j]*L[j]
)
status=optimize!(modelo)
which has a linear objective. Then, I will save the final solution:
X = value.(x)
Y = value.(y)
Z = value.(z)
W = value.(w)
E = value.(e)
V1 = value.(v1)
V2 = value.(v2)
My intention is use the final solution of the previous problem as initial solution of the same problem except the objetive function (quadratic). Then, I set:
@objective(modelo,Min,sum(Dist0[f]*(v1[i,f,h]+v2[i,f,h]) for i in 1:m-1 for f in 1:F for h in H) +
sum(Dist0[f]*(w[1,f,h] + w[m,f,h]) for f in 1:F for h in H) +
sum(Dist[f,fbar]*w[i+1,f,h]*w[i,fbar,h] for i in 1:m-1 for f in 1:F for fbar in setdiff(1:F,f) for h in H)
)
#Without mipstart
status=optimize!(modelo)
and resolve the quadratic problem (without mipstart). The CPLEX report is the following:
Version identifier: 20.1.0.0 | 2020-11-10 | 9bedb6d68
CPXPARAM_OptimalityTarget 3
CPXPARAM_Preprocessing_QToLin 1
CPXPARAM_TimeLimit 20
CPXPARAM_MIP_Tolerances_MIPGap 0.01
4 of 4 MIP starts provided solutions.
MIP start 'm1' defined initial solution with objective 1076.0000.
Tried aggregator 1 time.
MIQP Presolve eliminated 2751 rows and 552 columns.
MIQP Presolve modified 3483 coefficients.
Reduced MIQP has 3209 rows, 19220 columns, and 60494 nonzeros.
Reduced MIQP has 13509 binaries, 0 generals, 0 SOSs, and 0 indicators.
Reduced MIQP objective Q matrix has 5472 nonzeros.
Presolve time = 0.05 sec. (73.00 ticks)
Probing fixed 126 vars, tightened 1017 bounds.
Probing time = 0.06 sec. (71.20 ticks)
Clique table members: 1542.
MIP emphasis: balance optimality and feasibility.
MIP search method: dynamic search.
Parallel mode: deterministic, using up to 12 threads.
Root relaxation solution time = 0.14 sec. (148.94 ticks)
Nodes Cuts/
Node Left Objective IInf Best Integer Best Bound ItCnt Gap
0 0 182.7330 323 182.7330 15
0 0 274.2959 635 Cuts: 417 15282
0 0 274.3084 678 Cuts: 289 18452
0 0 274.3084 677 Cuts: 265 23063
* 0+ 0 1914.0000 274.3084 85.67%
* 0+ 0 1914.0000 274.3084 85.67%
* 0+ 0 1076.0000 274.3084 74.51%
0 0 274.3084 697 1076.0000 Cuts: 231 26875 74.51%
0 2 274.3084 697 1076.0000 274.3084 26875 74.51%
Elapsed time = 13.89 sec. (14904.47 ticks, tree = 0.02 MB, solutions = 3)
1 3 275.1115 742 1076.0000 274.3591 27123 74.50%
2 4 275.2371 656 1076.0000 274.3591 28348 74.50%
3 5 275.2371 633 1076.0000 274.3591 28376 74.50%
GUB cover cuts applied: 77
Clique cuts applied: 1
Cover cuts applied: 153
Implied bound cuts applied: 110
Flow cuts applied: 17
Mixed integer rounding cuts applied: 117
Zero-half cuts applied: 61
Gomory fractional cuts applied: 17
Root node processing (before b&c):
Real time = 13.50 sec. (14513.16 ticks)
Parallel b&c, 12 threads:
Real time = 6.58 sec. (5491.88 ticks)
Sync time (average) = 4.87 sec.
Wait time (average) = 0.00 sec.
------------
Total (root+branch&cut) = 20.08 sec. (20005.04 ticks)
As you can observe, in the line 1 of the report, column Best Integer
is blanck, as expected.
Now, I will provide (try) a feasible integer solution to my problem. Then, I run:
#With mipstart
for i in 1:m,j in 1:k
set_start_value(x[i,j],X[i,j])
end
for j in 1:k
set_start_value(e[j],E[j])
end
for i in 1:m,f in 1:F
set_start_value(y[i,f],Y[i,f])
end
for i in 1:m,j in 1:k,h in H
set_start_value(z[i,j,h],Z[i,j,h])
end
for i in 1:m,f in 1:F,h in H
set_start_value(w[i,f,h],W[i,f,h])
end
for i in 1:m-1,f in 1:F,h in H
set_start_value(v1[i,f,h],V1[i,f,h])
set_start_value(v2[i,f,h],V2[i,f,h])
end
and run the objective again and in the sequence, optimize:
#A Quadratic objective
@objective(modelo,Min,sum(Dist0[f]*(v1[i,f,h]+v2[i,f,h]) for i in 1:m-1 for f in 1:F for h in H) +
sum(Dist0[f]*(w[1,f,h] + w[m,f,h]) for f in 1:F for h in H) +
sum(Dist[f,fbar]*w[i+1,f,h]*w[i,fbar,h] for i in 1:m-1 for f in 1:F for fbar in setdiff(1:F,f) for h in H)
)
status=optimize!(modelo)
I will expeted a CPLEX report different of previous one. But are the same:
Nodes Cuts/
Node Left Objective IInf Best Integer Best Bound ItCnt Gap
0 0 182.7330 323 182.7330 15
0 0 274.2959 635 Cuts: 417 15282
0 0 274.3084 678 Cuts: 289 18452
0 0 274.3084 677 Cuts: 265 23063
* 0+ 0 1914.0000 274.3084 85.67%
* 0+ 0 1914.0000 274.3084 85.67%
* 0+ 0 1076.0000 274.3084 74.51%
0 0 274.3084 697 1076.0000 Cuts: 231 26875 74.51%
0 2 274.3084 697 1076.0000 274.3084 26875 74.51%
Elapsed time = 13.98 sec. (14904.47 ticks, tree = 0.02 MB, solutions = 3)
1 3 275.1115 742 1076.0000 274.3591 27123 74.50%
2 4 275.2371 656 1076.0000 274.3591 28348 74.50%
e.g, my feasible solution was ignored (see the column Best integer, line 1, is blanck).
However, when I execute he code:
#With mipstart
for i in 1:m,j in 1:k
set_start_value(x[i,j],X[i,j])
end
for j in 1:k
set_start_value(e[j],E[j])
end
for i in 1:m,f in 1:F
set_start_value(y[i,f],Y[i,f])
end
for i in 1:m,j in 1:k,h in H
set_start_value(z[i,j,h],Z[i,j,h])
end
for i in 1:m,f in 1:F,h in H
set_start_value(w[i,f,h],W[i,f,h])
end
for i in 1:m-1,f in 1:F,h in H
set_start_value(v1[i,f,h],V1[i,f,h])
set_start_value(v2[i,f,h],V2[i,f,h])
end
status=optimize!(modelo)
a new CPLEX report is generated, where my feasible solution is considered. Look:
Version identifier: 20.1.0.0 | 2020-11-10 | 9bedb6d68
CPXPARAM_OptimalityTarget 3
CPXPARAM_Preprocessing_QToLin 1
CPXPARAM_TimeLimit 20
CPXPARAM_MIP_Tolerances_MIPGap 0.01
1 of 4 MIP starts provided solutions.
MIP start 'm4' defined initial solution with objective 2816.0000.
MIP emphasis: balance optimality and feasibility.
MIP search method: dynamic search.
Parallel mode: deterministic, using up to 12 threads.
Nodes Cuts/
Node Left Objective IInf Best Integer Best Bound ItCnt Gap
4 6 384.4832 610 1076.0000 274.3591 46194 74.50%
Elapsed time = 4.34 sec. (1639.71 ticks, tree = 0.07 MB, solutions = 3)
8 7 401.9055 673 1076.0000 274.3591 46468 74.50%
12 9 275.2371 680 1076.0000 275.1115 46735 74.43%
GUB cover cuts applied: 77
Clique cuts applied: 1
Cover cuts applied: 153
Implied bound cuts applied: 154
Flow cuts applied: 17
Mixed integer rounding cuts applied: 117
Zero-half cuts applied: 61
Gomory fractional cuts applied: 17
Root node processing (before b&c):
Real time = 0.06 sec. (43.33 ticks)
Parallel b&c, 12 threads:
Real time = 20.08 sec. (4300.27 ticks)
Sync time (average) = 5.53 sec.
Wait time (average) = 0.00 sec.
------------
Total (root+branch&cut) = 20.14 sec. (4343.61 ticks)
My question is: Why, when I run the objective quadratic function again, CPLEX looses my feasible solution??
Please, help me to underestand this.
Note: when the objetive is linear, nothing wrong happens.