/** * do not allow more than 1 rule for a given symbol * Deterministic L-Systems allow only one production rule for each symbol * Deterministic LSystems do not allow setting different Probability Distributions for the Rewrite rules */ public override void AddRule(ProductionRule RewriteRule) { if (RulesLookUpMap.ContainsKey(RewriteRule.GetPredecessor())) { throw new InvalidProgramException("Could not add RewriteRule for Symbol: '" + RewriteRule.GetPredecessor() + "', because there is already a rule added for that symbol. Deterministic L-Systems have only one production rule per symbol by definition!"); } //Add the rule to the list of rules base.AddRule(RewriteRule); this.RulesLookUpMap.Add(RewriteRule.GetPredecessor(), RewriteRule); }
/** * Adds a RewriteRule with a certain Probability Distribution(should be between [0.0 - 1.0]). * It is assumed that for any letter a ∈ V , the * sum of probabilities of all productions with the predecessor a is equal * to 1. * */ public void AddRewriteRule(ProductionRule RewriteRule, Double ProbabilityDistrubution) { base.AddRule(RewriteRule); //associate the rule to a given probability distribution RulesProbabilityDistributionLookUpMap.Add(RewriteRule, ProbabilityDistrubution); //Add the Rule to the List of Rules associated to that predecessor symbol: if (RulesLookUpMap.ContainsKey(RewriteRule.GetPredecessor())) { IList <ProductionRule> PredecessorRules = RulesLookUpMap[RewriteRule.GetPredecessor()]; PredecessorRules.Add(RewriteRule); } else //init the list if that's the first rule to be added for that symbol { IList <ProductionRule> PredecessorRules = new List <ProductionRule>(1); PredecessorRules.Add(RewriteRule); //add to the lookup map: RulesLookUpMap.Add(RewriteRule.GetPredecessor(), PredecessorRules); } }
/** * Adds a RewriteRule with a Probability Distribution of 1.0 * */ public override void AddRule(ProductionRule RewriteRule) { AddRewriteRule(RewriteRule, 1.0); }
/** * Adds a rewrite rule to the set of rules used by the LSystem and validates it agains the policy of the LSystem implementation(Different implementation could not work with certain rules) */ public virtual void AddRule(ProductionRule ProductionRule) { ProductionRules.Add(ProductionRule); }