简体   繁体   English

如何将一个图分为两个图(类)? (编辑)

[英]How can I divide a graph into two graphs (classes)? (edited)

Basically I want to split the big graph into two (or three, depending on the size of the classes) smaller graphes of (nearly) equal size. 基本上,我想将大图分为(几乎)相等大小的两个(或三个,取决于类的大小)较小的图。 And each node should still have at least one edge. 并且每个节点仍应至少具有一个边缘。

So I made a graph in neo4j with the nodes and edges. 因此,我在neo4j中制作了一个带有节点和边的图形。 But now I have no idea how to continue. 但是现在我不知道如何继续。

"Real-World-Problem": “现实世界中的问题”:
A friend of mine (teacher in primary school) came to me with a problem. 我的一个朋友(小学老师)遇到问题。 When the children come from kindergarten into primary school, they can wish for three other childs they want to have in their class. 当孩子们从幼儿园进入小学时,他们可以希望再有三个孩子要上课。 And the teachers try to get them in one class with at least one of the three. 然后,教师尝试使他们至少与三者中的一者一起上一堂课。

This is my graph so far: 到目前为止,这是我的图表:

CREATE (Luke:Person { name: "Luke"}),
(Jan:Person { name: "Jan"}),
(Tim:Person { name: "Tim"}),
(Finn:Person { name: "Finn"}),
(Leon:Person { name: "Leon"}),
(Niklas:Person { name: "Niklas"}),
(Tom:Person { name: "Tom"}),
(Jonas:Person { name: "Jonas"}),
(Yannic:Person { name: "Yannic"}),
(Luca:Person { name: "Luca"}),
(Leia:Person { name: "Leia"}),
(Anna:Person { name: "Anna"}),
(Sarah:Person { name: "Sarah"}),
(Hannah:Person { name: "Hannah"}),
(Michelle:Person { name: "Michelle"}),
(Laura:Person { name: "Laura"}),
(Lisa:Person { name: "Lisa"}),
(Lara:Person { name: "Lara"}),
(Lena:Person { name: "Lena"}),
(Julia:Person { name: "Julia"}),
(Luke)-[:PRIORITY {rating: 1}]->(Leia),
(Jan)-[:PRIORITY {rating: 1}]->(Tim),
(Tim)-[:PRIORITY {rating: 1}]->(Lara),
(Finn)-[:PRIORITY {rating: 1}]->(Luke),
(Leon)-[:PRIORITY {rating: 1}]->(Luca),
(Niklas)-[:PRIORITY {rating: 1}]->(Lisa),
(Tom)-[:PRIORITY {rating: 1}]->(Michelle),
(Jonas)-[:PRIORITY {rating: 1}]->(Finn),
(Yannic)-[:PRIORITY {rating: 1}]->(Tim),
(Luca)-[:PRIORITY {rating: 1}]->(Jonas),
(Leia)-[:PRIORITY {rating: 1}]->(Laura),
(Anna)-[:PRIORITY {rating: 1}]->(Tom),
(Sarah)-[:PRIORITY {rating: 1}]->(Leon),
(Hannah)-[:PRIORITY {rating: 1}]->(Niklas),
(Michelle)-[:PRIORITY {rating: 1}]->(Lena),
(Laura)-[:PRIORITY {rating: 1}]->(Leia),
(Lisa)-[:PRIORITY {rating: 1}]->(Lara),
(Lara)-[:PRIORITY {rating: 1}]->(Lisa),
(Lena)-[:PRIORITY {rating: 1}]->(Sarah),
(Julia)-[:PRIORITY {rating: 1}]->(Jonas),
(Luke)-[:PRIORITY {rating: 2}]->(Niklas),
(Jan)-[:PRIORITY {rating: 2}]->(Jonas),
(Tim)-[:PRIORITY {rating: 2}]->(Luca),
(Finn)-[:PRIORITY {rating: 2}]->(Leon),
(Leon)-[:PRIORITY {rating: 2}]->(Luke),
(Niklas)-[:PRIORITY {rating: 2}]->(Anna),
(Tom)-[:PRIORITY {rating: 2}]->(Yannic),
(Jonas)-[:PRIORITY {rating: 2}]->(Michelle),
(Yannic)-[:PRIORITY {rating: 2}]->(Hannah),
(Luca)-[:PRIORITY {rating: 2}]->(Luke),
(Leia)-[:PRIORITY {rating: 2}]->(Jan),
(Anna)-[:PRIORITY {rating: 2}]->(Lisa),
(Sarah)-[:PRIORITY {rating: 2}]->(Tim),
(Hannah)-[:PRIORITY {rating: 2}]->(Finn),
(Michelle)-[:PRIORITY {rating: 2}]->(Leon),
(Laura)-[:PRIORITY {rating: 2}]->(Tom),
(Lisa)-[:PRIORITY {rating: 2}]->(Tom),
(Lara)-[:PRIORITY {rating: 2}]->(Tim),
(Lena)-[:PRIORITY {rating: 2}]->(Yannic),
(Julia)-[:PRIORITY {rating: 2}]->(Sarah),
(Luke)-[:PRIORITY {rating: 3}]->(Michelle),
(Jan)-[:PRIORITY {rating: 3}]->(Luca),
(Tim)-[:PRIORITY {rating: 3}]->(Tom),
(Finn)-[:PRIORITY {rating: 3}]->(Lara),
(Leon)-[:PRIORITY {rating: 3}]->(Anna),
(Niklas)-[:PRIORITY {rating: 3}]->(Lara),
(Tom)-[:PRIORITY {rating: 3}]->(Lena),
(Jonas)-[:PRIORITY {rating: 3}]->(Luke),
(Yannic)-[:PRIORITY {rating: 3}]->(Leia),
(Luca)-[:PRIORITY {rating: 3}]->(Lisa),
(Leia)-[:PRIORITY {rating: 3}]->(Yannic),
(Anna)-[:PRIORITY {rating: 3}]->(Hannah),
(Sarah)-[:PRIORITY {rating: 3}]->(Lena),
(Hannah)-[:PRIORITY {rating: 3}]->(Julia),
(Michelle)-[:PRIORITY {rating: 3}]->(Luke),
(Laura)-[:PRIORITY {rating: 3}]->(Jan),
(Lisa)-[:PRIORITY {rating: 3}]->(Tim),
(Lara)-[:PRIORITY {rating: 3}]->(Finn),
(Lena)-[:PRIORITY {rating: 3}]->(Leon),
(Julia)-[:PRIORITY {rating: 3}]->(Niklas)

