ProgramChromosome extends AbstractTreeChromosome<Op<A>, ProgramGene<A>> implements Function<A[], A> { public static <A> ProgramChromosome<A> of( final Tree<? extends Op<A>, ?> program, final Predicate<? super ProgramChromosome<A>> validator, final ISeq<? extends Op<A>> operations, final ISeq<? extends Op<A>> terminals ) { Program.check(program); checkOperations(operations); checkTerminals(terminals); return create(program, validator, operations, terminals); } protected  ProgramChromosome(
		final ISeq<ProgramGene<A>> program,
		final Predicate<? super ProgramChromosome<A>> validator,
		final ISeq<? extends Op<A>> operations,
		final ISeq<? extends Op<A>> terminals
	); ISeq<Op<A>> operations(); ISeq<Op<A>> terminals(); @Override boolean isValid(); @Override A apply(final A[] args); @SafeVarargs final A eval(final A... args); @Override ProgramChromosome<A> newInstance(final ISeq<ProgramGene<A>> genes); @Override ProgramChromosome<A> newInstance(); static ProgramChromosome<A> of(
		final Tree<? extends Op<A>, ?> program,
		final Predicate<? super ProgramChromosome<A>> validator,
		final ISeq<? extends Op<A>> operations,
		final ISeq<? extends Op<A>> terminals
	); static ProgramChromosome<A> of(
		final Tree<? extends Op<A>, ?> program,
		final ISeq<? extends Op<A>> operations,
		final ISeq<? extends Op<A>> terminals
	); static ProgramChromosome<A> of(
		final int depth,
		final Predicate<? super ProgramChromosome<A>> validator,
		final ISeq<? extends Op<A>> operations,
		final ISeq<? extends Op<A>> terminals
	); static ProgramChromosome<A> of(
		final int depth,
		final ISeq<? extends Op<A>> operations,
		final ISeq<? extends Op<A>> terminals
	); static ProgramChromosome<A> of(
		final ISeq<ProgramGene<A>> genes,
		final Predicate<? super ProgramChromosome<A>> validator,
		final ISeq<? extends Op<A>> operations,
		final ISeq<? extends Op<A>> terminals
	); static ProgramChromosome<A> of(
		final ISeq<ProgramGene<A>> genes,
		final ISeq<? extends Op<A>> operations,
		final ISeq<? extends Op<A>> terminals
	);  }
@Test(dataProvider = "programDepths") public void programDepth(final int depth) { final TreeNode<Op<Double>> tree = Program.of( depth, OPERATIONS, TERMINALS ); Assert.assertEquals(tree.depth(), depth); }
@Test(invocationCount = 10) public void createFromTree() { final TreeNode<Op<Double>> tree = Program.of( 6, OPERATIONS, TERMINALS ); final ProgramChromosome<Double> chromosome = ProgramChromosome .of(tree, OPERATIONS, TERMINALS); Assert.assertTrue(Tree.equals(tree, chromosome.root())); }
@Test(invocationCount = 10) public void createFromSeq() { final TreeNode<Op<Double>> tree = Program.of( 6, OPERATIONS, TERMINALS ); final ProgramChromosome<Double> ch1 = ProgramChromosome.of(tree, OPERATIONS, TERMINALS); final ISeq<ProgramGene<Double>> genes = ISeq.of(ch1); final ProgramChromosome<Double> ch2 = ProgramChromosome.of(genes, OPERATIONS, TERMINALS); Assert.assertEquals(ch2, ch1); }
@Test public void createTreeFromChromosome() { final TreeNode<Op<Double>> tree = Program.of( 6, OPERATIONS, TERMINALS ); final ProgramChromosome<Double> ch = ProgramChromosome.of(tree, OPERATIONS, TERMINALS); final TreeNode<Op<Double>> node = TreeNode.ofTree(ch.gene()); System.out.println(node); }
@Test public void sameRootAndFirstGene() { final ProgramChromosome<Double> ch = ProgramChromosome.of( 3, OPERATIONS, TERMINALS ); Assert.assertSame(ch.root(), ch.gene()); }
@Test public void serialize() throws IOException { final TreeNode<Op<Double>> tree = Program.of( 6, OPERATIONS, TERMINALS ); final ProgramChromosome<Double> object = ProgramChromosome.of(tree, OPERATIONS, TERMINALS); final byte[] data = IO.object.toByteArray(object); Assert.assertEquals(IO.object.fromByteArray(data), object); }