This paper presents a model-driven approach to developing pervasive computing applications that exploits design time information to support the engineering of planning and optimisation algorithms that reflect the presence of uncertainty, dynamism and complexity in the application domain. In particular the task of generating code to implement planning and optimisation algorithms in pervasive computing domains is addressed. We present a layered domain model containing a set of object oriented specifications for modelling physical and sensor/actuator infrastructure and state-space information. Our model-driven engineering approach is implemented in two transformation algorithms. The initial transformation parses the domain model and generates a planning model for the application being developed that encodes an application's states, actions and rewards. The second transformation parses the planning model and selects and seeds a planning or optimisation algorithm for use in the application. We present an empirical evaluation of the impact of our approach on the development effort associated with a pervasive computing application from the Intelligent Transportation Systems (ITS) domain, and provide a quantitative evaluation of the performance of the algorithms generated by the transformations.