public IParameterValueCache CreatePopulation(PopulationSettings matlabPopulationSettings, IEnumerable <MoleculeOntogeny> moleculeOntogenies) { var populationSettings = _populationSettingsMapper.MapFrom(matlabPopulationSettings); var population = _randomPopulationFactory.CreateFor(populationSettings, new CancellationToken()).Result; foreach (var moleculeOntogeny in moleculeOntogenies) { var allOntogeniesForSpecies = _ontogenyRepository.AllFor(matlabPopulationSettings.Individual.OriginData.Species).ToList(); if (!allOntogeniesForSpecies.Any()) { continue; } var ontogeny = allOntogeniesForSpecies.FindByName(moleculeOntogeny.Ontogeny); if (ontogeny == null) { continue; } var molecule = _individualEnzymeFactory.CreateEmpty().WithName(moleculeOntogeny.Molecule); molecule.Ontogeny = ontogeny; population.AddMolecule(molecule); } _ontogenyVariabilityUpdater.UpdateAllOntogenies(population); return(population.IndividualPropertiesCache); }
public CreatePopulationResults CreatePopulation(PopulationCharacteristics populationCharacteristics) { var populationSettings = _populationSettingsMapper.MapToModel(populationCharacteristics, new SnapshotContext()).Result; validate(populationSettings); var population = _randomPopulationFactory.CreateFor(populationSettings, new CancellationToken(), seed: populationCharacteristics.Seed).Result; foreach (var moleculeOntogeny in populationCharacteristics.MoleculeOntogenies) { var allOntogeniesForSpecies = _ontogenyRepository.AllFor(populationCharacteristics.Individual.OriginData.Species); if (!allOntogeniesForSpecies.Any()) { continue; } var ontogeny = allOntogeniesForSpecies.FindByName(moleculeOntogeny.Ontogeny); if (ontogeny == null) { continue; } var molecule = _individualEnzymeFactory.CreateEmpty().WithName(moleculeOntogeny.Molecule); molecule.Ontogeny = ontogeny; population.AddMolecule(molecule); } _ontogenyVariabilityUpdater.UpdateAllOntogenies(population); return(new CreatePopulationResults(population.IndividualValuesCache, population.Seed)); }
private void addUserDefinedVariabilityAndOntogenyForMolecules(RandomPopulation randomPopulation) { _moleculeParameterVariabilityCreator.AddVariabilityTo(randomPopulation); _moleculeOntogenyVariabilityUpdater.UpdateAllOntogenies(randomPopulation); }
public Task <RandomPopulation> CreateFor(RandomPopulationSettings populationSettings, CancellationToken cancellationToken, int?seed = null, bool addMoleculeParametersVariability = true) { return(Task.Run(() => { using (var progressUpdater = _progressManager.Create()) { var randomPopulation = createPopulationFor(populationSettings, seed); fllUpGenderQueueBasedOn(populationSettings); progressUpdater.Initialize(populationSettings.NumberOfIndividuals, PKSimConstants.UI.CreatingPopulation); //the base individual is used to retrieve the default values. var baseIndividual = populationSettings.BaseIndividual; //current individual defined as a clone of the based individual. The current individual will be the one varying var currentIndividual = _cloner.Clone(populationSettings.BaseIndividual); //cache containing all parameters changed by the create individual from the current individual. This will be used just as reference to the current parameters var allChangedByCreatedIndividualParameters = getAllCreateIndividualParametersFrom(currentIndividual); //all distributed parameters. This will be used to update the distribution for the current individual var allDistributedParameters = getAllDistributedParametersFrom(currentIndividual); var allBaseDistributedParameters = getAllDistributedParametersFrom(baseIndividual); //all individual parameters. Just an optimization to avoid call GetAllChildren for each individual var allIndividualParameters = currentIndividual.GetAllChildren <IParameter>().ToList(); int maxTotalIterations = populationSettings.NumberOfIndividuals * _maxIterations; uint numberOfTry = 0; var currentGender = _genderQueue.Dequeue(); do { cancellationToken.ThrowIfCancellationRequested(); numberOfTry++; //could not create one item in max Iteration try=>exit if (numberOfTry > _maxIterations && randomPopulation.NumberOfItems == 0) { throw new CannotCreatePopulationWithConstraintsException(_reportGenerator.StringReportFor(populationSettings)); } //create a new individual based on population settings defined by the user updateCurrentIndividualFromSettings(populationSettings, currentIndividual, allDistributedParameters, allBaseDistributedParameters, currentGender, randomPopulation.RandomGenerator); bool success = tryRandomize(currentIndividual, populationSettings, allIndividualParameters, randomPopulation.RandomGenerator); if (!success) { continue; } randomPopulation.AddIndividualValues(_individualValuesMapper.MapFrom(currentIndividual, allChangedByCreatedIndividualParameters)); currentGender = _genderQueue.Dequeue(); progressUpdater.IncrementProgress(PKSimConstants.UI.CreatingIndividualInPopulation(randomPopulation.NumberOfItems, populationSettings.NumberOfIndividuals)); } while (randomPopulation.NumberOfItems < populationSettings.NumberOfIndividuals && numberOfTry < maxTotalIterations); if (numberOfTry >= maxTotalIterations) { throw new CannotCreatePopulationWithConstraintsException(_reportGenerator.StringReportFor(populationSettings)); } if (addMoleculeParametersVariability) { _moleculeParameterVariabilityCreator.AddVariabilityTo(randomPopulation); } _moleculeOntogenyVariabilityUpdater.UpdateAllOntogenies(randomPopulation); randomPopulation.IsLoaded = true; return randomPopulation; } }, cancellationToken)); }