HAMA-681: add the cost function