示例#1
0
    public List <int> SM(List <int> inputList)
    // scramble mutation
    {
        List <int> outputList       = new List <int>(inputList);
        int        a                = Random.Range(0, outputList.Count - 1);
        int        b                = Random.Range(a + 1, outputList.Count);
        List <int> scrambleSectionA = new List <int>();
        List <int> scrambleSectionB = new List <int>();

        for (int i = a; i <= b; i++)
        {
            scrambleSectionA.Add(outputList[i]);
            scrambleSectionB.Add(outputList[i]);
        }
        while (df.CheckListsMatch(scrambleSectionA, scrambleSectionB))
        {
            scrambleSectionB = df.ShuffleIntList(scrambleSectionA);
        }
        Queue <int> scrambleQueue = new Queue <int>(scrambleSectionB);

        for (int i = a; i <= b; i++)
        {
            outputList[i] = scrambleQueue.Dequeue();
        }
        return(outputList);
    }