public void use_the_setter_function() { var theRule = new ARule(); var container = new Container( x => { x.For(typeof(ClassWithDependency)).Use(typeof(ClassWithDependency)).Setter <Rule>().Is( theRule); }); container.GetInstance <ClassWithDependency>().Rule.ShouldBeTheSameAs(theRule); }
public void inject_ctor_arg_with_object() { var rule = new ARule(); var container = Container.For(x => { x.For <IWidget>().Use <AWidget>(); x.For <Rule>().Use(rule); x.For <BigGuy>().Use <BigGuy>().Setter <IServer>().Is <NulloServer>(); }); var func = container.Model.For <BigGuy>().Default.Instance.As <GeneratedInstance>() .BuildFuncResolver(container); var guy = func(container).ShouldBeOfType <BigGuy>(); guy.Rule.ShouldBeSameAs(rule); }
public void use_the_child_function() { var theRule = new ARule(); var container = new Container( x => { x.For(typeof (ClassWithDependency)).Use(typeof (ClassWithDependency)).Child(typeof (Rule)).Is( theRule); }); container.GetInstance<ClassWithDependency>().Rule.ShouldBeTheSameAs(theRule); }
public static a_Fuzzy_System load_UFS(this a_Fuzzy_System Approx, string file_name) { a_Fuzzy_System result = Approx; Knowlege_base_ARules New_dataBase = new Knowlege_base_ARules(); List <string> added_term = new List <string>(); XmlDocument Source = new XmlDocument(); Source.Load(file_name); XmlNode rulles_node = Source.DocumentElement.SelectSingleNode("descendant::Rules"); if (rulles_node == null) { throw new System.FormatException("Нет базы правил в ufs файле"); } int count_rulles = XmlConvert.ToInt32(rulles_node.Attributes.GetNamedItem("Count").Value); XmlNode varibles_node = Source.DocumentElement.SelectSingleNode("descendant::Variables"); if (varibles_node == null) { throw new System.FormatException("Нет термов в базе правил, ошибка UFS"); } for (int i = 0; i < count_rulles; i++) { XmlNode antecedent_node = rulles_node.ChildNodes[i].SelectSingleNode("Antecedent"); int count_antecedent_term = XmlConvert.ToInt32(antecedent_node.Attributes.GetNamedItem("Count").Value); int [] Order_term = new int[count_antecedent_term]; for (int j = 0; j < count_antecedent_term; j++) { double[] Value_temp; Type_Term_Func_Enum type_term = Type_Term_Func_Enum.Треугольник; int num_var = Approx.Learn_Samples_set.Input_Attributes.IndexOf(Approx.Learn_Samples_set.Input_Attributes.Find(x => x.Name.Equals(antecedent_node.ChildNodes[j].Attributes.GetNamedItem("Variable").Value, StringComparison.OrdinalIgnoreCase))); string name_term = antecedent_node.ChildNodes[j].Attributes.GetNamedItem("Term").Value; if (added_term.Contains(name_term)) { Order_term[j] = added_term.IndexOf(name_term); } else { XmlNode term_node = varibles_node.SelectSingleNode("descendant::Term[@Name='" + name_term + "']"); int count_MB = 0; switch (term_node.Attributes.GetNamedItem("Type").Value) { case "Triangle": { count_MB = 3; type_term = Type_Term_Func_Enum.Треугольник; break; } case "Gauss": { count_MB = 2; type_term = Type_Term_Func_Enum.Гауссоида; break; } case "Parabolic": { count_MB = 2; type_term = Type_Term_Func_Enum.Парабола; break; } case "Trapezoid": { count_MB = 4; type_term = Type_Term_Func_Enum.Трапеция; break; } } Value_temp = new double[count_MB]; term_node = term_node.SelectSingleNode("Params"); for (int p = 0; p < count_MB; p++) { string tett = term_node.ChildNodes[p].Attributes.GetNamedItem("Number").Value; int number_param = XmlConvert.ToInt32(term_node.ChildNodes[p].Attributes.GetNamedItem("Number").Value); Value_temp[number_param] = XmlConvert.ToDouble(term_node.ChildNodes[p].Attributes.GetNamedItem("Value").Value); } Term temp_term = new Term(Value_temp, type_term, num_var); New_dataBase.Terms_Set.Add(temp_term); added_term.Add(name_term); Order_term[j] = New_dataBase.Terms_Set.Count - 1; } } XmlNode consequnt_node = rulles_node.ChildNodes[i].SelectSingleNode("Consequent"); double Approx_value = XmlConvert.ToDouble(consequnt_node.Attributes.GetNamedItem("Value").Value); ARule temp_rule = new ARule(New_dataBase.Terms_Set, Order_term, Approx_value); New_dataBase.Rules_Database.Add(temp_rule); } result.Rulles_Database_Set.Clear(); result.Rulles_Database_Set.Add(New_dataBase); GC.Collect(); return(result); }
public override a_Fuzzy_System Generate(Fuzzy_system.Approx_Singletone.a_Fuzzy_System Approximate, Abstract_generator_conf config) { Random rand = new Random(); a_Fuzzy_System result = Approximate; if (result.Count_Rulles_Databases == 0) { Knowlege_base_ARules temp_rules = new Knowlege_base_ARules(); result.Rulles_Database_Set.Add(temp_rules); } type_term = ((Generator_Rulles_simple_random_conf)config).Функция_принадлежности; stable_terms = (int)((Generator_Rulles_simple_random_conf)config).Тип_Термов; count_rules = ((Generator_Rulles_simple_random_conf)config).Количество_правил; for (int j = 0; j < count_rules; j++) { int[] order = new int[result.Count_Vars]; Type_Term_Func_Enum temp_type_term; if (stable_terms == 0) { temp_type_term = type_term; } else { temp_type_term = Generator_type_term(); } List <Term> temp_term_list = new List <Term>(); for (int k = 0; k < result.Count_Vars; k++) { double[] parametrs = new double[Member_Function.Count_Params_For_Term(temp_type_term)]; switch (temp_type_term) { case Type_Term_Func_Enum.Треугольник: parametrs[0] = result.Learn_Samples_set.Attribute_Min(k) + rand.NextDouble() * (result.Learn_Samples_set.Attribute_Max(k) - result.Learn_Samples_set.Attribute_Min(k)); parametrs[1] = result.Learn_Samples_set.Attribute_Min(k) + rand.NextDouble() * (result.Learn_Samples_set.Attribute_Max(k) - result.Learn_Samples_set.Attribute_Min(k)); parametrs[2] = result.Learn_Samples_set.Attribute_Min(k) + rand.NextDouble() * (result.Learn_Samples_set.Attribute_Max(k) - result.Learn_Samples_set.Attribute_Min(k)); Array.Sort(parametrs); break; case Type_Term_Func_Enum.Гауссоида: parametrs[0] = result.Learn_Samples_set.Attribute_Min(k) + rand.NextDouble() * (result.Learn_Samples_set.Attribute_Max(k) - result.Learn_Samples_set.Attribute_Min(k)); parametrs[1] = (rand.NextDouble() + 0.01) * 0.5 * (result.Learn_Samples_set.Attribute_Max(k) - result.Learn_Samples_set.Attribute_Min(k)); break; case Type_Term_Func_Enum.Парабола: parametrs[0] = result.Learn_Samples_set.Attribute_Min(k) + rand.NextDouble() * (result.Learn_Samples_set.Attribute_Max(k) - result.Learn_Samples_set.Attribute_Min(k)); parametrs[1] = result.Learn_Samples_set.Attribute_Min(k) + rand.NextDouble() * (result.Learn_Samples_set.Attribute_Max(k) - result.Learn_Samples_set.Attribute_Min(k)); Array.Sort(parametrs); break; case Type_Term_Func_Enum.Трапеция: parametrs[0] = result.Learn_Samples_set.Attribute_Min(k) + rand.NextDouble() * (result.Learn_Samples_set.Attribute_Max(k) - result.Learn_Samples_set.Attribute_Min(k)); parametrs[1] = result.Learn_Samples_set.Attribute_Min(k) + rand.NextDouble() * (result.Learn_Samples_set.Attribute_Max(k) - result.Learn_Samples_set.Attribute_Min(k)); parametrs[2] = result.Learn_Samples_set.Attribute_Min(k) + rand.NextDouble() * (result.Learn_Samples_set.Attribute_Max(k) - result.Learn_Samples_set.Attribute_Min(k)); parametrs[3] = result.Learn_Samples_set.Attribute_Min(k) + rand.NextDouble() * (result.Learn_Samples_set.Attribute_Max(k) - result.Learn_Samples_set.Attribute_Min(k)); Array.Sort(parametrs); break; } Term temp_term = new Term(parametrs, temp_type_term, k); result.Rulles_Database_Set[0].Terms_Set.Add(temp_term); temp_term_list.Add(temp_term); order[k] = result.Rulles_Database_Set[0].Terms_Set.Count - 1; } double approx_Value = result.Nearest_Approx(temp_term_list); ARule temp_Rule = new ARule(result.Rulles_Database_Set[0].Terms_Set, order, approx_Value); result.Rulles_Database_Set[0].Rules_Database.Add(temp_Rule); } result.unlaid_protection_fix(); GC.Collect(); return(result); }