Newsletter

Managing a leaky reservoir

26 October 2012

Continuing a fine tradition of atypical modelling topics used to focus on technique without the distraction of more familiar and precious assumptions

As a ‘wake-up exercise’ on day two of the recent STEM User Group Meeting, we explored a classic ‘leaky bucket’ problem of water supply, concerning a huge filling reservoir (HFR).

Creating a simulation of the varying water level in the reservoir over an annual rainfall cycle required a careful distinction between instantaneous and aggregate transformation outputs and some manual intervention to classify correctly the output mode of one or two key Expression transformations.

The potential addition of new Previous, Accumulation and Delta transformation types may facilitate a more natural expression of the logic which would remove the ambiguity about classification.

1. Managing water supply through the buffer of a reservoir

Consider a reservoir of maximum capacity = 5 million m3 (or cu m). (This is only 1km × 500m × 10m.) Imagine monthly rainfall varying between 4–20cm (subject to seasonal variation) over a collection area of 50 km2 (sq km), of which 50% trickles through into the reservoir feeder channels.

If we estimate the downstream supply rate for an average (subject to differently phased seasonal variation) of 100 litres per customer per day for 1m subscribers, then how ‘bursty’ can the weather be without either:

  • the reservoir overflowing, or
  • the reservoir drying up (and the downstream supply with it)?

1.1 Care when defining the traffic for a service

It is tempting to try setting up a service with an area of rainfall collection as the ‘connection’:

  • Connections = 50 sq km
  • Penetration = 50%
  • Traffic per Connection = x cm

Figure 1: Rainfall per unit area is not the same as traffic per connection

However, this is not ideal as the Traffic result output would be measured in cm and the required 1000 × 1000 / 100 unit conversion would have to be factored in a separate transformation.

The traffic volume input should be entered in actual traffic units per (‘dimensionless’) connection.

We should work with monthly rain volume from the start, and we shall proceed with:

  • Connections = 1 Catchment
  • Penetration = 1.0
  • Traffic per Connection =
    Collection area (sq km) × 1e6 ×
    Monthly rainfall (cm) / 100 ×
    Retention proportion

Figure 2: Working with monthly rain volume from the start

The traffic distribution reduces to flow in the (non-biased) busy hour. So we need to divide by 60 to measure Busy Hour Traffic in cu m / minute.

1.2 Flow in and out of the reservoir

Consider for the reservoir, each month, the flow of water in, fi, and the flow of water out, fo. We can simulate the ongoing volume of water (or water level) in the reservoir, vol , in terms of:

  • its capacity, cap = 5,000,000 cu m
  • the flow down of rainfall from the catchment area, fd
  • the flow required by customers, fr
  • the volume at the end of the previous period, vol’.

It is not hard to write out the following difference equations:

  • vol = vol’ + fifo
  • vol’ = prev (vol)
  • fi = min (fd, capvol’ + fo)
    limited either by actual rainfall or remaining available capacity
  • fo = min (fr, vol’ + fi)
    limited either by actual customer demand or current water level

Figure 3: Graphical representation of the dynamical system

1.3 Removing the inherent circularity

From the equations and associated commentary, it is clear that there is a mutual dependency:

  • the flow out may be limited by the flow in if the water level is low
  • the flow in may be limited by the flow out if the water level is high.

But only one limit applies, depending on whether there is more or less rain than demand. So a closed solution exists in both cases and these can be reconciled with a conditional expression:

  • if there is less rain than demand, then all the rain can flow in
  • if there is more rain than demand, then all the demand is satisfied.

This allows for a convenient substitution in either case:

  • if ( fd < fr)
  • fi = fd
  • fo = min (fr, vol’ + fd)
    substituting fd for fi
  • else (fdfr)
  • fo = fr
  • fi = min (fd, capvol’ + fr)
    substituting fr for fo.

So we can write:

  • fi = if (fd < fr, fd, min (fd, capvol’ + fr) )
  • fo = if (fdfr, fr, min (fr, vol’ + fd) )

As the circularity is already removed, we can leave fo more economically as-is:

  • fo = min ( fr , vol’ + fi )

1.4 Aggregate and instantaneous transformations

Even though the units throughout are cu m, the flows are aggregate (in period) while Volume and Volume’ are instantaneous measures. (See the proceedings of the STEM User Group Meeting for a similar example of relative and absolute distances for a mountain bike, all measured in km.)

