protected override Task Context()
        {
            _advancedParameterMapper        = A.Fake <AdvancedParameterMapper>();
            _randomPopulationFactory        = A.Fake <IRandomPopulationFactory>();
            _randomPopulationSettingsMapper = A.Fake <RandomPopulationSettingsMapper>();
            sut = new PopulationMapper(_advancedParameterMapper, _randomPopulationSettingsMapper, _randomPopulationFactory);

            _advancedParameters = new AdvancedParameterCollection();
            _advancedParameter  = new AdvancedParameter
            {
                DistributedParameter = DomainHelperForSpecs.NormalDistributedParameter()
            };

            _advancedParameters.AddAdvancedParameter(_advancedParameter);
            _advancedParameterSnapshot = new Snapshots.AdvancedParameter();
            A.CallTo(() => _advancedParameterMapper.MapToSnapshot(_advancedParameter)).Returns(_advancedParameterSnapshot);


            _population = CreateRandomPopulation();

            _settingsSnapshot = new PopulationSettings();
            A.CallTo(() => _randomPopulationSettingsMapper.MapToSnapshot(_population.Settings)).Returns(_settingsSnapshot);

            return(Task.FromResult(true));
        }
 protected override void Context()
 {
     base.Context();
     _population = A.Fake <RandomPopulation>();
     A.CallTo(() => _popSettingsPresenter.PopulationCreated).Returns(false);
     A.CallTo(() => _popSettingsPresenter.Population).Returns(_population);
 }
 protected override void Context()
 {
     base.Context();
     _population = A.Fake <RandomPopulation>();
     A.CallTo(() => _popSettingsPresenter.Population).Returns(_population);
     _popSettingsPresenter.PopulationCreationFinished += Raise.With(new PopulationCreationEventArgs(true, true));
 }
Beispiel #4
0
        public void Convert(RandomPopulation randomPopulation)
        {
            var parameterCache     = randomPopulation.IndividualPropertiesCache.ParameterValuesCache;
            var individual         = randomPopulation.FirstIndividual;
            var parameterPathCache = _containerTask.CacheAllChildren <IParameter>(individual);

            foreach (var parameterPath in parameterCache.AllParameterPaths().ToList())
            {
                var updatedPath = updatePath(parameterPath, parameterCache);
                var parameter   = parameterPathCache[updatedPath];
                if (parameter == null)
                {
                    continue;
                }

                var parameterValues = parameterCache.ParameterValuesFor(updatedPath);
                convertValues(parameterValues, parameter);
                var distributedParameter = parameter as IDistributedParameter;
                if (distributedParameter == null)
                {
                    addDefaultPercentileFor(parameterValues);
                }
                else
                {
                    addAgeDependentPercentileValues(parameterValues, randomPopulation, distributedParameter, individual);
                }
            }
        }
 protected override void Context()
 {
     base.Context();
     _anotherPopulation = A.Fake <RandomPopulation>();
     _parameter         = new AdvancedParameter();
     sut.EditPopulation(_population);
 }
Beispiel #6
0
        protected override void Context()
        {
            _moleculeParameterFactory = A.Fake <IMoleculeParameterRepository>();
            _advancedParmeterFactory  = A.Fake <IAdvancedParameterFactory>();
            _advancedParametersTask   = A.Fake <IAdvancedParametersTask>();
            _executionContext         = A.Fake <IExecutionContext>();
            sut = new MoleculeParameterVariabilityCreator(_advancedParmeterFactory, _moleculeParameterFactory, _advancedParametersTask, _executionContext);

            _randomPopulation = new RandomPopulation {
                Settings = new RandomPopulationSettings()
            };
            _randomPopulation.SetAdvancedParameters(new AdvancedParameterCollection());
            var individual = A.Fake <Individual>();

            _molecule1 = DomainHelperForSpecs.DefaultIndividualMolecule().WithName("CYP1");
            _molecule2 = DomainHelperForSpecs.DefaultIndividualMolecule().WithName("CYP2");
            A.CallTo(() => individual.AllMolecules()).Returns(new[] { _molecule1, _molecule2 });
            _randomPopulation.Settings.BaseIndividual = individual;

            A.CallTo(() => _advancedParametersTask.AddAdvancedParameter(A <IAdvancedParameter> ._, _randomPopulation))
            .Invokes(x =>
            {
                var advancedParameter = x.GetArgument <IAdvancedParameter>(0);
                _randomPopulation.AddAdvancedParameter(advancedParameter);
            })
            .Returns(new AddAdvancedParameterToContainerCommand(A.Fake <IAdvancedParameter>(), _randomPopulation, _executionContext));
        }
