예제 #1
0
        public IFormula RateFor(RateKey rateKey, IFormulaCache formulaCache)
        {
            if (rateKey == null)
            {
                return(null);
            }

            //no formula cache defined. Formula should be unique by id
            if (formulaCache == null)
            {
                return(createFormula(rateKey).WithId(_idGenerator.NewId()));
            }

            if (!formulaCache.Contains(rateKey))
            {
                var formula = createFormula(rateKey);
                if (formula.IsConstant())
                {
                    return(formula);
                }

                formulaCache.Add(formula);
            }

            return(formulaCache[rateKey]);
        }
예제 #2
0
        private IFormula createFormula(RateKey rateKey)
        {
            if (rateKey.IsBlackBoxFormula)
            {
                return(_objectBaseFactory.Create <BlackBoxFormula>()
                       .WithId(rateKey)
                       .WithName(rateKey.Rate));
            }

            if (rateKey.IsTableWithOffsetFormula)
            {
                return(createTableFormulaWithOffset(rateKey));
            }

            if (rateKey.IsTableWithXArgumentFormula)
            {
                return(createTableFormulaWithArgument(rateKey));
            }

            //now it can be either dynamic formula or explicit formula
            FormulaWithFormulaString formula;

            if (rateKey.IsDynamicSumFormula)
            {
                var sumFormula = _objectBaseFactory.Create <SumFormula>();
                sumFormula.Criteria = _dynamicFormulaCriteriaRepository.CriteriaFor(rateKey).Clone();
                formula             = sumFormula;
            }
            else
            {
                formula = _objectBaseFactory.Create <ExplicitFormula>();
            }

            formula.WithFormulaString(_rateFormulaRepository.FormulaFor(rateKey))
            .WithId(rateKey)
            .WithName(rateKey.Rate);

            foreach (var rateObjectPath in _rateObjectPathsRepository.ObjectPathsFor(rateKey))
            {
                formula.AddObjectPath(rateObjectPath.Clone <IFormulaUsablePath>());
            }

            addTimeReferenceIfNeeded(formula);

            //set formula dimension if available
            var dimensionName = _rateFormulaRepository.DimensionNameFor(rateKey);
            var dimension     = _dimensionRepository.DimensionByName(dimensionName);

            formula.Dimension = dimension;

            if (formula.ObjectPaths.Any() || formula.IsAnImplementationOf <DynamicFormula>())
            {
                return(formula);
            }

            //this is actually a constant formula! Evaluate the function and return a contant formula
            return(constantFormula(formula.Calculate(null)).WithDimension(dimension));
        }
예제 #3
0
        private IFormula createTableFormulaWithOffset(RateKey rateKey)
        {
            var formula = _objectBaseFactory.Create <TableFormulaWithOffset>()
                          .WithId(rateKey)
                          .WithName(rateKey.Rate);

            var tableObjectPath  = _rateObjectPathsRepository.PathWithAlias(rateKey, CoreConstants.Alias.TABLE);
            var offsetObjectPath = _rateObjectPathsRepository.PathWithAlias(rateKey, CoreConstants.Alias.OFFSET);

            if (tableObjectPath == null || offsetObjectPath == null)
            {
                throw new ArgumentException(PKSimConstants.Error.TableFormulaWithOffsetMissingRefs(rateKey.ToString(), CoreConstants.Alias.TABLE, CoreConstants.Alias.OFFSET));
            }

            formula.AddTableObjectPath(tableObjectPath.Clone <IFormulaUsablePath>());
            formula.AddOffsetObjectPath(offsetObjectPath.Clone <IFormulaUsablePath>());

            //Table formula with offest has the same dimension as its referenced table object
            formula.Dimension = tableObjectPath.Dimension;

            return(formula);
        }
예제 #4
0
        private IFormula createTableFormulaWithArgument(RateKey rateKey)
        {
            var formula = _objectBaseFactory.Create <TableFormulaWithXArgument>()
                          .WithId(rateKey)
                          .WithName(rateKey.Rate);

            var tableObjectPath = _rateObjectPathsRepository.PathWithAlias(rateKey, CoreConstants.Alias.TABLE);
            var xArgument       = _rateObjectPathsRepository.PathWithAlias(rateKey, CoreConstants.Alias.XARG);

            if (tableObjectPath == null || xArgument == null)
            {
                throw new ArgumentException(PKSimConstants.Error.TableFormulaWithXReferenceMissingRefs(rateKey.ToString(), CoreConstants.Alias.TABLE, CoreConstants.Alias.XARG));
            }

            formula.AddTableObjectPath(tableObjectPath);
            formula.AddXArgumentObjectPath(xArgument);

            //Table formula with reference has the same dimension as its referenced table object
            formula.Dimension = tableObjectPath.Dimension;

            return(formula);
        }
예제 #5
0
 public MoleculeStartFormula(IObjectPath moleculePath, string calculationMethod, string rate)
 {
     MoleculePath = moleculePath;
     RateKey      = new RateKey(calculationMethod, rate);
 }