However, there are no reliable clues in the formulation of the respective transformations: so far everything ‘looks aggregate’ to STEM (at least by default). So we have to ‘help’ classify Volume as instantaneous (in order to get the correct consolidation of results). The classification is inherited by Volume’, and then we have to also override the ensuing warnings for the subsequently mixed inputs to Flow in and Flow out.

Figure 4: Contrasting output modes

Please contact Implied Logic Support if you need help with similar issues in your own models.

1.5 Limitation and unsuitability of the Time Lag transformation

This model (and specifically the link from Volume to Volume’ ) would be fine running in years; but the Time Lag transformation does not support a sub-annual lag, and even if it did, what you really want is the immediately previous period, regardless of its length.

As a temporary workaround, the model described here uses a specially modified copy of STEM which allows an input of Time Lag = –1 and which it understands to signify that it should return the value of its Volume input from the immediately previous period, regardless of whether the model is running in months, quarters or years:

  • vol’ = prev (vol )

Figure 5: Using a specially modified Time Lag transformation pending the addition of a Previous type

It is clear that a new Previous transformation type would be useful for such aggregate models. Like the Time Lag, it would require a separate Costs input to avoid any circular cost allocation structures, but there is no obvious requirement for it to support more than ‘one step back’.

1.6 What comes in must go out

To avoid warnings at run-time, our final transformation(s) must drive a resource to ‘sink’ the demand. We assume a capacity of 1 cu m per minute (using an implicit time factor).

Figure 6: Defining persistent resource capacity with an implicit time factor to match a flow rate

Of course STEM will under-estimate the number of Sink resources required if their capacity is assumed to be fully utilised (i.e., water draining all day long)! In order to install a valid number of Sink resources, we would need to define a suitable Deployment:

  • Sites = Customers.Size
  • Distribution = Extended Monte Carlo

2. Metering the incidence of overflow

Based on its assumptions of seasonally varying rainfall (most in February) and consumption (most in August), with a randomised slant to the rainfall, the model calculates monthly results for the various flows modelled and the actual water level.

Figure 7: Seasonal rainfall (unpredictable) and customer demand

We can further monitor the Overflow = fdfi and Underflow = frfo to meter how much water is lost and does not transition through the system in the winter, and to what extent the reservoir cannot meet the demand from customers in the summer.

Figure 8: Reservoir level, rainfall overflow and demand underflow

3. Allowing for an expansion chamber

An alternative formulation of the classic ‘leaky bucket’ algorithm adds an expansion tank to the system. Excess rainfall is stored (queued) upstream from the reservoir and then passed through the system during a later lull (analogous to ‘traffic shaping’ in a communications system). In order to structure this extended problem, we consider:

  • the volume of water in the expansion chamber, exp
  • any flow presented to the reservoir later, return
  • the volume at the end of the previous period, exp’.

Thus we can write (with modifications shown thus):

  • fi = min (fd + exp’, capvol’ + fo)
    modified to allow for any return from the expansion chamber
  • fi = if (fd + exp’ < fr, fd + exp’, min (fd + exp’, capvol’ + fr) )
    ditto for the conditional version
  • overflow = max (0, fdfi)
    now possible for fi to exceed fd
  • return = max (0, fifd)
  • exp = exp’ + overflowreturn
  • exp’ = prev (exp)

Then you can see in the updated results the rainfall overflow, expansion, return and thus reduced underflow (to end customers at the summer peak). The overflow in Jan–Mar is returned in the subsequent lull of Apr–May. The expansion chamber fills, and then empties when the overflow is over. The next underflow or shortfall is mitigated by the return from expansion.

The Overflow variable now meters how much water is queued to transition through the system later.

Figure 9: Rainfall overflow, expansion, return and reduced underflow

Compare this with the results if the expansion facility is disabled. Overflow in Jan–Mar is not returned in the subsequent lull of Apr–May. So the next underflow or shortfall is worse for loss of return from the expansion chamber.

Figure 10: Corresponding results if expansion is disabled

4. Addressing the issues about classification of output mode

Working through the logic so far required manual intervention in two places:

  • to signal to STEM that the Volume transformation should be aggregate, and
  • to override the warning about mixed inputs to the Flow in / out transformations.

These issues suggest two further new transformations, in addition to the Previous type already mentioned.

4.1 Encapsulating and classifying an accumulation function

The Volume transformation uses a reference to Volume’ to calculate a cumulative value, vol = vol’ + fifo, and we have used the same approach for Expansion. This result could be achieved more elegantly using the prevThis() function, vol = prevThis (0) + fifo.

