Пример #1
0
 private static void Verify(Parent2 parent)
 {
     Assert.AreEqual(1, parent.ID);
     Assert.AreEqual(2, parent.Children.Count);
     Assert.AreEqual(2, parent.Children[0].Value);
     Assert.AreEqual(3, parent.Children[1].Value);
     Assert.AreEqual(1, parent.Children[0].ParentID);
     Assert.AreEqual(1, parent.Children[1].ParentID);
 }
Пример #2
0
 internal void AddAncestors(HashSet <GraphNode> set)
 {
     if (Parent1 != null && !set.Contains(Parent1))
     {
         set.Add(Parent1);
         Parent1.AddAncestors(set);
     }
     if (Parent2 != null && !set.Contains(Parent2))
     {
         set.Add(Parent2);
         Parent2.AddAncestors(set);
     }
 }
Пример #3
0
        private void MenuItemDelete_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                UnRegisterEvents();

                Parent.RemoveChild(this);
                WfCanvas.RemoveChild(this);
                Parent2.RemoveChild(this);
            }
            catch (Exception ex)
            {
                logger.Error(ex);
            }
        }
Пример #4
0
    // Update is called once per frame
    void Update()
    {
        MousePosNow = Input.mousePosition;
        //鏃嬭浆zz
        if (Input.GetMouseButtonDown(0))
        {
            BaseY        = Parent1.localEulerAngles.y;
            BaseX        = Parent2.localEulerAngles.x;
            BaseMousePos = Input.mousePosition;
        }
        if (Input.GetMouseButton(0))
        {
            Parent1.localEulerAngles = new Vector3(0, Input.mousePosition.x - BaseMousePos.x + BaseY, 0);
            Parent2.localEulerAngles = new Vector3(BaseMousePos.y - Input.mousePosition.y + BaseX, 0, 0);
        }

        //鎺ㄦ媺zz
        if (Input.GetMouseButtonDown(1))
        {
            BaseMousePos2 = Input.mousePosition;
            BasePosZ      = ThisCamera.localPosition.z;
        }
        if (Input.GetMouseButton(1))
        {
            ThisCamera.localPosition = new Vector3(0, 0, -(Input.mousePosition.y - BaseMousePos2.y) / 100 + BasePosZ);
        }


        ///
        if (Input.GetMouseButtonDown(2))
        {
        }
        if (Input.GetMouseButton(2))
        {
            Parent2.Translate((MousePosNow.x - MousePosLast.x) / 1000 * ThisCamera.localPosition.z, 0, 0);
            Parent1.transform.position = Parent2.position;
            Parent2.localPosition      = Vector3.zero;
            Parent1.Translate(0, (MousePosNow.y - MousePosLast.y) / 1000 * ThisCamera.localPosition.z, 0);
        }
        //
        if (Input.GetKey(KeyCode.F))       //褰掗浂zz
        {
            Parent1.position         = Vector3.zero;
            ThisCamera.localPosition = new Vector3(0, 0, -5);
        }

        MousePosLast = Input.mousePosition;
    }
Пример #5
0
    // Use this for initialization
    void Awake()
    {
        ThisCamera = Camera.main.transform;
        ThisCamera.GetComponent <Camera>().fieldOfView = MaxFOV;
        TargetFOV    = MaxFOV;
        MousePosLast = Input.mousePosition;


        Target1 = GameObject.CreatePrimitive(PrimitiveType.Cube).transform;
        Target2 = GameObject.CreatePrimitive(PrimitiveType.Cube).transform;

        //鍒涘缓鍙傝€冪墿浣搝z
        Target1.position = Vector3.zero;
        Target2.position = Vector3.zero;
        Target1.GetComponent <Renderer>().enabled = false;
        Target2.GetComponent <Renderer>().enabled = false;
        Target1.GetComponent <Collider>().enabled = false;
        Target2.GetComponent <Collider>().enabled = false;
        Target2.parent = Target1;

        Target1.localEulerAngles = new Vector3(0, BaseLookAt, 0);
        Target2.localEulerAngles = new Vector3(BaseAngles, 0, 0);

        //鍒涘缓鎽勫奖鏈鸿繍鍔ㄧ粨鏋剒z
        Parent1          = GameObject.CreatePrimitive(PrimitiveType.Cube).transform;
        Parent2          = GameObject.CreatePrimitive(PrimitiveType.Cube).transform;
        Parent1.position = Vector3.zero;
        Parent2.position = Vector3.zero;
        Parent1.GetComponent <Renderer>().enabled = false;
        Parent2.GetComponent <Renderer>().enabled = false;
        Parent1.GetComponent <Collider>().enabled = false;
        Parent2.GetComponent <Collider>().enabled = false;

        Parent2.parent    = Parent1;
        ThisCamera.parent = Parent2;

        //Parent1.localEulerAngles=new Vector3(0,BaseLookAt,0);
        Parent2.localEulerAngles    = new Vector3(BaseAngles, 0, 0);
        ThisCamera.localPosition    = new Vector3(0, 0, 0);
        ThisCamera.localEulerAngles = Vector3.zero;

        //
        Target1.position = BasePositton.position;
        Parent1.position = BasePositton.position;
        LastPosition     = Vector3.zero;
    }
