Пример #1
0
        public ParameterValue[] CreateIndividual(OriginData matlabOriginData, IEnumerable <MoleculeOntogeny> moleculeOntogenies)
        {
            var originData              = originDataFrom(matlabOriginData);
            var individual              = _individualFactory.CreateAndOptimizeFor(originData);
            var individualProperties    = _individualPropertiesMapper.MapFrom(individual);
            var allIndividualParameters = individualProperties.ParameterValues.ToList();

            allIndividualParameters.AddRange(_ontogenyFactorsRetriever.FactorsFor(originData, moleculeOntogenies));
            return(allIndividualParameters.ToArray());
        }
Пример #2
0
        public Task <RandomPopulation> CreateFor(RandomPopulationSettings populationSettings, CancellationToken cancellationToken)
        {
            Task <RandomPopulation> task = Task.Run(() =>
            {
                using (var progressUpdater = _progressManager.Create())
                {
                    var randomPopulation = createPopulationFor(populationSettings);

                    fllUpGenderQueueBasedOn(populationSettings);
                    progressUpdater.Initialize(populationSettings.NumberOfIndividuals, PKSimConstants.UI.CreatingPopulation);

                    _randomGenerator = randomPopulation.RandomGenerator;

                    //the base indiviudal 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 udpate the distribution for the current individual
                    var allDistributedParameters    = getAllDistributedParametersFrom(currentIndividual);
                    var allBaseDistributedParamters = getAllDistributedParametersFrom(baseIndividual);

                    //all individual parameters. Just an optimiztion 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, allBaseDistributedParamters, currentGender);

                        bool success = tryRandomize(currentIndividual, populationSettings, allIndividualParameters);
                        if (!success)
                        {
                            continue;
                        }

                        randomPopulation.AddIndividualProperties(_individualPropertiesMapper.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));
                    }

                    addUserDefinedVariabilityAndOntogenyForMolecules(randomPopulation);
                    randomPopulation.IsLoaded = true;
                    return(randomPopulation);
                }
            }, cancellationToken);

            return(task);
        }