public void Fix(Mutator mutator) { foreach (Configuration config in _configurations) { if (mutator.Rand(20) == 0) { config.Fix(mutator); } } }
public void Fix(Mutator mutator) { int weight = SumWeight(); while (weight > _knapsack.Capacity) { int idx = mutator.Rand(_presence.Length); int dir = mutator.Rand(2); int found = -1; if (dir == 0) { for (int i = idx; i < _presence.Length; i++) { if (_presence[idx]) { found = idx; break; } } } else { for (int i = idx; i >= 0; i--) { if (_presence[idx]) { found = idx; break; } } } if (found >= 0) { _presence[found] = false; weight -= _knapsack.ItemValues[found * 2]; } } }