Include memory in cost; added memory estimation.
Added query options and reset function.
Re-planning when memory estimate exceeds limit.