Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace MAD___CV1
- {
- class Program
- {
- private const string FILE_DESTINATION = @"C:\Users\jakubdolnicek\source\repos\MAD - CV1\MAD - CV1\results.txt";
- private static int allIterationsCount = 0;
- //outlook == sunny && humidity == high && play == no
- private static int firstRuleFounds = 0;
- private static int firstRuleFoundsCorrect = 0;
- //outlook == rainy && windy == true && play == no
- private static int secondRuleFounds = 0;
- private static int secondRuleFoundsCorrect = 0;
- //outlook == overcast && play == yes
- private static int thirdRuleFounds = 0;
- private static int thirdRuleFoundsCorrect = 0;
- //humidity == normal && play == yes
- private static int fourthRuleFounds = 0;
- private static int fourthRuleFoundsCorrect = 0;
- //none of above play == yes
- private static int fifthRuleFounds = 0;
- private static int fifthRuleFoundsCorrect = 0;
- enum OutlookOptions
- {
- sunny,
- overcast,
- rainy,
- none
- }
- enum TemperatureOptions
- {
- hot,
- mild,
- cool,
- none
- }
- enum HumidityOptions
- {
- high,
- normal,
- none
- }
- enum WindyOptions
- {
- TRUE,
- FALSE,
- none
- }
- enum PlayOptions
- {
- yes,
- no
- }
- static List<string> resultLines = new List<string>();
- static bool CheckFirstRule(OutlookOptions outlook, HumidityOptions humidity, PlayOptions play)
- {
- if (outlook == OutlookOptions.sunny && humidity == HumidityOptions.high)
- {
- Program.firstRuleFounds++;
- if (play == PlayOptions.no)
- {
- Program.firstRuleFoundsCorrect++;
- }
- return true;
- }
- return false;
- }
- static bool CheckSecondRule(OutlookOptions outlook, WindyOptions windy, PlayOptions play)
- {
- if (outlook == OutlookOptions.rainy && windy == WindyOptions.TRUE)
- {
- Program.secondRuleFounds++;
- if (play == PlayOptions.no)
- {
- Program.secondRuleFoundsCorrect++;
- }
- return true;
- }
- return false;
- }
- static bool CheckThirdRule(OutlookOptions outlook, PlayOptions play)
- {
- if (outlook == OutlookOptions.overcast)
- {
- Program.thirdRuleFounds++;
- if (play == PlayOptions.yes)
- {
- Program.thirdRuleFoundsCorrect++;
- }
- return true;
- }
- return false;
- }
- static bool CheckFourthRule(HumidityOptions humidity, PlayOptions play)
- {
- if (humidity == HumidityOptions.normal)
- {
- Program.fourthRuleFounds++;
- if (play == PlayOptions.yes)
- {
- Program.fourthRuleFoundsCorrect++;
- }
- return true;
- }
- return false;
- }
- static void CheckFifthRule(PlayOptions play)
- {
- Program.fifthRuleFounds++;
- if (play == PlayOptions.yes)
- {
- Program.fifthRuleFoundsCorrect++;
- }
- }
- static double Support(int r, int n)
- {
- return (double)r / n;
- }
- static double Confidence(int Cmax, int r)
- {
- return (double)Cmax / r;
- }
- static double toProcents(double value)
- {
- return value * 100;
- }
- static void calcResults(int ruleFounds, int ruleFoundsCorrect, string ruleName)
- {
- resultLines.Add(
- ruleName
- + " support: " + toProcents(Support(ruleFounds, allIterationsCount)).ToString()
- + "% confidence: " + toProcents(Confidence(ruleFoundsCorrect, ruleFounds)).ToString() + "%"
- );
- }
- static void printResults()
- {
- System.IO.File.WriteAllLines(FILE_DESTINATION, resultLines.ToArray());
- }
- public static void Main(string[] args)
- {
- foreach(OutlookOptions outlook in Enum.GetValues(typeof(OutlookOptions)))
- {
- foreach (TemperatureOptions temperature in Enum.GetValues(typeof(TemperatureOptions)))
- {
- foreach (HumidityOptions humidity in Enum.GetValues(typeof(HumidityOptions)))
- {
- foreach (WindyOptions windy in Enum.GetValues(typeof(WindyOptions)))
- {
- foreach (PlayOptions play in Enum.GetValues(typeof(PlayOptions)))
- {
- allIterationsCount++;
- bool somethingMatch = false;
- somethingMatch = CheckFirstRule(outlook, humidity, play) ? true : false;
- somethingMatch = CheckSecondRule(outlook, windy, play) || somethingMatch ? true : false;
- somethingMatch = CheckThirdRule(outlook, play) || somethingMatch ? true : false;
- somethingMatch = CheckFourthRule(humidity, play) || somethingMatch ? true : false;
- if (!somethingMatch)
- {
- CheckFifthRule(play);
- }
- }
- }
- }
- }
- }
- calcResults(Program.firstRuleFounds, Program.firstRuleFoundsCorrect, "outlook == sunny && humidity == high && play == no");
- calcResults(Program.secondRuleFounds, Program.secondRuleFoundsCorrect, "outlook == rainy && windy == true && play == no");
- calcResults(Program.thirdRuleFounds, Program.thirdRuleFoundsCorrect, "outlook == overcast && play == yes");
- calcResults(Program.fourthRuleFounds, Program.fourthRuleFoundsCorrect, "humidity == normal && play == yes");
- calcResults(Program.fifthRuleFounds, Program.fifthRuleFoundsCorrect, "none of above play == yes");
- printResults();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement