Analysis and optimisation of ventilation control in livestock buildings