简体   繁体   English

将节点分配给图形的算法设计

[英]Algorithm design to assign nodes to graphs

I have a graph-theoretic (which is also related to combinatorics) problem that is illustrated below, and wonder what is the best approach to design an algorithm to solve it.我有一个图论(也与组合学有关)问题,如下所示,我想知道设计算法来解决它的最佳方法是什么。

Given 4 different graphs of 6 nodes (by different, I mean different structures, eg STAR, LINE, COMPLETE, etc), and 24 unique objects, design an algorithm to assign these objects to these 4 graphs 4 times , so that the number of repeating neighbors on the graphs over the 4 assignments is minimized .给定 6 个节点的 4 个不同的图(不同,我的意思是不同的结构,例如 STAR、LINE、COMPLETE 等)和 24 个唯一对象,设计一个算法将这些对象分配给这 4 个图4 次,使得在 4 个分配上的图上重复的邻居被最小化 For example, if object A and B are neighbors on 1 of the 4 graphs in one assignment, then in the best case , A and B will not be neighbors again in the other 3 assignments.例如,如果 object A 和 B 在一个分配中的 4 个图之一上是邻居,那么在最好的情况下,A 和 B 在其他 3 个分配中不会再次成为邻居。

Obviously, the degree to which such minimization can go is dependent on the specific graph structures given.显然,这种最小化 go 的程度取决于给定的特定图结构。 But I am more interested in a general solution here so that given any 4 graph structures, such minimization is guaranteed as the result of the algorithm.但是我对这里的通用解决方案更感兴趣,因此给定任何 4 个图形结构,算法的结果可以保证这种最小化。

Any suggestion/idea of solving this problem is welcome, and some pseudo-code may well be sufficient to illustrate the design.欢迎任何解决此问题的建议/想法,并且一些伪代码可能足以说明设计。 Thank you.谢谢你。

Representation:表示:

You have 24 elements, I will name this elements from A to X (24 first letters).你有 24 个元素,我将这些元素命名为 A 到 X(24 个首字母)。 Each of these elements will have a place in one of the 4 graphs.这些元素中的每一个都将在 4 个图表中的一个中占有一席之地。 I will assign a number to the 24 nodes of the 4 graphs from 1 to 24.我将为从 1 到 24 的 4 个图的 24 个节点分配一个数字。

I will identify the position of A by a 24-uple =(xA1,xA2...,xA24), and if I want to assign A to the node number 8 for exemple, I will write (xa1,Xa2..xa24) = (0,0,0,0,0,0,0,1,0,0...0), where 1 is on position 8.我将通过 24-uple =(xA1,xA2...,xA24) 来识别 A 的 position,例如,如果我想将 A 分配给节点号 8,我会写 (xa1,Xa2..xa24) = (0,0,0,0,0,0,0,1,0,0...0),其中 1 在 position 8 上。

We can say that A =(xa1,...xa24)我们可以说 A =(xa1,...xa24)

e1...e24 are the unit vectors (1,0...0) to (0,0...1) e1...e24 是单位向量 (1,0...0) 到 (0,0...1)

note about the operator '.':关于运算符'.'的注意事项:

  • A.e1=xa1 A.e1=xa1
  • ... ...
  • X.e24=Xx24 X.e24=Xx24

There are some constraints on A,...X with these notations:使用这些符号对 A,...X 有一些限制:

Xii is in {0,1} and Xii 在 {0,1} 并且

Sum(Xai)=1... Sum(Xxi)=1和(Xai)=1...和(Xxi)=1

Sum(Xa1,xb1,...Xx1)=1... Sum(Xa24,Xb24,... Xx24)=1和(Xa1,xb1,...Xx1)=1... 和(Xa24,Xb24,...Xx24)=1

Since one element can be assign to only one node.因为一个元素只能分配给一个节点。

I will define a graph by defining the neighbors relation of each node, lets say node 8 has neighbors node 7 and node 10我将通过定义每个节点的邻居关系来定义一个图,假设节点 8 有邻居节点 7 和节点 10

to check that A and B are neighbors on node 8 for exemple I nedd:检查 A 和 B 是否是节点 8 上的邻居,例如我 nedd:

A.e8=1 and B.e7 or B.e10 =1 then I just need A.e8*(B.e7+B.e10)==1 A.e8=1 和 B.e7 或 B.e10 =1 那么我只需要 A.e8*(B.e7+B.e10)==1

in the function isNeighborInGraphs(A,B) I test that for every nodes and I get one or zero depending on the neighborhood.在 function isNeighborInGraphs(A,B) 中,我对每个节点进行测试,并根据邻域得到一个或零。

