I am designing some software for transportation companies (air, ground, water, etc). In these industries, you have rest rules where you need to get a certain amount of rest in between activities.

So lets say trucker/pilot/sailor has an activity to go from A to B that takes 4 hours, then has a 30 min break than wants to go C to D that takes 3 hours. Then he/she needs 10 hours of rest before starting another activity.

Now I want to figure out when the next activity can be scheduled. Of course in the very simple example above, I could just take the time that D ended, and add 10 hours, then look for an activity at that point. However, there are more variables in play so I need a broader solution where I can incorporate the other elements. For instance, the trucker has to have 34 hours off in a rolling 168 hour window... so I would be checking for that as well.

My initial thinking was put all the activity in to an array, where each key/value in the array is a minute. Then go through the array to check to make sure all the rules are complied with. However, this will be a huge array and very inefficient.

I appreciate any thoughts!!

  • Please tell me that the 34 hours off is not allowed to be consecutive!
    – Peter M
    Feb 10, 2019 at 19:05

2 Answers 2


Each trucker should have an own activity log over a certain time interval in the past (for example, three months, or last year, or whatever you need for evaluating rules). Activities should be logged there with start and ending times (not "per minute", as long as there is no reason for this). That log won't become "a huge array" for each trucker if we speak of activities which usually last some hours, quite the opposite.

Then, with this information at hand, you can implement any rule you like using the log.

  • What is the point of "implementing rules" based on a log, after the trip? I do not think this is to see if the driver took his mandatory naps (that what his "Fahrtenschreiber" is for), it is to make sure his schedule complies to local labour laws, before he is sent off.. Feb 10, 2019 at 20:59
  • @MartinMaat: please don't get nitty on the term "log" used in my answer. If you prefer "list" in context of schedule planning, then use that. Does not make a big difference.
    – Doc Brown
    Feb 10, 2019 at 21:10

This is for a planning application, right? You want to know whenever an activity about to be inserted into the schedule would violate a rule.

You can have a method for each rule check. You pass the schedule and the activity to be inserted to the rule checking method as arguments. The rule checking method will then backtrack from the new activity into the past to determine if it finds a violation or not. Issues are reported in an out parameter, the return value is a boolean that signals a violation.

One such method could named

ViolatesDailyRestingRequirement(Schedule schedule, Activity newActivity);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.