I have a problem that is similar to the interval scheduling algorithm but it involves priorities. My data sets consist of the following data:
- Cars with the start and end time of parking, along with their one or more attributes (e.g. electric vehicle, motorcycle, handicapped).
- Parking spots along with zero or more attributes and lot number.
- Attributes with their priorities. For example if the property
handicapped
is given a value of 1, cars that have that attribute should be assigned a parking spot first. Attributes are hard constraints, the priorities of the attributes determine the order of assignment.
There is no overnight parking so I have divided the data into buckets of days. Start and end times are in increments of 5 minutes (not sure if this is important).
To be considered a valid assignment, a car's attributes must be a subset of the attributes for the assigned spot. See examples below.
Objectives
This problem comes from overhauling an existing algorithm, which after observing how users interact with the system, it could definitely use improvement.
My first step is to get something going that can produce one or more possible solutions that meet all of the provided attributes. For example, a limo cannot be assigned to a motorcycle spot. There may not be a complete solution given the inputs, if there are 5 electric vehicles but only 4 spots, the algorithm should still try to assign 4 of them (the 4 that have the highest priority).
Given multiple solutions, the "best" solution would minimize the number of open lots at any given time (ideally all the cars parked in the same lot). Even if it is a small block of time in the middle of the day, the lot can still be closed to minimize the cost of security guards.
Example input/output
Set 1
- Attributes: [bus: -1; electric: -2; handicapped: -2]
- Cars: [C1: bus, electric; C2: handicapped, C3: electric]
- Spots: [P1: bus, electric; P2: bus, electric; P3: electric, handicapped]
- Valid assignments:
[C1-P1, C2-P3, C3-P2]
and[C1-P2, C2-P3, C3-P1]
Set 2
- Attributes: [bus: -1; electric: -2; handicapped: -2]
- Cars: [C1: bus, handicapped; C2: bus, C3: electric]
- Spots: [P1: bus, handicapped, electric; P2: bus, electric; P3: handicapped]
- Valid assignments:
[C1-P1, C2-P2, C3-null]
Spot 1 is the only spot that can accommodate car 1. Both cars 2 and 3 can take spot 2 but priority is given to the bus, leaving car 3 unassigned.
Set 3
- Attributes: [bus: -1; electric: -2; handicapped: -2]
- Cars: [C1: bus, electric; C2: electric, C3: bus]
- Spots: [P1: bus, electric; P2: electric; P3: electric, handicapped]
- Valid assignments:
[C1-P1, C2-P2, C3-null]
or[C1-P1, C2-P3, C3-null]
There are two buses but only one bus parking spot. Since C1 has a greater priority sum, it is assigned to the available spot even though C3 could have taken it.
Verifying a solution
- For each assigned car A, if any, verify the assigned spot (P) that it has been assigned to has all of its attributes. In other words, Attributes(A) is a subset of Attributes(P).
- For each unassigned car B, let X be the set of spots in the input data that meet the car's attribute criteria.
- If one or more spots in X is unassigned, abort these steps and mark the solution as invalid
- If one or more cars assigned to spots in X has a greater maximum priority than MaxPriority(B), abort these steps and mark the solution as invalid
- Let Z be the subset of cars assigned to spots in X where the maximum priority of the car = MaxPriority(B). If one or more cars in Z has a greater priority sum than SumPriority(B), abort these steps and mark the solution as invalid
What I have tried
- Find all the valid parking spots for each car.
- Sort each parking spot list in ascending order of the sum of priorities for the parking spot.
- Sort the list of cars in descending order of sum of priorities.
- Attempt to assign each car in order of the sorted parking spots. If the spot is taken for that time then try the next one and so on.
I am hoping to make this more efficient by taking into account the interval for each car, as it currently isn't being taken into account when sorting.
I stumbled upon Google Optimization Tools and it looks similar to the nurse scheduling problem but with more constraints. A key difference is that each shift in the NSP is defined whereas the intervals in my problem can partially overlap.
Questions
- How can I model the problem?
- Are tools like Google OR-Tools or pyschedule appropriate for solving this?