Beispiel #1
0
        protected IFormulaUsablePath CreateAlwaysAbsolutePaths(IObjectBase objectBase, IFormulaUsable formulaUsable)
        {
            if (formulaUsable.IsAtMolecule())
            {
                return(_objectPathFactory.CreateAbsoluteFormulaUsablePath(formulaUsable));
            }

            return(CreateFormulaUsablePathFrom(new[] { getReactionNameFor(formulaUsable), objectBase.Name }, formulaUsable));
        }
        protected override void Context()
        {
            var organism = new Container().WithName("Organism");

            _objectPathFactory = new ObjectPathFactory(new AliasCreator());
            _fuParameter       = new Parameter().WithName("fu").WithValue(0.5);

            organism.Add(_fuParameter);
            var liver       = new Container().WithName("Liver").WithParentContainer(organism);
            var liverVolume = new Parameter().WithName("Volume").WithValue(10).WithParentContainer(liver);
            var f_vas_liver = new Parameter().WithName("f_vas").WithValue(0.1);

            liver.Add(f_vas_liver);

            var kidney       = new Container().WithName("Kidney").WithParentContainer(organism);
            var kidneyVolume = new Parameter().WithName("Volume").WithValue(20).WithParentContainer(kidney);

            kidney.Add(new Parameter().WithName("f_vas").WithValue(0.2));

            sut               = new SumFormula();
            sut.Criteria      = Create.Criteria(x => x.With("Volume"));
            sut.Variable      = "V";
            sut.FormulaString = "fu * V_#i * f_vas_#i";
            sut.AddObjectPath(_objectPathFactory.CreateRelativeFormulaUsablePath(liverVolume, f_vas_liver).WithAlias("f_vas_#i"));
            sut.AddObjectPath(_objectPathFactory.CreateAbsoluteFormulaUsablePath(_fuParameter).WithAlias("fu"));

            sut.Dimension = new Dimension(new BaseDimensionRepresentation(), "dim1", "unit1");

            _allFormulaUsable = organism.GetAllChildren <IFormulaUsable>().ToEntityDescriptorMapList();

            _objectBaseFactory = A.Fake <IObjectBaseFactory>();
            A.CallTo(() => _objectBaseFactory.Create <ExplicitFormula>()).Returns(new ExplicitFormula());
        }
Beispiel #3
0
        private void addDynamicVariablesToFormula(ExplicitFormula explicitFormula, StringBuilder stringBuilder, IFormulaUsable formulaUsable, int index0, IObjectPathFactory objectPathFactory)
        {
            string index1          = $"{index0 + 1}";
            string currentVariable = $"{Variable}_{index1}";

            //replace current variable in formula string and add reference to the explicit formula
            string formulaStringPart = FormulaString.Replace(VariablePattern, currentVariable);

            explicitFormula.AddObjectPath(objectPathFactory.CreateAbsoluteFormulaUsablePath(formulaUsable).WithAlias(currentVariable));

            foreach (var objectPath in ObjectPaths)
            {
                if (explicitFormula.ObjectPaths.Contains(objectPath))
                {
                    continue;
                }

                if (objectPath.Alias.Contains(_iterationPattern))
                {
                    bool success;
                    var  referenceVariable = objectPath.TryResolve <IFormulaUsable>(formulaUsable, out success);
                    if (!success)
                    {
                        throw new UnableToResolvePathException(objectPath, formulaUsable);
                    }

                    var referenceAlias = objectPath.Alias.Replace(_iterationPattern, index1);
                    formulaStringPart = formulaStringPart.Replace(objectPath.Alias, referenceAlias);
                    explicitFormula.AddObjectPath(objectPathFactory.CreateAbsoluteFormulaUsablePath(referenceVariable).WithAlias(referenceAlias));
                }
                else
                {
                    //it is an usable path that is not dynamic. Simply add it
                    explicitFormula.AddObjectPath(objectPath);
                }
            }

            stringBuilder.Append(formulaStringPart);
        }
Beispiel #4
0
 private IFormulaUsablePath createFormulaUsablePath(IContainer container, string usableName, string alias)
 {
     return(_objectPathFactory.CreateAbsoluteFormulaUsablePath(container.GetSingleChildByName <IFormulaUsable>(usableName)).WithAlias(alias));
 }