Adaptive Mode Assignment in Cyber-physical Systems