为什么列表<long []>变量会自动更改另一个变量?

时间:2017-06-30 04:24:00

标签: c# list

我有两个变量:long[] nextStateList<long[]> TabuList。 我使用此代码将项目添加到TabuList

TabuList.add(nextState);

或者这个:

TabuList.insert(Index, nexState);

但问题是,在执行其中任何一项操作后,所有TabuList项都会自动转换为当前值nextState。 我的完整代码是:

class TabuSearch
    {
        private long[] current { get; set; }
        private double Delta;
        private Random rnd = new Random();
        int foundLists = 0;

        public TabuSearch()
        {
            current = new long[Convert.ToInt32(num_list1)];
        }

        public long[] TabuMOSA3Objectives(long[] c)
        {
            assign(current, c);
            long[] nextState = new long[Convert.ToInt32(num_list1)];
            List<long[]> TabuList = new List<long[]>();
            double proba;
            double alpha = 0.969;
            double temperature = 500.0;
            double epsilon = 0.0001;
            short domination_st;
            int iter = 0;

            while (temperature > epsilon)
            {
                iter++;
                Delta = 1;
                assign(nextState, GenerateNextState(primaryList, current));
                domination_st = CheckDomination3Objective(nextState, current);
                try { var tmp = TabuList.Find(x => x == nextState); if (tmp == null) foundLists = 0; else foundLists = tmp.Count(); }
                catch { }
                    if (foundLists == 0)
                    {
                        if (domination_st > 0)
                        {
                            assign(current, nextState);
                        }
                        else // domination_st < 0
                        {
                            proba = rnd.NextDouble();
                            if (proba < 1 / (1 + Math.Exp(Delta * temperature)))
                            {
                                assign(current, nextState);
                            }
                            else
                            {
                                if (TabuList.Count == 10)
                                    TabuList.RemoveAt(0);
                                assign(nextState, TabuList);
                            }
                        }

                }
                //cooling proces on every iteration
                temperature *= alpha;
            }

            return current;
        }
   } 
          static void assign(long[] c, long[] n)
            {
                for (int i = 0; i < c.Length; i++)
                    c[i] = n[i];
            }
            static void assign(long[] item, List<long[]> list)
            {
                list.Add(item);
            }

0 个答案:

没有答案