/*
 * Java Genetic Algorithm Library (@__identifier__@).
 * Copyright (c) @__year__@ Franz Wilhelmstötter
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * Author:
 *    Franz Wilhelmstötter (franz.wilhelmstoetter@gmail.com)
 */
package io.jenetics.incubator.grammar;

import java.util.List;

import io.jenetics.incubator.grammar.Cfg.Terminal;

public class ConvergingSentenceGenerator implements SentenceGenerator {

	@Override
	public List<Terminal> generate(final Cfg cfg) {
		return null;
	}

}

@@ -784,16 +784,23 @@
 %0Aimport 
+static 
 java.uti
@@ -805,217 +805,1020 @@
 til.
-List;%0A%0Aimport io.jenetics.incubator.grammar.Cfg.Terminal;%0A%0Apublic class ConvergingSentenceGenerator implements SentenceGenerator %7B%0A%0A%09@Override%0A%09public List%3CTerminal%3E generate(final Cfg cfg) %7B%0A%09%09return null
+Objects.requireNonNull;%0A%0Aimport java.util.HashMap;%0Aimport java.util.Map;%0A%0Aimport io.jenetics.incubator.grammar.Cfg.Rule;%0A%0Apublic class FairSymbolIndex implements SymbolIndex %7B%0A%0A%09private static final class Counts %7B%0A%09%09private final int%5B%5D _counts;%0A%0A%09%09private int _count = 0;%0A%0A%09%09private Counts(final int size) %7B%0A%09%09%09_counts = new int%5Bsize%5D;%0A%09%09%7D%0A%0A%09%09int update(final int index) %7B%0A%09%09%09final int max = Math.max(_count/_counts.length*3, 3);%0A%0A%09%09%09if (_counts%5Bindex%5D %3C= max) %7B%0A%09%09%09%09++_count;%0A%09%09%09%09++_counts%5Bindex%5D;%0A%0A%09%09%09%09return index;%0A%09%09%09%7D else %7B%0A%09%09%09%09//System.out.println(max + %22:%22 + _counts%5Bindex%5D + %22:%22 + index);%0A%09%09%09%09return update((index + 1)%25_counts.length);%0A%09%09%09%7D%0A%09%09%7D%0A%09%7D%0A%0A%09private final SymbolIndex _index;%0A%09private final Map%3CRule, Counts%3E _counts = new HashMap%3C%3E();%0A%0A%09public FairSymbolIndex(final SymbolIndex index) %7B%0A%09%09_index = requireNonNull(index);%0A%09%7D%0A%0A%09@Override%0A%09public int next(final Rule rule) %7B%0A%09%09return _counts%0A%09%09%09.computeIfAbsent(rule, key -%3E new Counts(rule.alternatives().size()))%0A%09%09%09.update(_index.next(rule))
 ;%0A%09%7D%0A
-%0A
 %7D%0A

Implement 'fair' SymbolIndex.