Without being able to give an exact reason why, I think your problem is in NP (comments on this is very welcome). 无法给出确切的原因,我认为您的问题在于NP(对此表示欢迎)。 I don't have a finished solution to offer, at least not for an optimal solution (also, knowing what the optimal solution is would require the problem to be a bit more specified. Like, do we aim for the children getting their highest possible priority satisfied? Or for getting the highest amount of ratings satisfied?). 我没有完整的解决方案,至少不能提供最佳解决方案(另外,知道最佳解决方案将需要对问题进行更具体的说明。例如,我们的目标是使孩子们尽可能获得最大的成就吗?是否满足优先级?还是为了获得最高的评分?)。 But I have an idea that might be useful. 但是我有一个可能有用的想法。

As I read your problem statement the graph is directed and after dividing the graph into smaller components, all nodes should have at least one outgoing edge to another node within the same component (as opposed to just any edge, as all children should be in a class with someone they chose and not just with someone who chose them). 当我阅读您的问题陈述时,该图是有向图的,并且在将图划分为较小的组件之后,所有节点都应至少具有到同一组件内另一节点的一个出站边缘(而不是任何边缘,因为所有子项都应位于一个与他们选择的人一起上课,而不仅仅是与选择他们的人一起上课)。

My idea is the following: Start by testing whether your graph is connected (weakly should be enough) and if so, then find 2 small cycles in the graph (or three if you want to divide the children into three classes) and make the nodes associated with these into the two "classes." 我的想法如下:首先测试图是否已连接(弱应该足够),如果可以,则在图中找到2个小循环(如果要将子级划分为三个类,则为3个小循环),并创建节点与这些相关联成两个“类”。 Keep track of all edges going into these two classes. 跟踪进入这两个类的所有边缘。 For the smallest class, find an ingoing edge that comes from a node that is not yet associated with a class and add it to the class. 对于最小的类,找到来自尚未与类关联的节点的入边,并将其添加到类中。 Keep doing this until they have the same size, and then you can alternate between adding a node to each of the classes until one of them has no more incomming edges from nodes not associated with a class. 继续执行此操作,直到它们具有相同的大小为止,然后可以在向每个类中添加节点之间进行切换,直到其中一个不再具有与类无关的节点的传入边缘为止。 The rest of the nodes are then added to the other class. 然后将其余节点添加到另一个类中。

