【发布时间】:2015-10-24 05:07:36
【问题描述】:
我刚刚开始使用遗传编程,但在初始化我的群体时遇到了问题。
我需要一棵树来代表每个候选解决方案 - 问题是,我不熟悉树。
我需要两种初始化方式,即Grow(可变大小的树)和Full(平衡相同形状和大小的树)。
FULL GROW
(*) (*)
(+) (-) (5) (-)
(1)(2) (3)(4) (6) (7)
我已经初始化了我的 Tree 类,但是,我不知道如何从这里开始填充树(Full 或 Grow)。
public class Tree{
Object value;
Tree left, right;
public Tree(Object value)
{
this.value=value;
}
public Tree (Object value, Tree left, Tree right)
{
this.value = value;
this.left = left;
this.right = right;
}
// Getter & setter for the value.
public Object getValue(){
return value;}
public void setValue(Object value){
this.value = value;}
// Getters & setters for left & right nodes.
public Tree getLeft(){
return left;}
public Tree getRight(){
return right;}
public void setLeft(Tree ln){
left = ln;}
public void setRight(Tree rn){
right = rn;}
}
谁能告诉我如何做到这一点,或者只是朝着正确的方向轻推。
我正在尝试随机填充树直到预定义的深度。
- 运算符 (+ - / *) 插入除叶节点之外的所有位置。
- 操作数 (1-100) 仅插入叶节点上
谢谢。
【问题讨论】:
标签: java tree binary-tree genetic-algorithm genetic-programming