A closed-loop control system for the control of the depth of hypnosis in anesthesia by using propofol-remifentanil coadministration and the Bispectral Index as feedback signal is proposed. A PID controller is employed together with a fixed ratio between propofol and remifentanil infusions. The ratio allows the anesthesiologist to control the opioid-hypnotic balance during surgery. Optimal tuning rules for the proposed controller are obtained off-line by using the particle swarm optimization method and by considering a given dataset of patients and a wide range of infusion ratios that covers a rich set of scenarios that might occur in clinical practice. Finally, a gain scheduling strategy guarantees the optimality of the performance both for the induction and the maintenance phase. A Monte Carlo approach is used to evaluate the robustness of the method with respect to intra- and inter-patient variability.