Design and control of public-service contracts and an application to public transportation systems