Two-time Olympic triathlon champion Alistair Brownlee has announced his retirement from the sport.