The Metabolic Algorithm for P Systems: Principles and Applications