Beispiel #7
0
 public void Visit(RandomPopulation randomPopulation)
 {
     _metaData = new RandomPopulationMetaData();
     //no need to compress population data. This is mostly only double arrays
     serializeContentFor(randomPopulation, compress: false);
     _metaData.Properties.Data = _serializationManager.Serialize(randomPopulation.Settings);
 }
 protected override void Context()
 {
     base.Context();
     _randomPopulation          = A.Fake <RandomPopulation>();
     _randomPopulation.Settings = new RandomPopulationSettings();
     _populationSettingsDTO     = new PopulationSettingsDTO();
     A.CallTo(() => _populationSettingsMapper.MapFrom(_randomPopulation.Settings)).Returns(_populationSettingsDTO);
 }
 public override void GlobalContext()
 {
     base.GlobalContext();
     LoadProject("PopulationRange_565");
     _populationSettings = _project.All <RandomPopulation>().First().Settings;
     _population         = First <RandomPopulation>();
     _simulation         = First <PopulationSimulation>();
 }
 protected override void Context()
 {
     base.Context();
     sut = new RandomPopulation();
     sut.SetAdvancedParameters(new AdvancedParameterCollection());
     sut.Settings = new RandomPopulationSettings {
         BaseIndividual = _baseIndividual
     };
 }
 protected override void Context()
 {
     base.Context();
     _buildingBlockDTO = new ObjectBaseDTO();
     _randomPopulation = A.Fake <RandomPopulation>();
     A.CallTo(() => _view.Canceled).Returns(false);
     A.CallTo(() => _buildingBlockDTOFactory.CreateFor <Population>()).Returns(_buildingBlockDTO);
     A.CallTo(() => _popSettingsPresenter.Population).Returns(_randomPopulation);
 }
        public void Visit(RandomPopulationMetaData randomPopulationMetaData)
        {
            var population = new RandomPopulation
            {
                Settings = _serializationManager.Deserialize <RandomPopulationSettings>(randomPopulationMetaData.Properties.Data)
            };

            _buildingBlock = population;
        }
Beispiel #13
0
 public void LoadPopulation(RandomPopulation population)
 {
     _view.UpdateLayoutForEditing();
     Population             = population;
     _populationSettingsDTO = _populationSettingsMapper.MapFrom(Population.Settings);
     //do in latch since no update should be perform
     this.DoWithinLatch(updateView);
     PopulationCreated = true;
 }
Beispiel #14
0
        public override void GlobalContext()
        {
            base.GlobalContext();
            LoadProject("Population_Individual_603");

            _population    = First <RandomPopulation>();
            _individual    = First <Individual>();
            _indSimulation = First <IndividualSimulation>();
            _popSimulation = First <PopulationSimulation>();
            _formulation   = First <Formulation>();
        }
Beispiel #15
0
 protected override void Context()
 {
     base.Context();
     _molecule   = new IndividualEnzyme();
     _population = new RandomPopulation {
         Settings = new RandomPopulationSettings {
             BaseIndividual = new Individual()
         }
     };
     _addVariabilityCommand = A.Fake <IPKSimCommand>();
     A.CallTo(_moleculeParameterVariabilityCreator).WithReturnType <ICommand>().Returns(_addVariabilityCommand);
 }
Beispiel #16
0
        protected override void Context()
        {
            base.Context();
            _populationSimulation = A.Fake <PopulationSimulation>();
            _parameterValueCache  = new ParameterValuesCache();
            _parameterValueCache.Add(new[] { new ParameterValue("PATH1", 1, 0.1), new ParameterValue("PATH2", 2, 0.2) });
            _parameterValueCache.Add(new[] { new ParameterValue("PATH1", 11, 0.11), new ParameterValue("PATH2", 11, 0.22) });

            _population = CreateRandomPopulation();
            A.CallTo(() => _populationSimulation.BuildingBlock <RandomPopulation>()).Returns(_population);
            A.CallTo(() => _populationSimulation.ParameterValuesCache).Returns(_parameterValueCache);
        }
 protected override void Context()
 {
     _protein    = new IndividualOtherProtein();
     _population = new RandomPopulation {
         new AdvancedParameterCollection()
     };
     _population.Settings = new RandomPopulationSettings {
         BaseIndividual = new Individual()
     };
     _context = A.Fake <IExecutionContext>();
     sut      = new AddMoleculeToPopulationCommand(_protein, _population, _context);
 }
        protected RandomPopulation CreateRandomPopulation()
        {
            var randomPopulation = new RandomPopulation
            {
                Name        = "RandomPop",
                Description = "Random Pop description",
                Seed        = 132,
                Settings    = new RandomPopulationSettings()
            };

            randomPopulation.SetAdvancedParameters(_advancedParameters);
            return(randomPopulation);
        }
