ParetoFront extends AbstractSet<T> { public ParetoFront<T> trim( final int size, final ElementComparator<? super T> comparator, final ElementDistance<? super T> distance, final ToIntFunction<? super T> dimension ) { requireNonNull(comparator); requireNonNull(distance); requireNonNull(dimension); if (size() > size) { final double[] distances = Pareto.crowdingDistance( Seq.viewOf(_population), comparator, distance, dimension ); final int[] indexes = ProxySorter.sort(distances); revert(indexes); final List<T> list = IntStream.of(indexes) .limit(size) .mapToObj(_population::get) .collect(Collectors.toList()); _population.clear(); _population.addAll(list); } return this; } ParetoFront(
		final Comparator<? super T> dominance,
		final BiPredicate<? super T, ? super T> equals
	);  ParetoFront(final Comparator<? super T> dominance); @Override boolean add(final T element); @Override boolean addAll(final Collection<? extends T> elements); ParetoFront<T> merge(final ParetoFront<? extends T> elements); ParetoFront<T> trim(
		final int size,
		final ElementComparator<? super T> comparator,
		final ElementDistance<? super T> distance,
		final ToIntFunction<? super T> dimension
	); @Override Iterator<T> iterator(); @Override int size(); @Override boolean isEmpty(); ISeq<T> toISeq(); static Collector<C, ?, ParetoFront<C>> toParetoFront(); static Collector<T, ?, ParetoFront<T>> toParetoFront(final Comparator<? super T> dominance);  }
@Test public void trim() { final Random random = new Random(); final ParetoFront<Vec<double[]>> set = new ParetoFront<>(Vec::dominance); final List<Vec<double[]>> elements = IntStream.range(0, 100_000) .mapToObj(i -> circle(random)) .collect(Collectors.toList()); set.addAll(elements); final Set<Vec<double[]>> front = new HashSet<>( Pareto.front(Seq.viewOf(elements)).asList() ); Assert.assertEquals(new HashSet<>(set), front); final int trimmedSize = set.size()/2; Assert.assertTrue(trimmedSize > 0); set.trim(trimmedSize, Vec::compare, Vec::distance, Vec::length); Assert.assertEquals(set.size(), trimmedSize); }