示例#1
0
 /// <summary>
 /// The basic constructor does a quicksort using the built in comparer and swapper
 /// </summary>
 /// <param name="array">The array to sort.</param>
 public static void QuickSort(ArrayList array)
 {
     Sort s=new Sort();
     Sort.comparer=s;
     Sort.swapper=s;
     QuickSort(array, 0, array.Count-1);
 }
示例#2
0
        /// <summary>
        /// The basic constructor does a quicksort using the built in comparer and swapper
        /// </summary>
        /// <param name="array">The array to sort.</param>
        public static void QuickSort(ArrayList array)
        {
            Sort s = new Sort();

            Sort.comparer = s;
            Sort.swapper  = s;
            QuickSort(array, 0, array.Count - 1);
        }
示例#3
0
        public SwapSorter(IComparer <T> comparer, ISwap <T> swapper)
        {
            Argument.IsNotNull(() => comparer);
            Argument.IsNotNull(() => swapper);

            _comparer = comparer;
            _swapper  = swapper;
        }
示例#4
0
        public ISwap DoOneImprovement()
        {
            ISwap bestSwap = null;

            void CheckIfSwapIsImprovement(ISwap swap)
            {
                if (!swap.IsPossible())
                {
                    return;
                }
                if (!swap.IsAllowed())
                {
                    return;
                }
                DoSwapAndRecalculate(swap);
                double score = Score(day);

                DoSwapAndRecalculate(swap);
                if (score < BestScore)
                {
                    BestScore = score;
                    bestSwap  = swap;
                }
            }

            // Simple swaps
            for (int p1 = 0; p1 < day.matches.Count * Match.MaxPlayers; p1++)
            {
                for (int p2 = 0; p2 < p1; p2++)
                {
                    CheckIfSwapIsImprovement(new RegularSwap(p1, p2, day));
                }
            }

            if (bestSwap != null)
            {
                DoSwapAndRecalculate(bestSwap);
                return(bestSwap);
            }

            // Paired swaps
            for (int p1 = 0; p1 < day.matches.Count * Team.MaxSize; p1++)
            {
                for (int p2 = 0; p2 < p1; p2++)
                {
                    CheckIfSwapIsImprovement(new SimpleDoubleSwap(p1, p2, day));
                }
            }

            if (bestSwap != null)
            {
                DoSwapAndRecalculate(bestSwap);
                return(bestSwap);
            }

            return(null);
        }
示例#5
0
        public SwapSorter(IComparer comparer, ISwap swapper)
        {
            if (comparer == null)
                throw new ArgumentNullException("comparer");
            if (swapper==null)
                throw new ArgumentNullException("swapper");

            this.comparer = comparer;
            this.swapper = swapper;
        }