Beispiel #19
0
        protected override async Task Context()
        {
            await base.Context();

            _randomPopulation      = CreateRandomPopulation();
            _newPopulationSettings = new RandomPopulationSettings();
            _snapshot = await sut.MapToSnapshot(_randomPopulation);

            A.CallTo(() => _randomPopulationSettingsMapper.MapToModel(_snapshot.Settings)).Returns(_newPopulationSettings);
            var mappedPopulation = A.Fake <RandomPopulation>();

            mappedPopulation.SetAdvancedParameters(new AdvancedParameterCollection());
            A.CallTo(() => _randomPopulationFactory.CreateFor(_newPopulationSettings, CancellationToken.None, _snapshot.Seed, false)).Returns(mappedPopulation);
        }
Beispiel #20
0
 protected override void Context()
 {
     _buildingBlockTask         = A.Fake <IBuildingBlockTask>();
     _executionContext          = A.Fake <IExecutionContext>();
     _project                   = A.Fake <PKSimProject>();
     _population                = A.Fake <RandomPopulation>();
     _randomPopulationPresenter = A.Fake <ICreateRandomPopulationPresenter>();
     _applicationController     = A.Fake <IApplicationController>();
     A.CallTo(() => _applicationController.Start <ICreateRandomPopulationPresenter>()).Returns(_randomPopulationPresenter);
     A.CallTo(() => _randomPopulationPresenter.BuildingBlock).Returns(_population);
     A.CallTo(() => _buildingBlockTask.TypeFor(_population)).Returns("pop");
     A.CallTo(() => _executionContext.CurrentProject).Returns(_project);
     sut = new PopulationTask(_executionContext, _buildingBlockTask, _applicationController);
 }
 protected override void Context()
 {
     _view = A.Fake <IAdvancedParametersView>();
     _allConstantParameterGroupsPresenter = A.Fake <IPopulationParameterGroupsPresenter>();
     _advancedParameterGroupsPresenter    = A.Fake <IPopulationParameterGroupsPresenter>();
     _advancedParameterPresenter          = A.Fake <IAdvancedParameterPresenter>();
     _entityPathResolver     = A.Fake <IEntityPathResolver>();
     _advancedParametersTask = A.Fake <IAdvancedParametersTask>();
     _eventPublisher         = A.Fake <IEventPublisher>();
     A.CallTo(() => _allConstantParameterGroupsPresenter.View).Returns(A.Fake <IPopulationParameterGroupsView>());
     A.CallTo(() => _advancedParameterGroupsPresenter.View).Returns(A.Fake <IPopulationParameterGroupsView>());
     A.CallTo(() => _advancedParameterPresenter.View).Returns(A.Fake <IAdvancedParameterView>());
     _population            = A.Fake <RandomPopulation>();
     _commandRegister       = A.Fake <ICommandCollector>();
     _allConstantParameters = new List <IParameter>();
     _allAdvancedParameters = new List <IParameter>();
     _allParameters         = new List <IParameter>();
     A.CallTo(() => _population.AllIndividualParameters()).Returns(_allParameters);
     A.CallTo(() => _population.AllConstantParameters(_entityPathResolver)).Returns(_allConstantParameters);
     A.CallTo(() => _population.AllAdvancedParameters(_entityPathResolver)).Returns(_allAdvancedParameters);
     _para1                                 = A.Fake <IParameter>().WithName("_para1");
     _para1.Visible                         = true;
     _para1.CanBeVaried                     = true;
     _para1.CanBeVariedInPopulation         = true;
     _para1.Editable                        = true;
     _para2                                 = A.Fake <IParameter>().WithName("_para2");
     _para2.Editable                        = true;
     _para2.Visible                         = true;
     _para2.CanBeVaried                     = true;
     _para2.CanBeVariedInPopulation         = true;
     _advancedPara1                         = A.Fake <IParameter>().WithName("_advancedPara1");
     _advancedPara1.Visible                 = true;
     _advancedPara1.Editable                = true;
     _advancedPara1.CanBeVaried             = true;
     _advancedPara1.CanBeVariedInPopulation = true;
     _pathPara1                             = "_pathPara1";
     _pathPara2                             = "_pathPara2";
     _pathAdvancedPara1                     = "_pathAdvancedPara1";
     _allParameters.AddRange(new[] { _para1, _para2, _advancedPara1 });
     _allConstantParameters.AddRange(new[] { _para1, _para2 });
     _allAdvancedParameters.AddRange(new[] { _advancedPara1 });
     A.CallTo(() => _entityPathResolver.PathFor(_para1)).Returns(_pathPara1);
     A.CallTo(() => _entityPathResolver.PathFor(_para2)).Returns(_pathPara2);
     A.CallTo(() => _entityPathResolver.PathFor(_advancedPara1)).Returns(_pathAdvancedPara1);
     _representationInfoRepository = A.Fake <IRepresentationInfoRepository>();
     sut = new PopulationAdvancedParametersPresenter(_view, _entityPathResolver, _allConstantParameterGroupsPresenter, _advancedParameterGroupsPresenter, _advancedParameterPresenter,
                                                     _advancedParametersTask, _eventPublisher);
     sut.InitializeWith(_commandRegister);
 }
