コード例 #1
0
ファイル: DecisionTree.cs プロジェクト: Kostuch6/Inzynierka
        public DecisionTree(List <int> probabilityList, State state, State maxValues, List <Test> tests, CryptoRandom r)
        {
            R = r;
            DecisionNode parent = generateDecisionNode(state, maxValues, tests);

            //Console.WriteLine("root: Stat -> {0}, Test -> {1}, Param -> {2}",parent.Decision.Statistic, parent.Decision.Test.ToString(), parent.Decision.Param);
            elementCount++;
            parent.Key = elementCount;
            root       = parent;
            generateTree(probabilityList, parent, 1, state, maxValues, tests);
        }
コード例 #2
0
ファイル: DecisionTree.cs プロジェクト: Kostuch6/Inzynierka
        public DecisionNode generateDecisionNode(State state, State maxValues, List <Test> tests)
        {
            List <string> statistics = state.Keys.ToList();                     // lista wszystkich statystyk
            string        stat       = statistics[R.Next(0, statistics.Count)]; // wybranie losowo jednej statystyki dla decyzji
            int           param      = R.Next(0, maxValues[stat] + 1);          // wylosowanie parametru do porownania statystyki z odpowiedniego przedzialu
            Test          test       = tests[R.Next(0, tests.Count)];           // wylosowanie operatora
            Decision      decision   = new Decision(stat, test, param);
            DecisionNode  node       = new DecisionNode(decision);

            //Console.WriteLine("Node: Stat -> {0}, Test -> {1}, Param -> {2}", node.Decision.Statistic, node.Decision.Test.ToString(), node.Decision.Param);

            return(node);
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: Kostuch6/Inzynierka
        public static DecisionTree CreateEnemy(CryptoRandom r, State state, List <Test> tests)
        {
            ResultNode node3 = new ResultNode {
                Key = 3, Move = Move.LONG_MOVE_FORWARD
            };
            ResultNode node5 = new ResultNode {
                Key = 5, Move = Move.LONG_MOVE_FORWARD
            };
            ResultNode node6 = new ResultNode {
                Key = 6, Move = Move.ATTACK_ROCKET
            };
            ResultNode node9 = new ResultNode {
                Key = 9, Move = Move.SHORT_MOVE_FORWARD_THEN_ATTACK
            };
            ResultNode node10 = new ResultNode {
                Key = 10, Move = Move.SHORT_MOVE_FORWARD
            };
            ResultNode node11 = new ResultNode {
                Key = 11, Move = Move.ATTACK_FAR
            };
            DecisionNode node4 = new DecisionNode {
                Key = 4, Decision = new Decision {
                    Statistic = "enemyIsInDanger", Param = 0, Test = tests[0]
                }, leftChild = node5, rightChild = node6
            };
            DecisionNode node8 = new DecisionNode {
                Key = 8, Decision = new Decision {
                    Statistic = "distance", Param = 4, Test = tests[2]
                }, leftChild = node9, rightChild = node10
            };
            DecisionNode node2 = new DecisionNode {
                Key = 2, Decision = new Decision {
                    Statistic = "enemyIsDefending", Param = 0, Test = tests[0]
                }, leftChild = node3, rightChild = node4
            };
            DecisionNode node7 = new DecisionNode {
                Key = 7, Decision = new Decision {
                    Statistic = "enemyIsInDanger", Param = 0, Test = tests[0]
                }, leftChild = node8, rightChild = node11
            };
            DecisionNode node1 = new DecisionNode {
                Key = 1, Decision = new Decision {
                    Statistic = "distance", Param = 6, Test = tests[0]
                }, leftChild = node2, rightChild = node7
            };

            return(new DecisionTree {
                R = r, elementCount = 11, fitness = 0, root = node1
            });
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: Kostuch6/Inzynierka
        public static void Mutation(DecisionTree individual, CryptoRandom r, State state, State maxValues, List <Test> tests)
        {
            int  node         = r.Next(1, individual.elementCount + 1);
            Node nodeToMutate = individual.Find(node, individual.root);

            if (nodeToMutate is DecisionNode)
            {
                DecisionNode newNode = individual.generateDecisionNode(state, maxValues, tests);
                ((DecisionNode)nodeToMutate).Decision = newNode.Decision;
            }
            else if (nodeToMutate is ResultNode)
            {
                ResultNode newNode = individual.GenerateResultNode();
                ((ResultNode)nodeToMutate).Move = newNode.Move;
            }
        }
コード例 #5
0
ファイル: DecisionTree.cs プロジェクト: Kostuch6/Inzynierka
        //utworzenie wezla (tylko w rootcie)

        // sprawdzenie czy powinien miec lewy wezel
        //TAK
        //utworzenie wezla, podczepienie do leftChild
        //rekurencja od leftChild
        //NIE
        //utworzenie liscia

        // sprawdzenie czy powinien miec prawy wezel
        //TAK
        //utworzenie wezla, podczepienie do rightChild
        //rekurencja od rightChild
        //NIE
        //utworzenie liscia

        public void generateTree(List <int> probabilityList, Node parent, int levelIndex, State state, State maxValues, List <Test> tests)
        {
            //Console.WriteLine("Poziom: {0}", levelIndex);
            //Console.ReadLine();
            if (probabilityList[levelIndex] >= R.Next(1, 101))
            {
                //Console.WriteLine("Generowanie lewego wezla");
                DecisionNode leftChild = generateDecisionNode(state, maxValues, tests);
                elementCount++;
                leftChild.Key    = elementCount;
                parent.leftChild = leftChild;
                generateTree(probabilityList, leftChild, levelIndex + 1, state, maxValues, tests);
            }
            else
            {
                //Console.WriteLine("Generowanie lewego liscia");
                parent.leftChild = GenerateResultNode();
                elementCount++;
                parent.leftChild.Key = elementCount;
            }

            //Console.WriteLine("Powrot na poziom: {0}", levelIndex);

            if (probabilityList[levelIndex] >= R.Next(1, 101))
            {
                //Console.WriteLine("Generowanie prawego wezla");
                DecisionNode rightChild = generateDecisionNode(state, maxValues, tests);
                elementCount++;
                rightChild.Key    = elementCount;
                parent.rightChild = rightChild;
                generateTree(probabilityList, rightChild, levelIndex + 1, state, maxValues, tests);
            }
            else
            {
                //Console.WriteLine("Generowanie prawego liscia");
                parent.rightChild = GenerateResultNode();
                elementCount++;
                parent.rightChild.Key = elementCount;
            }
        }