public void DoubleAddWorks()
        {
            var a = new Interval <double>(5, 10);
            var b = new Interval <double>(3, 15);
            var c = new Interval <double>(15, 100);

            Assert.AreEqual((8.0, 25.0).AsInterval(), a.Add(b));
            Assert.AreEqual((20.0, 110.0).AsInterval(), a.Add(c));
        }
Beispiel #2
0
 /// <summary>
 /// Initializes the storyboards and sets their duration
 /// </summary>
 private void InitializeStoryboards()
 {
     m_moveStoryboard          = (Storyboard)FindResource("MoveStoryboard");
     m_moveStoryboard.Duration = new Duration(Interval.Add(TimeSpan.FromSeconds(1)));
     foreach (var child in m_moveStoryboard.Children)
     {
         child.Duration = m_moveStoryboard.Duration;
         Storyboard.SetTargetName(child, "");
     }
 }
        public bool Conflicts(ShowtimeGroupEntry other, int movieLength)
        {
            SetInterval();
            other.SetInterval();

            if (Interval.Add(new TimeSpan(0, movieLength, 0)) > other.Interval && RoomID == other.RoomID)
            {
                return(true);
            }
            return(false);
        }
Beispiel #4
0
        public void TestIntervalAddOperation()
        {
            //add        [x1,x2] + [y1,y2] = [x1 + y1,x2 + y2]

            // [-1,1] + [-2,2] = [-3,3]
            Assert.AreEqual(Interval.Add(a, b), new Interval(-3, 3));
            //([-1, 1] + [-2, 2]) + [0, 3] = [-3, 6]
            Assert.AreEqual(Interval.Add(Interval.Add(a, b), c), new Interval(-3, 6));
            //([-1, 1] + [0, 3]) + [-2, 2] = [-3, 6]
            Assert.AreEqual(Interval.Add(Interval.Add(a, c), b), new Interval(-3, 6));
        }
Beispiel #5
0
        private Interval Evaluate(Instruction[] instructions, ref int instructionCounter, IDictionary <ISymbolicExpressionTreeNode, Interval> nodeIntervals = null)
        {
            Instruction currentInstr = instructions[instructionCounter];

            //Use ref parameter, because the tree will be iterated through recursively from the left-side branch to the right side
            //Update instructionCounter, whenever Evaluate is called
            instructionCounter++;
            Interval result = null;

            switch (currentInstr.opCode)
            {
            //Variables, Constants, ...
            case OpCodes.Variable: {
                var variableTreeNode = (VariableTreeNode)currentInstr.dynamicNode;
                var weightInterval   = new Interval(variableTreeNode.Weight, variableTreeNode.Weight);
                var variableInterval = (Interval)currentInstr.data;

                result = Interval.Multiply(variableInterval, weightInterval);
                break;
            }

            case OpCodes.Constant: {
                var constTreeNode = (ConstantTreeNode)currentInstr.dynamicNode;
                result = new Interval(constTreeNode.Value, constTreeNode.Value);
                break;
            }

            //Elementary arithmetic rules
            case OpCodes.Add: {
                result = Evaluate(instructions, ref instructionCounter, nodeIntervals);
                for (int i = 1; i < currentInstr.nArguments; i++)
                {
                    var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals);
                    result = Interval.Add(result, argumentInterval);
                }
                break;
            }

            case OpCodes.Sub: {
                result = Evaluate(instructions, ref instructionCounter, nodeIntervals);
                if (currentInstr.nArguments == 1)
                {
                    result = Interval.Multiply(new Interval(-1, -1), result);
                }

                for (int i = 1; i < currentInstr.nArguments; i++)
                {
                    var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals);
                    result = Interval.Subtract(result, argumentInterval);
                }
                break;
            }

            case OpCodes.Mul: {
                result = Evaluate(instructions, ref instructionCounter, nodeIntervals);
                for (int i = 1; i < currentInstr.nArguments; i++)
                {
                    var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals);
                    result = Interval.Multiply(result, argumentInterval);
                }
                break;
            }

            case OpCodes.Div: {
                result = Evaluate(instructions, ref instructionCounter, nodeIntervals);
                if (currentInstr.nArguments == 1)
                {
                    result = Interval.Divide(new Interval(1, 1), result);
                }

                for (int i = 1; i < currentInstr.nArguments; i++)
                {
                    var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals);
                    result = Interval.Divide(result, argumentInterval);
                }
                break;
            }

            //Trigonometric functions
            case OpCodes.Sin: {
                var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals);
                result = Interval.Sine(argumentInterval);
                break;
            }

            case OpCodes.Cos: {
                var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals);
                result = Interval.Cosine(argumentInterval);
                break;
            }

            case OpCodes.Tan: {
                var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals);
                result = Interval.Tangens(argumentInterval);
                break;
            }

            case OpCodes.Tanh: {
                var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals);
                result = Interval.HyperbolicTangent(argumentInterval);
                break;
            }

            //Exponential functions
            case OpCodes.Log: {
                var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals);
                result = Interval.Logarithm(argumentInterval);
                break;
            }

            case OpCodes.Exp: {
                var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals);
                result = Interval.Exponential(argumentInterval);
                break;
            }

            case OpCodes.Power: {
                result = Evaluate(instructions, ref instructionCounter, nodeIntervals);
                for (int i = 1; i < currentInstr.nArguments; i++)
                {
                    var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals);
                    result = Interval.Power(result, argumentInterval);
                }
                break;
            }

            case OpCodes.Square: {
                var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals);
                result = Interval.Square(argumentInterval);
                break;
            }

            case OpCodes.Root: {
                result = Evaluate(instructions, ref instructionCounter, nodeIntervals);
                for (int i = 1; i < currentInstr.nArguments; i++)
                {
                    var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals);
                    result = Interval.Root(result, argumentInterval);
                }
                break;
            }

            case OpCodes.SquareRoot: {
                var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals);
                result = Interval.SquareRoot(argumentInterval);
                break;
            }

            default:
                throw new NotSupportedException($"The tree contains the unknown symbol {currentInstr.dynamicNode.Symbol}");
            }

            if (nodeIntervals != null)
            {
                nodeIntervals.Add(currentInstr.dynamicNode, result);
            }

            return(result);
        }