Exemplo n.º 1
0
 private Model.DistributionMetaData modelDistributionDataFrom(DistributionMetaData distributionMetaData)
 {
     return(new Model.DistributionMetaData
     {
         Mean = distributionMetaData.Mean,
         Deviation = distributionMetaData.Deviation,
         Distribution = DistributionTypes.ById(distributionMetaData.Distribution)
     });
 }
Exemplo n.º 2
0
        public IEnumerable <DistributionType> AllDistributions(AdvancedParameterDTO advancedParameterDTO)
        {
            var allDistributions = DistributionTypes.All().ToList();

            if (advancedParameterDTO.DistributionType != DistributionTypes.Unknown)
            {
                allDistributions.Remove(DistributionTypes.Unknown);
            }

            return(allDistributions);
        }
Exemplo n.º 3
0
        protected override async Task Context()
        {
            await base.Context();

            _snapshot = await sut.MapToSnapshot(_advancedParameter);

            _parameter = DomainHelperForSpecs.ConstantParameterWithValue(5);
            _mappedAdvancedParameter = new AdvancedParameter {
                DistributedParameter = DomainHelperForSpecs.NormalDistributedParameter()
            };
            _pathCache = new PathCacheForSpecs <IParameter> {
                { _advancedParameter.ParameterPath, _parameter }
            };
            A.CallTo(() => _advancedParameterFactory.Create(_parameter, DistributionTypes.ById(_snapshot.DistributionType))).Returns(_mappedAdvancedParameter);
        }
Exemplo n.º 4
0
        public override async Task <ModelAdvancedParameter> MapToModel(SnapshotAdvancedParameter snapshot, PathCache <IParameter> allParameters)
        {
            var parameter = allParameters[snapshot.Name];

            if (parameter == null)
            {
                _logger.AddWarning(PKSimConstants.Error.SnapshotParameterNotFound(snapshot.Name));
                return(null);
            }

            var advancedParameter = _advancedParameterFactory.Create(parameter, DistributionTypes.ById(snapshot.DistributionType));

            advancedParameter.Seed = snapshot.Seed;

            await UpdateParametersFromSnapshot(snapshot, advancedParameter.DistributedParameter);

            return(advancedParameter);
        }
Exemplo n.º 5
0
        /// <summary>
        /// distribute the input based on the distribution type specified.
        /// </summary>
        /// <param name="distributionType"></param>
        public void DistributeInput(DistributionTypes distributionType)
        {
            #region Sanity Checks
            if ((this.mtObjects == null) || (this.mtObjects.Count == 0))
            {
                throw new ArgumentNullException("mtObjects is null or empty");
            }

            if ((this.mainInputList == null) || (this.mainInputList.Count == 0))
            {
                throw new ArgumentNullException("mainInputList is null or empty");
            }
            #endregion Sanity Checks

            int numRecords = this.MainInputList.Count;
            int numThreads = (numRecords < this.mtObjects.Count) ? numRecords : this.mtObjects.Count;

            string s = string.Format("Distributing {0} records among {1} threads using {2} distribution type.",
                                     numRecords, numThreads, distributionType);
            RaiseMasterWorkStatus(s, THREADNAME, 0, 0);

            switch (distributionType)
            {
            case DistributionTypes.RoundRobin:
                for (int i = 0; i < numThreads; i++)
                {
                    this.mtObjects[i].InputList = new List <T>();
                }

                for (int i = 0; i < numRecords; i++)
                {
                    int idx = i % numThreads;
                    this.mtObjects[idx].InputList.Add(this.mainInputList[i]);
                }
                break;

            case DistributionTypes.Evenly:
                #region Codes to distribute input evenly

                /*
                 * distribute records evenly amount the total number of threads.
                 * The remainder is spread out even among the threads.
                 * */
            {
                int recordPerGroup = numRecords / numThreads;
                int remainder      = numRecords % numThreads;
                int firstIndex     = 0;

                for (int i = 0; i < numThreads; i++)
                {
                    int totalRecords = recordPerGroup;

                    // spread the remainders to the top threads
                    if (remainder > 0)
                    {
                        totalRecords++;
                        remainder--;
                    }

                    this.mtObjects[i].InputList = this.mainInputList.GetRange(firstIndex, totalRecords);
                    this.mtObjects[i].Offset    = firstIndex;
                    firstIndex += totalRecords;
                }
            }

                /*{
                 *      // calculate the record per group.
                 *      int recordPerGroup = numRecords / numThreads;
                 *      int reminder = numRecords % numThreads;
                 *
                 *      for (int i = 0; i < numThreads; i++)
                 *      {
                 *              int totalRecords;
                 *              int firstIndex;
                 *
                 *              firstIndex = i * recordPerGroup;
                 *              totalRecords = recordPerGroup;
                 *
                 *              // last thread process the remainder too.
                 *              if (i + 1 == numThreads)
                 *                      totalRecords += reminder;
                 *
                 *              this.mtObjects[i].InputList = this.mainInputList.GetRange(firstIndex, totalRecords);
                 *
                 *              // store this offset for MergeInput()
                 *              this.mtObjects[i].Offset = firstIndex;
                 *      }
                 * }*/
                #endregion Codes to distribute input evenly
                break;

            default:
                throw new ArgumentOutOfRangeException("distributeType=" + distributionType.ToString());
            }

            inputDistributed = true;
        }
Exemplo n.º 6
0
 public override object ConvertFrom(string attributeValue, SerializationContext context)
 {
     return(DistributionTypes.ById(attributeValue));
 }