This would remove the circularity (and the ‘clashing’ links both ways) and also allows for the definition of the initial volume in the reservoir. The ‘previous’ element, Volume’, need only be added if required for other calculations (as it is here).

Figure 11: Using the prevThis() function to make an implicit reference to the previous value

Better still would be to have a new, purpose-designed Accumulation transformation type (strictly, an accumulation over time) which would avoid requiring specialist knowledge of the prevThis() function. It would also need an Initial Value input, like the prevThis() function it would replace, but crucially it would be designed to expect an aggregate input and make its output instantaneous, thus obviating the need for one manual intervention.

Note: the ‘previous’ element would be obsolete if an alternative Previous Output basis were available when selected as a transformation input. However, this was frowned upon at the recent STEM User Group Meeting where the consensus was that such an approach would obfuscate the logic compared to the greater visibility of an explicit Previous transformation.

4.2 Recognising a delta when you see one

The Accumulation idea also suggests a converse Delta transformation type which would expect an instantaneous input and make the output aggregate, defined as inputinput’.

However, this would not have helped classify the more complex expression for fi :

  • fi = if ( fd + exp’ < fr , fd + exp’ , min ( fd + exp’ , cap vol’ + fr ) )
    with its instantaneous / aggregate inputs.

The strict rule in STEM 7.3 is that the inputs considered by an expression transformation must all match on output mode (either instantaneous or aggregate). Once we override this constraint for fi, STEM then correctly determines this must be aggregate as at least one of the inputs is aggregate.

The new transformation types suggested above would address the most common cases where STEM can’t determine the output mode automatically, and then the ‘aggregate if any input aggregate’ rule might be sufficient in all other cases.

5. Summary and applications more relevant to telecoms

With only minor modifications, we have a leaky reservoir model which generates realistic results for both Meter and Queue modes:

  • the addition of a Previous transformation
  • manually classifying the Volume transformation as instantaneous
  • relaxing the strict consistency checking of inputs for fi .

Leaky bucket algorithms like this are commonplace in the design of traffic management for packet-switched networks, although evidently a much shorter sampling period would be required to model this aspect of an ATM switch in STEM!

Another more relevant and credible telecoms example would be a queue of incoming customer requests for service activation:

  • fd would represent requests
  • fr would represent fulfilment.

Free subscription when we review your business model

How well do you understand your business? It may be profitable now, but how prepared are you for this to change? We have a track record of analysing individual services or entire businesses in an interactive workshop style that engages and informs. Our visual software enables multi-disciplinary dialogue about the business you thought you knew and the more uncertain future ahead.

Read the article

STEM User Group Meeting 2017 proceedings

Our most recent customer event was held on 27–28 September 2017 at King’s College, Cambridge. The modelling track explored three growth models for a start-up business, from unconstrained to measured to driven. The remainder of the event covered the forthcoming STEM version 8.0, the revised business model for Implied Logic, and two guest presentations.

Read the article

A freshly baked model of a start-up

We examine Michaela’s Best Bread Direct service, from her first unconstrained vision, through a more realistic measured phase and finally to a more ambitious, customer-driven approach. We demonstrate how STEM can be applied to almost any business topic and always delivers a systematic and reliable treatment of time and money.

Read the article

Business-case design and training at your service

Ever wondered what we do at Implied Logic? We have recently posted a comprehensive update to our services portfolio online which is effectively a self-service proposal for everything from online training on-demand through to on-site business-modelling consulting and hosting services for business models on the web.

Read the article

Connecting elements to graphs and publishing online

In what is likely to be the final preview article for the forthcoming STEM version 8.0, we explore visual connections between individual icons and a related graph, as well as intuitive, interactive options for adding an element to an existing graph. We also explore new layout options for pushing a presentation of results in STEM to the web.

Read the article

Our latest help and training materials

Documentation is never regarded as a very exciting activity, but our comprehensive help and training materials are a vital element of the self-serve experience with STEM. In the last quarter we have posted two significant updates to our online help site which enhance both of these aspects.

Read the article

A radical re-think on STEM pricing

We announce a new freemium strategy for accessing the STEM software, including a free and fully-functional demo system for small projects and study as a taster for an innovative minimal-support subscription to the Conventional STEM (C-STEM) desktop solution at just GBP 330 p.a..

Read the article

Vision for the forthcoming STEM 8.0

As part of our vision for a more intuitive way of working that bridges previous mental leaps wherever possible, we preview another two features of the forthcoming STEM version 8.0 – direct-draw connect mode and more flexible user data – that form part of a joined-up approach to fulfilling this dream.

Read the article

© Implied Logic Limited