Tree.RootNode VectorToTree(double[] vector) { var tree = Original.CloneTree(); int i = 0; foreach (var c in GetActiveConstants(tree)) { c.Value = vector[i]; i++; } return(tree); }
/// <summary> /// 自分自身を他個体と交叉させる /// </summary> /// <param name="another"></param> /// <returns>交叉が行えなかったらfalse</returns> public bool CrossOver(RootNode another, Random rand) { another = another.CloneTree(); var target = GetRandomChildWithoutConstant(rand, false); var type = target.NodeType & SynthTree.NodeType.Mask; var candidate = another.ToBreadthFirstList() .Where(x => (type & x.NodeType) == type).ToArray(); if (!candidate.Any()) { return(false); } var t2 = candidate[rand.Next(candidate.Length)]; var t2p = t2.Parent; target.Parent.ChangeChild(target, t2); t2p.ChangeChild(t2, target); SetIndex(); return(true); }
/// <summary> /// 1個体をオリジナルに変異体で構成する /// </summary> /// <param name="p"></param> public void Init(Tree.RootNode p) { items[0] = new Individual(p, true); UpdateInner(() => p.CloneTree().Mutate(rand), new[] { 0 }); }