Beispiel #22
0
 protected override void Context()
 {
     _workspace                     = A.Fake <IWorkspace>();
     _view                          = A.Fake <IEditRandomPopulationView>();
     _subPresenterManager           = SubPresenterHelper.Create <IPopulationItemPresenter>();
     _popSettingsPresenter          = _subPresenterManager.CreateFake(RamdomPopulationItems.Settings);
     _popAdvancedParameterPresenter = _subPresenterManager.CreateFake(RamdomPopulationItems.AdvancedParameters);
     _popDistributionPresenter      = _subPresenterManager.CreateFake(RamdomPopulationItems.ParameterDistribution);
     //This line is required because of some generic issues
     A.CallTo(_subPresenterManager).WithReturnType <IPopulationSettingsPresenter <RandomPopulation> >().Returns(_popSettingsPresenter);
     _randomPopulation = A.Fake <RandomPopulation>();
     A.CallTo(() => _popSettingsPresenter.Population).Returns(_randomPopulation);
     sut = new EditRandomPopulationPresenter(_view, _subPresenterManager);
     sut.InitializeWith(_workspace);
 }
Beispiel #23
0
        protected RandomPopulation CreateRandomPopulation()
        {
            var pop = new RandomPopulation();

            pop.Settings = new RandomPopulationSettings();
            var cache = new PathCache <IParameter>(_entityPathResolver);

            cache.Add("PATH1", DomainHelperForSpecs.ConstantParameterWithValue(4).WithName("PARA1"));
            cache.Add("PATH2", DomainHelperForSpecs.ConstantParameterWithValue(5).WithName("PARA2"));
            pop.IndividualPropertiesCache.ParameterValuesCache.Add(new[] { new ParameterValue("PATH1", 1, 0.1), new ParameterValue("PATH2", 2, 0.2) });
            pop.IndividualPropertiesCache.ParameterValuesCache.Add(new[] { new ParameterValue("PATH1", 11, 0.11), new ParameterValue("PATH2", 11, 0.22) });
            pop.Settings.BaseIndividual = DomainHelperForSpecs.CreateIndividual();
            A.CallTo(() => _containerTask.CacheAllChildren <IParameter>(pop.Settings.BaseIndividual)).Returns(cache);

            return(pop);
        }
Beispiel #24
0
        public T EvolveBest()
        {
            var population = this.PopulationControl.CreateInstances(this.InitialPopulation);

            // population.Sort(using comparator);

            while (true)             // not terminated ...
            {
                ISelectPopulation <T> select = new RandomPopulation <T>(this.PopulationSize);

                // parent selection process - best x, random x, best x out of random y
                var fitParents = select.Select(population);
            }

            return(default(T));
        }
