public void TestSerializationEmptyFormulaUsable() { Observer x1 = CreateObject <Observer>().WithName("Obasi"); IFormulaUsable x2 = SerializeAndDeserialize(x1); AssertForSpecs.AreEqualFormulaUsable(x2, x1); }
protected override IFormulaUsablePath CreateRelativePath(IFormulaUsable formulaUsable, IEntity refObject, IUsingFormula editedObject) { if (formulaUsable.IsAtReaction()) { return(GenerateLocalReference(formulaUsable, editedObject)); } return(base.CreateRelativePath(formulaUsable, refObject, editedObject)); }
public void TestSerializationNonEmptyFormulaUsable() { Observer x1 = CreateObject <Observer>().WithName("Obasi").WithDimension(DimensionLength); x1.Value = 2.3D; IFormulaUsable x2 = SerializeAndDeserialize(x1); AssertForSpecs.AreEqualFormulaUsable(x2, x1); }
public IFormulaUsablePath CreateAbsoluteFormulaUsablePath(IFormulaUsable entity) { var newFormulaUseablePath = new FormulaUsablePath(); addPathEntry(entity, newFormulaUseablePath); newFormulaUseablePath.Alias = createAliasFrom(entity.Name); newFormulaUseablePath.Dimension = entity.Dimension; return(newFormulaUseablePath); }
protected override void Because() { var parameter = new Parameter(3, 1); parameter.setName("Param"); parameter.setId("p1"); parameter.setValue(5); _res = sut.CreateParameter(parameter); }
private IFormulaUsablePath formulaUsablePathReferencing(IFormula formula, IFormulaUsable reference) { if (formula == null) { return(null); } var referenceIndex = formula.ObjectReferences.Select(x => x.Object).IndexOf(reference); return((referenceIndex >= 0) ? formula.ObjectPaths[referenceIndex] : null); }
protected IReactionBuilder GetReactionBuilderFor(IFormulaUsable formulaUsable) { var parameter = formulaUsable as IParameter; if (parameter != null && parameter.IsAtReaction()) { return(parameter.RootContainer as IReactionBuilder); } throw new MoBiException($"cant find reaction for parameter{formulaUsable.Name}"); }
protected virtual IFormulaUsablePath CreateRelativePath(IFormulaUsable formulaUsable, IEntity refObject, IUsingFormula editedObject) { var path = createRelativePathBase(formulaUsable, refObject); if (path == null) { return(null); } path.Replace(Constants.MOLECULE_PROPERTIES, ObjectPathKeywords.MOLECULE); return(AdjustReferences(formulaUsable, path)); }
private IFormulaUsablePath objectPathFor(IFormulaUsable referencedObject, IFormulaUsablePath originalObjectPath) { if (referencedObject == null) { return(originalObjectPath); } var consolidatedPath = _entityPathResolver.ObjectPathFor(referencedObject); return(_objectPathFactory.CreateFormulaUsablePathFrom(consolidatedPath) .WithAlias(originalObjectPath.Alias) .WithDimension(originalObjectPath.Dimension)); }
private IFormulaUsablePath createRelativePathBase(IFormulaUsable formulaUsable, IEntity refObject) { if (refObject == null) { return(null); } if (formulaUsable.IsAtMolecule() && formulaUsable.RootContainer.Equals(formulaUsable.ParentContainer)) { return(CreateFormulaUsablePathFrom(new[] { formulaUsable.ParentContainer.Name, formulaUsable.Name }, formulaUsable)); } return(_objectPathFactory.CreateRelativeFormulaUsablePath(refObject, formulaUsable)); }
protected override IFormulaUsablePath CreateRelativePath(IFormulaUsable formulaUsable, IEntity refObject, IUsingFormula editedObject) { if (refObject == null) { return(null); } var container = formulaUsable.ParentContainer; var keywordForContainer = getPathKeywordForContainer(container); if (keywordForContainer.IsNullOrEmpty()) { //we have a parameter that is not located at Target or Source so we create a normal relative path return(base.CreateRelativePath(formulaUsable, refObject, editedObject)); } // We have a target or source parameter in use return(_objectPathFactory.CreateRelativeFormulaUsablePath(container, formulaUsable) .AndAddAtFront(keywordForContainer)); }
protected override IFormulaUsablePath CreateRelativePath(IFormulaUsable formulaUseable, IEntity refObject, IUsingFormula editedObject) { IFormulaUsablePath path; if (!formulaUseable.IsAtMolecule()) { path = base.CreateRelativePath(formulaUseable, refObject, editedObject); } else { path = GenerateLocalReference(formulaUseable, editedObject); if (Equals(formulaUseable.ParentContainer, editedObject.ParentContainer)) { path.Replace(editedObject.ParentContainer.Name, ObjectPathKeywords.MOLECULE); } } return(path); }
protected IFormulaUsablePath GenerateLocalReference(IFormulaUsable formulaUsable, IUsingFormula editedObject) { if (editedObject == null) { return(null); } IFormulaUsablePath path; if (formulaUsable.ParentContainer.Equals(editedObject.ParentContainer)) { path = _objectPathFactory.CreateFormulaUsablePathFrom(ObjectPath.PARENT_CONTAINER, formulaUsable.Name); } else { path = _objectPathFactory.CreateFormulaUsablePathFrom(ObjectPath.PARENT_CONTAINER, ObjectPath.PARENT_CONTAINER, formulaUsable.ParentContainer.Name, formulaUsable.Name); } path.Dimension = formulaUsable.Dimension; path.Alias = formulaUsable.Name; return(path); }
protected override IFormulaUsablePath CreateRelativePath(IFormulaUsable formulaUsable, IEntity refObject, IUsingFormula editedObject) { // relative paths are only used for parameter in the same event group if (refObject != null && formulaUsable.RootContainer.Equals(refObject.RootContainer)) { IFormulaUsablePath path; if (formulaUsable.IsAtMolecule()) { if (formulaUsable.IsAnImplementationOf <IParameter>()) { path = _objectPathFactory.CreateAbsoluteFormulaUsablePath(formulaUsable) .AndAddAtFront((ObjectPath.PARENT_CONTAINER)); } else { //Molecule replace With Amount path = CreateFormulaUsablePathFrom(new[] { ObjectPath.PARENT_CONTAINER, formulaUsable.Name }, formulaUsable.Name, Constants.Dimension.MOLAR_AMOUNT); } correctPath(path, refObject as IContainer); } else { if (formulaUsable.IsAtReaction()) { path = CreateFormulaUsablePathFrom(new[] { formulaUsable.Name }, formulaUsable); correctPath(path, refObject as IContainer); } else { path = base.CreateRelativePath(formulaUsable, refObject, editedObject); } } return(path); } return(CreateAbsolutePath(formulaUsable)); }
protected override void Context() { _x = A.Fake <IFormulaUsable>(); A.CallTo(() => _x.Value).Returns(2); _y = A.Fake <IFormulaUsable>(); A.CallTo(() => _y.Value).Returns(3); _pathX = A.Fake <IFormulaUsablePath>(); A.CallTo(() => _pathX.Alias).Returns("x"); A.CallTo(() => _pathX.Resolve <IFormulaUsable>(_usingObj)).Returns(_x); _pathY = A.Fake <IFormulaUsablePath>(); A.CallTo(() => _pathY.Alias).Returns("y"); A.CallTo(() => _pathY.Resolve <IFormulaUsable>(_usingObj)).Returns(_y); sut = new ExplicitFormula(); sut.AddObjectPath(_pathX); sut.AddObjectPath(_pathY); }
public IReadOnlyCollection <IUsingFormula> AllUsingFormulaReferencing(IFormulaUsable reference, IModelCoreSimulation simulation) { return(AllUsingFormulaReferencing(reference, simulation.Model)); }
private bool isReferencing(IUsingFormula usingFormula, IFormulaUsable reference) { var formula = usingFormula.Formula; return(formulaReferences(formula, reference) || rhsReferences(usingFormula as IParameter, reference)); }
public IReadOnlyCollection <IUsingFormula> AllUsingFormulaReferencing(IFormulaUsable reference, IModel model) { return(model.Root.GetAllChildren <IUsingFormula>(o => isReferencing(o, reference))); }
private bool formulaReferences(IFormula formula, IFormulaUsable reference) { return(formula != null && formula.ObjectReferences.Select(x => x.Object).Contains(reference)); }
private bool rhsReferences(IParameter parameter, IFormulaUsable reference) { return(parameter != null && formulaReferences(parameter.RHSFormula, reference)); }
private void renameFormulaPathInFormulas(IReadOnlyCollection <IUsingFormula> referencingFormulas, IFormulaUsable reference, string newName, string oldName) { foreach (var usingFormula in referencingFormulas) { var objectPath = formulaUsablePathReferencing(usingFormula, reference); //Reference is always found by construction and this should never happen if (objectPath == null) { return; } //The reference is used. The path needs to be updated only if it is a path referencing the old name if (!objectPath.Contains(oldName)) { continue; } objectPath.ReplaceWith(reference.EntityPath().ToPathArray()); } }
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(ITERATION_PATTERN)) { var referenceVariable = objectPath.TryResolve <IFormulaUsable>(formulaUsable, out var success); if (!success) { throw new UnableToResolvePathException(objectPath, formulaUsable); } var referenceAlias = objectPath.Alias.Replace(ITERATION_PATTERN, 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); }
private string getReactionNameFor(IFormulaUsable formulaUsable) { return(GetReactionBuilderFor(formulaUsable).Name); }
protected IFormulaUsablePath CreateAbsolutePath(IFormulaUsable formulaUsable) { return(_objectPathFactory.CreateAbsoluteFormulaUsablePath(formulaUsable)); }
private IFormulaUsablePath formulaUsablePathReferencing(IUsingFormula usingFormula, IFormulaUsable reference) { var parameter = usingFormula as IParameter; return(formulaUsablePathReferencing(usingFormula.Formula, reference) ?? formulaUsablePathReferencing(parameter?.RHSFormula, reference)); }
public IFormulaUsablePath CreateRelativeFormulaUsablePath(IEntity usingObject, IFormulaUsable usedObject) { var newFormulaUseablePath = new FormulaUsablePath(); addRelativePathEntries(usingObject, usedObject, newFormulaUseablePath); newFormulaUseablePath.Alias = createAliasFrom(usedObject.Name); newFormulaUseablePath.Dimension = usedObject.Dimension; return(newFormulaUseablePath); }
protected IFormulaUsablePath CreateFormulaUsablePathFrom(IEnumerable <string> paths, IFormulaUsable formulaUsable) { return(CreateFormulaUsablePathFrom(paths, formulaUsable.Name, formulaUsable.Dimension)); }
protected IFormulaUsablePath CreateAlwaysAbsolutePaths(IObjectBase objectBase, IFormulaUsable formulaUsable) { if (formulaUsable.IsAtMolecule()) { return(_objectPathFactory.CreateAbsoluteFormulaUsablePath(formulaUsable)); } return(CreateFormulaUsablePathFrom(new[] { getReactionNameFor(formulaUsable), objectBase.Name }, formulaUsable)); }
public ObjectReference(IFormulaUsable usedObject, string alias) { Object = usedObject; Alias = alias; }