public void SimplePinTest() { using (var session = Domain.OpenSession()) using (session.OpenTransaction()) { var butcher = new Killer(); var firstVictim = new Victim(); // "Killers" who have not killed yet should not be considered as killers using (session.DisableSaveChanges(butcher)) { session.SaveChanges(); Assert.AreEqual(PersistenceState.New, butcher.PersistenceState); Assert.AreEqual(PersistenceState.Synchronized, firstVictim.PersistenceState); butcher.Kill(firstVictim); session.SaveChanges(); Assert.AreEqual(PersistenceState.New, butcher.PersistenceState); Assert.AreEqual(PersistenceState.Modified, firstVictim.PersistenceState); } session.SaveChanges(); using (session.DisableSaveChanges(butcher)) { firstVictim.Resurrect(); var secondVictim = new Victim(); butcher.Kill(secondVictim); session.SaveChanges(); Assert.AreEqual(PersistenceState.Modified, butcher.PersistenceState); Assert.AreEqual(PersistenceState.Synchronized, firstVictim.PersistenceState); Assert.AreEqual(PersistenceState.Synchronized, secondVictim.PersistenceState); } } }
public State <T> Step() { State = Killer.Kill(State); State = CrossOver.CrossOver(State); //State = Mutator.Mutate(State); return(State); }
public void Run() { for (int i = 0; i < Generations; i++) { if (BeforeRun != null) { BeforeRun(this, new GeneticEventArgs(i)); } foreach (var chromosome in Population.Chromosomes) { chromosome.Fitness = Evaluator.ComputeFitness(chromosome.Genes); } Population.Chromosomes = Population.Chromosomes.OrderByDescending(x => x.Fitness).ToList(); if (BeforeKill != null) { BeforeKill(this, EventArgs.Empty); } Killer.Kill(Population); if (AfterKill != null) { AfterKill(this, EventArgs.Empty); } var selected = Selector.Select(Population.Chromosomes); if (BeforeCrossOver != null) { BeforeCrossOver(this, EventArgs.Empty); } foreach (var pair in selected) { var offspring = CrossOver.CrossOver(pair.Item1, pair.Item2); Population.AddChromosome(offspring); } if (AfterCrossOver != null) { AfterCrossOver(this, EventArgs.Empty); } if (BeforeMutate != null) { BeforeMutate(this, EventArgs.Empty); } MutateStep(Population); if (AfterMutate != null) { AfterMutate(this, EventArgs.Empty); } if (AfterRun != null) { AfterRun(this, new GeneticEventArgs(i)); } if (Solution.IsSolution(Population.Best)) { if (OnSolution != null) { OnSolution(this, EventArgs.Empty); } return; } } }