Monday, October 5, 2009

A simple example of agents and contexts


In the last few days, dishes in my house are washed by hand. Our dish washer have seen signs of old age, thus I acquired a new one. First step was to order delivery from the store. There is the software engineering principle of "separation of concerns", thus those who do the delivery don't install it. I am not allowed to install it myself, since if I open the package I am losing the warranty, only a technician of the service company related to the importer is authorized to open the package. After some coordination this technician arrived today, looked at our kitchen and said -- "this is very common, they have changed the standard, now there is a thermostat on the pipe, so the size of the hole that your need in the kitchen closet is larger". Since there is a separation of concerns, he does not do holes, and I had to call the Carpenter who came later today, so I'll be able to call the technician again tomorrow... This is the result of the fact that the event of "standard of pipe changed, thus it effects the size of the pipe" was not reported by the store, since they don't install dish washers so they probably don't know --- this separation of concerns, and not seeing event over a larger story, wasted a lot of time and money to the society...

Anyway -- enough complaining.

I got a question from Hans, related to my posting on context, I am copying the question here:

"
I would be interested to hear about how the context concept works in a particular use case: Let's say I have events that contain, among other things, a number. I would like to capture the third quartile (a data point that sits immediately above 75% of the other points) of the number, every hour. I would then like to perform some operation over the previous 8 of these hourly numbers.

How would this be expressed as contexts and agents?"

OK -- here it is:

We start by event of type E1 that flows into the system from some consumer and has some numeric attribute A, for which we want to capture the third quartile.

  • First we define a context C1 of type of sliding fixed temporal interval with both duration and period of 1 hour.
  • Then we define an agent A1, which is valid within C1, and calculates the third quartile and produces event of type E2, with an attribute B which that captures the derived value.
  • Further we define a context C2 that is a sliding event temporal interval on event E2, with event count period and event count duration both of 8.
  • And finally we define an agent A2 that subscribe to events of type E2, and is valid with context C2, that does some operation on E2, and may in turn produce (say) event of type E3, which is flowing to some consumer.

This is the basic model. Of course, it is a bit more complicated, if our agent library does not contain an agent that calculate quartiles may not be a basic, this can be somehow combined from some combination of agents, since an agent can be recursive and include mini-EPN, but as such we can still model it as a single agent in the high level view.

The nice thing about this abstraction that it is quite simple to model such problems... More - Later.



2 comments:

Hans said...

Thanks for responding. I meant for this question to express a tough scenario. I will figure out whether I simplified it into an easy scenario, or it was never tough to begin with.

In the mean time, another question (although maybe I should wait for your book chapter?):

Do you see a use of a context within a context?

Opher Etzion said...

Hello Hans.

The scenario you specified is simple from modelling POV, the difficulty is that the calculation you asked for is not available as a built-in operation in languages, so if needed such an operation, or operations like that, need to be constructed, however from the conceptual model of agents and context it is fairly easy,

As for your second question, there is a notion of composite context such as: you would like to create a context partition for each customer (segmentation oriented context) and within it a partition for each hour (temporal context) -- the result is a composite context. Maybe deserves additional posting.

cheers,

Opher