Optimal treatment and rational reuse of water in textile industry