예제 #1
0
        public ICommand ExtractIndividualsFromPopulationCommand(Population population, IndividualExtractionOptions individualExtractionOptions)
        {
            if (population.IsAnImplementationOf <MoBiPopulation>())
            {
                throw new PKSimException(PKSimConstants.Error.CannotExtractIndividualFrom(_executionContext.TypeFor(population)));
            }

            var allPopulationParameters = population.AllVectorialParameters(_entityPathResolver).ToList();

            var allDistributedParameters = allPopulationParameters.Where(x => x.Formula.IsDistributed()).ToList();
            var allConstantParameters    = allPopulationParameters.Where(x => x.Formula.IsConstant()).ToList();
            var allRemainingParameters   = allPopulationParameters.Except(allConstantParameters).Except(allDistributedParameters);

            //Update constant parameters first, then distributed and last all others. This ensures that formula parameters in the extracted individuals are not updated with a constant value
            var allParametersOrderedByFormulaType = allConstantParameters.Union(allDistributedParameters).Union(allRemainingParameters).ToList();

            var addCommands = individualExtractionOptions.IndividualIds.Distinct()
                              .Select(individualId => extractIndividualFrom(population, individualId, allParametersOrderedByFormulaType, individualExtractionOptions))
                              .ToList();

            var overallCommand = new PKSimMacroCommand
            {
                CommandType       = PKSimConstants.Command.CommandTypeAdd,
                ObjectType        = PKSimConstants.ObjectTypes.Population,
                Description       = PKSimConstants.Command.ExtractingIndividualsDescription(population.Name),
                BuildingBlockName = population.Name,
                BuildingBlockType = PKSimConstants.ObjectTypes.Population
            };

            overallCommand.AddRange(addCommands);

            return(overallCommand);
        }
예제 #2
0
        private string createIndividualName(Population population, int individualId, IndividualExtractionOptions options)
        {
            var proposedName = options.GenerateIndividualName(population.Name, individualId);

            return(_containerTask.CreateUniqueName(_buildingBlockRepository.All <Individual>(), proposedName, canUseBaseName: true));
        }
예제 #3
0
 public void ExtractIndividualsFrom(Population population, IndividualExtractionOptions individualExtractionOptions)
 {
     _executionContext.AddToHistory(ExtractIndividualsFromPopulationCommand(population, individualExtractionOptions));
 }
예제 #4
0
        private IPKSimCommand extractIndividualFrom(Population population, int individualId, IEnumerable <IParameter> allParametersOrderedByFormulaType, IndividualExtractionOptions individualExtractionOptions)
        {
            if (population.NumberOfItems <= individualId)
            {
                return(new PKSimEmptyCommand());
            }

            var individual = _executionContext.Clone(population.FirstIndividual)
                             .WithName(createIndividualName(population, individualId, individualExtractionOptions));

            var extractedIndividualParameterCache = new PathCache <IParameter>(_entityPathResolver).For(individual.GetAllChildren <IParameter>());

            foreach (var parameter in allParametersOrderedByFormulaType)
            {
                updateParameterValue(population, individualId, parameter, extractedIndividualParameterCache);
            }

            var originData = individual.OriginData;

            updateOriginDataFromIndividual(individual, originData);

            // TODO
//         originData.Gender = population.AllGenders[individualId];
//         originData.SpeciesPopulation = population.AllRaces[individualId];

            return(_individualTask.AddToProject(individual, editBuildingBlock: false, addToHistory: false));
        }