算法EX pressing重新排序,作为对象移动的最小数量 [英] Algorithm for expressing reordering, as minimum number of object moves

查看:189
本文介绍了算法EX pressing重新排序,作为对象移动的最小数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题出现在对象数组(有序集合)的同步。

This problem arises in synchronization of arrays (ordered sets) of objects.

具体地讲,考虑物品的阵列,同步到另一台计算机。当用户移动一个或多个对象,从而重新排序阵列,在我背后。当我的程序醒来,我看到了新的订单,我知道旧秩序。我必须更改传输到另一台计算机,再现新订单出现。这里有一个例子:

Specifically, consider an array of items, synchronized to another computer. The user moves one or more objects, thus reordering the array, behind my back. When my program wakes up, I see the new order, and I know the old order. I must transmit the changes to the other computer, reproducing the new order there. Here's an example:

index         0    1    2
old order     A    B    C
new order     C    A    B

定义的移动的作为给定对象移动到一个给定的新指标。问题是要离preSS的重排序通过发送的的移动的两端的通信链路,以使得最小数量的另一端可以推断的其余通过采取动作在旧秩序,将它们转移到的尚未使用的索引,在新秩序,从最低的指数涨不动的物体。传输的这种方法将是在一个小数量的对象被大阵内移动的情况下非常有效的,移位大量对象的

Define a move as moving a given object to a given new index. The problem is to express the reordering by transmitting a minimum number of moves across a communication link, such that the other end can infer the remaining moves by taking the unmoved objects in the old order and moving them into as-yet unused indexes in the new order, starting with the lowest index and going up. This method of transmission would be very efficient in cases where a small number of objects are moved within a large array, displacing a large number of objects.

坚持下去。让我们继续该示例。我们有

Hang on. Let's continue the example. We have

CANDIDATE 1
Move A to index 1
Move B to index 2
Infer moving C to index 0  (the only place it can go)

请注意,前两个的移动的需要被发送。如果我们不传输的 b移动到索引2 的,B将被推断为指数0,我们将结束与BAC,这是不对的。我们需要传输两个动作。让我们来看看,如果我们可以做的更好......

Note that the first two moves are required to be transmitted. If we don't transmit Move B to index 2, B will be inferred to index 0, and we'll end up with B A C, which is wrong. We need to transmit two moves. Let's see if we can do better…

CANDIDATE 2
Move C to index 0
Infer moving A to index 1  (the first available index)
Infer moving B to index 2  (the next available index)

在这种情况下,我们得到正确的答案,CAB,只传送一招,移动C至索引0 的。候选人2因此比候选1.有四种以上的候选人更好,但因为很明显,至少有一招是需要做什么,我们现在可以停止,并宣布候选人2是赢家。

In this case, we get the correct answer, C A B, transmitting only one move, Move C to index 0. Candidate 2 is therefore better than Candidate 1. There are four more candidates, but since it's obvious that at least one move is needed to do anything, we can stop now and declare Candidate 2 to be the winner.

我想我可以用蛮力做到这一点强行尝试所有可能的人选,但对于N个项的数组有N个! (N阶乘)可能的候选人,即使我足够聪明,截断不必要的搜索在这个例子中,事情可能仍然得到pretty的昂贵的一个典型的阵列可以包含上百个对象。

I think I can do this by brute forcibly trying all possible candidates, but for an array of N items there are N! (N factorial) possible candidates, and even if I am smart enough to truncate unnecessary searches as in the example, things might still get pretty costly in a typical array which may contain hundreds of objects.

只是传输整个订单的解决方案是不能接受的,因为,为了兼容,我需要效仿其他程序的传输。

The solution of just transmitting the whole order is not acceptable, because, for compatibility, I need to emulate the transmissions of another program.

如果有人可以只写下来,答案将是巨大的,但建议的去读计算机科学的第n章教材XXX 的将是完全可以接受的。我不知道那些书,因为,我,哎,的只有的电气工程师。

If someone could just write down the answer that would be great, but advice to go read Chapter N of computer science textbook XXX would be quite acceptable. I don't know those books because, I'm, hey, only an electrical engineer.

谢谢!

杰里Krinock

推荐答案

我认为这个问题可以还原为最长公共子问题,只要找到这个共同的序列和发送那些不属于它的移动。有没有证明最优的,只是我的直觉,所以我可能是错的。即使我错了,这可能是一个很好的起点,一些花哨的算法。

I think that the problem is reducible to Longest common subsequence problem, just find this common subsequence and transmit the moves that are not belonging to it. There is no prove of optimality, just my intuition, so I might be wrong. Even if I'm wrong, that may be a good starting point to some more fancy algorithm.

这篇关于算法EX pressing重新排序,作为对象移动的最小数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