Mobile applications run in environments where the
context is continuously changing. Therefore, it is necessary to
provide support for the run-time adaptation of these applications.
This support is usually achieved by middleware platforms that
offer a context-aware dynamic reconfiguration service. However,
the main shortcoming of existing approaches is that both the list
of possible configurations and the plans to adapt the application
to a new configuration are usually specified at design-time. In
this paper we present an approach that allows the automatic
generation at run-time of application configurations and of
reconfiguration plans. Moreover, the generated configurations
are optimal regarding the provided functionality and, more
importantly, without exceeding the available resources (e.g. battery).
This is performed by: (1) having the information about
the application variability available at runtime using feature
models, and (2) using an genetic algorithm that allows generating
an optimal configuration at runtime. We have specified a case
study and evaluated our approach, and the results show that
it is efficient enough as to be used on mobile devices without
introducing an excessive overhead.