Bipartite Matching with divisible tasks - graph

I am trying to solve an extension of Assignment problem, where both tasks and the man hours are divisible.
for instance, a man X has 4 hours available in a day, can do 1/3 of task A in 2 hours, 1/4 of task B in 4 hours. Man Y has 10 hours available can do 1/5 of a task A in 1.3 hours, 1/8 of task B in 6 hours. Is there an extension of BiPartite matching which can solve this?
Thanks!

I don't think that you can easily model this as a bipartite matching. However, it should be fairly easy to create a linear program for your problem. Just have for every worker a set of variables x_{i,j} which indicates how much of person i's time is allocated to task j.
Let h_i be the number of hours available for person i. Then, for every person i it must hold that
Let a_{i,j} be the "efficiency" of person i at task j, i.e., how much of the task the person can do in one hour. Then, for every task j it must hold that:
That's it. No integrality constraints or anything.

Related

Understanding computation graph

I'm trying to understand micro-ops and computation graphs for intel architecture. I have the following graph :
With the standard 6 functional units: 1 load, 1 store, 2 integer, and 2 floating point, can the machine execute the given execution graph?
My answer is yes, because there is only one integer op per each cycle. What I'm not sure about are load ops. I know that they can be pipelined, but don't know if that can be done three at a time. I would like to know if this can be done. Thanks.

Classroom Scheduling Using Graph Algorithm

This is another question from my past midterm, and i am supposed to give a formal formulation, describe the algorithm used, and justify the correctness. Here is the problem:
The University is trying to schedule n different classes. Each class has a start and finish time. All classes have to be taught on Friday. There are only two classrooms available.
Help the university decide whether it is possible to schedule these classes without causing any time conflict (i.e. two classes with overlapping class times are scheduled in the same classroom).
Sort the classes by starting time (O(nlogn)), then go through them in order (O(n)), noting starting and ending times and looking for the case of more than two classes going on at the same time.
This isn't a problem with a bipartite graph solution. Who told you it was?
#Beta is nearly correct. Create a list of pairs <START, time> and <END, time>. Each class has two pairs in the list, one START, and one END.
Now sort the list by time. Or if you like, put them in a min heap, which amounts to heapsort. For equal times, put the END triples before START. Then execute the following loop:
set N = 0
while sorted list not empty
pop <tag, time> from the head of the list
if tag == START
N = N + 1
if N > 2 return "can't schedule"
else // tag == END
N = N - 1
end
end
return "can schedule"
You can easily enrich the algorithm a bit to return the time periods where more than 2 classes are in session at the same time, return those classes, and other useful information.
This indeed IS a bipartite/bicoloring problem.
Imagine each class to be a node of a graph. Now create an edge between 2 nodes if they have time overlap. Now the final graph that you get if you can bicolor this graph then its possible to schedule all the class. Otherwise not.
The graph you created if it can be bicolored, then each "black" node will belong to room1 and each "white" node will belong to room2

Game Logic Math headbreaker

I have 10 objects traveling at the same speed to 5 different destinations in my game world.
The 5 destinations take 5,10,15,20 and 25 seconds to reach. So each destination has 2 objects traveling to it.
My 10 objects all start from the same origin, at 5 seconds intervals. So when object1 is still traveling, after 5 seconds object2 starts to move and so on. The problem is, is that the object's destinations are random...so object1 may have the furthest destination in case 1 and in case 2 it may be that object10 has the furthest destination. In this particular example, I have 5 destinations that each will receive 2 objects.
How do I calculate the maximum time it could potentially take for all objects to reach their destination? Preferably breaking it down in a logical function that captures the above. Doesn't have to be in C# or anything like that, i just want some help in creating a function that could capture more complex scenarios where I have more objects and more destinations as well....
So the variables are:
Objects,
Destinations + Time to reach the particular destination,
Interval at which they start.
For the avoidance of doubt: each destination will receive an equal amount of objects. So the number of total objects traveling is always an even number.
The outcome should be the longest hypothetical time it would take for all cubes to reach their destination (and bonuspoints for the shortest amount of time it would take.)
I have been trying to capture this in Excel to calculate a few scenarions but I fail miserably...
Apologies for the Grade 9 Highschool level question here, but this one has me really puzzled!
The maximum time it takes for all objects to reach the destination:
The latest time objects start to travel: 10 objects, one every 5 seconds, means the last one starts at 45s.
Plus:
The longest time to reach a target: 25s.
So the maximum time it takes for the worst case is 70 seconds.

Say a customer could enter a bank randomly every 2-6 seconds, what would be the statistical percentage of a person entering each second?

I'm writing a bank simulation program and I'm trying to find that percent to know how fast to program a new person coming in based on a timer that executes code every second. Sorry if it sounds kinda confusing, but I appreciate any help!
If you need to generate a new person entity every 2-6 seconds, why not generate a random number between 2 and 6, and set the timer to wait that amount of time. When the timer expires, generate the new customer.
However, if you really want the equivalent probability, you can get it by asking what it represents: the stochastic experiment is "at any given second of the clock, what is proability of a client entering, such that it will result in one client every 2-6 seconds?". Pick a specific incidence: say one client every 2 seconds. If on average you get 1 client every 2 seconds, then clearly the probability of getting a client at any given second is 1/2. If on average you get 1 client every 6 seconds, the probability of getting a client at any given second is 1/6.
The Poisson distribution gives the probability of observing k independant events in a period for which the average number of events is λ
P(k) = λk e-λ / k!
This covers the case of more than one customer arriving at the same time.
The easiest way to generate Poisson distributed random numbers is to repeatedly draw from the exponential distribution, which yields the waiting time for the next event, until the total time exceeds the period.
int k = 0;
double t = 0.0;
while(t<period)
{
t += -log(1.0-rnd())/lambda;
if(t<period) ++k;
}
where rnd returns a uniform random number between 0 and (strictly less than) 1, period is the number of seconds and lambda is the average number of arrivals per second (or, as noted in the previous answer, 1 divided by the average number of seconds between arrivals).

Friends selection algorithm

In a .net project we have a group of 200 people of two types, lets say x and y, who need to be separated into groups of 7 or 8.
We have a web page where the people write other members they want to be in a group with. Each person builds a list of wanted members.
After this, there should be an algorithm to build the 7-8 member groups considering the peoples ratings, and the following condition: each group has at least 2 people of each type (x/y).
I'm pretty sure there must be a well known algorithm similar to this but didn't find one. Anyone knows how to do it?
this problem smells NP-Hard, so I suggest using Artificial Intelligence tools.
A possible approach is steepest ascent hill climbing [SAHC]
first, we will define our utility function (let it be u) as mentioned in the comments to the question. [sum of friends in group for each user]. let's define u(illegal) = -1 for illegal solution.
next,we define our 'world': S is the group of all possible solutions].
for each solution in S we define:
next(s)={all possibilities moving one person to a different group}
all we have to do now is run SAHC with random restarts:
1. best<- -INFINITY
2. while there is more time
3. choose a random legal solution
4. NEXT <- next(s)
5. if max{ U(NEXT) } < u(s): //s is the top of the hill
5.1. if u(s) > best: best <- u(s) //if s is better then the previous result - store it.
5.2. go to 2. //restart the hill climbing from a different random point.
6. else:
6.1. s <- max{ NEXT } //climb on the steepest hill.
6.2. goto 4.
7. return best //when out of time, return the best solution found so far.
It is anytime algorithm, meaning it will get a better result as you give it more time to run, and eventually [at time infinity] it will find the optimal result.

Resources