Пример #6
0
    // Use this for initialization
    void Start()
    {
        ThisCamera = Camera.main.transform;

        Parent1          = GameObject.CreatePrimitive(PrimitiveType.Cube).transform;
        Parent2          = GameObject.CreatePrimitive(PrimitiveType.Cube).transform;
        Parent1.position = Vector3.zero;
        Parent2.position = Vector3.zero;
        Parent1.GetComponent <Renderer>().enabled = false;
        Parent2.GetComponent <Renderer>().enabled = false;
        Parent1.GetComponent <Collider>().enabled = false;
        Parent2.GetComponent <Collider>().enabled = false;

        Parent2.parent    = Parent1;
        ThisCamera.parent = Parent2;

        Parent2.localEulerAngles    = new Vector3(45, 0, 0);
        ThisCamera.localPosition    = new Vector3(0, 0, -StartDistance);
        ThisCamera.localEulerAngles = Vector3.zero;

        MousePosLast = Input.mousePosition;
    }
Пример #7
0
			private static void Verify(Parent2 parent)
			{
				Assert.AreEqual(1, parent.ID);
				Assert.AreEqual(2, parent.Children.Count);
				Assert.AreEqual(2, parent.Children[0].Value);
				Assert.AreEqual(3, parent.Children[1].Value);
				Assert.AreEqual(1, parent.Children[0].ParentID);
				Assert.AreEqual(1, parent.Children[1].ParentID);
			}
Пример #8
0
    public static Genome CrossOver(Genome Parent1, Genome Parent2)
    {
        System.Random random = new System.Random();
        if (Parent1.GetAdjustedFitness() < Parent2.GetAdjustedFitness())
        {
            Genome temp = Parent1;
            Parent2 = Parent1;
            Parent1 = temp;
        }
        Genome child = new Genome();

        Dictionary <int, ConnectionGene> Parent1Genes = new Dictionary <int, ConnectionGene>();
        Dictionary <int, ConnectionGene> Parent2Genes = new Dictionary <int, ConnectionGene>();

        foreach (ConnectionGene connection in Parent1.GetConnectionGenes())
        {
            Parent1Genes.Add(connection.GetInnovation(), connection);
        }

        foreach (ConnectionGene connection in Parent2.GetConnectionGenes())
        {
            Parent2Genes.Add(connection.GetInnovation(), connection);
        }

        HashSet <int> Parent1Key = new HashSet <int>(Parent1Genes.Keys);
        HashSet <int> Parent2Key = new HashSet <int>(Parent2Genes.Keys);
        HashSet <int> AllKeys    = new HashSet <int>(Parent1Key);

        AllKeys.UnionWith(Parent2Key);

        foreach (int key in AllKeys)
        {
            ConnectionGene trait;
            if (Parent1Genes.ContainsKey(key) && Parent2Genes.ContainsKey(key))
            {
                if (random.NextDouble() > 0.5)
                {
                    trait = new ConnectionGene(Parent1Genes[key]);
                }
                else
                {
                    trait = new ConnectionGene(Parent2Genes[key]);
                }

                if (Parent1Genes[key].GetEnabled() != Parent2Genes[key].GetEnabled())
                {
                    //If the gene is enabled in one genome but disabled in another there is a 75% chance we take it from the better genome
                    if (random.NextDouble() < 0.75)
                    {
                        trait.SetEnabled(Parent1Genes[key].GetEnabled());
                    }
                    else
                    {
                        trait.SetEnabled(Parent2Genes[key].GetEnabled());
                    }
                }
                else
                {
                    if (Parent1.GetAdjustedFitness() == Parent2.GetAdjustedFitness())
                    {
                        if (Parent1Genes.ContainsKey(key))
                        {
                            trait = Parent1Genes[key];
                        }
                        else
                        {
                            trait = Parent2Genes[key];
                        }

                        //Only want to take half of the excess/Disjoint genes
                        if (random.NextDouble() > 0.5)
                        {
                            continue;
                        }
                    }
                }

                child.GetConnectionGenes().Add(trait);
            }
        }


        //NODES
        foreach (ConnectionGene con in child.GetConnectionGenes())
        {
            if (!child.GetNodeGenes().ContainsKey(con.GetInputNode()))
            {
                child.GetNodeGenes().Add(con.GetInputNode(), new NodeGene(con.GetInputNode(), NodeGene.TYPE.HIDDEN, 0));
            }
            if (!child.GetNodeGenes().ContainsKey(con.GetOutputNode()))
            {
                child.GetNodeGenes().Add(con.GetOutputNode(), new NodeGene(con.GetOutputNode(), NodeGene.TYPE.HIDDEN, 0));
            }
            child.GetNodeGenes()[con.GetOutputNode()].AddIncomingConnection(con);
        }



        return(child);
    }