Optimization of environmental flow to preserve/improve ecological function