コード例 #1
0
ファイル: GAIndividual.cs プロジェクト: arbihaza/topic1core
    public virtual GAIndividual mutate()
    {
        int[] child_picklist = new int[nvert];
        for (int i = 0; i < nvert; i++)
        {
            child_picklist[i] = picklist[i];
        }

        // mutate one point:
        int m_point = randg.Next(nvert - 1);         // mutation point

        child_picklist[m_point] = randg.Next(nvert - m_point);

        int[] tmp = GAUtils.picklist2perm(child_picklist);
        int[] l, r;

        if (nextBoolean() == true)
        {
            // this mutation preserves structure:
            if (nextBoolean() == true)
            {
                l = new int[left.Length];
                r = new int[right.Length];
            }
            else
            {
                l = new int[right.Length];
                r = new int[left.Length];
            }
        }
        else
        {
            // mutate structure:
            int dpoint = 1 + randg.Next(nvert - 1);             // tmp division point
            l = new int[dpoint];
            r = new int[nvert - dpoint];
        }

        for (int i = 0; i < l.Length; i++)
        {
            l[i] = tmp[i];
        }
        for (int i = 0; i < r.Length; i++)
        {
            r[i] = tmp[l.Length + i];
        }

        return(new GAIndividual(l, r));
    }
コード例 #2
0
ファイル: GAIndividual.cs プロジェクト: arbihaza/topic1core
    public static GAIndividual xover1p(GAIndividual f, GAIndividual m)
    {
        // 1-point cross over
        int xpoint = 1 + randg.Next(f.nvert - 1);

        int[] child_picklist = new int[f.nvert];
        for (int i = 0; i < xpoint; i++)
        {
            child_picklist[i] = f.picklist[i];
        }

        for (int i = xpoint; i < f.nvert; i++)
        {
            child_picklist[i] = m.picklist[i];
        }

        int[] tmp = GAUtils.picklist2perm(child_picklist);
        int[] l, r;

        if (nextBoolean() == true)
        {
            l = new int[f.left.Length]; // WHY?
            r = new int[tmp.Length - f.left.Length];
        }
        else
        {
            l = new int[m.left.Length]; // WHY?
            r = new int[tmp.Length - m.left.Length];
        }

        for (int i = 0; i < l.Length; i++)
        {
            l[i] = tmp[i];
        }
        for (int i = 0; i < r.Length; i++)
        {
            r[i] = tmp[l.Length + i];
        }

        return(new GAIndividual(l, r));
    }