add cost function for bp