public Kontener(Kontener old) { this.wartosci = old.wartosci.Select(item => (string)item.Clone()).ToList(); this.cross = old.cross; this.first = old.first; this.LiczWartosci(); }
public Kontener Run() { TheBest = ko.Test(); Best = new Kontener(ko); for (int i = 0; i < 500; i++) { Kontener temp = MakeStep(); int sw = ko.Test(); if (temp.first != "") { ko = temp; } int iiii = ko.Test(); if (iiii < TheBest) { TheBest = iiii; Best = new Kontener(ko); Console.WriteLine(); Console.WriteLine(i); Console.WriteLine(TheBest); Console.WriteLine((double)TheBest / 100.0); } } return(Best); }
public Kontener insert(int from, int to) { Kontener result = new Kontener(this); string temp = result.wartosci[from]; result.wartosci.RemoveAt(from); result.wartosci.Insert(to, temp); return(result); }
private Kontener MakeStep() { int min = ko.Test(); Kontener best = ko; foreach (var x in ko.wartosci) { int number = ko.wartosci.IndexOf(x); for (int i = 0; i < ko.wartosci.Count; i++) { if (i == number) { continue; } Kontener temp = ko.insert(number, i); if (temp.Test() <= min) { best = temp; min = temp.Test(); } } } if (best.Test() == ko.Test()) { if (Enumerable.SequenceEqual(best.wartosci, Best.wartosci)) { Console.WriteLine("\npowtorzenie"); } Random rnd = new Random(); int size = ko.wartosci.Count(); swap(rnd.Next() % size, rnd.Next() % size); best = ko; } return(best); }
static void Main() { CrossOligos ol = new CrossOligos(); OligoMeta meta = new OligoMeta(); string first = Prepare("10.in", meta); ol.GenerateMap(meta, first); Kontener kon = new Kontener(meta, ol); kon.first = first; kon.LiczWartosci(); Algorytm alg = new Algorytm(kon); alg.Run(); }
public Algorytm(Kontener kon) { ko = kon; }