If your graph is not connected you will have to take this into account, but any connected component that is smaller than the desired class-size will consist of children that gets all their priorities satisfied and could therefore just be added to one of the small cycles you start from before you start adding other nodes. 如果您的图形未连接,则必须考虑到这一点,但是任何小于所需类大小的连接组件都将包含满足所有优先级的子级,因此可以将其添加到一个小周期中从开始添加其他节点开始。 A connected component that is bigger than the maximal class size (if such a limit exists) will probably need some extra calculations in order to find out who to remove without causing the constraints to be violated. 大于最大类大小(如果存在这样的限制)的连接组件可能需要进行一些额外的计算,以便找出要删除的对象而不会导致违反约束的情况。

As mentioned this is neither optimal nor a finished solution, but assuming that all children made at least one wish, this should place every child in a class, and if all children made all three wishes, my intuition says that there should be a fair chance that the classes are more or less evenly sized. 如前所述,这既不是最佳解决方案,也不是最终的解决方案,但是假设所有孩子都至少希望一个,这应该将每个孩子都放在一个班级中;如果所有孩子都希望全部三个愿望,我的直觉就是应该有一个公平的机会类的大小或多或少均匀。 If not, running the code from a few different choices of start-cycles could give some alternate solutions from which to choose. 如果没有,从几个不同的启动周期选择中运行代码可能会提供一些可供选择的解决方案。

Hope that this can get you started. 希望这可以帮助您入门。

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

相关问题 两个图的图同构 - Graph isomorphism of two graphs 将图表分为两组 - Divide a graph into two sets 如何在一页上显示两个或两个以上带有笔画的图表? - How can i show two or more graphs with dygraphs on one page? 如何重新创建这些图? - how can I recreate these graphs? 如何从 Networkx 或 DyNetx 上的图形列表生成动态图形 - How can I generate a dynamic graph from a list of graphs on Networkx or DyNetx 我可以在带有python的Yed-Graphs上使用图形算法吗? - Can i use a Graph-Algorithm on Yed-Graphs with python? 如何将图分为两组最大连接? - How to divide a graph into two sets having maximum interset connection? 如何使用邻接表/集合实现图形。 它对有向图如何起作用? 无向图? 加权图? - how a graph can be implemented using adjacency lists/sets. How does it work for directed graphs? Undirected graphs? Weighted graphs? 我正在尝试使用Android Plot在Android Activity中显示图形,如何在图形中显示数据? - I am trying to use Android Plot to display graphs in Android Activity, how can I display my data in the graph? 如何在igraph中比较两个图的顶点并将第一个图的社区成员分配给第二个图? - How to compare vertices of two graphs and assign community membership of the first graph to the second graph, in igraph?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM