コード例 #1
0
ファイル: LogicNode.cs プロジェクト: Hawkie/Solver
 public virtual void Parse(object data, ILogicStack stack)
 {
     foreach (ILogicNode node in this)
     {
         node.Parse(data, stack);
     }
 }
コード例 #2
0
ファイル: LogicNode2.cs プロジェクト: Hawkie/Solver
 /// <summary>
 /// The min, max, add, sub nodes all expect two nodes that have one result on its leaf
 /// </summary>
 /// <param name="data"></param>
 /// <returns></returns>
 public override void Parse(object data, ILogicStack stack)
 {
     base.Parse(data, stack);
     if (stack.Count() < 2)
     {
         throw new InvalidExpressionException("Node should only have two sub nodes");
     }
 }
コード例 #3
0
        public override void Parse(object data, ILogicStack stack)
        {
            ILogicResult    sum = new LogicResult(0);
            ILogicOperation op  = new LogicOperation("Add", true);

            foreach (ILogicNode node in this)
            {
                node.Parse(data, stack);
                KeyValuePair <ILogicOperation, ILogicResult> item = stack.Pop();
                sum = sum.Add(item.Value);
                if (item.Key != null)
                {
                    op.Add(item.Key);
                }
            }
            op.Result = sum.ToString();
            stack.Push(new KeyValuePair <ILogicOperation, ILogicResult>(op, sum));
        }
コード例 #4
0
        public override void Parse(object data, ILogicStack stack)
        {
            ILogicOperation op = new LogicOperation("Min");
            ILogicResult    r1 = new LogicResult(LogicResult.MaxValue);

            foreach (ILogicNode node in this)
            {
                node.Parse(data, stack);
                KeyValuePair <ILogicOperation, ILogicResult> r = stack.Pop();
                if (r.Value.CompareTo(r1) < 0)
                {
                    // Set the minimum
                    r1.Value = r.Value.Value;
                }
                op.Add(r.Key);
            }
            op.Result = r1.Value.ToString();
            stack.Push(new KeyValuePair <ILogicOperation, ILogicResult>(op, r1));
        }
コード例 #5
0
ファイル: LinearLowerLimit.cs プロジェクト: Hawkie/Solver
        /// <summary>
        /// The min, max, add, sub nodes all expect two nodes that have one result on its leaf
        /// </summary>
        /// <param name="data"></param>
        /// <param name="stack"></param>
        /// <returns></returns>
        public override void Parse(object data, ILogicStack stack)
        {
            base.Parse(data, stack);

            KeyValuePair <ILogicOperation, ILogicResult> v2 = stack.Pop();
            KeyValuePair <ILogicOperation, ILogicResult> v1 = stack.Pop();

            ILogicOperation op = new LogicOperation("LinearLower");

            op.Add(v2.Key);
            op.Add(v1.Key);
            ILogicResult below = new LogicResult(0);

            if (v1.Value.CompareTo(v2.Value) == -1)
            {
                below = v1.Value.Subtract(v2.Value);
            }
            op.Result = below.ToString();
            stack.Push(new KeyValuePair <ILogicOperation, ILogicResult>(op, below));
        }
コード例 #6
0
        /// <summary>
        /// The min, max, add, sub nodes all expect two nodes that have one result on its leaf
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public override void Parse(object data, ILogicStack stack)
        {
            base.Parse(data, stack);

            KeyValuePair <ILogicOperation, ILogicResult> v2 = stack.Pop();
            KeyValuePair <ILogicOperation, ILogicResult> v1 = stack.Pop();

            ILogicResult    result = new LogicResult(0);
            ILogicOperation op     = new LogicOperation("LinearEqual");

            op.Add(v2.Key);
            op.Add(v1.Key);
            if (v1.Value.CompareTo(v2.Value) != 0)
            {
                result = new LogicResult(v2.Value.ToInt32 - v1.Value.ToInt32);
            }

            op.Result = result.ToString();
            stack.Push(new KeyValuePair <ILogicOperation, ILogicResult>(op, result));
        }
コード例 #7
0
        /// <summary>
        /// The min, max, add, sub nodes all expect two nodes that have one result on its leaf
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public override void Parse(object data, ILogicStack stack)
        {
            base.Parse(data, stack);

            KeyValuePair <ILogicOperation, ILogicResult> v2 = stack.Pop();
            KeyValuePair <ILogicOperation, ILogicResult> v1 = stack.Pop();

            ILogicOperation op = new LogicOperation("BitwiseAndTrue");

            op.Add(v2.Key);
            op.Add(v1.Key);
            ILogicResult result = new LogicResult(LogicResult.MinValue);

            if (v1.Value.And(v2.Value).NotZero)
            {
                result = new LogicResult(0);
            }

            op.Result = result.ToString();
            stack.Push(new KeyValuePair <ILogicOperation, ILogicResult>(op, result));
        }
コード例 #8
0
ファイル: AbsoluteUpperLimit.cs プロジェクト: Hawkie/Solver
        /// <summary>
        /// The min, max, add, sub nodes all expect two nodes that have one result on its leaf
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public override void Parse(object data, ILogicStack stack)
        {
            base.Parse(data, stack);

            KeyValuePair <ILogicOperation, ILogicResult> v3 = stack.Pop();
            KeyValuePair <ILogicOperation, ILogicResult> v2 = stack.Pop();
            KeyValuePair <ILogicOperation, ILogicResult> v1 = stack.Pop();

            ILogicOperation op = new LogicOperation("AbsoluteUpper");

            op.Add(v3.Key);
            op.Add(v2.Key);
            op.Add(v1.Key);
            ILogicResult above = new LogicResult(0);

            if (v1.Value.CompareTo(v2.Value) == 1)
            {
                above = new LogicResult(v3.Value.ToInt32);
            }

            op.Result = above.ToString();
            stack.Push(new KeyValuePair <ILogicOperation, ILogicResult>(op, above));
        }
コード例 #9
0
        /// <summary>
        /// The min, max, add, sub nodes all expect two nodes that have one result on its leaf
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public override void Parse(object data, ILogicStack stack)
        {
            base.Parse(data, stack);

            KeyValuePair <ILogicOperation, ILogicResult> v3 = stack.Pop();
            KeyValuePair <ILogicOperation, ILogicResult> v2 = stack.Pop();
            KeyValuePair <ILogicOperation, ILogicResult> v1 = stack.Pop();

            ILogicOperation op = new LogicOperation("AbsoluteEqual");

            op.Add(v3.Key);
            op.Add(v2.Key);
            op.Add(v1.Key);
            ILogicResult notequal = new LogicResult(0);

            if (v1.Value.CompareTo(v2.Value) != 0)
            {
                notequal.Value = v3.Value.ToInt32;
            }

            op.Result = notequal.ToString();
            stack.Push(new KeyValuePair <ILogicOperation, ILogicResult>(op, notequal));
        }
コード例 #10
0
ファイル: LogicNodeLeaf.cs プロジェクト: Hawkie/Solver
 public override void Parse(object data, ILogicStack stack)
 {
     stack.Push(this.Leaf.Check(data));
 }