Beispiel #25
0
        protected override void Context()
        {
            base.Context();
            _populationSimulation            = new PopulationSimulation();
            _populationSimulation.Model      = new OSPSuite.Core.Domain.Model();
            _populationSimulation.Model.Root = new Container();
            var randomPopulation = new RandomPopulation();

            _populationSimulation.AddUsedBuildingBlock(new UsedBuildingBlock("id", PKSimBuildingBlockType.Population)
            {
                BuildingBlock = randomPopulation
            });
            _populationSimulation.SetAdvancedParameters(new AdvancedParameterCollection());
            _populationSimulation.Add(new Parameter().WithName("Param1"));
            _advancedParameter = new AdvancedParameter {
                ParameterPath = "OLD|Param1"
            };
            _populationSimulation.AddAdvancedParameter(_advancedParameter);
            _populationSimulation.Name = "NEW";
        }
Beispiel #26
0
        public static void Main(string[] args)
        {
            var files = new List <string> {
                "berlin52", "kroA100", "kroA150", "kroA200", "fl417"
            };
            var stopwatch = new Stopwatch();

            Console.WriteLine("");

            files.ForEach(file =>
            {
                var tsp = TSP.FromFile(file);

                stopwatch.Start();
                var randomPopulation = new RandomPopulation(10000, tsp);
                stopwatch.Stop();
                Console.WriteLine("Random for " + file);
                Console.WriteLine("Best: " + randomPopulation.CalculateBestDistance());
                Console.WriteLine("Worst: " + randomPopulation.CalculateWorstDistance());
                Console.WriteLine("Average: " + randomPopulation.CalculateAverageDistance());
                Console.WriteLine("Time elapsed: " + stopwatch.ElapsedMilliseconds / 1000.0 + " s\n");

                stopwatch.Start();
                var greedyPopulation = new GreedyPopulation(tsp);
                stopwatch.Stop();
                Console.WriteLine("Greedy for " + file);
                Console.WriteLine("Best: " + greedyPopulation.CalculateBestDistance());
                Console.WriteLine("Worst: " + greedyPopulation.CalculateWorstDistance());
                Console.WriteLine("Average: " + greedyPopulation.CalculateAverageDistance());
                Console.WriteLine("Time elapsed: " + stopwatch.ElapsedMilliseconds / 1000.0 + " s\n");

                Console.WriteLine("----------------------------\n");
            });

            CreateHostBuilder(args).Build().Run();
        }
        protected override void Context()
        {
            base.Context();
            _population = A.Fake <RandomPopulation>().WithName("POP");
            A.CallTo(() => _population.NumberOfItems).Returns(7);

            _baseIndividual  = A.Fake <Individual>();
            _cloneIndividual = A.Fake <Individual>();
            var organism = new Organism();

            A.CallTo(() => _cloneIndividual.Organism).Returns(organism);
            organism.Add(DomainHelperForSpecs.ConstantParameterWithValue(40).WithName(CoreConstants.Parameters.WEIGHT));
            organism.Add(DomainHelperForSpecs.ConstantParameterWithValue(50).WithName(CoreConstants.Parameters.HEIGHT));
            organism.Add(DomainHelperForSpecs.ConstantParameterWithValue(60).WithName(CoreConstants.Parameters.BMI));
            organism.Add(DomainHelperForSpecs.ConstantParameterWithValue(70).WithName(CoreConstants.Parameters.AGE));
            organism.Add(DomainHelperForSpecs.ConstantParameterWithValue(80).WithName(Constants.Parameters.GESTATIONAL_AGE));

            _constParam1 = DomainHelperForSpecs.ConstantParameterWithValue(1).WithName("P1");
            _constParam2 = DomainHelperForSpecs.ConstantParameterWithValue(1).WithName("P2");

            //create a reference to another parameter to ensure that formula parameter are not overwritten if nothing has changed
            _formulaParameter = new PKSimParameter().WithName("P3").WithFormula(new ExplicitFormula("P2*2"));
            _formulaParameter.Formula.AddObjectPath(new FormulaUsablePath("..", "P2").WithAlias("P2"));
            var container1 = new Container {
                _constParam1, _constParam2, _formulaParameter
            };

            _indParam1 = DomainHelperForSpecs.ConstantParameterWithValue(1).WithName("P1");
            _indParam2 = DomainHelperForSpecs.ConstantParameterWithValue(2).WithName("P2");
            _indParam3 = new PKSimParameter().WithName("P3").WithFormula(new ExplicitFormula("P2*2"));
            _indParam3.Formula.AddObjectPath(new FormulaUsablePath("..", "P2").WithAlias("P2"));
            _indParam4 = DomainHelperForSpecs.ConstantParameterWithValue(4).WithName("P4");
            var container2 = new Container {
                _indParam1, _indParam2, _indParam3, _indParam4
            };

            A.CallTo(() => _executionContext.Clone(_baseIndividual)).Returns(_cloneIndividual);
            A.CallTo(() => _population.FirstIndividual).Returns(_baseIndividual);
            //put explicit formula first
            A.CallTo(() => _population.AllVectorialParameters(_entityPathResolver)).Returns(new[] { _formulaParameter, _constParam1, _constParam2 });
            A.CallTo(() => _cloneIndividual.GetAllChildren <IParameter>()).Returns(new[] { _indParam1, _indParam2, _indParam3, _indParam4 });

            A.CallTo(() => _entityPathResolver.PathFor(_constParam1)).Returns("PATH1");
            A.CallTo(() => _entityPathResolver.PathFor(_constParam2)).Returns("PATH2");
            A.CallTo(() => _entityPathResolver.PathFor(_formulaParameter)).Returns("PATH3");

            A.CallTo(() => _entityPathResolver.PathFor(_indParam1)).Returns("PATH1");
            A.CallTo(() => _entityPathResolver.PathFor(_indParam2)).Returns("PATH2");
            A.CallTo(() => _entityPathResolver.PathFor(_indParam3)).Returns("PATH3");
            A.CallTo(() => _entityPathResolver.PathFor(_indParam4)).Returns("PATH4");

            A.CallTo(() => _population.AllValuesFor("PATH1")).Returns(new[] { 10d, 11, 12, 13, 14, 15, 16 });
            A.CallTo(() => _population.AllValuesFor("PATH2")).Returns(new[] { 20d, 21, 22, 23, 24, 25, 26 });
            A.CallTo(() => _population.AllValuesFor("PATH3")).Returns(new[] { 40d, 42, 44, 46, 48, 50, 52 });

            _templateIndividual1.Name = "POP-3";

            _addIndividualCommand = A.Fake <IPKSimCommand>();
            A.CallTo(() => _individualTask.AddToProject(_cloneIndividual, false, false)).Returns(_addIndividualCommand);

            A.CallTo(() => _executionContext.AddToHistory(A <ICommand> ._))
            .Invokes(x => _overallCommand = x.GetArgument <ICommand>(0));
        }
