public static Interval Calculate(Operation operation, Interval a, Interval b) { Interval result = new Interval(); switch (operation) { case Operation.Add: result.UpperBound = a.UpperBound + b.UpperBound; result.LowerBound = a.LowerBound + b.LowerBound; break; case Operation.Sub: result.UpperBound = a.UpperBound - b.LowerBound; result.LowerBound = a.LowerBound - b.UpperBound; break; case Operation.Mul: result.UpperBound = Math.Max(Math.Max(a.UpperBound * b.UpperBound, a.UpperBound * b.LowerBound), Math.Max(a.LowerBound * b.UpperBound, a.LowerBound * b.LowerBound)); result.LowerBound = Math.Min(Math.Min(a.UpperBound * b.UpperBound, a.UpperBound * b.LowerBound), Math.Min(a.LowerBound * b.UpperBound, a.LowerBound * b.LowerBound)); break; case Operation.Div: if (b.UpperBound != 0 && b.LowerBound != 0) { result.UpperBound = Math.Max(Math.Max(a.UpperBound / b.UpperBound, a.UpperBound / b.LowerBound), Math.Max(a.LowerBound / b.UpperBound, a.LowerBound / b.LowerBound)); result.LowerBound = Math.Min(Math.Min(a.UpperBound / b.UpperBound, a.UpperBound / b.LowerBound), Math.Min(a.LowerBound / b.UpperBound, a.LowerBound / b.LowerBound)); } break; default: break; } return result; }
public Interval AlphaCut(decimal y) { Interval result = new Interval(); if (y < 0 || y > 1) return null; if (y == 0) { result.LowerBound = BottomLeft; result.UpperBound = BottomRight; } else if (y == 1) { result.LowerBound = TopLeft; result.UpperBound = TopRight; } else //if (0 < y && y < 1) { result.LowerBound = y * (TopLeft - BottomLeft) + BottomLeft; result.UpperBound = y * (TopRight - BottomRight) + BottomRight; } return result; }