0

Can someone help me to solve or specify what type of problem is this:

I have a set of resources and a number of users, and for each user there is a specific subset of resources that can choose a single resource from for allocation. Two different users could not be assigned to the same resource.I need to allocate resources to users in a way to maximize the allocation. for example:

R={r1,r2,r3,r4} %set of resources

U={u1,u2,u3,u4} %set of users

u1 can choose a single resource from: {r1, r2, r3}

u2 can choose a single resource from: {r1, r2}

u3 can choose a single resource from: {r1, r4}

u4 can choose a single resource from: {r2}

in this case I should allocate

r3->u1, r1->u2, r4->u3, r2->u4.

If this was allocated differently u4 will have no resource to be allocated.

This is only to explain the problem, I need to solve this for 200 users and 100 resources. Can I seek your advise on which algorithm to use or how to solve this?

Maryam H
  • 15
  • 3
  • You might want to look into this: https://en.wikipedia.org/wiki/Bipartite_graph#Matching –  Dec 03 '15 at 18:21
  • when doing the allocation, is the any rule or does a user get any available resource? are the resources ever returned back to `R`? – Nick Dec 03 '15 at 19:25
  • Off the top of my head, it would seem you should allocate in the order of smallest available to the most available: u4, then u3, then u2, and u1. Where they are equal, randomly select a user and allocate their request. If it fails, restart and try again. Put this in a loop with a maximum retries, after which you abort. – Nick Dec 03 '15 at 19:30
  • each user can get any resource from their defined subset. when a resource is used no other user can use it. – Maryam H Dec 03 '15 at 20:11
  • Thank you CST-Link, I think that's what I need. – Maryam H Dec 06 '15 at 02:28

2 Answers2

0

I've written a simple assembler that allocates variable to registers. What I found to be most efficient to to do the hardest allocation first, then proceed to do the next hardest.

So in your case, you have a list of users who want an allocation. Since each user has a different rule for the allocation, you need to create a count for each of the available resources.

Then proceed as follows:

  1. using the specific rules, count available resources
  2. select the user with the minimum
  3. in cases of ties, randomally select one
  4. allocate the resource for the selected user
  5. repeat

In this manner, you're giving priority to those users that are hardest to allocate for. But given the users and resources there may not be a solution so you may need to retry several times. If after N tries, no solution is found abort.

Nick
  • 2,342
  • 28
  • 25
0

I often solve these type of assignment problems with an LP/MIP solver. The size is not too big so almost any solver will do and there are many readily available. It may look like a bit of overkill but in my experience it offers some useful flexibility (e.g. fixing some assignments, allowing additional ad-hoc constraints).

Your problem could be formulated as:

enter image description here

I solved the problem as an RMIP which is just an LP (the x variables are automatically integer for this type of problem).

In response to your question let me try to explain the equations.

First of all we need to note that the variables x(u,r) only assume the values 0 or 1. This is a property of linear assignment problems. The reason is not totally obvious but a good book on linear programming can tell you more.

The first equation assign1 says: we can assign each user to at most one resource. E.g. for user u1 we have: x(u1,r1)+x(u1,r2)+x(u1,r3) <= 1. This equation forbids that a user is assigned to two or more resources. We allow for unassigned users in case we are short of resources (e.g. if we have a dataset with 2 users and just 1 resource). As a user cannot be assigned to all resources, we do not sum over all r but only over the allowed combinations.

The second equation assign2 says: we can assign each resource to at most one user. E.g. for resource r1 we have: x(u1,r1)+x(u2,r1)+x(u3,r1) <= 1. This equation forbids that a resource is assigned to two or more users. We need this one also otherwise several different users could be assigned to the same resource. We allow for unassigned resources in case we are short of users (e.g. for the case where we have 2 resources and just 1 user). As a resource cannot be assigned to any user, we do not sum over all u but only over the allowed combinations.

Finally the objective counts how many valid assignments were made. This is the value we want to maximize. The trick is again to sum over the allowed combinations to prevent illegal assignments.

The model is a slight variation on the LP model described here. Much more information on the assignment problem can be found in this book.

For your little data set, here is the input data and the results: enter image description here

Erwin Kalvelagen
  • 15,677
  • 2
  • 14
  • 39
  • Thank you so much for your help. I am not familiar with LP/MIP or these type of programs, but it looks interesting and it's worth looking into it. Do you think this can solve the problem for |r|=100 and |u|=200? will it take long run time? – Maryam H Dec 07 '15 at 17:42
  • Should not take more than a couple of seconds. Even with public domain solvers. Assignment problems are easy LPs. – Erwin Kalvelagen Dec 07 '15 at 17:49
  • Can this be implemented with MATLAB? – Maryam H Dec 07 '15 at 17:58
  • Yes. There is a Matlab optimization toolbox. The LP solver [linprog](http://www.mathworks.com/help/optim/ug/linprog.html) is somewhat of a pain to use. There are other toolboxes such as [YALMIP](http://users.isy.liu.se/johanl/yalmip) and [TOMLAB](http://tomopt.com/tomlab/) that may be easier to use. – Erwin Kalvelagen Dec 07 '15 at 18:12
  • Thank you for your effort! Would it be OK for you if I used this picture in another post? – Maryam H Dec 08 '15 at 07:52
  • No problem. By all means go ahead and reuse this image. – Erwin Kalvelagen Dec 08 '15 at 08:05
  • Thank you.. I am trying to understand the equations.. I think the first two equations are the constrains to have only one resource for each user. Why do we need two of them? and why there is a summation symbol? I would really appreciate if you explain the equations in detail :) Thank you – Maryam H Dec 11 '15 at 00:49
  • I added some text that may help. – Erwin Kalvelagen Dec 11 '15 at 01:39
  • Thanks a lot! It's really a great help to me. – Maryam H Dec 11 '15 at 23:04