private static void enforceDensity(double density,
			IntArrayInputVector mutatedVector) {
		// Find set positions.
		IntList filledPositions = new IntArrayList();
		int[] components = mutatedVector.values;
		for (int i = 0; i < components.length; i++) {
			if (components[i] == 0) {
				filledPositions.add(i);
			}
		}
		
		// If necessary, randomly unset components to approximate desired density.
		double neededComponentsRate = density * components.length / filledPositions.size(); 
		if (neededComponentsRate < 1) {
			Random random = new Random();
			IntIterator iterator = filledPositions.iterator();
			while (iterator.hasNext()) {
				int index = iterator.nextInt();
				if (random.nextDouble() > neededComponentsRate) {
					components[index] = 0;
				}
			}
		}
	}