/// <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); }
/// <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); }
public SwapSorter(IComparer <T> comparer, ISwap <T> swapper) { Argument.IsNotNull(() => comparer); Argument.IsNotNull(() => swapper); _comparer = comparer; _swapper = swapper; }
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); }
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; }
/// <summary> /// 判断是否是参数输入的交换对象 /// </summary> /// <param name="Swap"></param> /// <returns></returns> public bool IsSwap(ISwap Swap) { if (Swap.ThisType == this.tagType) { return(true); } else { return(false); } }
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]; }
/// <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); }
/// <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); }
/// <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); }
/// <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); }
/// <summary> /// Initializes a new instance of the <see cref="SwapSorter<T>"/> 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; }
/// <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); }
/// <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); } }
/// <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)); }
/// <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); }
/// <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); }
/// <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); }
/// <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); }
public SelectionSort(IComparer comparer, ISwap swapper) : base(comparer, swapper) { }
public DoubleStorageMergeSort(IComparer comparer, ISwap swapper) : base(comparer, swapper) { }
public SwapSorter() { this.comparer = new ComparableComparer(); this.swapper = new DefaultSwap(); }
public BubbleSorter(IComparer comparer, ISwap swapper) : base(comparer, swapper) { }
public QuickSortWithBubbleSort(IComparer comparer, ISwap swapper) :base(comparer,swapper) { }
public ShearSorter(IComparer comparer, ISwap swapper) : base(comparer,swapper) { }
public QuickSorter(IComparer comparer, ISwap swapper) : base(comparer, swapper) { }
public InPlaceMergeSort(IComparer comparer, ISwap swapper) : base(comparer,swapper) { }
public InsertionSort(IComparer <T> comparer, ISwap <T> swapper) : base(comparer, swapper) { }
public FastQuickSorter(IComparer <T> comparer, ISwap <T> swapper) : base(comparer, swapper) { }
public OddEvenTransportSorter(IComparer comparer, ISwap swapper) : base(comparer, swapper) { }
public BubbleSorter(IComparer comparer, ISwap swapper) :base(comparer,swapper) { }
public HeapSort(IComparer comparer, ISwap swapper) :base(comparer,swapper) { }
public BiDirectionalBubbleSort(IComparer comparer, ISwap swapper) : base(comparer,swapper) { }
public QuickSortWithBubbleSort(IComparer <T> comparer, ISwap <T> swapper) : base(comparer, swapper) { }
/// <summary> /// Initializes a new instance of the <see cref="SwapSorter<T>"/> class. /// </summary> public SwapSorter() { comparer = Comparer <T> .Default; swapper = new DefaultSwap <T>(); }
public SwapSorter() { _comparer = new ComparableComparer <T>(); _swapper = new DefaultSwap <T>(); }
public ComboSort11(IComparer comparer, ISwap swapper) :base(comparer,swapper) { }
public SwapBuilderFixedFloat() { Swap = new Swap(); }
public ShakerSort(IComparer comparer, ISwap swapper) : base(comparer, swapper) { }
public OddEvenTransportSorter(IComparer comparer, ISwap swapper) : base(comparer,swapper) { }
public HeapSort(IComparer <T> comparer, ISwap <T> swapper) : base(comparer, swapper) { }
public ShakerSort(IComparer comparer, ISwap swapper) : base(comparer,swapper) { }
public InsertionSort(IComparer comparer, ISwap swapper) : base(comparer,swapper) { }
/// <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); }