@@ -392,19 +392,29 @@ Memory estimation in number of bytes to compute certain `property` of a `problem
392392`T` is the base type.
393393"""
394394function estimate_memory (problem:: GraphProblem , property:: AbstractProperty ; T= Float64)
395- if property isa SingleConfigMax{true } || property isa SingleConfigMin{true }
396- # TODO : fix this
397- @warn " The estimation of memory might be unreliable for the bounded computation of a single solution due to the caching."
398- end
399- estimate_memory (tensor_element_type (T, length (labels (problem)), nflavor (problem), property), problem)
395+ _estimate_memory (tensor_element_type (T, length (labels (problem)), nflavor (problem), property), problem)
396+ end
397+ function estimate_memory (problem:: GraphProblem , :: Union{SingleConfigMax{true},SingleConfigMin{true}} ; T= Float64)
398+ tc, sc, rw = timespacereadwrite_complexity (problem. code, _size_dict (problem))
399+ # caching all tensors is equivalent to counting the total number of writes
400+ return ceil (Int, exp2 (rw - 1 )) * sizeof (Tropical{T})
401+ end
402+ function estimate_memory (problem:: GraphProblem , :: GraphPolynomial{:polynomial} ; T= Float64)
403+ # this is the upper bound
404+ return peak_memory (problem. code, _size_dict (problem)) * (sizeof (T) * length (labels (problem)))
405+ end
406+
407+ function _size_dict (problem)
408+ lbs = labels (problem)
409+ nf = nflavor (problem)
410+ return Dict ([lb=> nf for lb in lbs])
400411end
401- function estimate_memory (:: Type{ET} , problem:: GraphProblem ) where ET
412+
413+ function _estimate_memory (:: Type{ET} , problem:: GraphProblem ) where ET
402414 if ! isbitstype (ET) && ! (ET <: Mod )
403415 @warn " Target tensor element type `$ET ` is not a bits type, the estimation of memory might be unreliable."
404416 end
405- lbs = labels (problem)
406- nf = nflavor (problem)
407- return peak_memory (problem. code, Dict ([lb=> nf for lb in lbs])) * sizeof (ET)
417+ return peak_memory (problem. code, _size_dict (problem)) * sizeof (ET)
408418end
409419
410420for (PROP, ET) in [(:SizeMax , :(Tropical{T})), (:SizeMin , :(Tropical{T})),
0 commit comments