  We consider a linear consensus system with n agents that can switch between r
different connectivity patterns. A natural question is which switching law
yields the best (or worst) possible speed of convergence to consensus? We
formulate this question in a rigorous manner by relaxing the switched system
into a bilinear consensus control system, with the control playing the role of
the switching law. A best (or worst) possible switching law then corresponds to
an optimal control. We derive a necessary condition for optimality, stated in
the form of a maximum principle (MP). Our approach, combined with suitable
algorithms for numerically solving optimal control problems, may be used to
obtain explicit lower and upper bounds on the achievable rate of convergence to
consensus. We also show that the system will converge to consensus for any
switching law if and only if a certain (n-1) dimensional linear switched system
converges to the origin for any switching law. For the case n=3 and r=2, this
yields a necessary and sufficient condition for convergence to consensus that
admits a simple graph-theoretic interpretation.
