Another version

many improvements
the allocation code is better needs to be tested on simple example
it should be working with hydro power variable now