Notations:注释:

  • 4 graphs of 6 nodes, the position of each element is defined by an integer from 1 to 24. (1 to 6 for first graph, etc...) 6 个节点的 4 个图,每个元素的 position 由从 1 到 24 的 integer 定义。(第一个图为 1 到 6,等等...)
  • e1... e24 are the unit vectors (1,0,0...0) to (0,0...1) e1...e24 是单位向量 (1,0,0...0) 到 (0,0...1)
  • Let A, B...X be the N elements.设 A, B...X 为 N 个元素。

A=(0,0...,1,...,0)=(xa1,xa2...xa24) A=(0,0...,1,...,0)=(xa1,xa2...xa24)

B=...乙=...

... ...

X=(0,0...,1,...,0) X=(0,0...,1,...,0)

  • Graph descriptions:图表说明:

IsNeigborInGraphs(A,B)=A.e1*B.e2+... //if 1 and 2 are neigbors in one graph for exemple IsNeigborInGraphs(A,B)=A.e1*B.e2+... //如果1和2是一个图中的邻居,例如

  • State of the system: State系统:

L(A)=[B,B,C,E,G...] // list of neigbors of A (can repeat) L(A)=[B,B,C,E,G...] // A的邻居列表(可以重复)

actualise(L(A)):
for element in [B,X]
if IsNeigbotInGraphs(A,Element)
L(A).append(Element)
endIf
endfor
  • Objective functions目标函数

N(A)=len(L(A))+Sum(IsneigborInGraph(A,i),i in L(A)) N(A)=len(L(A))+Sum(IsneigborInGraph(A,i),i in L(A))

... ...

N(X)=... N(X)=...

Description of the algorithm算法描述

  1. start with an initial position A=e1... X=e24从初始 position A=e1... X=e24 开始
  2. Actualize L(A),L(B)... L(X)实现 L(A),L(B)... L(X)
  3. Solve this (with a solveur, ampl for exemple will work I guess since it's a nonlinear optimization problem):解决这个问题(使用求解器,例如ampl会起作用,因为它是一个非线性优化问题):

Objective function物镜 function

min(Sum(N(Z),Z=A to X) min(总和(N(Z),Z=A 到 X)

Constraints:约束:

Sum(Xai)=1... Sum(Xxi)=1和(Xai)=1...和(Xxi)=1

Sum(Xa1,xb1,...Xx1)=1... Sum(Xa24,Xb24,... Xx24)=1和(Xa1,xb1,...Xx1)=1... 和(Xa24,Xb24,...Xx24)=1

You get the best solution你得到最好的解决方案

4.Repeat step 2 and 3, 3 more times. 4.重复步骤 2 和 3,再重复 3 次。

If all four graphs are K_6 , then the best you can do is choose 4 set partitions of your 24 objects into 4 sets each of cardinality 6 so that the pairwise intersection of any two sets has cardinality at most 2. You can do this by choosing set partitions that are maximally far apart in the Hasse diagram of set partitions with partial order given by refinement.如果所有四个图都是K_6 ,那么您可以做的最好的事情是选择 24 个对象的 4 个集合划分为 4 个集合,每个集合的基数为 6,这样任何两个集合的成对交集的基数最多为 2。您可以通过选择在集分区的 Hasse 图中相距最大的集分区,具有由细化给出的偏序。 The general case is much harder, but perhaps you can still begin with this crude approximation of a solution and then be clever with which vertex is assigned which object in the four assignments.一般情况要困难得多,但也许您仍然可以从解决方案的这种粗略近似开始,然后巧妙地在四个分配中分配哪个顶点 object。

Assuming you don't want to cycle all combinations and calculate the sum every time and choose the lowest, you can implement a minimum problem (solved depending on your constraints using either a linear programming solver ie symplex algorithm engines or a non-linear solver, much harder talking in terms of time) with constraints on your variables (24) depending on the shape of your path.假设您不想循环所有组合并每次都计算总和并选择最低的,您可以实现最小问题(根据您的约束使用线性规划求解器,即 symplex 算法引擎或非线性求解器来解决,在时间方面更难谈论)对变量的限制(24)取决于路径的形状。 You can also use free software like LINGO/LINDO to create rapidly a decision theory model and test its correctness (you need decision theory notions though)您还可以使用 LINGO/LINDO 等免费软件快速创建决策理论 model 并测试其正确性(尽管您需要决策理论概念)

If this has anything to do with the real world, then it's unlikely that you absolutely must have a solution that is the true minimum.如果这与现实世界有任何关系,那么您不太可能绝对必须有一个真正最低限度的解决方案。 Close to the minimum should be good enough, right?接近最小值应该足够了,对吧? If so, you could repeatedly randomly make the 4 assignments and check the results until you either run out of time or have a good-enough solution or appear to have stopped improving your best solution.如果是这样,您可以反复随机分配 4 个作业并检查结果,直到时间用完或有足够好的解决方案或似乎已停止改进您的最佳解决方案。

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

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