Beispiel #28
0
 public void Visit(RandomPopulation population)
 {
     Visit(population.FirstIndividual);
 }
Beispiel #29
0
        protected override Task Context()
        {
            _solverSettingsMapper               = A.Fake <SolverSettingsMapper>();
            _outputSchemaMapper                 = A.Fake <OutputSchemaMapper>();
            _outputSelectionMapper              = A.Fake <OutputSelectionsMapper>();
            _parameterMapper                    = A.Fake <ParameterMapper>();
            _compoundPropertiesMapper           = A.Fake <CompoundPropertiesMapper>();
            _advancedParameterMapper            = A.Fake <AdvancedParameterMapper>();
            _eventMappingMapper                 = A.Fake <EventMappingMapper>();
            _observerSetMappingMapper           = A.Fake <ObserverSetMappingMapper>();
            _curveChartMapper                   = A.Fake <SimulationTimeProfileChartMapper>();
            _processMappingMapper               = A.Fake <ProcessMappingMapper>();
            _simulationFactory                  = A.Fake <ISimulationFactory>();
            _executionContext                   = A.Fake <IExecutionContext>();
            _simulationModelCreator             = A.Fake <ISimulationModelCreator>();
            _simulationBuildingBlockUpdater     = A.Fake <ISimulationBuildingBlockUpdater>();
            _modelPropertiesTask                = A.Fake <IModelPropertiesTask>();
            _simulationRunner                   = A.Fake <ISimulationRunner>();
            _populationAnalysisChartMapper      = A.Fake <PopulationAnalysisChartMapper>();
            _simulationParameterOriginIdUpdater = A.Fake <ISimulationParameterOriginIdUpdater>();
            _logger             = A.Fake <ILogger>();
            _containerTask      = A.Fake <IContainerTask>();
            _entityPathResolver = A.Fake <IEntityPathResolver>();

            sut = new SimulationMapper(_solverSettingsMapper, _outputSchemaMapper,
                                       _outputSelectionMapper, _compoundPropertiesMapper, _parameterMapper,
                                       _advancedParameterMapper, _eventMappingMapper, _observerSetMappingMapper, _curveChartMapper,
                                       _populationAnalysisChartMapper, _processMappingMapper,
                                       _simulationFactory, _executionContext, _simulationModelCreator,
                                       _simulationBuildingBlockUpdater, _modelPropertiesTask,
                                       _simulationRunner, _simulationParameterOriginIdUpdater,
                                       _logger, _containerTask, _entityPathResolver
                                       );

            _project    = new PKSimProject();
            _individual = new Individual {
                Name = "IND", Id = "IND"
            };
            _compound = new Compound {
                Name = "COMP", Id = "COMP"
            };
            _observerSet = new ObserverSet {
                Name = "OBS_SET", Id = "OBS_SET"
            };
            _protocol = new SimpleProtocol {
                Name = "PROT", Id = "PROT"
            };
            _inductionProcess = new InductionProcess().WithName("Interaction process");
            _compound.AddProcess(_inductionProcess);


            _event = new PKSimEvent {
                Name = "Event"
            };
            _population = new RandomPopulation()
            {
                Name = "POP"
            };
            _observedData = new DataRepository("OBS_ID").WithName("OBS");
            _project.AddBuildingBlock(_individual);
            _project.AddBuildingBlock(_compound);
            _project.AddBuildingBlock(_event);
            _project.AddBuildingBlock(_population);
            _project.AddBuildingBlock(_observerSet);
            _project.AddObservedData(_observedData);

            _simulationProperties = new SimulationProperties
            {
                ModelProperties = new ModelProperties
                {
                    ModelConfiguration = new ModelConfiguration {
                        ModelName = "4Comp"
                    }
                }
            };
            _interactionSelection = new InteractionSelection {
                ProcessName = _inductionProcess.Name
            };
            _noInteractionSelection = new InteractionSelection {
                MoleculeName = "CYP2D6"
            };

            _simulationProperties.InteractionProperties.AddInteraction(_interactionSelection);
            _simulationProperties.InteractionProperties.AddInteraction(_noInteractionSelection);

            _settings      = new SimulationSettings();
            _rootContainer = new Container().WithName("Sim");
            _model         = new OSPSuite.Core.Domain.Model {
                Root = _rootContainer
            };

            _individualSimulation = new IndividualSimulation
            {
                Name               = "S1",
                Properties         = _simulationProperties,
                SimulationSettings = _settings,
                Description        = "Simulation Description",
                Model              = _model
            };

            _simulationTimeProfile         = new SimulationTimeProfileChart();
            _snapshotSimulationTimeProfile = new CurveChart();
            _individualSimulation.AddAnalysis(_simulationTimeProfile);

            A.CallTo(() => _curveChartMapper.MapToSnapshot(_simulationTimeProfile)).Returns(_snapshotSimulationTimeProfile);


            _populationSimulation = new PopulationSimulation
            {
                Properties         = _simulationProperties,
                SimulationSettings = _settings,
                Model = _model
            };

            _advancedParameterCollection       = new AdvancedParameterCollection();
            _populationSimulationAnalysisChart = new BoxWhiskerAnalysisChart();
            _populationSimulation.SetAdvancedParameters(_advancedParameterCollection);
            _populationSimulation.AddAnalysis(_populationSimulationAnalysisChart);
            _populationSimulation.AddUsedBuildingBlock(new UsedBuildingBlock("IndTemplateId", PKSimBuildingBlockType.Individual)
            {
                BuildingBlock = _individual
            });

            _snapshotPopulationAnalysisChart = new Snapshots.PopulationAnalysisChart();

            A.CallTo(() => _populationAnalysisChartMapper.MapToSnapshot(_populationSimulationAnalysisChart)).Returns(_snapshotPopulationAnalysisChart);

            _snapshotInteraction = new CompoundProcessSelection();
            A.CallTo(() => _processMappingMapper.MapToSnapshot(_interactionSelection)).Returns(_snapshotInteraction);
            _snapshotInteraction.CompoundName = _compound.Name;
            _snapshotInteraction.Name         = _inductionProcess.Name;

            _noSelectionSnapshotInteraction = new CompoundProcessSelection();
            A.CallTo(() => _processMappingMapper.MapToSnapshot(_noInteractionSelection)).Returns(_noSelectionSnapshotInteraction);
            _noSelectionSnapshotInteraction.MoleculeName = _noInteractionSelection.MoleculeName;

            _compoundProperties         = new CompoundProperties();
            _snapshotCompoundProperties = new Snapshots.CompoundProperties {
                Name = _compound.Name
            };
            _individualSimulation.Properties.AddCompoundProperties(_compoundProperties);

            _eventMapping = new EventMapping();
            _individualSimulation.EventProperties.AddEventMapping(_eventMapping);

            _observerSetMapping = new ObserverSetMapping();
            _individualSimulation.ObserverSetProperties.AddObserverSetMapping(_observerSetMapping);

            A.CallTo(() => _compoundPropertiesMapper.MapToSnapshot(_compoundProperties, _project)).Returns(_snapshotCompoundProperties);


            _eventSelection = new EventSelection
            {
                Name = _event.Name,
            };

            _observerSetSelection = new ObserverSetSelection
            {
                Name = _observerSet.Name,
            };

            _individualSimulation.AddUsedBuildingBlock(new UsedBuildingBlock("IndTemplateId", PKSimBuildingBlockType.Individual)
            {
                BuildingBlock = _individual,

                Altered = true
            });

            _individualSimulation.AddUsedBuildingBlock(new UsedBuildingBlock("CompTemplateId", PKSimBuildingBlockType.Compound)
            {
                BuildingBlock = _compound
            });

            _individualSimulation.AddUsedBuildingBlock(new UsedBuildingBlock("ProtTemplateId", PKSimBuildingBlockType.Protocol)
            {
                BuildingBlock = _protocol
            });

            _individualSimulation.AddUsedBuildingBlock(new UsedBuildingBlock("ObserveSetTemplateId", PKSimBuildingBlockType.ObserverSet)
            {
                BuildingBlock = _observerSet
            });

            _populationSimulation.AddUsedBuildingBlock(new UsedBuildingBlock("PopTemplateId", PKSimBuildingBlockType.Population)
            {
                BuildingBlock = _population
            });


            _individualSimulation.AddUsedObservedData(_observedData);

            A.CallTo(() => _eventMappingMapper.MapToSnapshot(_eventMapping, _project)).Returns(_eventSelection);
            A.CallTo(() => _observerSetMappingMapper.MapToSnapshot(_observerSetMapping, _project)).Returns(_observerSetSelection);

            _outputSelectionSnapshot = new OutputSelections();
            A.CallTo(() => _outputSelectionMapper.MapToSnapshot(_individualSimulation.OutputSelections)).Returns(_outputSelectionSnapshot);

            A.CallTo(() => _processMappingMapper.MapToModel(_snapshotInteraction, _inductionProcess)).Returns(_interactionSelection);

            return(_completed);
        }
