A Formal Framework for Optimizing the Design of Distributed Real-time Embedded Systems