I have a requirement where there are multiple projects available with corresponding schedule dates and schedule reviewing dates.
There will be N number of projects available and each project will have a schedule date as part of the deliverable process. The requirement is to assign each project to the earliest available project schedule review slot. Lets say a project is having a schedule date which is tomorrow, i need to find a available review date slot prior to the schedule date and assign the project based on priority level. Maximum I can assign a project to the earliest available slot is 7 days prior to the actual scheduling date of the project.
For example
Project
Complexity
Schedule Date
schedule review slot
1
A
15-02-2022
12-02-2022 09:00 - 10:00
2
B
15-02-2022
12-02-2022 11:00 - 12:00
3
C
15-02-2022
12-02-2022 12:00 - 01:00
4
A
16-02-2022
13-02-2022 09:00 - 10:00
My desired output
Project
Complexity
Schedule Date
schedule review slot
1
A
15-02-2022
12-02-2022 09:00 - 10:00
4
A
16-02-2022
12-02-2022 12:00 - 01:00
2
B
15-02-2022
12-02-2022 11:00 - 12:00
3
C
15-02-2022
13-02-2022 09:00 - 10:00
I am new to algorithm concepts. So could anyone please guide me in this
What you can do is the following:
Sort the projects into groups with equal complexity/priority, so that all projects with priority A are in the same group, all projects with priority B are in the same group and so on.
Sort the projects in each group by their schedule date, so that the projects with the earliest schedule date come first.
Sort the awailable review time slots by time, so that the earliest time slot comes first.
With this input you can go with the following algorithm:
Take the first (earliest) time slot. Let's call it T.
Take the first (earliest) project P from the sorted priority A list. If P is scheduled less than 7 days after T, assign it to T, remove T and P from their lists and go to step 1.
Else try the same for the earliest project from the priority B and C lists. If none is scheduled less than 7 days after the T, leave the time slot T unassigned and move back to step 1.
Related
I need to come up with an algorithm that can find free intervals on the timeline.
There is a time scale. From 00:00 to 24:00. Initially, when there are no vacancies, all the time is free, and the free interval is (0...1440) (in minutes).
For example, we add a vacancy, I mean that we set the working time for example from 08:00 to 21:00.
Now we will already have 2 free intervals. From 00:00 to 08:00. And from 21:00 to 24:00.
I'll attach pictures below to make it clear what I mean.
*Default variant
*Intervals of vacancies (working hours) may overlap
*Intervals of vacancies can be set without restrictions on the number, and intersect with anything, most importantly within 24 hours (1 day)
The result that I expect: Initially, we have an array with 1 free interval from 0 to 1440 (in minutes), we call the function and pass working time to it, and at the output we get an updated array of intervals, in which there are already 2 intervals. Then we can add 1 more working time, and the output function will always give us the actual array with the correct number of intervals and the free time of the intervals themselves
For writing code I use swift, but I will understand the solution in Python or similar
I really hope for your help! I hope at least that the community will help put me on the right path, at the moment, I can't figure out which way to go. :(
Turn intervals into pairs of start/end events, sort the events by time, then run through the list and keep a count of how many more start than end.
Any stretch of time where the two are equal becomes an interval in your answer.
Here is an explanatory example. Suppose we have the following intervals:
04:00 - 09:00
15:00 - 20:00
08:00 - 12:00
We get the following list of events from them.
04:00 start
09:00 end
15:00 start
20:00 end
08:00 start
12:00 end
Add 2 more to bookend the day
00:00 analysis_start
24:00 analysis_end
Which get sorted into:
00:00 analysis_start
04:00 start
08:00 start
09:00 end
12:00 end
15:00 start
20:00 end
24:00 analysis_end
And now we process them to come up with the following counts of open intervals:
00:00 - 04:00 0
04:00 - 08:00 1
08:00 - 09:00 2
09:00 - 12:00 1
12:00 - 15:00 0
15:00 - 20:00 1
20:00 - 24:00 0
And now the answer is where our tally was 0:
00:00 - 04:00
12:00 - 15:00
20:00 - 24:00
One possible way to do it could be to have an array of size 1440 (number of minutes). You can initialize all to 0 indicating all are free minutes.
For each vacancy interval you need to add, flip the values from 0 -> 1 in that interval, where 1 indicates working minute.
Whenever you need the array, you can iterate through the array and find "collections" of 0s and 1s for free-time and vacancies.
However, this is a very crude way of doing this and every query (update and select) takes linear time. You can do much better performancewise if you implement this whole thing as a segment tree (Read RMQ - range minimum query) where time complexity of your updates and selects will be logarithmic. Take this decision based on number of updates and selects and how you want your performance of code. eg. If total queries are ~10k, you need not go for segment tree. If they be ~10^5 or more, then you should.
Given the new legal regulations due to covid-19 the daycare of my child and all involved parents are overwhelmed and we need to come up with a schedule of when which child can be cared for.
Given the demanded care time per child (s. below), We need an algorithm to optimize the following:
Minimal total contacts / fixed groups. If children meet, it is best if they stay in that group and do not see children of other groups.
While point 1 is more important, the 2nd prio would be to reduce the size per group or maybe it should be phrased as minimal count of different children met per child
Even less important: reduce total contact time.
(Maybe there are other requirements, that I overlooked?)
The demands are of following nature (Timespan and type) :
Case
Child
Timespan
Type
(1) Fixed time, Required
1
Monday, 8:30 - 13:00
Required
(2) Fixed time, nice to have
1
Tuesday, 8:30 - 13:00
Nice to have
(see (1))
1
Tuesday, 13:00 - 16:00
Required
(see (1))
1
Thursday, 8:30 - 13:00
Required
(see (1))
2
Monday 8:30 - 13:00
Required
(3) Flexibel date, required
2
Any 2 other days 8:30 - 13:00
Required
(4) Flexibel date, nice to have
2
Any day 13:00 - 16:00
Nice to have
(5) Flexibel datetime, Required
3
3 hours
Required
(6) Flexibel datetime, Nice to have
3
3 additional hours
Nice to have
...
...
...
Required = The child must have daycare
Nice to have = daycare is demanded but not required. E.g. if child 1 meets child 2 and 3 on Monday and Thursday, it would be fine to meet the same children on Tuesday morning as well, but if it is a completely different group of children than this would not make sense.
All provided timespans must stay in one continuous piece (meaning that 3 hours cannot be split up into multiple slots).
Additional Information
There is only one room available.
There are 15 children in total.
If a solution is much better than the other it is ok-ish to violate "Required" demands for a few cases. We might be able to find a different solution for the parents in few situations. The algorithm should hence contain a parameter like maxAllowedViolations - let's say it's 3 and it should compare how much the solution is better than without the errors.
The demand is provided per week and might change from week to week. I only know the demand one week in advance. The ideal grouping hence might change per week, but it might be better to respect the grouping of the last week as a guidance, because corona has about 7 to 10 days of incubation time.
The caregivers are tested for covid-19 twice a week, the children are not.
I do not care in which language or pseudo-code-ish way the algorithm is, but I will try to implement the algorithm in a web-based format so other daycare centers can use it as well.
I have a database of time's that are not necessarily exact to the specified time. For example, if I want to pick 12:00 PM and my columns have times in column A:
[9:00 AM, 11:55 AM, 2:00 PM, 6:00 PM],
The closest before would be 11:55 AM, and closest after would be 2:00 PM. My attempt at the code:
=MAXIF(A:A, A:A, 12:00)
=MINIF(A:A, A:A, 12:00)
But to no avail, anythoughts?
You want the max where the time is less than or equal to the criteria and the Min for the time greater than or equal to the criteria:
=MAXIFS(A:A, A:A,"<=12:00")
=MINIFS(A:A, A:A,">=12:00")
A group of friends decided to meetup on a chosen date. Everyone in the group provided his/her schedule on that date.
Finally you are given a joined schedule of all members, which lists all the time slots when at least one member is unavailable.
The schedule is a list of lists. Each element in the list is a pair of strings
[[startTime1, endTime1],[startTime2, endTime2],[startTime3, endTime3]]
Start time and end time follows the format HH:MM, where the first 2 digits denote hour and the last 2 digits denote minute, delimited by :.
Your job is to find all the potential time slots for the meetup. Find all time slots that
between 7:00 and 18:00
when all group members are available
Example 1:
Input: schedule = [["16:00", "16:30"], ["6:00", "7:30"], ["8:00", "9:20"], ["8:00", "9:00"], ["17:30", "19:20"]]
Output: [["7:30", "8:00"], ["9:20", "16:00"], ["16:30", "17:30"]]
Example 2:
Input: schedule = [["12:00", "17:30"], ["8:00", "10:00"], ["10:00", "11:30"]]
Output: [["7:00", "8:00"], ["11:30", "12:00"], ["17:30", "18:00"]]
I was thinking about: Sort by start time
Keep track of largest end time
If we got a start time which is greater than the previous largest end time: record the time range
If extra memory is allowed,
Make a pair of time and bool whether the time is start or end.
Sort this array.
Start a running counter with 0
If it is start time, increment the counter, and decrement if it end time
Time periods when this counter is 0 is the free time available
Which column type should be used to store a periodicity in Oracle?
Daily: time, e. g. "14:00"
Weekly: day of week, time, e. g. "Mon 14:00"
Monthly: day of month, time, e. g. "24 14:00"
Yearly: month, day, time, e. g. "12-24 14:00"
Week of year: calendar week, day, time, e. g. "W01 Mon 14:00"
Especially because of the calendar week I guess storing a pattern as text in ISO 8601 format could work. Or is there a better solution that works e. g. on timestamps?
The intent is only to store a pattern in the database. This pattern will then be used to create a periodicity for dates in a given time interval.
Example using Jodatime in Java:
Start DateTime: 2017-01-01
End DateTime: 2017-01-03
Periodicity: Daily, 02:00 - 06:00
(this is what my question is about, i. e. how to store it)
In Java the following intervals will be created using these data, the created intervals will not be stored in the database, they'll be only processed:
2017-01-01 02:00 - 2017-01-01 06:00
2017-01-02 02:00 - 2017-01-02 06:00