Over the last few years, agent technology has proposed different approaches for the development of systems that support the formation and dynamic management of teams or groups. Following this idea, this paper proposes a model for group formation in elderly communities defining it as a Coalition Structure Generation Problem. Specifically, the proposal has been used to analyse which is the best way to organize older people into activity groups in elderly communities. The model parameters are physical requirements, preferences and social relationships, being the model able to learn from each execution and improve the future configurations. The results show near-optimal solutions to all proposed scenarios, beating greatly the computational time of CPLEX, and flexibility to deal with different scenarios and configurations.; - This work has been supported by COMPETE: POCI-01-0145-FEDER-007043 and FCT - Fundacao para a Ciencia e Tecnologia within the Project Scope: UID/CEC/00319/2013. A. Costa thanks the FCT - Fundacao para a Ciencia e Tecnologia the Post-Doc scholarship with the Ref. SFRH/BPD/102696/2014. This work is also partially supported by the MINECO/FEDER TIN2017-89156-R and the Post-Doc scholarship with the Ref. SP20170057.