Главная страница

Курсовая ОИИ. Курсовая работа по дисциплине Основы искусственного интеллекта


Скачать 0.98 Mb.
НазваниеКурсовая работа по дисциплине Основы искусственного интеллекта
АнкорКурсовая ОИИ
Дата09.06.2022
Размер0.98 Mb.
Формат файлаdocx
Имя файлаkurovaya_OII (1).docx
ТипКурсовая
#580413
страница6 из 6
1   2   3   4   5   6




Лист

31


using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;
namespace ExpertSystem

{

public class InformationBase

{

public Variable[] variables;

public Rule[] rules;

public InformationBase()

{

variables = new Variable[1];

rules = new Rule[1];

}

public void AddVariable(string name, float min, float max, FuzzyLabel[] fuzzyLabels, string units)

{

variables[variables.Length - 1] = new Variable(name, min, max, fuzzyLabels, units);

Array.Resize(ref variables, variables.Length + 1);

}

public void AddRule(string name, string value)

{

rules[rules.Length - 1] = new Rule(name, value);

Array.Resize(ref rules, rules.Length + 1);

}

public string[] GetVariablesList()

{

string[] vars = new string[variables.Length];

for (int i = 0; i < variables.Length - 1; i++)

vars[i] = variables[i].Name;

return vars;

}

public string[] GetRulesList()

{

string[] vars = new string[rules.Length];

for (int i = 0; i < rules.Length - 1; i++)

vars[i] = rules[i].Name;

return vars;

}

public Variable GetVariable(string name)

{

foreach(Variable var in variables)

{

if (var.Name == name)

return var;

}

return null;

}

public Rule GetRule(string name)

{

foreach (Rule var in rules)

{

if (var.Name == name)

return var;

}

return null;

}




Лист

32

public void DeleteVariable(string name)

{

for (int i = 0; i < variables.Length; i++)

{

if (variables[i].Name == name)

{

variables[i] = null;

break;

}

}

variables = variables.Where(x => x != null).ToArray();

Array.Resize(ref variables, variables.Length + 1);

}
public void DeleteRule(string name)

{

for (int i = 0; i < rules.Length; i++)

{

if (rules[i].Name == name)

{

rules[i] = null;

break;

}

}

rules = rules.Where(x => x != null).ToArray();

Array.Resize(ref rules, rules.Length + 1);

}
}

}

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using AForge.Fuzzy;

using Newtonsoft.Json;
namespace ExpertSystem

{

public class Logic

{

private InformationBase informationBase;

private DatabaseCreator databaseCreator;

private InferenceSystem inferenceSystem;

public Logic()

{

informationBase = new InformationBase();

databaseCreator = new DatabaseCreator();

}
public string[] Calculate(string[] varsNames, float[] varsValues, string findName)

{

string[] rezult = new string[2];

inferenceSystem = databaseCreator.Create(informationBase);
for (int i = 0; i < varsNames.Length; i++)

{

inferenceSystem.SetInput(varsNames[i], varsValues[i]);

}

try

{




Лист

33

rezult[0] = inferenceSystem.Evaluate(findName).ToString();

}

catch(Exception ex)

{

rezult[1] = ex.Message;

}

return rezult;

}
public void OpenFile(string file)

{

informationBase = JsonConvert.DeserializeObject(file);

}
public string SaveFile()

{

return JsonConvert.SerializeObject(informationBase);

}
public List GetListForGrid()

{

List list = new List();

foreach (Variable var in informationBase.variables)

if(var != null)

list.Add(var.Name + " | "+ var.Min + " — " + var.Max + " " + var.Units);

return list;

}

public void AddVariable(string name, float min, float max, FuzzyLabel[] fuzzyLabels, string units)

{

informationBase.AddVariable(name, min, max, fuzzyLabels, units);

}
public void DeleteVariable(string name)

{

informationBase.DeleteVariable(name);

}
public string[] GetVariablesList()

{

return informationBase.GetVariablesList();

}
public Variable GetVariable(string name)

{

return informationBase.GetVariable(name);

}
public Variable[] GetVariables()

{

return informationBase.variables;

}
public void AddRule(string name, string value)

{

informationBase.AddRule(name, value);

}
public void DeleteRule(string name)

{

informationBase.DeleteRule(name);

}

public string[] GetRulesList()




Лист

34


public string[] GetRulesList()

{

return informationBase.GetRulesList();

}
public Rule GetRule(string name)

{

return informationBase.GetRule(name);

}

}

}

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;
namespace ExpertSystem

{

public class Rule

{

public string Name { get; set; }

public string Value { get; set; }
public Rule(string name, string value)

{

Name = name;

Value = value;

}

}

}

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;
namespace ExpertSystem

{

public class Variable

{

public string Name { get; set; }

public float Min { get; set; }

public float Max { get; set; }

public FuzzyLabel[] FuzzyLabels { get; set; }

public string Units { get; set; }
public Variable(string name, float min, float max, FuzzyLabel[] fuzzyLabels, string units)

{

Name = name;

Min = min;

Max = max;

FuzzyLabels = fuzzyLabels;

Units = units;

}
public string[] GetLabelsList()

{

string[] vars = new string[FuzzyLabels.Length];

for (int i = 0; i < FuzzyLabels.Length; i++)

vars[i] = FuzzyLabels[i].Name;

return vars;




Лист

35

}

public FuzzyLabel GetFuzzyLabel(string name)

{

foreach (FuzzyLabel var in FuzzyLabels)

if (var.Name == name)

return var;

return null;

}

}

}
1   2   3   4   5   6


написать администратору сайта