Cost functions and saving of JSON results files.

Added cost functions for allocation, deallocation and validation.
Saves the JSON results as a bunch of files under a `results` directory.