public Person LogIn(string username, string password) { cmd.CommandText = "Select * FROM Person WHERE Username = @Username and [Password] = @Password"; cmd.Parameters.Add(new OleDbParameter("@Username", username)); cmd.Parameters.Add(new OleDbParameter("@Password", password)); PersonList list = new PersonList(base.Select()); if (list.Count == 1) { return(list.ElementAt(0) as Person); } return(null); }
// Çaprazlama => Tek noktalı çaprazlama yapılıyor. // Çaprazlama yaparken Sayılar Bit'e dönüştürülür. Ve bu orana göre bir çaprazlama yapılır // Örn: x1 = [1,1,1,1,1] ile x2 = [0,0,0,0,0] iki bireyimiz olsun. Bu oran da 0.6 olsun bu durumda ; // Yeni Birey(x1)=> x1'in 0.6sına kadar olan kısmı ve x2'in 0.6'sından sonra olan kısmı yani => [1,1,1,0,0] // Yeni Birey(x2))=> [0,0,0,1,1] olur // Her 2 Birey İçin Yapılır, bundan Önce hepsi büyükten küçüğe sıralanır private void CrossOver() { // İlk önce bireylerin kromozom yapısı çıkartılır // Her bir birey bite dönüştürülür ve değeri tanımlanır // Önemli => Bireyleri çaprazlarken uygunluk değerine göre çaprazlancağı için ilk önce uygunluk değerlerine göre sıralandı PersonList = PersonList.OrderByDescending(s => s.AccordanceValue).ToList(); PersonList.ForEach(person => person.BitsValue = ConverToBinary(Math.Abs(person.Value))); List <Person> temp = new List <Person>(); // Çaprazlamayı 2 birey arasında yapacağımız için populasyon sayısı tek ise sondaki elemanı almıyacağız, o yüzden tek olur ise 1 eksilttik int length = PopulationCount % 2 == 0 ? PopulationCount : PopulationCount - 1; // Girilen Çaprazlama oranına göre kromozomdaki bölüm noktası // => Örn: 5 bitlik ise crossRate = 0.6 ise 3.bit hedef noktaso olur // Anlamı ilk bireyin => ilk 3 bitini al , 2.bireyin => 3.bitten sonrakini al int targetPoint = Convert.ToInt32(Math.Round((CrossProbability * BitCount), 0)); // 2 Birey Çaprazlamaya tutulacağı için döngüyü 2 şer arttırdık for (int i = 0; i < length; i = i + 2) { // Çaprazlama İşlemine tabi tutlacak Bireyler Person p1 = PersonList.ElementAt(i); // İlk birey Person p2 = PersonList.ElementAt(i + 1); // Bir sonraki birey // Yeni Bireyler // Tek noktalı çaprazlama ile yeni bireyler oluşturulup, yeni değerleri hesaplanır // populasyona eklenir // Yeni bireyler eski bireyden kalıtım aldıkları için ilk bireyin işaretini taşırlar => "Negatif" yada "Pozitif" Person firstPerson = new Person(); firstPerson.BitsValue = SinglePointCrossover(p1, p2, targetPoint, true); //Negatiflik Kontrolü if (Math.Abs(p1.Value) == p1.Value) { firstPerson.Value = BinaryToInt(firstPerson.BitsValue); } else // Negaitf Yapma { firstPerson.Value = BinaryToInt(firstPerson.BitsValue) * -1; } temp.Add(firstPerson); Person secondPerson = new Person(); secondPerson.BitsValue = SinglePointCrossover(p1, p2, targetPoint, false); // 2. Birey oldugu için False //Negatiflik Kontrolü if (Math.Abs(p2.Value) == p2.Value) { secondPerson.Value = BinaryToInt(secondPerson.BitsValue); } else // Negaitf Yapma { secondPerson.Value = BinaryToInt(secondPerson.BitsValue) * -1; } temp.Add(secondPerson); } PersonList.Clear(); PersonList.AddRange(temp); // Yeni Bireyler Oluşturuldukta sonra Uygunluk Değerleri Yeniden Hesaplanır this.PurposeFunction(); }
/// <summary> /// Event which fires on each tick of the simulationTimer, advancing the simulation by allowing people to move and determining if any new tiles need to catch on fire. /// </summary> /// <param name="source"></param> /// <param name="e"></param> private void AdvanceSimulation(Object source, System.Timers.ElapsedEventArgs e) { previousStates.Add(new SimulationState(this)); Map.SpreadFire(); dead = 0; for (int i = PersonList.Count - 1; i >= 0; i--) { Person person = PersonList.ElementAt(i); if (person.Health != 0) { if (map.TilesArray[person.Location.X, person.Location.Y] is TileFloor) { if (((TileFloor)map.TilesArray[person.Location.X, person.Location.Y]).HasSmoke) { person.DecreaseHealth(Person.DamageType.Smoke); } if (((TileFloor)map.TilesArray[person.Location.X, person.Location.Y]).OnFire) { person.DecreaseHealth(Person.DamageType.Fire); } person.IncreasePanicLevel(map.TilesArray[person.Location.X, person.Location.Y]); } if (map.TilesArray[person.Location.X, person.Location.Y] is TileExit) { PersonList.RemoveAt(i); escaped++; } else if (map.TilesArray[person.Location.X, person.Location.Y] is TileWindow) { Random rng = new Random(); if (rng.Next(1, 21) <= 5 * map.FloorLevel) // Survival chance of jumping out of the window. Increased by floor level. { person.DecreaseHealth(Person.DamageType.Falling); } else { escaped++; PersonList.RemoveAt(i); } person.Jumped = true; } else { if (person.Health > 0) { person.Move(); } } } else { dead++; } } timeElapsed += (double)simulationInterval / 1000; RedrawPanel(); }