Gravar-mail: Mitigation of epidemics in contact networks through optimal contact adaptation