Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Logical Problem regarding time intervals 1

Status
Not open for further replies.

Coolstep

Programmer
Dec 7, 2004
50
EG
My project is a billing system for airlines using local airports.
we have Airports, Resources, Agents and Airlines.
- Resources: Resources in the airport used by airlines. Each resource has Tariffs with From-To intervals
- Agents: Companies who register with us to make their related airlines use specific resources in time intervals (From-To) for each airport and according to contracts each agent and each airline may have its own billed value (different than the Tariff specified for the selected resource).
- Airlines: individual airlines who are exactly like agents
except that they don't have other related airlines and they are treated in bills different than agents.

The problem is:
as you can see, I have more than one time interval that i have to validate and handle. Consider the following scenario to simplify it:
1. 'Swiss Air' is an airline that's handled by an agent called 'Tiger' from 1-Feb-2005 to 15-May-2005. 'Swiss Air' will join other agent called 'Lotus' from 16-May-2005 to 'Not specified'.
2. A resource called 'DCS' has 'Tariff 1' from 1-Jan-2005 to 10-Apr-2005 ($1.5) and 'Tariff 2' from 11-Apr-2005 to 1-Sep-2005 ($2.0).
3. At the proposed view I want to assign:
'Tiger' / 'Swiss Air' at 'Cairo Airport' uses the resource 'DCS' from 1-Feb-2005 to 1-Mar-2005 ($1.3) and at 'Sharm airport' uses the resource 'DCS' from 1-Feb-2005 to 1-Apr-2005 ($1.0). and so on with hundreds of airlines and agents and about 10 resorces!

Any one can help me to validate these time intervals? knowing that I'v already implemented (Agent/Airline) and (Resource/Tariff) and time intervals are valid till now.


 
Interesting problem. These are what Peter Coad calls 'moment-intervals'. The resources in question, are they finite, like parking spaces or baggage handling? In other words, is it a 'rental' model?

For example, in a video rental store, you can hire a resource for a time, but only if they have one in stock.

If the resource is something consumable, like fuel or BA airline meals [smile], then you need a different model.
 
Dear Stevexff,

Actually it's like a membership not a rental. Airlines have no other way to use a certain resource, this resource is available by more than one company and each company offer its prices and offers. so our company have some resources and wants to handle users with their offers and hoe much to charge them for their usages. We also specify these charges according to our contracts with Agents who handle a group or Airlines(Actual resource user). Also we'r interrested to Monitor other competing resources and their member users. Can u get it?

I'm glad u'r interrested in it, anyway we may all face such a situation so our ideas here may reach us to a best practice ;)
 
It looks complex, but if you stand back it is not.

You have a number of types (classes) time intervals, each attached to different business object. By looking at the business objects, you should be able to see the priorities these time intervals have.

You have airport resources, Agents and airlines.
There is a many-to-many associations between each pair.
Each of these is resolved by a link class whose key is the combination of the keys of the two associated classes.
Each link class has a tariff and a time slot.

Draw a simple diagram with three boxes in a triagle.
Name them as 'Airport Resource', 'Agent' and 'Airline'.
Draw three kines joining them.
Write 'tariff' and 'timeslot' against each line.
Then think it through.

If an airline is working directly with an airport, the tariff and time slot on that link class prevail.

If an airline is working through an agent, then two tariffs and the time slots apply.
The airline-agent timeslots MUST cover the agent-airport timeslots.
For Tarriffs applied to the agent by the airline are probably less than from the agent to the airline.

If the two time slots do not overlap for certain time periods, then the airline has no agent or the agent has no resources. In either situation, the airline must deal directly with the airport.

I hope this helps.

Gil
 
I forgot. There is another one.

The box labelled 'Airport Resource' is also a link class betwee two: 'Airport' and 'Resource'. It also has a tariff and time slot.

So, if an airline wants a resource, it has to specify the airport and the time slot that it wants it for. That is on the original diagram. However, that resource has to be available at that resource at that time, which is this new one.

Of course, using an agent, the airline has to have an agreement with the agent. The agent then needs an agreement with the airport covering that time slot and then finally, the resorce has to be available at the airport at that time.

My diagram may be too simplistic, because I dont have a web site currently working where I can put a picture and I have tried to simplify it. However, I hope you get the concept and approach.

Gil
 
Gil,
I'm so thankful for your valuable post it's really professional :)

There's a point that I may didn't clearify previously, an airline from time to time changes its agent! and in order to simplify it in my design I created an agent called 'Self Handler' where it represents airlines who don't have agents
so regarding ur triangle we can remove the line from airline to airport.
currently I have 5 business class which are
1. Agent
2. Airline
3. Resource
4. Tariff
5. Airport
and 2 linking entities
1. Airline_Agent
2. Charge (airport / Resource / airline_Agent / From / To)

