cost function for bridge