In the last few years, the number of devices connected to the Internet has increased
considerably; so has the data interchanged between these devices and the Cloud, as well as energy
consumption and the risk of network congestion. The problem can be alleviated by reducing
communication between Internet-of-Things devices and the Cloud. Recent paradigms, such as Edge
Computing and Fog Computing, propose to move data processing tasks from the Cloud to nearby
devices to where data is produced or consumed. One of the main challenges of these paradigms is to
cope with the heterogeneity of the infrastructures where tasks can be offloaded. This paper presents a
solution for the optimal allocation of computational tasks to edge devices, with the aim of minimizing
the energy consumption of the overall application. The heterogeneity is represented and managed
by using Feature Models, widely employed in Software Product Lines. Given the application and
infrastructure configurations, our Optimal Tasks Assignment Framework generates the optimal task
allocation and resources assignment. The resultant deployment represents the most energy efficient
configuration at load-time, without compromising the user experience. The scalability and energy
saving of the approach are evaluated in the domain of augmented reality applications