Group modeling is still an open challenge problem in pedestrian crowd simulations. Most existing work is based on socio-psychological models which can only describe the dynamics of pedestrians' socio-psychological states. The ability of dynamic grouping also requires that pedestrians are intelligent to behave adaptively in the ever changing environment. However, little work has incorporated the effect of artificial intelligence in the study of group behaviors. This paper describes a novel model to simulate dynamic groups based on both utility theory and social comparison theory. To our knowledge, the model is one of few models using utility theory and social comparison theory to model group behaviors. Experiment results suggest that groups can be dynamically formed and grouping has significant effect on crowd behaviors. Besides, the model can also be used to simulate various structures in dynamic groups.