从这些集合的组合中重新创建集合
我遇到了一个特定的问题并正在寻找一些算法来解决它。要解决的问题如下所述。
假设我们有如下组合
1 - 3 - 5
1 - 4 - 5
1 - 8 - 5
2 - 4 - 5
3 - 4 - 5
2 - 4 - 7
这些组合是从给定的集合生成的,在这种特殊情况下让我们比如说
{1},{3,4,8},{5}
{2,3},{4},{5}
{2},{4},{7}
我想要做的是重新创建集合这些组合。我知道对于这些组合,您有多个解决方案,例如
第一个解决方案
{1}、{3, 4, 8}、{5}
{2, 3}、{4}、{5}
{2}、{4} 、{7}
第二个解决方案
{1}、{3, 8}、{5}
{1, 2, 3}、{4}、{5}
{2}、{4}、{7}
第三个解决方案
{1} , {3, 4, 8}, {5}
{3}, {4}, {5}
{2}, {4}, {5, 7}
但最终(最佳)解决方案将是具有尽可能少的解决方案尽可能设置一组或随机一组,以防它们在组数方面全部相等。
存在解决此类问题的算法吗?如果任何一直在处理此类问题的人能给我一些提示,我将不胜感激。
编辑:看起来我正在寻找的是n元乘积(N的笛卡尔乘积)的分解
编辑:在对该主题进行更多研究后,我发现该问题在“图论”中被称为“最小值”集团封面'问题
问候, 巴兹
I came across a specific problem and looking for some algorithm for it. The problem to solve is as described below.
Let's say we have combinations like below
1 - 3 - 5
1 - 4 - 5
1 - 8 - 5
2 - 4 - 5
3 - 4 - 5
2 - 4 - 7
These combinations were generated from given sets, in this particular case let's say from
{1},{3,4,8},{5}
{2,3},{4},{5}
{2},{4},{7}
What I want to do is recreate sets from these combinations. I know for these combinations you have more than one solution, e.g.
1st solution
{1}, {3, 4, 8}, {5}
{2, 3}, {4}, {5}
{2}, {4}, {7}
2nd solution
{1}, {3, 8}, {5}
{1, 2, 3}, {4}, {5}
{2}, {4}, {7}
3rd solution
{1}, {3, 4, 8}, {5}
{3}, {4}, {5}
{2}, {4}, {5, 7}
But the final (optimal) solution would be the one with as little sets as possible or the random one in case they are all equivalent in terms of sets count.
Do algorithms for such a problem exist? I appreciate if anybody who has been dealing with this kind of problem can give me some hints.
EDIT: looks like what I'm looking for is a decomposition of n-ary product (Cartesian product for N)
EDIT: after more research on the topic I found out that the problem is known in a 'graph theory' as the 'minimum clique cover' problem
regards,
baz
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这并不是一个真正的答案,而是一个扩展的评论。事实上,您的“压缩表示”根本不节省任何空间。
在您存储的未压缩表示中:
这可以存储在 1R+18S 中(其中 R 是存储规则所需的空间,S 是存储符号所需的空间)
在您假定的压缩表示中,您必须存储:
在您的第一个“压缩”表示中,我计算了 1R+12S+8D(其中 D 是存储一个分隔符所需的空间)。如果 S==D 则为 1R+20S——比未压缩的表示还要多。
在您的其他两个“压缩”表示中,我计数相同:1R+12S+8D 和 1R+12S+8D。
我还没有弄清楚这种非压缩是否是您提案的基本特征,还是您选择的示例的偶然特征。
你的意思是,当你写下这个的时候
,某些组合将具有 3 个元素,其他组合将具有 4 个元素,其他组合将具有 2 或 5 个元素等?
我建议你澄清你的问题。
编辑:@bazeusz:现在看来您正在寻找集合的笛卡尔积。
This is not really an answer, more an extended comment. Your 'compressed representations' do not, in fact save any space at all.
In the uncompressed representation you store:
This can be stored in 1R+18S (where R is the space required to store a rule, S the space required to store a symbol)
In your supposed-to-be compressed representations you have to store:
In your first 'compressed' representation I count 1R+12S+8D (where D is the space required for storing one delimiter). If S==D then this is 1R+20S -- more than your uncompressed representation.
In your other two 'compressed' representations I count the same: 1R+12S+8D, and 1R+12S+8D.
I haven't figured out whether this non-compression is an essential feature of your proposal, or an accidental feature of the example you have chosen.
Do you mean, when you write that
that some combinations will have 3 elements, others 4, others 2 or 5 etc ?
I suggest that you clarify your question.
EDIT: @bazeusz: now it seems that you are looking for the cartesian product of the sets.