Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'IntermediateCrossover' not terminating #718

Closed
jenetics opened this issue Jun 22, 2020 · 1 comment
Closed

'IntermediateCrossover' not terminating #718

jenetics opened this issue Jun 22, 2020 · 1 comment
Assignees
Labels
Milestone

Comments

@jenetics
Copy link
Owner

jenetics commented Jun 22, 2020

The IntermediateCrossover is not terminating if it tries to crossover two equal individuals with the maximal value.

@Override
protected int crossover(final MSeq<G> v, final MSeq<G> w) {
    final Random random = RandomRegistry.random();

    final double min = v.get(0).min().doubleValue();
    final double max = v.get(0).max().doubleValue();

    for (int i = 0, n = min(v.length(), w.length()); i < n; ++i) {
        final double vi = v.get(i).doubleValue();
        final double wi = w.get(i).doubleValue();

        double t, s;
        do {
            final double a = nextDouble(-_p, 1 + _p, random);
            final double b = nextDouble(-_p, 1 + _p, random);

            t = a*vi + (1 - a)*wi;
            s = b*wi + (1 - b)*vi;
            System.out.println(format(
                "min=%s, max=%s, vi=%s, wi=%s, t=%s, s=%s, a=%s, b=%s, p=%s",
                min, max, vi, wi, t, s, a, b, _p
            ));
        } while (t < min || s < min || t >= max || s >= max);

        v.set(i, v.get(i).newInstance(t));
        w.set(i, w.get(i).newInstance(s));
    }

    return 2;
}

With two equal individuals to crossover, the while-Loop will not terminate with maximal values.

min=0.0, max=100.0, vi=100.0, wi=100.0, t=100.0, s=100.0, a=0.060927758442538615, b=0.30894420728757566, p=0.0
min=0.0, max=100.0, vi=100.0, wi=100.0, t=100.0, s=100.0, a=0.9357120721578135, b=0.5412833594065434, p=0.0
min=0.0, max=100.0, vi=100.0, wi=100.0, t=100.0, s=100.0, a=0.7560184530335406, b=0.6390527838043711, p=0.0
min=0.0, max=100.0, vi=100.0, wi=100.0, t=100.0, s=100.0, a=0.7442361608972529, b=0.025760472728500128, p=0.0
min=0.0, max=100.0, vi=100.0, wi=100.0, t=100.0, s=100.0, a=0.8100080637707349, b=0.4297138951658802, p=0.0
min=0.0, max=100.0, vi=100.0, wi=100.0, t=100.0, s=100.0, a=0.02417624509603533, b=0.43765099704303234, p=0.0
min=0.0, max=100.0, vi=100.0, wi=100.0, t=100.0, s=100.0, a=0.11362305896001412, b=0.9704788776706555, p=0.0
min=0.0, max=100.0, vi=100.0, wi=100.0, t=100.0, s=100.0, a=0.480805088126826, b=0.3683165017056297, p=0.0
min=0.0, max=100.0, vi=100.0, wi=100.0, t=100.0, s=100.0, a=0.5278484685192272, b=0.36546356885717, p=0.0
min=0.0, max=100.0, vi=100.0, wi=100.0, t=100.0, s=100.0, a=0.20217221236223726, b=0.28337988416641846, p=0.0
min=0.0, max=100.0, vi=100.0, wi=100.0, t=100.0, s=100.0, a=0.9605925711966199, b=0.011420085223559528, p=0.0
min=0.0, max=100.0, vi=100.0, wi=100.0, t=100.0, s=100.0, a=0.9265911385512179, b=0.9814060743806482, p=0.0
...

Is related to #701

@jenetics jenetics self-assigned this Jun 22, 2020
@jenetics jenetics added the bug label Jun 22, 2020
@jenetics jenetics modified the milestones: v6.1.0, v6.0.1 Jun 22, 2020
jenetics added a commit that referenced this issue Jun 23, 2020
…e_crossover_non_terminating

#718: Non-terminating 'IntermediateCrossover'
@jenetics
Copy link
Owner Author

Merged into r6.0.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant