예제 #1
0
        static void Main(string[] args)
        {
            ExperimentDataEntities dbContext = new ExperimentDataEntities();

            ExperimentDictionary dictionary =
                dbContext.ExperimentDictionaries.Single(expName => expName.ExperimentName == "Experiment 48");

            int maxRun =
                dictionary.NoveltyExperimentEvaluationDatas.Max(x => x.Run);

            NoveltyExperimentEvaluationData ne = new NoveltyExperimentEvaluationData();

            ne.ExperimentDictionaryID = 1;
            ne.Generation = 2;
            ne.SpecieCount = 10;
            ne.AsexualOffspringCount = 5;
            ne.SexualOffspringCount = 5;
            ne.TotalOffspringCount = 10;
            ne.InterspeciesOffspringCount = 5;
            ne.MaxFitness = 100;
            ne.MeanFitness = 50.5;
            ne.MeanSpecieChampFitness = 40.23;
            ne.MaxComplexity = 20;
            ne.MeanComplexity = 15.8;
            ne.MinSpecieSize = 3;
            ne.MaxSpecieSize = 30;

            //ne.TotalEvaluations = 300;
            ne.TotalEvaluations = null;

            //ne.EvaluationsPerSecond = 15;
            ne.EvaluationsPerSecond = null;

            ne.ChampGenomeID = 1;
            ne.ChampGenomeBirthGeneration = 5;
            ne.ChampGenomeConnectionGeneCount = 12;
            ne.ChampGenomeNeuronGeneCount = 5;
            ne.ChampGenomeTotalGeneCount = 17;

            //ne.ChampGenomeEvaluationCount = 13;
            ne.ChampGenomeEvaluationCount = null;

            ne.ChampGenomeBehavior1 = null;
            ne.ChampGenomeBehavior2 = null;

            dbContext.NoveltyExperimentEvaluationDatas.Add(ne);
            dbContext.SaveChanges();
        }
        /// <summary>
        ///     Maps applicable entity fields for the novelty experiment evaluation entity and persists to the database.
        /// </summary>
        /// <param name="loggableElements">The loggable elements (data) to persist.</param>
        public override void LogRow(params List<LoggableElement>[] loggableElements)
        {
            // Initialize new DB context
            ExperimentDataEntities localDbContext = new ExperimentDataEntities
            {
                Configuration = {AutoDetectChangesEnabled = false, ValidateOnSaveEnabled = false}
            };

            // Combine and sort the loggable elements
            LoggableElement[] combinedElements = ExtractLoggableElementArray(EvolutionFieldElements.NumFieldElements,
                loggableElements);

            NoveltyExperimentEvaluationData noveltyData = new NoveltyExperimentEvaluationData
            {
                ExperimentDictionaryID = ExperimentConfiguration.ExperimentDictionaryID,
                Run = Run
            };

            noveltyData.Generation =
                (int)
                    Convert.ChangeType(combinedElements[EvolutionFieldElements.Generation.Position].Value,
                        noveltyData.Generation.GetType());
            noveltyData.SpecieCount =
                (int)
                    Convert.ChangeType(combinedElements[EvolutionFieldElements.SpecieCount.Position].Value,
                        noveltyData.SpecieCount.GetType());
            noveltyData.AsexualOffspringCount =
                (int)
                    Convert.ChangeType(
                        combinedElements[EvolutionFieldElements.AsexualOffspringCount.Position].Value,
                        noveltyData.AsexualOffspringCount.GetType());
            noveltyData.SexualOffspringCount =
                (int)
                    Convert.ChangeType(
                        combinedElements[EvolutionFieldElements.SexualOffspringCount.Position].Value,
                        noveltyData.SexualOffspringCount.GetType());
            noveltyData.TotalOffspringCount =
                (int)
                    Convert.ChangeType(
                        combinedElements[EvolutionFieldElements.TotalOffspringCount.Position].Value,
                        noveltyData.TotalOffspringCount.GetType());
            noveltyData.InterspeciesOffspringCount =
                (int)
                    Convert.ChangeType(
                        combinedElements[EvolutionFieldElements.InterspeciesOffspringCount.Position].Value,
                        noveltyData.InterspeciesOffspringCount.GetType());
            noveltyData.MaxFitness =
                (double)
                    Convert.ChangeType(combinedElements[EvolutionFieldElements.MaxFitness.Position].Value,
                        noveltyData.MaxFitness.GetType());
            noveltyData.MeanFitness =
                (double)
                    Convert.ChangeType(combinedElements[EvolutionFieldElements.MeanFitness.Position].Value,
                        noveltyData.MeanFitness.GetType());
            noveltyData.MeanSpecieChampFitness =
                (double)
                    Convert.ChangeType(
                        combinedElements[EvolutionFieldElements.MeanSpecieChampFitness.Position].Value,
                        noveltyData.MeanSpecieChampFitness.GetType());
            noveltyData.MaxComplexity =
                (int)
                    Convert.ChangeType(combinedElements[EvolutionFieldElements.MaxComplexity.Position].Value,
                        noveltyData.MaxComplexity.GetType());
            noveltyData.MeanComplexity =
                (double)
                    Convert.ChangeType(combinedElements[EvolutionFieldElements.MeanComplexity.Position].Value,
                        noveltyData.MeanComplexity.GetType());
            noveltyData.MinSpecieSize =
                (int)
                    Convert.ChangeType(combinedElements[EvolutionFieldElements.MinSpecieSize.Position].Value,
                        noveltyData.MinSpecieSize.GetType());
            noveltyData.MaxSpecieSize =
                (int)
                    Convert.ChangeType(combinedElements[EvolutionFieldElements.MaxSpecieSize.Position].Value,
                        noveltyData.MaxSpecieSize.GetType());
            noveltyData.TotalEvaluations =
                (int)
                    Convert.ChangeType(
                        combinedElements[EvolutionFieldElements.TotalEvaluations.Position].Value,
                        typeof (int));
            noveltyData.EvaluationsPerSecond =
                (int)
                    Convert.ChangeType(
                        combinedElements[EvolutionFieldElements.EvaluationsPerSecond.Position].Value,
                        typeof (int));
            noveltyData.ChampGenomeID =
                (int)
                    Convert.ChangeType(
                        combinedElements[EvolutionFieldElements.ChampGenomeGenomeId.Position].Value,
                        noveltyData.ChampGenomeID.GetType());
            noveltyData.ChampGenomeFitness =
                (double)
                    Convert.ChangeType(
                        combinedElements[EvolutionFieldElements.ChampGenomeFitness.Position].Value,
                        noveltyData.ChampGenomeFitness.GetType());
            noveltyData.ChampGenomeBirthGeneration =
                (int)
                    Convert.ChangeType(
                        combinedElements[EvolutionFieldElements.ChampGenomeBirthGeneration.Position].Value,
                        noveltyData.ChampGenomeBirthGeneration.GetType());
            noveltyData.ChampGenomeConnectionGeneCount =
                (int)
                    Convert.ChangeType(
                        combinedElements[EvolutionFieldElements.ChampGenomeConnectionGeneCount.Position].Value,
                        noveltyData.ChampGenomeConnectionGeneCount.GetType());
            noveltyData.ChampGenomeNeuronGeneCount =
                (int)
                    Convert.ChangeType(
                        combinedElements[EvolutionFieldElements.ChampGenomeNeuronGeneCount.Position].Value,
                        noveltyData.ChampGenomeNeuronGeneCount.GetType());
            noveltyData.ChampGenomeTotalGeneCount =
                (int)
                    Convert.ChangeType(
                        combinedElements[EvolutionFieldElements.ChampGenomeTotalGeneCount.Position].Value,
                        noveltyData.ChampGenomeTotalGeneCount.GetType());
            noveltyData.ChampGenomeEvaluationCount =
                (int)
                    Convert.ChangeType(
                        combinedElements[EvolutionFieldElements.ChampGenomeEvaluationCount.Position].Value,
                        typeof (int));
            noveltyData.ChampGenomeBehavior1 =
                (double)
                    Convert.ChangeType(
                        combinedElements[EvolutionFieldElements.ChampGenomeBehaviorX.Position].Value,
                        typeof (double));
            noveltyData.ChampGenomeBehavior2 =
                (double)
                    Convert.ChangeType(
                        combinedElements[EvolutionFieldElements.ChampGenomeBehaviorY.Position].Value,
                        typeof (double));

            // Add the new evaluation data
            localDbContext.NoveltyExperimentEvaluationDatas.Add(noveltyData);

            // Save the changes and dispose of the context
            localDbContext.SaveChanges();
            localDbContext.Dispose();
        }