public void TestSerializationEvent() { Event x1 = CreateObject <Event>().WithName("Eve").WithDimension(DimensionLength); x1.Formula = CreateObject <ConstantFormula>().WithDimension(DimensionLength).WithValue(1.0); x1.ParentContainer = C0; EventAssignment ea1 = CreateObject <EventAssignment>().WithName("Eva").WithDimension(DimensionLength); ea1.UseAsValue = true; ea1.Formula = CreateObject <ConstantFormula>().WithDimension(DimensionLength).WithValue(23.4); ea1.ObjectPath = ObjectPathFactory.CreateAbsoluteObjectPath(P); x1.AddAssignment(ea1); ea1.ResolveChangedEntity(); IEvent x2 = SerializeAndDeserialize(x1); x2.ParentContainer = C0; var refResolver = new ReferencesResolver(); refResolver.ResolveReferencesIn(x2); AssertForSpecs.AreEqualEvent(x2, x1); }
/// <summary> /// Copy the references for first and second Neighbor from <paramref name="sourcecNeighborhoodBuilder" /> to /// <paramref name="targetNeighborhoodBuilder" />. /// </summary> /// <param name="sourcecNeighborhoodBuilder">The source neighborhood builder to copy neighbors from.</param> /// <param name="targetNeighborhoodBuilder">The neighborhood builder to copy neighbors to.</param> private void updateNeighborsReferences(INeighborhoodBuilder sourcecNeighborhoodBuilder, INeighborhoodBuilder targetNeighborhoodBuilder) { var objectPathFactory = new ObjectPathFactory(new AliasCreator()); var firstPath = objectPathFactory.CreateAbsoluteObjectPath(sourcecNeighborhoodBuilder.FirstNeighbor); var secondPath = objectPathFactory.CreateAbsoluteObjectPath(sourcecNeighborhoodBuilder.SecondNeighbor); foreach (var topContainer in TopContainers) { var firstNeighbor = firstPath.Resolve <IContainer>(topContainer); var secondNeighbor = secondPath.Resolve <IContainer>(topContainer); if (firstNeighbor != null) { targetNeighborhoodBuilder.FirstNeighbor = firstNeighbor; } if (secondNeighbor != null) { targetNeighborhoodBuilder.SecondNeighbor = secondNeighbor; } //both neighbors set. early exit if (targetNeighborhoodBuilder.FirstNeighbor != null && targetNeighborhoodBuilder.SecondNeighbor != null) { return; } } }
public void TestSerializationQuantityWithExplicitFormula() { Observer x1 = CreateObject <Observer>().WithName("Quentin").WithDimension(DimensionLength); x1.ParentContainer = C1; x1.IsFixedValue = false; x1.Persistable = false; x1.Formula = CreateObject <ConstantFormula>().WithDimension(DimensionLength).WithValue(23.4); ExplicitFormula f1 = CreateObject <ExplicitFormula>().WithName("Fortunato").WithDimension(DimensionLength); f1.AddObjectPath(ObjectPathFactory.CreateAbsoluteFormulaUsablePath(P1)); f1.AddObjectPath(ObjectPathFactory.CreateRelativeFormulaUsablePath(P, P0)); f1.AddObjectPath(ObjectPathFactory.CreateRelativeFormulaUsablePath(P, P2).WithAlias("Pitter")); f1.ResolveObjectPathsFor(P); f1.FormulaString = "Paul + Peter + Pitter"; P1.Value = 1.0; P0.Value = 10.0; P2.Value = 2.0; x1.Formula = f1; IQuantity x2 = SerializeAndDeserialize(x1); x2.ParentContainer = C1; x2.Formula.ResolveObjectPathsFor(x2); AssertForSpecs.AreEqualQuantity(x2, x1); }
/// <summary> /// Sets all the autogenerated Molecule Start Values to the right values and updates their /// "IsPresent" property. /// </summary> private void SetMoleculeStartValues(Model model) { foreach (var molInfo in _sbmlInformation.MoleculeInformation) { foreach (var msv in _moleculeStartValuesBuildingBlock) { if (msv.Name != molInfo.GetMoleculeBuilderName()) { continue; } if (molInfo.GetContainer().Any(x => x.Name == msv.ContainerPath.LastOrDefault())) { msv.IsPresent = true; msv.NegativeValuesAllowed = true; var sbmlSpecies = molInfo.GetSpeciesIfOne(); if (sbmlSpecies == null) { return; } var sbmlUnit = GetUnit(sbmlSpecies, model); var amountDimension = _unitDefinitionImporter.DimensionFor(sbmlUnit); //unit is set by the Unit of SubstanceUnit if (sbmlSpecies.isSetInitialAmount()) { msv.StartValue = sbmlSpecies.getInitialAmount(); if (amountDimension != null) { msv.Dimension = amountDimension; molInfo.SetDimension(amountDimension); } } if (!sbmlSpecies.isSetInitialConcentration()) { continue; } //unit is {unit of amount}/{unit of size} var baseValue = _unitDefinitionImporter.ToMobiBaseUnit(sbmlUnit, sbmlSpecies.getInitialConcentration()); msv.StartValue = baseValue.value; msv.Formula = _context.Create <ExplicitFormula>($"{msv.Name}_0").WithName($"{msv.Name}_0").WithDimension(amountDimension).WithFormulaString($"{baseValue.value} * {Constants.VOLUME_ALIAS}"); msv.Formula.AddObjectPath( ObjectPathFactory.CreateFormulaUsablePathFrom(ObjectPath.PARENT_CONTAINER, Constants.Parameters.VOLUME) .WithAlias(Constants.VOLUME_ALIAS) .WithDimension(_moBiDimensionFactory.Dimension(Constants.Dimension.VOLUME)) ); _moleculeStartValuesBuildingBlock.AddFormula(msv.Formula); msv.Dimension = amountDimension; molInfo.SetDimension(amountDimension); UseConcentrations = true; } else { msv.IsPresent = false; msv.StartValue = 0; } } } }
protected override void Context() { _pathFactory = new ObjectPathFactory(new AliasCreator()); _userSettings = A.Fake <IUserSettings>(); _userSettings.CheckDimensions = true; _buildConfiguration = A.Fake <IBuildConfiguration>(); A.CallTo(() => _buildConfiguration.BuilderFor(A <IObjectBase> ._)).ReturnsLazily(x => x.GetArgument <IObjectBase>(0)); sut = new DimensionValidator(new DimensionParser(), _pathFactory, _userSettings); }
protected override void Context() { _organ = new Container().WithName("organ"); var comp = new Container().WithName("comp").WithParentContainer(_organ); _parameter = new Parameter().WithName("P1").WithParentContainer(comp); var objectPathFactory = new ObjectPathFactory(new AliasCreator()); sut = objectPathFactory.CreateAbsoluteFormulaUsablePath(_parameter); }
public void TestSerializationTableFormulaWithArgument() { var x1 = CreateObject <TableFormulaWithXArgument>().WithName("Fortunato").WithDimension(DimensionLength); x1.AddTableObjectPath(ObjectPathFactory.CreateAbsoluteFormulaUsablePath(P1)); x1.AddXArgumentObjectPath(ObjectPathFactory.CreateRelativeFormulaUsablePath(P, P0)); var x2 = SerializeAndDeserialize(x1); AssertForSpecs.AreEqualTableFormulaWithArgument(x2, x1); }
protected override void Context() { _topContainer = new Container().WithName("top"); _organ = new Container().WithName("organ").WithParentContainer(_topContainer); _comp = new Container().WithName("comp").WithParentContainer(_organ); _parameter = new DistributedParameter().WithName("P1").WithParentContainer(_comp); new Parameter().WithName("LALA").WithParentContainer(_parameter); _reak = A.Fake <IUsingFormula>(); A.CallTo(() => _reak.ParentContainer).Returns(_topContainer); A.CallTo(() => _reak.RootContainer).Returns(_topContainer); sut = new ObjectPathFactory(new AliasCreator()); }
public void TestSerializationFormulaWithObjectPathsWithoutObjectReferences() { ExplicitFormula x1 = CreateObject <ExplicitFormula>().WithName("Fortunato").WithDimension(DimensionLength); x1.AddObjectPath(ObjectPathFactory.CreateAbsoluteFormulaUsablePath(P1)); x1.AddObjectPath(ObjectPathFactory.CreateRelativeFormulaUsablePath(P, P0)); x1.AddObjectPath(ObjectPathFactory.CreateRelativeFormulaUsablePath(P, P2).WithAlias("Pitter")); IFormula x2 = SerializeAndDeserialize(x1); AssertForSpecs.AreEqualFormula(x2, x1); }
public void TestSerialization() { ConstantFormula x1 = CreateObject <ConstantFormula>().WithName("Fortunato").WithDimension(DimensionLength).WithValue(5.3); x1.AddObjectPath(ObjectPathFactory.CreateAbsoluteFormulaUsablePath(P1)); x1.AddObjectPath(ObjectPathFactory.CreateRelativeFormulaUsablePath(P, P0)); x1.AddObjectPath(ObjectPathFactory.CreateRelativeFormulaUsablePath(P, P2).WithAlias("Pitter")); x1.ResolveObjectPathsFor(P); ConstantFormula x2 = SerializeAndDeserialize(x1); x2.ResolveObjectPathsFor(P); AssertForSpecs.AreEqualConstantFormula(x2, x1); }
public void TestSerialization() { ExplicitFormula x1 = CreateObject <ExplicitFormula>().WithName("Fortunato").WithDimension(DimensionLength); x1.AddObjectPath(ObjectPathFactory.CreateAbsoluteFormulaUsablePath(P1)); x1.AddObjectPath(ObjectPathFactory.CreateRelativeFormulaUsablePath(P, P0)); x1.AddObjectPath(ObjectPathFactory.CreateRelativeFormulaUsablePath(P, P2).WithAlias("Pitter")); x1.ResolveObjectPathsFor(P); x1.FormulaString = "1.1 + 2.2"; ExplicitFormula x2 = SerializeAndDeserialize(x1); x2.ResolveObjectPathsFor(P); AssertForSpecs.AreEqualExplicitFormula(x2, x1); }
public void TestSerializationWithDependencies() { ExplicitFormula x1 = CreateObject <ExplicitFormula>().WithName("Fortunato").WithDimension(DimensionLength); x1.AddObjectPath(ObjectPathFactory.CreateAbsoluteFormulaUsablePath(P1)); x1.AddObjectPath(ObjectPathFactory.CreateRelativeFormulaUsablePath(P, P0)); x1.AddObjectPath(ObjectPathFactory.CreateRelativeFormulaUsablePath(P, P2).WithAlias("Pitter")); x1.ResolveObjectPathsFor(P); x1.FormulaString = "Paul + Peter + Pitter"; P1.Value = 1.0; P0.Value = 10.0; P2.Value = 2.0; ExplicitFormula x2 = SerializeAndDeserialize(x1); x2.ResolveObjectPathsFor(P); AssertForSpecs.AreEqualExplicitFormula(x2, x1); }
protected override void Context() { sut = new DistributedParameter(); var pathFactory = new ObjectPathFactory(new AliasCreator()); _meanParameter = new Parameter { Name = Constants.Distribution.MEAN }.WithFormula(new ExplicitFormula("0")); _stdParameter = new Parameter { Name = Constants.Distribution.DEVIATION }.WithFormula(new ExplicitFormula("1")); _percentileParameter = new Parameter { Name = Constants.Distribution.PERCENTILE }.WithFormula(new ExplicitFormula("0.5")); sut.Add(_meanParameter); sut.Add(_stdParameter); sut.Add(_percentileParameter); sut.Formula = new NormalDistributionFormula(); sut.Formula.AddObjectPath(pathFactory.CreateRelativeFormulaUsablePath(sut, _meanParameter)); sut.Formula.AddObjectPath(pathFactory.CreateRelativeFormulaUsablePath(sut, _stdParameter)); sut.Formula.ResolveObjectPathsFor(sut); }
protected override void Context() { base.Context(); var pathFactory = new ObjectPathFactory(new AliasCreator()); _distributedParameter = new DistributedParameter(); var meanParameter = new Parameter { Name = Constants.Distribution.MEAN }.WithFormula(new ExplicitFormula("0")); var stdParameter = new Parameter { Name = Constants.Distribution.DEVIATION }.WithFormula(new ExplicitFormula("1")); var percentileParameter = new Parameter { Name = Constants.Distribution.PERCENTILE }.WithFormula(new ExplicitFormula("0.7")); _distributedParameter.Add(meanParameter); _distributedParameter.Add(stdParameter); _distributedParameter.Add(percentileParameter); _distributedParameter.Formula = new NormalDistributionFormula(); _distributedParameter.Formula.AddObjectPath(pathFactory.CreateRelativeFormulaUsablePath(_distributedParameter, meanParameter)); _distributedParameter.Formula.AddObjectPath(pathFactory.CreateRelativeFormulaUsablePath(_distributedParameter, stdParameter)); }
/// <summary> /// Gets the path to a Container by a given compartment id. /// </summary> protected internal IObjectPath GetPathToContainerOfCompartmentId(string compartmentId) { return((from container in GetMainTopContainer().Children where container.Name == compartmentId select ObjectPathFactory.CreateAbsoluteObjectPath(container)).FirstOrDefault()); }
public MolWeightDimensionConverterForFormulaUsable(IDimension sourceDimension, IDimension targetDimension) : base(sourceDimension, targetDimension) { _pathFactory = new ObjectPathFactory(new AliasCreator()); }
public ExcelRequestContext(string url) : base(url) { m_workbook = new Workbook(this, ObjectPathFactory._CreateGlobalObjectObjectPath(this)); this._RootObject = m_workbook; }