Beispiel #30
0
        private void addAgeDependentPercentileValues(ParameterValues parameterValues, RandomPopulation randomPopulation, IDistributedParameter parameter, Individual individual)
        {
            var originData     = individual.OriginData.Clone();
            var allAges        = randomPopulation.AllValuesFor(_entityPathResolver.PathFor(individual.Organism.Parameter(CoreConstants.Parameter.AGE))).ToList();
            var allGender      = randomPopulation.AllGenders.ToList();
            var allValues      = randomPopulation.AllValuesFor(_entityPathResolver.PathFor(parameter)).ToList();
            var allPercentiles = new double[allValues.Count].InitializeWith(0);

            originData.GestationalAge = CoreConstants.NOT_PRETERM_GESTATIONAL_AGE_IN_WEEKS;

            //cache female and male distributions
            originData.Gender = _genderRepository.Female;
            var allFemalesDistributions = _parameterQuery.ParameterDistributionsFor(parameter.ParentContainer, originData, p => string.Equals(p.ParameterName, parameter.Name)).ToList();

            originData.Gender = _genderRepository.Male;
            var allMaleDistributions = _parameterQuery.ParameterDistributionsFor(parameter.ParentContainer, originData, p => string.Equals(p.ParameterName, parameter.Name)).ToList();

            for (int individualIndex = 0; individualIndex < randomPopulation.NumberOfItems; individualIndex++)
            {
                //create orgin data for individual i
                originData.Age = allAges[individualIndex];
                var distributions = allFemalesDistributions;
                if (_genderRepository.Male == allGender[individualIndex])
                {
                    distributions = allMaleDistributions;
                }

                if (distributions.Count == 0)
                {
                    allPercentiles[individualIndex] = CoreConstants.DEFAULT_PERCENTILE;
                }
                else
                {
                    allPercentiles[individualIndex] = percentileFrom(distributions, originData, allValues[individualIndex]);
                }
            }
            addPercentileValues(parameterValues, allPercentiles);
        }