C# 遗传交叉问题的求解算法
我有一个对象列表,如:C# 遗传交叉问题的求解算法,c#,algorithm,bioinformatics,C#,Algorithm,Bioinformatics,我有一个对象列表,如: class PairingStrand { int startInt; // the start pos int endInt; // the end pos int Index; // the index of pairing int Strand; // Strand is either "5" or "3" } 每个位置(整数)只能与一个对象关联 具有Strand=5的对象与具有相同“索引”和Strand=3的对象配对 列表按
class PairingStrand
{
int startInt; // the start pos
int endInt; // the end pos
int Index; // the index of pairing
int Strand; // Strand is either "5" or "3"
}
每个位置(整数)只能与一个对象关联
具有Strand=5
的对象与具有相同“索引”和Strand=3
的对象配对
列表按每个对象的“起始色调”排序。因此,不同的配对区域可以相互交叉
交叉”指两个区域重叠,但如果一个区域足够大,足以完全吞没另一个区域,则不视为“交叉”。
例如
{10~15 : 40~45} (startInt ~ endInt : startInd ~ endInx)
与…交叉
{20~30 : 60~70}
{20~25: 30~35}
但是,
{10~15 : 40~45}
不被视为与
{20~30 : 60~70}
{20~25: 30~35}
我的问题是如何识别与列表中任何其他块都没有交叉的最大块。允许在块内交叉。(换言之,“交叉”是允许的,但在区块内不需要,而区块之间不允许)
也许我没有很清楚地描述这个问题。下面是一个简单的例子:
名单如下:
obj1 (10~20, index 1, strand 5)
obj2 (25~30, index 2, strand 5)
obj3 (31~32, index 4, strand 5)
obj4 (33~34, index 4, strand 3)
obj5 (35~45, index 1, strand 3)
obj6 (50~55, index 2, strand3)
obj7 (60~80, index 3, strand 5)
obj8 (90~110, index 3, strand 3)
处理后,函数应返回由(obj1~obj6)
组成的块
提前感谢。伪代码:
Dictionary<Index, Pairing> openPairings;
List<Index> possibilities;
foreach(pairing)
{
if(openPairings.ContainsKey(pairing.Index))
{
// This is the closing of the pair
// When there are no other open strands at the time of closing,
// AND the pairing was in the possibilities list, it could be the largest
if(possibilities.Contains(pairing.Index))
{
// The opening entry: openPairings[pairing.Index]
// The closing pairing: pairing
// Do your size check here to find the largest
}
openPairings.Remove(pairing.Index);
}
else
{
// This is the opening of the pair
// There must be no other open pairings or there will be an overlap OR
// the outer pairing is larger anyway, as it completely engulfs this pairing
if(openPairings.IsEmpty)
possibilities.Add(pairing.Index);
openPairings.Add(pairing.Index, pairing);
}
}
字典openpairing;
列出可能性;
foreach(配对)
{
if(openPairings.ContainsKey(pairing.Index))
{
//这是这一对的结束
//当闭合时没有其他开口股时,
//而这对组合在可能性列表中,它可能是最大的
if(可能性.包含(配对.索引))
{
//开场白:openPairings[pairing.Index]
//结对:结对
//请在此查看您的尺码,以找到最大的尺码
}
openPairings.Remove(pairing.Index);
}
其他的
{
//这是这一对的开场白
//不得有其他开放配对,否则将有重叠或重叠
//不管怎么说,外部配对更大,因为它完全吞没了这个配对
if(openPairings.IsEmpty)
可能性。添加(配对。索引);
openPairings.Add(pairing.Index,pairing);
}
}
我对这类事情不了解,但这是一个遗传算法问题吗?是的,这是一个解决遗传问题的算法。遗传算法是另一回事。你能更详细地解释一下“交叉”对你意味着什么吗?因为你的例子对我来说毫无意义。一点也不。你是说在街区内需要交叉线吗?否则,我不明白为什么答案不总是完整的列表,因为它是最大的块,不重叠它之外的任何东西。