Pollution prevention with chemical process simulators: the generalized waste reduction (WAR) algorithm—full version