protected void Populate() { using (var session = this.Database.CreateSession()) { var population = new TestPopulation(session); this.c1A = population.C1A; this.c1B = population.C1B; this.c1C = population.C1C; this.c1D = population.C1D; this.c2A = population.C2A; this.c2B = population.C2B; this.c2C = population.C2C; this.c2D = population.C2D; this.c3A = population.C3A; this.c3B = population.C3B; this.c3C = population.C3C; this.c3D = population.C3D; this.c4A = population.C4A; this.c4B = population.C4B; this.c4C = population.C4C; this.c4D = population.C4D; session.Commit(); } }
public void MetricsChart_RefreshPlotOnFitnessEvaluated() { TestPopulation population = new TestPopulation(); TestAlgorithm algorithm = new TestAlgorithm(); Metric metric1 = Mock.Of <Metric>(); List <MetricResult> metric1Results = new List <MetricResult> { new MetricResult(0, 0, 3, metric1), new MetricResult(0, 1, 4, metric1) }; metric1.GetResults(0).AddRange(metric1Results); algorithm.Metrics.Add(metric1); MetricsChart chart = new MetricsChart { Algorithm = algorithm, Population = population }; Assert.Single(chart.PlotModel.Series); // Clear the series to ensure it doesn't gets refreshed when the fitness is evaluated chart.PlotModel.Series.Clear(); PrivateObject algorithmAccessor = new PrivateObject(algorithm, new PrivateType(typeof(GeneticAlgorithm))); algorithmAccessor.Invoke("OnFitnessEvaluated", new EnvironmentFitnessEvaluatedEventArgs(new GeneticEnvironment(algorithm), 1)); Assert.Empty(chart.PlotModel.Series); }
public void MetricsChart_MetricWithNonDoubleResult() { TestPopulation population = new TestPopulation(); TestAlgorithm algorithm = new TestAlgorithm(); Metric metric1 = Mock.Of <Metric>(); List <MetricResult> metric1Results = new List <MetricResult> { new MetricResult(0, 0, "foo", metric1), new MetricResult(0, 1, "bar", metric1) }; metric1.GetResults(0).AddRange(metric1Results); Metric metric2 = Mock.Of <Metric>(); List <MetricResult> metric2Results = new List <MetricResult> { new MetricResult(0, 0, 3, metric1), new MetricResult(0, 1, 4, metric1) }; metric2.GetResults(0).AddRange(metric2Results); algorithm.Metrics.Add(metric1); algorithm.Metrics.Add(metric2); MetricsChart chart = new MetricsChart { Algorithm = algorithm, Population = population }; Assert.Single(chart.PlotModel.Series); Assert.Equal(metric2Results, (ICollection)((LineSeries)chart.PlotModel.Series[0]).ItemsSource); }
private static void TestStateTransition(ExecutionState fromState, ExecutionState toState, bool expectEntitiesToUpdate) { PopulationViewer viewer = new PopulationViewer { ExecutionState = fromState }; TestPopulation population = new TestPopulation(); population.Entities.Add(Mock.Of <GeneticEntity>()); population.Entities.Add(Mock.Of <GeneticEntity>()); viewer.Population = population; viewer.ExecutionState = toState; if (expectEntitiesToUpdate) { Assert.Equal(population.Entities, viewer.SelectedPopulationEntities.ToList()); } else { Assert.Null(viewer.SelectedPopulationEntities); } }
public void PopulationViewer_OnSelectedPopulationChanged_InitialPopulation() { PopulationViewer viewer = new PopulationViewer { ExecutionState = ExecutionState.Idle }; TestPopulation population = new TestPopulation(); population.Entities.Add(Mock.Of <GeneticEntity>()); population.Entities.Add(Mock.Of <GeneticEntity>()); viewer.Population = population; Assert.Null(viewer.SelectedPopulationEntities); }
public void FitnessChart_OnPopulationChanged_NonPopulated() { FitnessChart chart = new FitnessChart(); PlotModel model = chart.PlotModel; CategoryAxis axis = (CategoryAxis)model.Axes[0]; axis.Labels.Add("test"); TestPopulation population = new TestPopulation(); population.Initialize(Mock.Of <GeneticAlgorithm>()); chart.Population = population; Assert.Equal("test", axis.Labels[0]); }
public void MetricsChart_OnPopulationChanged_FromOtherPopulation() { TestPopulation population = new TestPopulation(); TestAlgorithm algorithm = new TestAlgorithm(); Metric metric1 = Mock.Of <Metric>(); List <MetricResult> metric1Results = new List <MetricResult> { new MetricResult(0, 0, 1, metric1), new MetricResult(0, 1, 2, metric1) }; metric1.GetResults(0).AddRange(metric1Results); Metric metric2 = Mock.Of <Metric>(); List <MetricResult> metric2Results = new List <MetricResult> { new MetricResult(0, 0, 3, metric1), new MetricResult(0, 1, 4, metric1) }; metric2.GetResults(0).AddRange(metric2Results); algorithm.Metrics.Add(metric1); algorithm.Metrics.Add(metric2); VerifyChartRefresh(chart => { chart.Algorithm = new TestAlgorithm(); chart.Population = new TestPopulation(); }, chart => { chart.Algorithm = algorithm; chart.Population = population; }, (metric, series) => { if (metric == metric1) { Assert.Equal(metric1Results, (ICollection)series.ItemsSource); } else if (metric == metric2) { Assert.Equal(metric2Results, (ICollection)series.ItemsSource); } }); }
static void Main(string[] args) { string path = @"..\..\samples\MK250.txt"; KnapsackList knapsackList = InputOutput.ReadInput(path); knapsackList.Show(); init_static_GA_GT(knapsackList); TestPopulation t = new TestPopulation(); GA_GT ga_gt = new GA_GT(); ga_gt.RunGA_GT().Show(); Console.WriteLine("End"); Console.ReadLine(); }
public void MetricsChart_OnSelectedMetricsChanged() { TestPopulation population = new TestPopulation(); TestAlgorithm algorithm = new TestAlgorithm(); Metric metric1 = Mock.Of <Metric>(); List <MetricResult> metric1Results = new List <MetricResult> { new MetricResult(0, 0, 3, metric1), new MetricResult(0, 1, 4, metric1) }; metric1.GetResults(0).AddRange(metric1Results); algorithm.Metrics.Add(metric1); Metric metric2 = Mock.Of <Metric>(); List <MetricResult> metric2Results = new List <MetricResult> { new MetricResult(0, 0, 3, metric1), new MetricResult(0, 1, 4, metric1) }; metric2.GetResults(0).AddRange(metric2Results); algorithm.Metrics.Add(metric2); MetricsChart chart = new MetricsChart { Algorithm = algorithm, Population = population }; Assert.Equal(2, chart.PlotModel.Series.Count); chart.PlotModel.Series.Clear(); chart.SelectedMetrics = new List <Metric> { algorithm.Metrics[0] }; Assert.Single(chart.PlotModel.Series); }
protected void Populate() { var population = new TestPopulation(this.Session); this.c1A = population.C1A; this.c1B = population.C1B; this.c1C = population.C1C; this.c1D = population.C1D; this.c2A = population.C2A; this.c2B = population.C2B; this.c2C = population.C2C; this.c2D = population.C2D; this.c3A = population.C3A; this.c3B = population.C3B; this.c3C = population.C3C; this.c3D = population.C3D; this.c4A = population.C4A; this.c4B = population.C4B; this.c4C = population.C4C; this.c4D = population.C4D; }