public void test_RateRule() { RateRule r = new RateRule(2, 4); assertEquals(false, (r.hasRequiredAttributes())); r.setVariable("r"); assertEquals(true, r.hasRequiredAttributes()); r = null; }
public void test_RateRule() { RateRule r = new RateRule(2, 4); assertEquals(false, (r.hasRequiredElements())); r.setMath(libsbml.parseFormula("ar")); assertEquals(true, r.hasRequiredElements()); r = null; }
public void test_RateRule_parent_create() { Model m = new Model(2, 4); RateRule r = m.createRateRule(); ListOf lo = m.getListOfRules(); assertTrue(lo == m.getRule(0).getParentSBMLObject()); assertTrue(lo == r.getParentSBMLObject()); assertTrue(m == lo.getParentSBMLObject()); }
public void test_Rule_parent_add() { Rule ia = new RateRule(2, 4); ia.setVariable("a"); ia.setMath(libsbml.parseFormula("9")); Model m = new Model(2, 4); m.addRule(ia); ia = null; ListOf lo = m.getListOfRules(); assertTrue(lo == m.getRule(0).getParentSBMLObject()); assertTrue(m == lo.getParentSBMLObject()); }
public void test_Model_addRules() { Rule r1 = new AlgebraicRule(2, 4); Rule r2 = new AssignmentRule(2, 4); Rule r3 = new RateRule(2, 4); r2.setVariable("r2"); r3.setVariable("r3"); r1.setMath(libsbml.parseFormula("2")); r2.setMath(libsbml.parseFormula("2")); r3.setMath(libsbml.parseFormula("2")); M.addRule(r1); M.addRule(r2); M.addRule(r3); assertTrue(M.getNumRules() == 3); }
public Task <RateResult> FetchRate(RateRule rateRule, CancellationToken cancellationToken) { ArgumentNullException.ThrowIfNull(rateRule); var fetchingExchanges = new Dictionary <string, Task <QueryRateResult> >(); var dependentQueries = new List <Task <QueryRateResult> >(); foreach (var requiredExchange in rateRule.ExchangeRates) { if (!fetchingExchanges.TryGetValue(requiredExchange.Exchange, out var fetching)) { fetching = _rateProviderFactory.QueryRates(requiredExchange.Exchange, cancellationToken); fetchingExchanges.Add(requiredExchange.Exchange, fetching); } dependentQueries.Add(fetching); } return(GetRuleValue(dependentQueries, rateRule)); }
public void test_RateRule_ancestor_create() { Model m = new Model(2, 4); RateRule r = m.createRateRule(); ListOf lo = m.getListOfRules(); assertTrue(r.getAncestorOfType(libsbml.SBML_MODEL) == m); assertTrue(r.getAncestorOfType(libsbml.SBML_LIST_OF) == lo); assertTrue(r.getAncestorOfType(libsbml.SBML_DOCUMENT) == null); assertTrue(r.getAncestorOfType(libsbml.SBML_EVENT) == null); Rule obj = m.getRule(0); assertTrue(obj.getAncestorOfType(libsbml.SBML_MODEL) == m); assertTrue(obj.getAncestorOfType(libsbml.SBML_LIST_OF) == lo); assertTrue(obj.getAncestorOfType(libsbml.SBML_DOCUMENT) == null); assertTrue(obj.getAncestorOfType(libsbml.SBML_EVENT) == null); }
public void test_Rule_ancestor_add() { Rule ia = new RateRule(2, 4); ia.setVariable("a"); ia.setMath(libsbml.parseFormula("9")); Model m = new Model(2, 4); m.addRule(ia); ia = null; ListOf lo = m.getListOfRules(); Rule obj = m.getRule(0); assertTrue(obj.getAncestorOfType(libsbml.SBML_MODEL) == m); assertTrue(obj.getAncestorOfType(libsbml.SBML_LIST_OF) == lo); assertTrue(obj.getAncestorOfType(libsbml.SBML_DOCUMENT) == null); assertTrue(obj.getAncestorOfType(libsbml.SBML_EVENT) == null); }
public void test_Rule_copyConstructor() { Rule o1 = new RateRule(2, 1); o1.setVariable("a"); assertTrue(o1.getVariable() == "a"); ASTNode node = new ASTNode(libsbml.AST_CONSTANT_PI); o1.setMath(node); node = null; assertTrue(o1.isSetMath() == true); Rule o2 = new Rule(o1); assertTrue(o2.getVariable() == "a"); assertTrue(o2.isSetMath() == true); assertTrue(o2.getParentSBMLObject() == o1.getParentSBMLObject()); o2 = null; o1 = null; }
public void test_RateRule_createWithNS() { XMLNamespaces xmlns = new XMLNamespaces(); xmlns.add("http://www.sbml.org", "testsbml"); SBMLNamespaces sbmlns = new SBMLNamespaces(2, 1); sbmlns.addNamespaces(xmlns); Rule object1 = new RateRule(sbmlns); assertTrue(object1.getTypeCode() == libsbml.SBML_RATE_RULE); assertTrue(object1.getMetaId() == ""); assertTrue(object1.getNotes() == null); assertTrue(object1.getAnnotation() == null); assertTrue(object1.getLevel() == 2); assertTrue(object1.getVersion() == 1); assertTrue(object1.getNamespaces() != null); assertTrue(object1.getNamespaces().getLength() == 2); object1 = null; }
private async Task <RateResult> GetRuleValue(List <Task <QueryRateResult> > dependentQueries, RateRule rateRule) { var result = new RateResult(); foreach (var queryAsync in dependentQueries) { var query = await queryAsync; result.Latency = query.Latency; if (query.Exception != null) { result.ExchangeExceptions.Add(query.Exception); } foreach (var rule in query.PairRates) { rateRule.ExchangeRates.SetRate(query.Exchange, rule.CurrencyPair, rule.BidAsk); } } rateRule.Reevaluate(); result.BidAsk = rateRule.BidAsk; result.Errors = rateRule.Errors; result.EvaluatedRule = rateRule.ToString(true); result.Rule = rateRule.ToString(false); return(result); }
static void testClone(SBase s) { string ename = s.getElementName(); SBase c = s.clone(); if (c is Compartment) { Compartment x = (s as Compartment).clone(); c = x; } else if (c is CompartmentType) { CompartmentType x = (s as CompartmentType).clone(); c = x; } else if (c is Constraint) { Constraint x = (s as Constraint).clone(); c = x; } else if (c is Delay) { Delay x = (s as Delay).clone(); c = x; } else if (c is Event) { Event x = (s as Event).clone(); c = x; } else if (c is EventAssignment) { EventAssignment x = (s as EventAssignment).clone(); c = x; } else if (c is FunctionDefinition) { FunctionDefinition x = (s as FunctionDefinition).clone(); c = x; } else if (c is InitialAssignment) { InitialAssignment x = (s as InitialAssignment).clone(); c = x; } else if (c is KineticLaw) { KineticLaw x = (s as KineticLaw).clone(); c = x; } // currently return type of ListOf::clone() is SBase else if (c is ListOf) { SBase x = (s as ListOf).clone(); c = x; } else if (c is Model) { Model x = (s as Model).clone(); c = x; } else if (c is Parameter) { Parameter x = (s as Parameter).clone(); c = x; } else if (c is Reaction) { Reaction x = (s as Reaction).clone(); c = x; } else if (c is AlgebraicRule) { AlgebraicRule x = (s as AlgebraicRule).clone(); c = x; } else if (c is AssignmentRule) { AssignmentRule x = (s as AssignmentRule).clone(); c = x; } else if (c is RateRule) { RateRule x = (s as RateRule).clone(); c = x; } else if (c is SBMLDocument) { SBMLDocument x = (s as SBMLDocument).clone(); c = x; } else if (c is Species) { Species x = (s as Species).clone(); c = x; } else if (c is SpeciesReference) { SpeciesReference x = (s as SpeciesReference).clone(); c = x; } else if (c is SpeciesType) { SpeciesType x = (s as SpeciesType).clone(); c = x; } else if (c is SpeciesReference) { SpeciesReference x = (s as SpeciesReference).clone(); c = x; } else if (c is StoichiometryMath) { StoichiometryMath x = (s as StoichiometryMath).clone(); c = x; } else if (c is Trigger) { Trigger x = (s as Trigger).clone(); c = x; } else if (c is Unit) { Unit x = (s as Unit).clone(); c = x; } else if (c is UnitDefinition) { UnitDefinition x = (s as UnitDefinition).clone(); c = x; } else if (c is ListOfCompartmentTypes) { ListOfCompartmentTypes x = (s as ListOfCompartmentTypes).clone(); c = x; } else if (c is ListOfCompartments) { ListOfCompartments x = (s as ListOfCompartments).clone(); c = x; } else if (c is ListOfConstraints) { ListOfConstraints x = (s as ListOfConstraints).clone(); c = x; } else if (c is ListOfEventAssignments) { ListOfEventAssignments x = (s as ListOfEventAssignments).clone(); c = x; } else if (c is ListOfEvents) { ListOfEvents x = (s as ListOfEvents).clone(); c = x; } else if (c is ListOfFunctionDefinitions) { ListOfFunctionDefinitions x = (s as ListOfFunctionDefinitions).clone(); c = x; } else if (c is ListOfInitialAssignments) { ListOfInitialAssignments x = (s as ListOfInitialAssignments).clone(); c = x; } else if (c is ListOfParameters) { ListOfParameters x = (s as ListOfParameters).clone(); c = x; } else if (c is ListOfReactions) { ListOfReactions x = (s as ListOfReactions).clone(); c = x; } else if (c is ListOfRules) { ListOfRules x = (s as ListOfRules).clone(); c = x; } else if (c is ListOfSpecies) { ListOfSpecies x = (s as ListOfSpecies).clone(); c = x; } else if (c is ListOfSpeciesReferences) { ListOfSpeciesReferences x = (s as ListOfSpeciesReferences).clone(); c = x; } else if (c is ListOfSpeciesTypes) { ListOfSpeciesTypes x = (s as ListOfSpeciesTypes).clone(); c = x; } else if (c is ListOfUnitDefinitions) { ListOfUnitDefinitions x = (s as ListOfUnitDefinitions).clone(); c = x; } else if (c is ListOfUnits) { ListOfUnits x = (s as ListOfUnits).clone(); c = x; } else { ERR("[testClone] Error: (" + ename + ") : clone() failed."); return; } if (c == null) { ERR("[testClone] Error: (" + ename + ") : clone() failed."); return; } string enameClone = c.getElementName(); if (ename == enameClone) { //Console.Out.WriteLine("[testClone] OK: (" + ename + ") clone(" + enameClone + ") : type match."); OK(); } else { ERR("[testClone] Error: (" + ename + ") clone(" + enameClone + ") : type mismatch."); } }
public void ConstructExpressionTree(IDomainRule domainRule) { // TODO: validate Op for each field in RateRule RateRule rateRule = (RateRule)domainRule; ParameterExpression landPlotPE = Expression.Parameter(typeof(LandPlot), "landPlot"); MemberExpression locationTypeME = Expression.Property(landPlotPE, "LocationType"); ConstantExpression locationTypeCV = Expression.Constant(rateRule.LocationType, typeof(int)); BinaryExpression locationTypeBody = Common.CreateBinaryExpression(locationTypeME, locationTypeCV, rateRule.LocationTypeOp); var locationTypeExprTree = Expression.Lambda <Func <LandPlot, bool> >(locationTypeBody, new[] { landPlotPE }); Common.DebugExprTree("LandPlot.LocationType", locationTypeExprTree); MemberExpression isWaterfrontME = Expression.Property(landPlotPE, "IsWaterfront"); ConstantExpression isWaterfrontCV = Expression.Constant(rateRule.IsWaterfront, typeof(bool)); BinaryExpression isWaterfrontBody = Common.CreateBinaryExpression(isWaterfrontME, isWaterfrontCV, rateRule.IsWaterfrontOp); var isWaterfrontExprTree = Expression.Lambda <Func <LandPlot, bool> >(isWaterfrontBody, new[] { landPlotPE }); Common.DebugExprTree("LandPlot.IsWaterfront", isWaterfrontExprTree); ParameterExpression unitPE = Expression.Parameter(typeof(Unit), "unit"); MemberExpression usageTypeME = Expression.Property(unitPE, "UsageType"); ConstantExpression usageTypeCV = Expression.Constant(rateRule.UsageType, typeof(int)); BinaryExpression usageTypeBody = Common.CreateBinaryExpression(usageTypeME, usageTypeCV, rateRule.UsageTypeOp); var usageTypeExprTree = Expression.Lambda <Func <Unit, bool> >(usageTypeBody, new[] { unitPE }); Common.DebugExprTree("Unit.UsageType", usageTypeExprTree); MemberExpression qualityTypeME = Expression.Property(unitPE, "QualityType"); ConstantExpression qualityTypeCV = Expression.Constant(rateRule.QualityType, typeof(int)); BinaryExpression qualityTypeBody = Common.CreateBinaryExpression(qualityTypeME, qualityTypeCV, rateRule.QualityTypeOp); var qualityTypeExprTree = Expression.Lambda <Func <Unit, bool> >(qualityTypeBody, new[] { unitPE }); Common.DebugExprTree("Unit.QualityType", qualityTypeExprTree); MemberExpression floorLevelME = Expression.Property(unitPE, "FloorNo"); ConstantExpression floorLevelCV = Expression.Constant(rateRule.FloorLevel, typeof(int)); BinaryExpression floorLevelBody = Common.CreateBinaryExpression(floorLevelME, floorLevelCV, rateRule.FloorLevelOp); var floorLevelExprTree = Expression.Lambda <Func <Unit, bool> >(floorLevelBody, new[] { unitPE }); Common.DebugExprTree("Unit.FloorLevel", floorLevelExprTree); MemberExpression isWindowME = Expression.Property(unitPE, "IsWindows"); ConstantExpression isWindowCV = Expression.Constant(rateRule.IsWindow, typeof(bool)); BinaryExpression isWindowBody = Common.CreateBinaryExpression(isWindowME, isWindowCV, rateRule.IsWindowOp); var isWindowExprTree = Expression.Lambda <Func <Unit, bool> >(isWindowBody, new[] { unitPE }); Common.DebugExprTree("Unit.IsWindow", isWindowExprTree); ParameterExpression buildingPE = Expression.Parameter(typeof(Building), "building"); MemberExpression plotRatioME = Expression.Property(buildingPE, "PlotRatio"); ConstantExpression plotRatioCV = Expression.Constant(rateRule.PlotRatio, typeof(int)); BinaryExpression plotRatioBody = Common.CreateBinaryExpression(plotRatioME, plotRatioCV, rateRule.PlotRatioOp); var plotRatioExprTree = Expression.Lambda <Func <Building, bool> >(plotRatioBody, new[] { buildingPE }); Common.DebugExprTree("Building.PlotRatio", plotRatioExprTree); ParameterExpression productPE = Expression.Parameter(typeof(Product), "product"); MemberExpression productTypePE = Expression.Property(productPE, "ProductType"); ConstantExpression productTypeCV = Expression.Constant(rateRule.ProductType, typeof(int)); BinaryExpression productTypeBody = Common.CreateBinaryExpression(productTypePE, productTypeCV, rateRule.ProductTypeOp); var productTypeExprTree = Expression.Lambda <Func <Product, bool> >(productTypeBody, new[] { productPE }); Common.DebugExprTree("Product.ProductType", productTypeExprTree); }
private async Task <RateResult> GetRuleValue(List <Task <QueryRateResult> > dependentQueries, RateRule rateRule) { var result = new RateResult(); result.Cached = true; foreach (var queryAsync in dependentQueries) { var query = await queryAsync; if (!query.CachedResult) { result.Cached = false; } result.ExchangeExceptions.AddRange(query.Exceptions); foreach (var rule in query.ExchangeRates) { rateRule.ExchangeRates.Add(rule); } } rateRule.Reevaluate(); result.Value = rateRule.Value; result.Errors = rateRule.Errors; result.EvaluatedRule = rateRule.ToString(true); result.Rule = rateRule.ToString(false); return(result); }
public void RateRuleElement(Hashtable attrs) { String variable; SBase parameter = null; if (attrs.Contains("variable")) { variable = (String)attrs["variable"]; if (this.model.findObject(variable) != null) parameter = (SBase)this.model.findObject(variable); } // else throw exception on required attribute RateRule rateRule = new RateRule(this.model, parameter); this.model.listOfRules.Add(rateRule); elementStack.Push(rateRule); }
private async Task <RateResult> GetRuleValue(List <Task <QueryRateResult> > dependentQueries, RateRule rateRule) { var result = new RateResult(); result.Cached = true; foreach (var queryAsync in dependentQueries) { var query = await queryAsync; if (!query.CachedResult) { result.Cached = false; } result.ExchangeExceptions.AddRange(query.Exceptions); foreach (var rule in query.ExchangeRates) { rateRule.ExchangeRates.Add(rule); } } rateRule.Reevaluate(); result.Value = rateRule.Value; var currencyData = _CurrencyTable?.GetCurrencyData(rateRule.CurrencyPair.Right); if (currencyData != null && result.Value.HasValue) { result.Value = decimal.Round(result.Value.Value, currencyData.Divisibility, MidpointRounding.AwayFromZero); } result.Errors = rateRule.Errors; result.EvaluatedRule = rateRule.ToString(true); result.Rule = rateRule.ToString(false); return(result); }