Text this: Distributed optimization and consensus based on population dynamics and graphs