Codecs { public static InvertibleCodec<int[][], IntegerGene> ofMatrix( final IntRange domain, final int rows, final int cols ) { requireNonNull(domain); Requires.positive(rows); Requires.positive(cols); return InvertibleCodec.of( Genotype.of( IntegerChromosome.of(domain, cols).instances() .limit(rows) .collect(ISeq.toISeq()) ), gt -> gt.stream() .map(ch -> ch.stream() .mapToInt(IntegerGene::intValue) .toArray()) .toArray(int[][]::new), matrix -> Genotype.of( Stream.of(matrix) .map(row -> IntegerChromosome.of( IntStream.of(row) .mapToObj(v -> IntegerGene.of(v, domain)) .collect(ISeq.toISeq()) )) .collect(ISeq.toISeq()) ) ); } private  Codecs(); static InvertibleCodec<Integer, IntegerGene> ofScalar(final IntRange domain); static InvertibleCodec<Long, LongGene> ofScalar(final LongRange domain); static InvertibleCodec<Double, DoubleGene> ofScalar(final DoubleRange domain); static Codec<A, AnyGene<A>> ofScalar(
		final Supplier<? extends A> supplier,
		final Predicate<? super A> validator
	); static Codec<A, AnyGene<A>> ofScalar(
		final Supplier<? extends A> supplier
	); static InvertibleCodec<int[], IntegerGene> ofVector(
		final IntRange domain,
		final int length
	); static InvertibleCodec<long[], LongGene> ofVector(
		final LongRange domain,
		final int length
	); static InvertibleCodec<double[], DoubleGene> ofVector(
		final DoubleRange domain,
		final int length
	); static InvertibleCodec<int[], IntegerGene> ofVector(final IntRange... domains); static InvertibleCodec<long[], LongGene> ofVector(final LongRange... domains); static InvertibleCodec<double[], DoubleGene> ofVector(final DoubleRange... domains); static Codec<ISeq<A>, AnyGene<A>> ofVector(
		final Supplier<? extends A> supplier,
		final Predicate<? super A> alleleValidator,
		final Predicate<? super ISeq<A>> alleleSeqValidator,
		final int length
	); static Codec<ISeq<A>, AnyGene<A>> ofVector(
		final Supplier<? extends A> supplier,
		final Predicate<? super A> validator,
		final int length
	); static Codec<ISeq<A>, AnyGene<A>> ofVector(
		final Supplier<? extends A> supplier,
		final int length
	); static InvertibleCodec<int[], EnumGene<Integer>> ofPermutation(final int length); static InvertibleCodec<ISeq<T>, EnumGene<T>> ofPermutation(final ISeq<? extends T> alleles); static InvertibleCodec<int[][], IntegerGene> ofMatrix(
		final IntRange domain,
		final int rows,
		final int cols
	); static InvertibleCodec<long[][], LongGene> ofMatrix(
		final LongRange domain,
		final int rows,
		final int cols
	); static InvertibleCodec<double[][], DoubleGene> ofMatrix(
		final DoubleRange domain,
		final int rows,
		final int cols
	); static InvertibleCodec<M, EnumGene<Integer>> ofMapping(
		final ISeq<? extends A> source,
		final ISeq<? extends B> target,
		final Supplier<M> mapSupplier
	); static InvertibleCodec<Map<A, B>, EnumGene<Integer>> ofMapping(final ISeq<? extends A> source, final ISeq<? extends B> target); static InvertibleCodec<ISeq<T>, BitGene> ofSubSet(final ISeq<? extends T> basicSet); static InvertibleCodec<ISeq<T>, EnumGene<T>> ofSubSet(
		final ISeq<? extends T> basicSet,
		final int size
	);  }
@Test public void ofIntMatrix() { final int rows = 10; final int cols = 15; final Codec<int[][], IntegerGene> codec = Codecs.ofMatrix( IntRange.of(0, 1_000), rows, cols ); final Genotype<IntegerGene> gt = codec.encoding().newInstance(); final int[][] matrix = codec.decode(gt); assertEquals(matrix.length, rows); assertEquals(matrix[0].length, cols); for (int row = 0; row < rows; ++row) { for (int col = 0; col < cols; ++col) { assertEquals(matrix[row][col], gt.get(row).get(col).intValue()); } } }
@Test public void ofLongMatrix() { final int rows = 10; final int cols = 15; final Codec<long[][], LongGene> codec = Codecs.ofMatrix( LongRange.of(0, 1_000), rows, cols ); final Genotype<LongGene> gt = codec.encoding().newInstance(); final long[][] matrix = codec.decode(gt); assertEquals(matrix.length, rows); assertEquals(matrix[0].length, cols); for (int row = 0; row < rows; ++row) { for (int col = 0; col < cols; ++col) { assertEquals(matrix[row][col], gt.get(row).get(col).longValue()); } } }
@Test public void ofDoubleMatrix() { final int rows = 10; final int cols = 15; final Codec<double[][], DoubleGene> codec = Codecs.ofMatrix( DoubleRange.of(0, 1_000), rows, cols ); final Genotype<DoubleGene> gt = codec.encoding().newInstance(); final double[][] matrix = codec.decode(gt); assertEquals(matrix.length, rows); assertEquals(matrix[0].length, cols); for (int row = 0; row < rows; ++row) { for (int col = 0; col < cols; ++col) { assertEquals(matrix[row][col], gt.get(row).get(col).doubleValue()); } } }