I'm trying to solve a problem where I have no idea what algorithm is to be used here to get the optimized answer. The problem is like this...
Consider there are 10 shuttle vehicles and 2 different routes in which they travel. Each vehicle has a seating capacity of 10 people. Normally each route will have 5 vehicles each (10 vehicles, 2 routes). I want to make the shuttle system smarter in a way that if Route 1 has more demand in users(shuttle running with full capacity) and Route 2 has minimal(where the number of passengers in each shuttle is less than 4), to tackle the demand needs, certain number of shuttle vehicles of Route 2 will come to Route 1. If the shuttle service in both routes are not in so demand(all running with less than 4 people), certain number of shuttle vehicles in both routes will stop running, and will be back running when the demand in users arises again.
Things to note : Distance is same in both routes, and the shuttles run free of charge for the passengers.
Which algorithm is best suited for these situations?
Thanks in advance!
Related
There is a carwash that can only service 1 customer at a time. The goal of the car wash is to have as many happy customers as possible by making them wait the least amount of time in the queue. If the customers can be serviced under 15 minutes they are joyful, under an hour they are happy, between 1 hour to 3 hours neutral and 3 hours to 8 hours angry. (The goal is to minimize angry people and maximize happy people). The only caveat to this problem is that each car takes a different amount of time to wash and service so we cannot always serve on first come first serve basis given the goal we have to maximize customer utility. So it may look like this:
Customer Line :
Customer1) Task:6 Minutes (1st arrival)
Customer2) Task:3 Minutes (2nd arrival)
Customer3) Task:9 Minutes (3rd)
Customer4) Task:4 Minutes (4th)
Service Line:
Serve Customer 2, Serve Customer 1, Serve Customer 4, Serve Customer 3.
In this way, no one waited in line for more than 15 minutes before being served. I know I should use some form of priority queue to implement this but I honestly know how should I give priority to different customers. I cannot give priority to customers with the least amount of work needed since they may be the last customer to have arrived for example (others would be very angry) and I cannot just compare based on time since the first guy might have a task that takes the whole day.So how would I compare these customers to each other with the goal of maximizing happiness?
Cheers
This is similar to ordering calls to a call center. It becomes more interesting when you have gold and silver customers. Anyway:
Every car has readyTime (the earliest time it can be washed, so it's arrival time - which might be different for each car) and a dueTime (the moment the customer becomes angry, so 3 hours after readyTime).
Then use a constraint solver (like OptaPlanner) to determine the order of the cars (*). The order of the cars (which is a genuine planning variable) implies the startWashingTime of each car (which is a shadow variable), because in your example, if customer 1 is ordered after customer 2 and if we start at 08:00, we can deduce that customer 1's startWashingTime is 08:03.
Then the endWashingTime is startWashingTime + washingDuration.
Then it's just a matter of adding 2 constraints and let the solver solve() it:
endWashingTime must be lower than dueTime, this is a hard constraint. This is to have no angry customers.
endWashingTime must be lower than startTime plus 15 minutes, this is a soft constraint. This is to maximize happy customers.
(*) This problem is NP-complete or NP-hard because you can relax it to a knapsack problem. In practice this means: you can't write an algorithm for it that scales out and finds the optimal solution in reasonable time. But a constraint solver can get you close.
I am facing problem in assigning buses to routes. I have four buses and four routes with their capacities.
Bus capacity is the number of seats in each bus. Route capacity is number of people on each stop of a route. Route is actually a combination of multiple stops.
An example of a single test case is:
BUS CAPACITY ROUTE CAPACITY
BUS 1 44 Seats Route 1 30 Peoples
BUS 2 63 Seats Route 2 50 Peoples
BUS 3 14 Seats Route 3 40 Peoples
BUS 4 17 Seats Route 4 17 Peoples
There is a lot of test cases with multiple combinations for this problem. The numbers of routes and buses are always equal.
I am looking for a algorithm that helps out in solve this problem optimally.
Try
https://en.wikipedia.org/wiki/K-nearest_neighbors_algorithm
or
https://en.wikipedia.org/wiki/Euclidean_distance
approaches basically you are looking for best match.
In layman's terms what you might want to do is find the best matching route to a bus where best matching is defined as where the bus capacity to route capacity is optimal i.e. busCapacity - routeCapacity is lowest positive number.
Once you find such matches they will be eliminated from the problem world.
Then repeat this for the remaining world.
The end product is that everything is matched.
However prepare of the unexpected:-
You may exhaust all the possible combination and left with smaller capacity and bigger route capacity. In this case you look for difference between i.e. routeCapacity - busCapacity to be least as the best match.
This is so that the number of people you gave to let know that they can't be served is minimal.
You don't actually say what optimal means here, and that might change what the best solution is, but I would be inclined to sort the routes and buses and then assign the largest bus to the route with the largest number of people waiting, the next largest bus to the route with the next largest number of people waiting, and so on.
There will be unhappy people here if a route is assigned a bus that doesn't have enough seats for the people on the route, but with this assignment all of the buses with more seats are assigned to routes with even more people waiting, so giving a bigger bus would leave at least as many other people without a seat.
For a more sophisticated way of matching people and buses look at https://en.wikipedia.org/wiki/Assignment_problem
An example of how the definition of optimal changes things is if you don't care about the number of people annoyed but about the number of routes where people don't get a seat. In this case if you have routes with 2,3,5,9 people waiting and buses to carry 1,2,4,8 people it might make sense to assign them as 2 people-2 seats, 3 people-4 seats, 5 people-8 seats, 9-people-1 seat which leaves 8 people without a seat instead of 4 but all of those 8 people are on just 1 route.
Gurus,
I am in the process of writing some code to optimize employee transport for corporate. I need all you expert's advice on how can this be achieved. Here is my scenario.
There are 100 pick up points all over city from where employees need to be brought to company with multiple vehicles. Each vehicle can occupy say 4 or 6 employees. My objective is to write some code which will group the people from nearby areas and bring them to company. Master data will have addresses and its latitude/longitude. I want to build an algorithm to optimize vehicle occupancy as well as distance and time. Could you guys please give some directions how can this be achieved. I understand I may need to use google maps or direction API for this but looking for some logic hint/advice how this can be achieved.
Some more inputs: These vehicles are of company's vehicle with driver. Travel time should not be more than 1.5 Hrs.
Thanks in advance.
Your problem description is a more complicated version of "The travelling salesman problem". You can look it up on and find some different examples and how they are implemented.
One point that need to be clarified : the vehicules to be use will be the employee vehicule that will be carshared or it will be company's vehicule with a driver?
You also need to define some time constrain. For example 50 employees should have under 30 min travel, 40 employe under 1h travel and 10 employe under 1,5H.
You also need to define the travel time for each road depending of the time, because at different time there will be traffic jam or not.
You also need to define group within the employee: usually people (admin clerck or CEO) in a company don't commute at the same time, it can have 1 hour range or more.
In fine, don't forget to include about 10% of the employee that wil be 2 to 5 min late to their meeting point.
I am writing a program that will simulate how members of a certain timeshare will request their apartments. The apartments are only available for certain 'events' throughout the year, and the events each have different durations (counted in days). For each event, there are a number of apartments available, which are divided into groups according to cost (points per day).
We may also have the situation that some of the apartments are already rented out, so it is possible that certain events cannot admit a certain apartment type.
Now I want a member to request apartments according to this strategy:
Maximizing the number of total event days is first priority.
Maximizing the number of points spent is second priority (so the user requests the best possible apartment that he/she can afford and still have as many days as possible).
The total cost of the requested apartments cannot exceed the total amount of available points for that user.
Obviously, if there are no more apartments of a given type for a certain event, the user should not request that particular apartment/event combo.
I am wondering whether the problem is similar to the problem described here:
http://en.wikipedia.org/wiki/Hungarian_algorithm
in that it (I suppose) possible to frame this as a matrix problem where each entry has a cost associated with it.
However, the difference is that for my problem, I am allowed to use the same apartment for several events - it's not 'spent' once it has been used for one event. Also, the cost per entry is not really one-dimensional, since each event/apartment combo both has a number of days associated with it and a number of points - both of which should be maximized (but with priority given to the number of days).
As an example, let's say there are three apartment types, costing 75, 100, and 125 points per day, and three events, with a duration of 2, 10, and 4 days. Let's further say many of the apartments are taken, so the availability matrix looks like this:
cost
75 100 125
2 True False True
days 10 False False True
4 True False True
Let's also say the user has 1250 points available. The solution, in this case, would be that the user requests the 10-day event with the 125-point apartment and nothing else.
The brute-force way of doing this would perhaps be a recursive algorithm:
Let n be the number of events you are currently trying
Find all combinations of events and apartments, and calculate the combo that maximizes the number of days, then the number of points spent (this will both include all permutations of n events, but also the number of ways 3 apartment types can be assigned to n events).
Let n=n-1
This will quickly become overwhelming when the number of events goes up, I think, so I am wondering whether there are any algorithms that can solve this in a less expensive way?
If you have access to a library for http://en.wikipedia.org/wiki/Integer_programming you could try throwing this at it.
Even if you have only one choice of cost for each event, so that you are just trying to chose combinations of events that cover as many total days as possible without going over budget, I think this reduces to http://en.wikipedia.org/wiki/Knapsack_problem. This means that it is unlikely to be solved exactly by a worst case polynomial time algorithm such as the Hungarian algorithm.
I have a scheduling problem I'm trying to figure out a best fit algorithm to use.
A hotel owns a theme park and is a highlight for visitors staying at the hotel. However, the hotel has more rooms than day passes for visitors wanting to go to the theme park. So during the peak months, there is a possibility that some will not get to go to the theme park.
We want to have every visitor given at least 1 chance to visit the theme park.
If there is contention, we would want to favour giving the day pass to visitors who stay longer at the hotel.
Can anyone point me in the right direction on which algorithm will fit the problem best?
No this is not homework. :)
Thanks in advance.
You can use Priority Queue (PQ). Every day you put customers in your (PQ) computing the priority as p = 1/r where r is the number of remaining days for that guest in your hotel. In this way, every day you give away your n passes to the n customers who have fewer days to stay at your hotel (if a customer has just 1 more day to stay, she/he must have the highest priority in getting the pass, because there just one possibility). If you have several customers with equal p then you choose among them by looking at the total number of days that they stay at your hotel, and you favour those customers staying longer.
You can assign each guest a weight, or priority, according to length of stay (and maybe the number of days the guy's been a guest already without a pass) and then sort the guests by priority. Then it should be easy to give out passes just starting at the top of the sorted list.
You can use a priority queue for this. The priority queue has to be arranged based on the number of chances and number of days the visitors are staying.