so adding a charge I should assure that the (from-to) is within the airline_agent and not overlapping with other (from-to) in Charges for same airline with same resource in same airport.
e.g. of valid cases
1. 'Swiss Air' - 'Cairo AP' - DCS - 1/Jan/2005 - 20/Feb/2005
2. 'Swiss Air' - 'Sharm AP' - DCS - 1/Jan/2005 - 20/Feb/2005
3. 'Swiss Air' - 'Alex AP' - MSDCS - 1/Jan/2005 - 20/Feb/2005

Hope this helps make it more clear
 
I agree, that having a 'Self Handling' agent is one solution and it does remove the association. It depends on how easy it is to implement. There is an old saying from the database world 'One man's attribute is another man's entity' (or 'class' in this case). Does the 'Self Handler' have lots of different code or just a bit? I'll return to that.

I think the base classes are sort of correct.
Where is Tarriff applied? I would have guessed that it could be on EVERY link class. In other words, charges may differ for every combination.

The link classes concern me, possibly because I dont understand the problem fully.
Airline_Agent (From/To) is fine.
Charge is a bit strange.

The agent (or pseudo-agent) provide a specific resource at specific airports. This puts you in danger of having a ternary relationship, which is usually worth avoiding.

As a customer, the airline-agent requires a resource at an airport over a data range. This requirement is probably the dominant pair, so link them with a link class: airport-resource. or 'availability'.

This is what the agent is being asked to organise, which makes him the odd one out; he is dispensible, because there may be several possible agents. The 'availability' would be harder to change (maybe). So we have many 'availabilities' that are accessible through many agents. This also requires a link class.

All the Link Classes could possibly have From/To values.
When is that resource available at that airport? (Maybe its always available; like meals at HR :))
When is that agent able to access these resources? (Do agents exist forever?)
When is the agent working for the airline? (Do airlines change them?)
Not all of these 'From/To' ranges are applicable, as the questions show, but these questions must be answered.

Taking your example:
1a. 'Swiss Air' - 'Cairo AP' - DCS Agent 1 - 1/Jan/2005 - 31/Jan/2005
1b. 'Swiss Air' - 'Cairo AP' - DCS Agent 2 - 1/Feb/2005 - 20/Feb/2005

Finally, when does the airline require the resource at the airport? Now there is an association between airline and 'availability'. This association is the 'requirement'. This highlights the airlines requirement of when and where they want these resources to be available. So even if they are always available at the airport, the airline is only interested in access over discrete chunks of this time.

Now to meet the requirement using a specific agent the dates associated with the requirement must be matched by:
Agent is working for airline
The resources are available at the airport and
The agent can get access to them (has a licence or something)

I make that 4 'From/To' ranges, some of which may be OTT and you can dispense with them. But you cant have less than 2; the requirement and some form of access arrangement.

My worry with your response was that you only seemed to show 1 From/TO range.

Gil


 
Gil,
It's a lil bit simpler than what u expect, the point is that the resource is always available and always accessible, it's like a gate and it's mandatory to pass through, so the airport takes the responsibility of arranging its traffic. Sometimes it happens that this resource is down, so flights worked while it was down are not charged. I'm affraid i didn't clearify the life cycle well.

After I set the charges I'v described previously, to generate bills, the airport operators fill in my system each flight's loads and weather the resource was down or not. According to loads for each flight syste should calculate their bills according to their settings at the Charge entity(Airport-Agent-Airline-Resource-From-To). After bills are ready, they'r sent to handling agents of each airline, weather they'r self handling or related to one of the agents. Consider this example
1. Cairo Airport-Self Agent-British Airways-MSDCS-1/Jan/2005-20/Jan/2005
2. Cairo Airport-Tiger Agent-British Airways-MSDCS-21/Jan/2005-31/Mar/2005
so after January is over, two bills are generated regarding British Airways Fees. One for the British Airways head office for the interval 1/Jan/2005-20/Jan/2005 and one for the Tiger Agent Head office for the interval 21/Jan/2005-31/Jan/2005. Accordingly each bill will represent a different charge.

About the 'Self Handler' its treated like a normal agent, no extra code.

Could you please give me example on how the link class will act, specially that my most hard point is validating the objects of this link class, where to validate them?

I have an idea but i know it's not professional but i guess it'll work. It's simply getting the date intervals by direct SQL stateemnts and comparring them using ArrayLists.

e.g.:
adding a new charge like
Cairo Airport-Tiger-Swiss Air-DCS-1/Feb/2005-1/Mar/2005 -$1.3
1. Get Array(From) and Array(To) from Airline_Agent and check if the mentioned interval is valid for any of the From-To in the arrays
2. If Valid, Get Array(From) and Array(To) from Charge where the Airport is 'Cairo Airport' and the resource is of the same type like 'DCS' and airline is 'Swiss Air'. Then check if the mentioned interval overlap with any of the intervals in the arrays.

if these two comparisons passed I guess it'll be valid.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top