简体   繁体   English

指定资源分配算法?

[英]Specifying Resource Allocation algorithm?

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 R = {r1,r2,r3,r4}资源集的%

U={u1,u2,u3,u4} %set of users U = {u1,u2,u3,u4}用户组数

u1 can choose a single resource from: {r1, r2, r3} u1可以从以下资源中选择一个资源:{r1,r2,r3}

u2 can choose a single resource from: {r1, r2} u2可以从以下资源中选择一个资源:{r1,r2}

u3 can choose a single resource from: {r1, r4} u3可以从以下资源中选择一个资源:{r1,r4}

u4 can choose a single resource from: {r2} u4可以从以下资源中选择一种资源:{r2}

in this case I should allocate 在这种情况下,我应该分配

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

If this was allocated differently u4 will have no resource to be allocated. 如果对此分配不同,则u4将没有资源可分配。

This is only to explain the problem, I need to solve this for 200 users and 100 resources. 这仅是为了解释问题,我需要为200个用户和100个资源解决此问题。 Can I seek your advise on which algorithm to use or how to solve this? 我可以就使用哪种算法或如何解决这个问题寻求您的建议吗?

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. 如果在N次尝试之后,找不到解决方案中止。

I often solve these type of assignment problems with an LP/MIP solver. 我经常使用LP / MIP求解器解决这类分配问题。 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 (eg fixing some assignments, allowing additional ad-hoc constraints). 看起来有些矫kill过正,但以我的经验来看,它提供了一些有用的灵活性(例如,修复某些任务,允许附加的临时约束)。

Your problem could be formulated as: 您的问题可以表述为:

在此处输入图片说明

I solved the problem as an RMIP which is just an LP (the x variables are automatically integer for this type of problem). 我解决了这个问题,因为它只是一个LP的RMIP(对于这种类型的问题,x变量自动为整数)。

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. 首先,我们需要注意变量x(u,r)仅假定值为0或1。这是线性分配问题的一个属性。 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. 第一个等式assign1说:我们可以为每个用户分配最多一个资源。 Eg for user u1 we have: x(u1,r1)+x(u1,r2)+x(u1,r3) <= 1 . 例如,对于用户u1,我们有: 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 (eg if we have a dataset with 2 users and just 1 resource). 如果资源不足(例如,如果我们的数据集包含2个用户和1个资源),我们可以允许未分配的用户。 As a user cannot be assigned to all resources, we do not sum over all r but only over the allowed combinations. 由于无法将用户分配给所有资源,因此我们不对所有r求和,而仅对允许的组合求和。

The second equation assign2 says: we can assign each resource to at most one user. 第二个等式assign2说:我们可以将每个资源最多分配给一个用户。 Eg for resource r1 we have: x(u1,r1)+x(u2,r1)+x(u3,r1) <= 1 . 例如,对于资源r1,我们具有: 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 (eg for the case where we have 2 resources and just 1 user). 在我们缺少用户的情况下(例如,对于我们有2个资源而只有1个用户的情况),我们允许使用未分配的资源。 As a resource cannot be assigned to any user, we do not sum over all u but only over the allowed combinations. 由于无法将资源分配给任何用户,因此我们不对所有u求和,而仅对允许的组合求和。

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 . 该模型与此处描述的LP模型略有不同。 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: 对于您的少量数据集,以下是输入数据和结果: 在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM