예제 #1
0
int ReplacementIndividual(GainType Cost) {
    int i, j, d, *P;
    int MinDist = INT_MAX, CMin = PopulationSize - 1;
    Node *N = FirstNode;
    while ((N = N->OldSuc = N->Suc) != FirstNode);
    for (i = PopulationSize - 1; i >= 0 && Fitness[i] > Cost; i--) {
        if ((d = DistanceToIndividual(i)) < MinDist) {
            CMin = i;
            MinDist = d;
        }
    }
    if (CMin == PopulationSize - 1)
        return CMin;
    P = Population[CMin];
    for (j = 0; j < Dimension; j++)
        NodeSet[P[j]].OldSuc = &NodeSet[P[j + 1]];
    for (i = 0; i < PopulationSize; i++)
        if (i != CMin && (d = DistanceToIndividual(i)) < MinDist)
            return PopulationSize - 1;
    return CMin;
}
예제 #2
0
int ReplacementIndividual(GainType Cost,LKH::LKHAlg *Alg) {
    int i, j, d, *P;
    int MinDist = INT_MAX, CMin = *PopulationSize - 1;
    LKH::LKHAlg::Node *N = Alg->FirstNode;
    while ((N = N->OldSuc = N->Suc) != Alg->FirstNode);
    for (i = *PopulationSize - 1; i >= 0 && Fitness.get()[i] > Cost; i--) {
		if ((d = DistanceToIndividual(i,Alg)) < MinDist) {
            CMin = i;
            MinDist = d;
        }
    }
    if (CMin == *PopulationSize - 1)
        return CMin;
    P = Population.get()[CMin];
    for (j = 0; j < Alg->Dimension; j++)
        Alg->NodeSet[P[j]].OldSuc = &Alg->NodeSet[P[j + 1]];
    for (i = 0; i < *PopulationSize; i++)
		if (i != CMin && (d = DistanceToIndividual(i,Alg)) < MinDist)
            return *PopulationSize - 1;
    return CMin;
}