示例#6
0
 /// <summary>
 /// 判断是否是参数输入的交换对象
 /// </summary>
 /// <param name="Swap"></param>
 /// <returns></returns>
 public bool IsSwap(ISwap Swap)
 {
     if (Swap.ThisType == this.tagType)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
示例#7
0
 public Evolution(IInitalise initalise, ISelectionStrategy selectionStrategy, ICrossover crossoverStratergy, ISwap swap, TerminateStrategy terminate, IStepFunction stepFunction, uint populationSize, float eliteism, float mutationRate, string name = "Evolution Search")
 {
     this.InitalisationStrategy = initalise;
     this.selectionStrategy     = selectionStrategy;
     this.crossoverStratergy    = crossoverStratergy;
     this.step = stepFunction;
     this.swap = swap;
     this.terminateStrategy = terminate;
     this.name         = name;
     this.eliteism     = eliteism;
     this.mutationRate = mutationRate;
     population        = new Route[populationSize];
 }
示例#8
0
        /// <summary>
        /// 根据自定义交换匹配实例查找交换池中的对象实例
        /// </summary>
        public static object SwapFindObject(ISwapMatch Match)
        {
            object result = null;
            ISwap  swap   = LemonEnvironment.GetInstance().SwapPool.FindSwap(Match);

            if (swap != null)
            {
                if (swap.PackageObject != null)
                {
                    result = swap.PackageObject;
                }
            }
            return(result);
        }
示例#9
0
        /// <summary>
        /// 查找数据交换对象
        /// </summary>
        /// <param name="Match"></param>
        /// <returns></returns>
        public ISwap FindSwap(ISwapMatch Match)
        {
            ISwap result = null;

            foreach (ISwap swp in this.swaplist)
            {
                if (Match.IsSwap(swp))
                {
                    result = swp;
                    break;
                }
            }
            return(result);
        }
示例#10
0
        /// <summary>
        /// 根据类全名查找交换池中的对象实例
        /// </summary>
        public static object SwapFindObject(string FullClassName)
        {
            object result = null;
            ISwap  swap   = LemonEnvironment.GetInstance().SwapPool.FindSwap(FullClassName);

            if (swap != null)
            {
                if (swap.PackageObject != null)
                {
                    result = swap.PackageObject;
                }
            }
            return(result);
        }
示例#11
0
 /// <summary>
 /// 定义框架在查找交换对象时复合什么条件的Swap对象能使用该匹配器
 /// </summary>
 /// <param name="Swap"></param>
 /// <returns></returns>
 public bool IsSwap(ISwap Swap)
 {
     if (Swap.PackageObject != null)
     {
         if (Swap.PackageObject.GetType().IsSubclassOf(typeof(Food)))
         {
             if (((Food)Swap.PackageObject).Name == this.foodname)
             {
                 return(true);
             }
         }
     }
     return(false);
 }
示例#12
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SwapSorter&lt;T&gt;"/> class.
        /// </summary>
        /// <param name="comparer">The comparer.</param>
        /// <param name="swapper">The swapper.</param>
        public SwapSorter(IComparer <T> comparer, ISwap <T> swapper)
        {
            if (comparer == null)
            {
                throw new ArgumentNullException("comparer");
            }
            if (swapper == null)
            {
                throw new ArgumentNullException("swapper");
            }

            this.comparer = comparer;
            this.swapper  = swapper;
        }
示例#13
0
        /// <summary>
        /// 是否包含
        /// </summary>
        /// <param name="Swap"></param>
        /// <returns></returns>
        public int HasSwap(ISwap Swap)
        {
            int           result = -1;
            SwapMatchKeys smk    = new SwapMatchKeys(Swap.CustomKeys);

            foreach (ISwap sp in this.swaplist)
            {
                if (smk.IsSwap(sp))
                {
                    result = this.swaplist.IndexOf(sp);
                }
            }
            return(result);
        }
示例#14
0
 /// <summary>
 /// 判断是否是参数输入的交换对象
 /// </summary>
 /// <param name="Swap"></param>
 /// <returns></returns>
 public bool IsSwap(ISwap Swap)
 {
     if (Swap.PackageObject == null)
     {
         return(false);
     }
     if (Lemon.GetFullClassName(Swap.PackageObject) == this.fcn)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
示例#15
0
        /// <summary>
        /// 添加数据交换对象,同时添加自定义关键字
        /// </summary>
        public static int SwapAppend(object Obj, params object[] CustomKey)
        {
            List <object> ck = new List <object>();

            if (CustomKey != null)
            {
                foreach (object s in CustomKey)
                {
                    ck.Add(s);
                }
            }
            ISwap swap = LemonEnvironment.GetInstance().SwapPool.CreateSwap(Obj, ck);

            return(LemonEnvironment.GetInstance().SwapPool.AddSwapping(swap));
        }
示例#16
0
        /// <summary>
        /// 判断是否是参数输入的交换对象
        /// </summary>
        /// <param name="Swap"></param>
        /// <returns></returns>
        public bool IsSwap(ISwap Swap)
        {
            IEnumerable <object> eA        = Swap.CustomKeys;
            IEnumerable <object> eB        = this.keys;
            IEnumerable <object> intersect = eA.Intersect(eB);

            if (intersect != null)
            {
                if (intersect.Count() == this.keys.Count() && this.keys.Count() > 0)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            return(false);
        }
示例#17
0
        /// <summary>
        /// 添加交换对象
        /// </summary>
        /// <param name="Swap"></param>
        public int AddSwapping(ISwap Swap)
        {
            int result = HasSwap(Swap);

            if (result > -1)
            {
                //覆盖
                this.swaplist.RemoveAt(result);
                this.swaplist.Insert(result, Swap);
            }
            else
            {
                //添加新的
                Swap.Index = this.CurrentMaxIndex() + 1;
                this.swaplist.Add(Swap);
                result = Swap.Index;
            }
            return(result);
        }
示例#18
0
        /// <summary>
        /// 根据类全名查找交换池中的对象实例
        /// <param name="IsMulti">是否查询多个</param>
        /// <param name="Keys">任意多个参数,待查询对象的关键字必须完全包含该参数</param>
        /// </summary>
        public static List <object> SwapFindObject(bool IsMulti, params object[] Keys)
        {
            List <object> result = new List <object>();

            if (Keys == null)
            {
                return(null);
            }
            if (IsMulti)
            {
                List <ISwap> swaps = LemonEnvironment.GetInstance().SwapPool.FindSwaps(Keys.ToList());
                if (swaps != null)
                {
                    foreach (ISwap swap in swaps)
                    {
                        if (swap != null)
                        {
                            if (swap.PackageObject != null)
                            {
                                result.Add(swap.PackageObject);
                            }
                        }
                    }
                }
            }
            else
            {
                ISwap swap = LemonEnvironment.GetInstance().SwapPool.FindSwap(Keys.ToList());
                if (swap != null)
                {
                    if (swap.PackageObject != null)
                    {
                        result.Add(swap.PackageObject);
                    }
                }
            }
            return(result);
        }
示例#19
0
        /// <summary>
        /// 根据关键字查找
        /// <param name="Keys">任意多个参数,待查询对象的关键字必须完全包含该参数</param>
        /// </summary>
        public static T SwapFindOneObject <T>(params object[] Keys)
        {
            T result = default(T);

            if (Keys == null)
            {
                return(result);
            }
            else
            {
                ISwap swap = LemonEnvironment.GetInstance().SwapPool.FindSwap(Keys.ToList());
                if (swap != null)
                {
                    if (swap.PackageObject != null)
                    {
                        if (swap.PackageObject.GetObjTypeFromProxy() == typeof(T))
                        {
                            result = (T)swap.PackageObject;
                        }
                    }
                }
            }
            return(result);
        }
示例#20
0
 public SelectionSort(IComparer comparer, ISwap swapper)
     : base(comparer, swapper)
 {
 }
示例#21
0
 public DoubleStorageMergeSort(IComparer comparer, ISwap swapper)
     : base(comparer, swapper)
 {
 }
示例#22
0
 public SwapSorter()
 {
     this.comparer = new ComparableComparer();
     this.swapper = new DefaultSwap();
 }
示例#23
0
 public BubbleSorter(IComparer comparer, ISwap swapper)
     : base(comparer, swapper)
 {
 }
		public QuickSortWithBubbleSort(IComparer comparer, ISwap swapper)
			:base(comparer,swapper)
		{
		}
示例#25
0
 public ShearSorter(IComparer comparer, ISwap swapper)
     : base(comparer,swapper)
 {
 }
示例#26
0
 public QuickSorter(IComparer comparer, ISwap swapper)
     : base(comparer, swapper)
 {
 }
示例#27
0
 public InPlaceMergeSort(IComparer comparer, ISwap swapper)
     : base(comparer,swapper)
 {
 }
示例#28
0
 public InsertionSort(IComparer <T> comparer, ISwap <T> swapper)
     : base(comparer, swapper)
 {
 }
示例#29
0
 public FastQuickSorter(IComparer <T> comparer, ISwap <T> swapper)
     : base(comparer, swapper)
 {
 }
示例#30
0
 public OddEvenTransportSorter(IComparer comparer, ISwap swapper)
     : base(comparer, swapper)
 {
 }
示例#31
0
		public BubbleSorter(IComparer comparer, ISwap swapper)
			:base(comparer,swapper)
		{
		}
示例#32
0
		public HeapSort(IComparer comparer, ISwap swapper)
			:base(comparer,swapper)
		{
		}
 public BiDirectionalBubbleSort(IComparer comparer, ISwap swapper)
     : base(comparer,swapper)
 {
 }
示例#34
0
 public QuickSortWithBubbleSort(IComparer <T> comparer, ISwap <T> swapper)
     : base(comparer, swapper)
 {
 }
示例#35
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SwapSorter&lt;T&gt;"/> class.
 /// </summary>
 public SwapSorter()
 {
     comparer = Comparer <T> .Default;
     swapper  = new DefaultSwap <T>();
 }
示例#36
0
 public SwapSorter()
 {
     _comparer = new ComparableComparer <T>();
     _swapper  = new DefaultSwap <T>();
 }
示例#37
0
		public ComboSort11(IComparer comparer, ISwap swapper)
			:base(comparer,swapper)
		{
		}
示例#38
0
 public SwapBuilderFixedFloat()
 {
     Swap = new Swap();
 }
示例#39
0
 public ShakerSort(IComparer comparer, ISwap swapper)
     : base(comparer, swapper)
 {
 }
示例#40
0
 public DoubleStorageMergeSort(IComparer comparer, ISwap swapper)
     : base(comparer, swapper)
 {
 }
示例#41
0
 public OddEvenTransportSorter(IComparer comparer, ISwap swapper)
     : base(comparer,swapper)
 {
 }
示例#42
0
 public HeapSort(IComparer <T> comparer, ISwap <T> swapper)
     : base(comparer, swapper)
 {
 }
示例#43
0
 public ShakerSort(IComparer comparer, ISwap swapper)
     : base(comparer,swapper)
 {
 }
示例#44
0
 public InsertionSort(IComparer comparer, ISwap swapper)
     : base(comparer,swapper)
 {
 }
示例#45
0
 /// <summary>
 /// Specifies both my comparer and my swapper
 /// </summary>
 /// <param name="array">The array to sort.</param>
 /// <param name="comparer">The custom comparer.</param>
 /// <param name="swapper">The custom swapper.</param>
 public static void QuickSort(ArrayList array, IComparer comparer, ISwap swapper)
 {
     Sort.comparer=comparer;
     Sort.swapper=swapper;
     QuickSort(array, 0, array.Count-1);
 }
示例#46
0
 public QuickSorter(IComparer comparer, ISwap swapper)
     : base(comparer, swapper)
 {
 }
示例#47
0
 public SwapSorter()
 {
     this.comparer = new ComparableComparer();
     this.swapper  = new DefaultSwap();
 }