@@ -71,7 +71,8 @@ type GLPKCallbackData <: MathProgCallbackData
7171 tree:: Ptr{Void}
7272 state:: Symbol
7373 reason:: Cint
74- GLPKCallbackData (model:: GLPKMathProgModelMIP ) = new (model, C_NULL , :Other , - 1 )
74+ sol:: Vector{Float64}
75+ GLPKCallbackData (model:: GLPKMathProgModelMIP ) = new (model, C_NULL , :Other , - 1 , Float64[])
7576end
7677
7778type GLPKSolverMIP <: AbstractMathProgSolver
@@ -188,7 +189,7 @@ function cbgetexplorednodes(d::GLPKCallbackData)
188189end
189190
190191function cbaddlazy! (d:: GLPKCallbackData , colidx:: Vector , colcoef:: Vector , sense:: Char , rhs:: Real )
191- println (" Adding lazy" )
192+ # println("Adding lazy")
192193 (d. tree != C_NULL && d. reason == GLPK. IROWGEN) ||
193194 error (" cbaddlazy! can only be called from within a lazycallback" )
194195 length (colidx) == length (colcoef) || error (" colidx and colcoef have different legths" )
@@ -216,7 +217,7 @@ function cbaddlazy!(d::GLPKCallbackData, colidx::Vector, colcoef::Vector, sense:
216217end
217218
218219function cbaddcut! (d:: GLPKCallbackData , colidx:: Vector , colcoef:: Vector , sense:: Char , rhs:: Real )
219- println (" Adding cut" )
220+ # println("Adding cut")
220221 (d. tree != C_NULL && d. reason == GLPK. ICUTGEN) ||
221222 error (" cbaddcut! can only be called from within a cutcallback" )
222223 if sense == ' <'
@@ -232,11 +233,39 @@ function cbaddcut!(d::GLPKCallbackData, colidx::Vector, colcoef::Vector, sense::
232233 return
233234end
234235
235- function cbaddsolution! (d:: GLPKCallbackData , x:: Vector )
236- println (" Adding sol" )
236+ function _initsolution! (d:: GLPKCallbackData )
237+ isempty (d. sol) || return
238+ lp = GLPK. ios_get_prob (d. tree)
239+ n = GLPK. get_num_cols (lp)
240+ resize! (d. sol, n)
241+ fill! (d. sol, NaN )
242+ return
243+ end
244+
245+ function _fillsolution! (d:: GLPKCallbackData )
246+ lp = GLPK. ios_get_prob (d. tree)
247+ n = GLPK. get_num_cols (lp)
248+ sol = d. sol
249+ for c = 1 : n
250+ isnan (sol[c]) || continue
251+ sol[c] = GLPK. mip_col_val (lp, c)
252+ end
253+ end
254+
255+ function cbaddsolution! (d:: GLPKCallbackData )
256+ # println("Adding sol")
237257 (d. tree != C_NULL && d. reason == GLPK. IHEUR) ||
238- error (" cbaddcut! can only be called from within a heuristiccallback" )
239- GLPK. ios_heur_sol (d. tree, x)
258+ error (" cbaddsolution! can only be called from within a heuristiccallback" )
259+ _initsolution! (d)
260+ _fillsolution! (d)
261+ GLPK. ios_heur_sol (d. tree, d. sol)
262+ fill! (d. sol, NaN )
263+ end
264+
265+ function cbsetsolutionvalue! (d:: GLPKCallbackData , idx:: Integer , val:: Real )
266+ _check_tree (d, " cbsetsolutionvalue!" )
267+ _initsolution! (d)
268+ d. sol[idx] = val
240269end
241270
242271function setsense! (lpm:: GLPKMathProgModelMIP , sense)
0 commit comments