Exemplo n.º 1
0
    private DecisionTree CreateTree(Queue <String> prioritizedColumns, String currItem, Operand operation)
    {
        //nodeValue = ColumnName
        String nodeValue;
        String debugOperation = " | " + operation.ToString();

        nodeValue = currItem.Equals(prioritizedColumns.Peek()) ? prioritizedColumns.Dequeue() : currItem;

        //DecisionTree node = new DecisionTree(nodeValue + debugOperation);

        if (prioritizedColumns.Count != 0)
        {
            DecisionTree  node           = new DecisionTree(nodeValue);
            List <Object> possibleValues = db.GetDistinctValues(this.tableName, nodeValue, operation);
            String        nextValue      = prioritizedColumns.Peek();
            possibleValues.ForEach(delegate(Object obj){
                Queue <String> queueClone = new Queue <String>();
                prioritizedColumns.ToList <String>().ForEach(i => queueClone.Enqueue(i));
                node.AddEdge(obj, CreateTree(queueClone, nextValue, Operand.Clone(operation).Add(Operand.Comparison.EQUALS, nodeValue, obj)));
            });
            return(node);
        }
        else //Leaf Node so we add one more node for its value
        {
            DecisionTreeLeaf node           = new DecisionTreeLeaf(nodeValue);
            List <Object>    possibleValues = db.GetColumnValues(this.tableName, nodeValue, false, operation);
            node.AddLeafValue(possibleValues);
            node.GetValuesCount().ToList().ForEach(delegate(KeyValuePair <string, int> kv)
            {
                DecisionTreeLeaf leaf = new DecisionTreeLeaf(kv.Key + " : " + kv.Value + debugOperation);
                node.AddEdge(kv.Key, leaf);
            });
            return(node);
        }
    }
Exemplo n.º 2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        DecisionTree root      = new DecisionTree("Weather");
        DecisionTree temp      = new DecisionTree("Temperature");
        DecisionTree rainTemp  = new DecisionTree("RainTemperature");
        DecisionTree cloudTemp = new DecisionTree("CloudTemperature");


        root.AddEdge("Sun", temp);
        root.AddEdge("Rain", rainTemp);
        root.AddEdge("Cloudy", cloudTemp);

        temp.AddEdge("High", rainTemp);
        rainTemp.AddEdge("Rain", cloudTemp);



        List <DecisionTree> trees = root.Traverse(1.2);

        //Response.Write("Value: " + trees.First().node.value);
        //TraverseTree(root);
        GenerateJS(root);
    }