Exemple #1
0
 private void startToolStripMenuItem_Click(object sender, EventArgs e)
 {
     roadSelection = new FuzzyEngine();
     random        = new Random();
     setEngines();
     setTLights(state);
 }
Exemple #2
0
        private void setEngines()
        {
            roadpopulation = new MembershipFunctionCollection();

            roadpopulation.Add(new MembershipFunction("Low", -25, -25, 0, 20));
            roadpopulation.Add(new MembershipFunction("Mid", 10, 30, 30, 50));
            roadpopulation.Add(new MembershipFunction("High", 40, 60, 85, 85));

            road1 = new LinguisticVariable("Road1", roadpopulation);
            road2 = new LinguisticVariable("Road2", roadpopulation);
            road3 = new LinguisticVariable("Road3", roadpopulation);
            road4 = new LinguisticVariable("Road4", roadpopulation);

            nextGreenSelection = new MembershipFunctionCollection();
            nextGreenSelection.Add(new MembershipFunction("TrafficLight1", 0, 0, 1, 3));
            nextGreenSelection.Add(new MembershipFunction("TrafficLight2", 3, 4, 4, 6));
            nextGreenSelection.Add(new MembershipFunction("TrafficLight3", 6, 7, 7, 9));
            nextGreenSelection.Add(new MembershipFunction("TrafficLight4", 9, 10, 10, 12));
            nextGreenSelection.Add(new MembershipFunction("Uncertain", 12, 13, 14, 14));
            nextGreen = new LinguisticVariable("NextGreen", nextGreenSelection);

            roadSelection = new FuzzyEngine();

            roadSelection.LinguisticVariableCollection.Add(road1);
            roadSelection.LinguisticVariableCollection.Add(road2);
            roadSelection.LinguisticVariableCollection.Add(road3);
            roadSelection.LinguisticVariableCollection.Add(road4);
            roadSelection.LinguisticVariableCollection.Add(nextGreen);



            roadSelection.FuzzyRuleCollection.Add(new FuzzyRule("IF (Road1 IS Low) AND (Road2 IS Low) AND (Road3 IS Low) AND (Road4 IS Low) THEN NextGreen IS TrafficLight2"));
            roadSelection.FuzzyRuleCollection.Add(new FuzzyRule("IF (Road1 IS Low) AND (Road2 IS Low) AND (Road3 IS Low) AND (Road4 IS Mid) THEN NextGreen IS TrafficLight4"));
            roadSelection.FuzzyRuleCollection.Add(new FuzzyRule("IF (Road1 IS Low) AND (Road2 IS Low) AND (Road3 IS Low) AND (Road4 IS High) THEN NextGreen IS TrafficLight4"));
            roadSelection.FuzzyRuleCollection.Add(new FuzzyRule("IF (Road1 IS Low) AND (Road2 IS Low) AND (Road3 IS Mid) AND (Road4 IS Low) THEN NextGreen IS TrafficLight3"));
            roadSelection.FuzzyRuleCollection.Add(new FuzzyRule("IF (Road1 IS Low) AND (Road2 IS Low) AND (Road3 IS Mid) AND (Road4 IS Mid) THEN NextGreen IS TrafficLight3"));
            roadSelection.FuzzyRuleCollection.Add(new FuzzyRule("IF (Road1 IS Low) AND (Road2 IS Low) AND (Road3 IS Mid) AND (Road4 IS High) THEN NextGreen IS TrafficLight4"));
            roadSelection.FuzzyRuleCollection.Add(new FuzzyRule("IF (Road1 IS Low) AND (Road2 IS Low) AND (Road3 IS High) AND (Road4 IS Low) THEN NextGreen IS TrafficLight3"));
            roadSelection.FuzzyRuleCollection.Add(new FuzzyRule("IF (Road1 IS Low) AND (Road2 IS Low) AND (Road3 IS High) AND (Road4 IS Mid) THEN NextGreen IS TrafficLight3"));
            roadSelection.FuzzyRuleCollection.Add(new FuzzyRule("IF (Road1 IS Low) AND (Road2 IS Low) AND (Road3 IS High) AND (Road4 IS High) THEN NextGreen IS TrafficLight3"));
            roadSelection.FuzzyRuleCollection.Add(new FuzzyRule("IF (Road1 IS Low) AND (Road2 IS Mid) AND (Road3 IS Low) AND (Road4 IS Low) THEN NextGreen IS TrafficLight2"));
            roadSelection.FuzzyRuleCollection.Add(new FuzzyRule("IF (Road1 IS Low) AND (Road2 IS Mid) AND (Road3 IS Low) AND (Road4 IS Mid) THEN NextGreen IS TrafficLight2"));
            roadSelection.FuzzyRuleCollection.Add(new FuzzyRule("IF (Road1 IS Low) AND (Road2 IS Mid) AND (Road3 IS Low) AND (Road4 IS High) THEN NextGreen IS TrafficLight4"));
            roadSelection.FuzzyRuleCollection.Add(new FuzzyRule("IF (Road1 IS Low) AND (Road2 IS Mid) AND (Road3 IS Mid) AND (Road4 IS Low) THEN NextGreen IS TrafficLight3"));
            roadSelection.FuzzyRuleCollection.Add(new FuzzyRule("IF (Road1 IS Low) AND (Road2 IS Mid) AND (Road3 IS Mid) AND (Road4 IS Mid) THEN NextGreen IS TrafficLight2"));
            roadSelection.FuzzyRuleCollection.Add(new FuzzyRule("IF (Road1 IS Low) AND (Road2 IS Mid) AND (Road3 IS Mid) AND (Road4 IS High) THEN NextGreen IS TrafficLight4"));
            roadSelection.FuzzyRuleCollection.Add(new FuzzyRule("IF (Road1 IS Low) AND (Road2 IS Mid) AND (Road3 IS High) AND (Road4 IS Low) THEN NextGreen IS TrafficLight3"));
            roadSelection.FuzzyRuleCollection.Add(new FuzzyRule("IF (Road1 IS Low) AND (Road2 IS Mid) AND (Road3 IS High) AND (Road4 IS Mid) THEN NextGreen IS TrafficLight3"));
            roadSelection.FuzzyRuleCollection.Add(new FuzzyRule("IF (Road1 IS Low) AND (Road2 IS Mid) AND (Road3 IS High) AND (Road4 IS High) THEN NextGreen IS TrafficLight4"));
            roadSelection.FuzzyRuleCollection.Add(new FuzzyRule("IF (Road1 IS Low) AND (Road2 IS High) AND (Road3 IS Low) AND (Road4 IS Low) THEN NextGreen IS TrafficLight2"));
            roadSelection.FuzzyRuleCollection.Add(new FuzzyRule("IF (Road1 IS Low) AND (Road2 IS High) AND (Road3 IS Low) AND (Road4 IS Mid) THEN NextGreen IS TrafficLight2"));
            roadSelection.FuzzyRuleCollection.Add(new FuzzyRule("IF (Road1 IS Low) AND (Road2 IS High) AND (Road3 IS Low) AND (Road4 IS High) THEN NextGreen IS TrafficLight2"));
            roadSelection.FuzzyRuleCollection.Add(new FuzzyRule("IF (Road1 IS Low) AND (Road2 IS High) AND (Road3 IS Mid) AND (Road4 IS Low) THEN NextGreen IS TrafficLight2"));
            roadSelection.FuzzyRuleCollection.Add(new FuzzyRule("IF (Road1 IS Low) AND (Road2 IS High) AND (Road3 IS Mid) AND (Road4 IS Mid) THEN NextGreen IS TrafficLight2"));
            roadSelection.FuzzyRuleCollection.Add(new FuzzyRule("IF (Road1 IS Low) AND (Road2 IS High) AND (Road3 IS Mid) AND (Road4 IS High) THEN NextGreen IS TrafficLight4"));
            roadSelection.FuzzyRuleCollection.Add(new FuzzyRule("IF (Road1 IS Low) AND (Road2 IS High) AND (Road3 IS High) AND (Road4 IS Low) THEN NextGreen IS TrafficLight2"));
            roadSelection.FuzzyRuleCollection.Add(new FuzzyRule("IF (Road1 IS Low) AND (Road2 IS High) AND (Road3 IS High) AND (Road4 IS Mid) THEN NextGreen IS TrafficLight3"));
            roadSelection.FuzzyRuleCollection.Add(new FuzzyRule("IF (Road1 IS Low) AND (Road2 IS High) AND (Road3 IS High) AND (Road4 IS High) THEN NextGreen IS TrafficLight2"));
            roadSelection.FuzzyRuleCollection.Add(new FuzzyRule("IF (Road1 IS Mid) AND (Road2 IS Low) AND (Road3 IS Low) AND (Road4 IS Low) THEN NextGreen IS TrafficLight1"));
            roadSelection.FuzzyRuleCollection.Add(new FuzzyRule("IF (Road1 IS Mid) AND (Road2 IS Low) AND (Road3 IS Low) AND (Road4 IS Mid) THEN NextGreen IS TrafficLight1"));
            roadSelection.FuzzyRuleCollection.Add(new FuzzyRule("IF (Road1 IS Mid) AND (Road2 IS Low) AND (Road3 IS Low) AND (Road4 IS High) THEN NextGreen IS TrafficLight4"));
            roadSelection.FuzzyRuleCollection.Add(new FuzzyRule("IF (Road1 IS Mid) AND (Road2 IS Low) AND (Road3 IS Mid) AND (Road4 IS Low) THEN NextGreen IS TrafficLight1"));
            roadSelection.FuzzyRuleCollection.Add(new FuzzyRule("IF (Road1 IS Mid) AND (Road2 IS Low) AND (Road3 IS Mid) AND (Road4 IS Mid) THEN NextGreen IS TrafficLight1"));
            roadSelection.FuzzyRuleCollection.Add(new FuzzyRule("IF (Road1 IS Mid) AND (Road2 IS Low) AND (Road3 IS Mid) AND (Road4 IS High) THEN NextGreen IS TrafficLight4"));
            roadSelection.FuzzyRuleCollection.Add(new FuzzyRule("IF (Road1 IS Mid) AND (Road2 IS Low) AND (Road3 IS High) AND (Road4 IS Low) THEN NextGreen IS TrafficLight3"));
            roadSelection.FuzzyRuleCollection.Add(new FuzzyRule("IF (Road1 IS Mid) AND (Road2 IS Low) AND (Road3 IS High) AND (Road4 IS Mid) THEN NextGreen IS TrafficLight3"));
            roadSelection.FuzzyRuleCollection.Add(new FuzzyRule("IF (Road1 IS Mid) AND (Road2 IS Low) AND (Road3 IS High) AND (Road4 IS High) THEN NextGreen IS TrafficLight3"));
            roadSelection.FuzzyRuleCollection.Add(new FuzzyRule("IF (Road1 IS Mid) AND (Road2 IS Mid) AND (Road3 IS Low) AND (Road4 IS Low) THEN NextGreen IS TrafficLight2"));
            roadSelection.FuzzyRuleCollection.Add(new FuzzyRule("IF (Road1 IS Mid) AND (Road2 IS Mid) AND (Road3 IS Low) AND (Road4 IS Mid) THEN NextGreen IS TrafficLight1"));
            roadSelection.FuzzyRuleCollection.Add(new FuzzyRule("IF (Road1 IS Mid) AND (Road2 IS Mid) AND (Road3 IS Low) AND (Road4 IS High) THEN NextGreen IS TrafficLight4"));
            roadSelection.FuzzyRuleCollection.Add(new FuzzyRule("IF (Road1 IS Mid) AND (Road2 IS Mid) AND (Road3 IS Mid) AND (Road4 IS Low) THEN NextGreen IS TrafficLight2"));
            roadSelection.FuzzyRuleCollection.Add(new FuzzyRule("IF (Road1 IS Mid) AND (Road2 IS Mid) AND (Road3 IS Mid) AND (Road4 IS Mid) THEN NextGreen IS TrafficLight1"));
            roadSelection.FuzzyRuleCollection.Add(new FuzzyRule("IF (Road1 IS Mid) AND (Road2 IS Mid) AND (Road3 IS Mid) AND (Road4 IS High) THEN NextGreen IS TrafficLight4"));
            roadSelection.FuzzyRuleCollection.Add(new FuzzyRule("IF (Road1 IS Mid) AND (Road2 IS Mid) AND (Road3 IS High) AND (Road4 IS Low) THEN NextGreen IS TrafficLight3"));
            roadSelection.FuzzyRuleCollection.Add(new FuzzyRule("IF (Road1 IS Mid) AND (Road2 IS Mid) AND (Road3 IS High) AND (Road4 IS Mid) THEN NextGreen IS TrafficLight3"));
            roadSelection.FuzzyRuleCollection.Add(new FuzzyRule("IF (Road1 IS Mid) AND (Road2 IS Mid) AND (Road3 IS High) AND (Road4 IS High) THEN NextGreen IS TrafficLight3"));
            roadSelection.FuzzyRuleCollection.Add(new FuzzyRule("IF (Road1 IS Mid) AND (Road2 IS High) AND (Road3 IS Low) AND (Road4 IS Low) THEN NextGreen IS TrafficLight2"));
            roadSelection.FuzzyRuleCollection.Add(new FuzzyRule("IF (Road1 IS Mid) AND (Road2 IS High) AND (Road3 IS Low) AND (Road4 IS Mid) THEN NextGreen IS TrafficLight2"));
            roadSelection.FuzzyRuleCollection.Add(new FuzzyRule("IF (Road1 IS Mid) AND (Road2 IS High) AND (Road3 IS Low) AND (Road4 IS High) THEN NextGreen IS TrafficLight4"));
            roadSelection.FuzzyRuleCollection.Add(new FuzzyRule("IF (Road1 IS Mid) AND (Road2 IS High) AND (Road3 IS Mid) AND (Road4 IS Low) THEN NextGreen IS TrafficLight2"));
            roadSelection.FuzzyRuleCollection.Add(new FuzzyRule("IF (Road1 IS Mid) AND (Road2 IS High) AND (Road3 IS Mid) AND (Road4 IS Mid) THEN NextGreen IS TrafficLight2"));
            roadSelection.FuzzyRuleCollection.Add(new FuzzyRule("IF (Road1 IS Mid) AND (Road2 IS High) AND (Road3 IS Mid) AND (Road4 IS High) THEN NextGreen IS TrafficLight4"));
            roadSelection.FuzzyRuleCollection.Add(new FuzzyRule("IF (Road1 IS Mid) AND (Road2 IS High) AND (Road3 IS High) AND (Road4 IS Low) THEN NextGreen IS TrafficLight4"));
            roadSelection.FuzzyRuleCollection.Add(new FuzzyRule("IF (Road1 IS Mid) AND (Road2 IS High) AND (Road3 IS High) AND (Road4 IS Mid) THEN NextGreen IS TrafficLight3"));
            roadSelection.FuzzyRuleCollection.Add(new FuzzyRule("IF (Road1 IS Mid) AND (Road2 IS High) AND (Road3 IS High) AND (Road4 IS High) THEN NextGreen IS TrafficLight2"));
            roadSelection.FuzzyRuleCollection.Add(new FuzzyRule("IF (Road1 IS High) AND (Road2 IS Low) AND (Road3 IS Low) AND (Road4 IS Low) THEN NextGreen IS TrafficLight1"));
            roadSelection.FuzzyRuleCollection.Add(new FuzzyRule("IF (Road1 IS High) AND (Road2 IS Low) AND (Road3 IS Low) AND (Road4 IS Mid) THEN NextGreen IS TrafficLight1"));
            roadSelection.FuzzyRuleCollection.Add(new FuzzyRule("IF (Road1 IS High) AND (Road2 IS Low) AND (Road3 IS Low) AND (Road4 IS High) THEN NextGreen IS TrafficLight1"));
            roadSelection.FuzzyRuleCollection.Add(new FuzzyRule("IF (Road1 IS High) AND (Road2 IS Low) AND (Road3 IS Mid) AND (Road4 IS Low) THEN NextGreen IS TrafficLight1"));
            roadSelection.FuzzyRuleCollection.Add(new FuzzyRule("IF (Road1 IS High) AND (Road2 IS Low) AND (Road3 IS Mid) AND (Road4 IS Mid) THEN NextGreen IS TrafficLight1"));
            roadSelection.FuzzyRuleCollection.Add(new FuzzyRule("IF (Road1 IS High) AND (Road2 IS Low) AND (Road3 IS Mid) AND (Road4 IS High) THEN NextGreen IS TrafficLight4"));
            roadSelection.FuzzyRuleCollection.Add(new FuzzyRule("IF (Road1 IS High) AND (Road2 IS Low) AND (Road3 IS High) AND (Road4 IS Low) THEN NextGreen IS TrafficLight3"));
            roadSelection.FuzzyRuleCollection.Add(new FuzzyRule("IF (Road1 IS High) AND (Road2 IS Low) AND (Road3 IS High) AND (Road4 IS Mid) THEN NextGreen IS TrafficLight1"));
            roadSelection.FuzzyRuleCollection.Add(new FuzzyRule("IF (Road1 IS High) AND (Road2 IS Low) AND (Road3 IS High) AND (Road4 IS High) THEN NextGreen IS TrafficLight3"));
            roadSelection.FuzzyRuleCollection.Add(new FuzzyRule("IF (Road1 IS High) AND (Road2 IS Mid) AND (Road3 IS Low) AND (Road4 IS Low) THEN NextGreen IS TrafficLight1"));
            roadSelection.FuzzyRuleCollection.Add(new FuzzyRule("IF (Road1 IS High) AND (Road2 IS Mid) AND (Road3 IS Low) AND (Road4 IS Mid) THEN NextGreen IS TrafficLight1"));
            roadSelection.FuzzyRuleCollection.Add(new FuzzyRule("IF (Road1 IS High) AND (Road2 IS Mid) AND (Road3 IS Low) AND (Road4 IS High) THEN NextGreen IS TrafficLight4"));
            roadSelection.FuzzyRuleCollection.Add(new FuzzyRule("IF (Road1 IS High) AND (Road2 IS Mid) AND (Road3 IS Mid) AND (Road4 IS Low) THEN NextGreen IS TrafficLight1"));
            roadSelection.FuzzyRuleCollection.Add(new FuzzyRule("IF (Road1 IS High) AND (Road2 IS Mid) AND (Road3 IS Mid) AND (Road4 IS Mid) THEN NextGreen IS TrafficLight1"));
            roadSelection.FuzzyRuleCollection.Add(new FuzzyRule("IF (Road1 IS High) AND (Road2 IS Mid) AND (Road3 IS Mid) AND (Road4 IS High) THEN NextGreen IS TrafficLight4"));
            roadSelection.FuzzyRuleCollection.Add(new FuzzyRule("IF (Road1 IS High) AND (Road2 IS Mid) AND (Road3 IS High) AND (Road4 IS Low) THEN NextGreen IS TrafficLight1"));
            roadSelection.FuzzyRuleCollection.Add(new FuzzyRule("IF (Road1 IS High) AND (Road2 IS Mid) AND (Road3 IS High) AND (Road4 IS Mid) THEN NextGreen IS TrafficLight1"));
            roadSelection.FuzzyRuleCollection.Add(new FuzzyRule("IF (Road1 IS High) AND (Road2 IS Mid) AND (Road3 IS High) AND (Road4 IS High) THEN NextGreen IS TrafficLight3"));
            roadSelection.FuzzyRuleCollection.Add(new FuzzyRule("IF (Road1 IS High) AND (Road2 IS High) AND (Road3 IS Low) AND (Road4 IS Low) THEN NextGreen IS TrafficLight1"));
            roadSelection.FuzzyRuleCollection.Add(new FuzzyRule("IF (Road1 IS High) AND (Road2 IS High) AND (Road3 IS Low) AND (Road4 IS Mid) THEN NextGreen IS TrafficLight2"));
            roadSelection.FuzzyRuleCollection.Add(new FuzzyRule("IF (Road1 IS High) AND (Road2 IS High) AND (Road3 IS Low) AND (Road4 IS High) THEN NextGreen IS TrafficLight1"));
            roadSelection.FuzzyRuleCollection.Add(new FuzzyRule("IF (Road1 IS High) AND (Road2 IS High) AND (Road3 IS Mid) AND (Road4 IS Low) THEN NextGreen IS TrafficLight1"));
            roadSelection.FuzzyRuleCollection.Add(new FuzzyRule("IF (Road1 IS High) AND (Road2 IS High) AND (Road3 IS Mid) AND (Road4 IS Mid) THEN NextGreen IS TrafficLight3"));
            roadSelection.FuzzyRuleCollection.Add(new FuzzyRule("IF (Road1 IS High) AND (Road2 IS High) AND (Road3 IS Mid) AND (Road4 IS High) THEN NextGreen IS TrafficLight2"));
            roadSelection.FuzzyRuleCollection.Add(new FuzzyRule("IF (Road1 IS High) AND (Road2 IS High) AND (Road3 IS High) AND (Road4 IS Low) THEN NextGreen IS TrafficLight1"));
            roadSelection.FuzzyRuleCollection.Add(new FuzzyRule("IF (Road1 IS High) AND (Road2 IS High) AND (Road3 IS High) AND (Road4 IS Mid) THEN NextGreen IS TrafficLight1"));
            roadSelection.FuzzyRuleCollection.Add(new FuzzyRule("IF (Road1 IS High) AND (Road2 IS High) AND (Road3 IS High) AND (Road4 IS High) THEN NextGreen IS TrafficLight2"));

            roadSelection.Consequent = "NextGreen";
        }