FIPA algorithm (python code)