Computer Optimization of Pharmaceutical Formulations I: General procedure