Beispiel #1
0
 private void ChangeWindowState(string command)
 {
     if (command == Minimize.ToString())
     {
         this.window.WindowState = WindowState.Minimized;
     }
     else if (command == Maximize.ToString())
     {
         if (this.window.WindowState == WindowState.Maximized)
         {
             this.window.WindowState = WindowState.Normal;
         }
         else
         {
             this.window.WindowState = WindowState.Maximized;
         }
     }
     else if (command == Close.ToString())
     {
         this.window.Close();
     }
     else
     {
         throw new InvalidOperationException(INVALID_WINDOW_COMMAND_EXCEPTION);
     }
 }
Beispiel #2
0
 /// <summary>
 /// Raises event 'Minimize'
 /// </summary>
 protected virtual void OnMinimize()
 {
     if (Minimize != null)
     {
         Minimize.Invoke(this, System.EventArgs.Empty);
     }
 }
Beispiel #3
0
        public void TestMinimizeTunet()
        {
            var netsMust = new IPv4Network[]
            {
                new IPv4Network(IPv4Address.Parse("128.130.0.0"), 15),
                new IPv4Network(IPv4Address.Parse("192.35.240.0"), 22),
                new IPv4Network(IPv4Address.Parse("192.35.244.0"), 24),
                new IPv4Network(IPv4Address.Parse("193.170.72.0"), 21),
                new IPv4Network(IPv4Address.Parse("193.170.72.0"), 22),
                new IPv4Network(IPv4Address.Parse("193.170.76.0"), 23),
                new IPv4Network(IPv4Address.Parse("193.170.78.0"), 24),
                new IPv4Network(IPv4Address.Parse("193.170.79.0"), 24),
            };

            List <IPNetwork <IPv4Address> > netsMinimized = Minimize.MinimizeSubnets(netsMust,
                                                                                     (addr, mask) => new IPv4Network(addr, mask));

            foreach (IPNetwork <IPv4Address> minNet in netsMinimized)
            {
                for (IPv4Address addr = minNet.BaseAddress; addr.CompareTo(minNet.LastAddressOfSubnet) <= 0; addr = addr + 1)
                {
                    bool contained = false;
                    foreach (IPNetwork <IPv4Address> origNet in netsMust)
                    {
                        if (origNet.Contains(addr))
                        {
                            contained = true;
                            break;
                        }
                    }

                    if (!contained)
                    {
                        Assert.True(false, $"IP address {addr} in minimized net {minNet} not contained in any original net");
                    }
                }
            }

            foreach (IPNetwork <IPv4Address> origNet in netsMust)
            {
                for (IPv4Address addr = origNet.BaseAddress; addr.CompareTo(origNet.LastAddressOfSubnet) <= 0; addr = addr + 1)
                {
                    bool contained = false;
                    foreach (IPNetwork <IPv4Address> minNet in netsMinimized)
                    {
                        if (minNet.Contains(addr))
                        {
                            contained = true;
                            break;
                        }
                    }

                    if (!contained)
                    {
                        Assert.True(false, $"IP address {addr} in original net {origNet} not contained in any minimized net");
                    }
                }
            }
        }
        private void Docking_GroupUpdate(object sender, dynamic groups)
        {
            // When shutting down, Application.Current can be null. Check here to prevent NRE
            if (Application.Current == null)
            {
                return;
            }

            /** DH 4/25/2019
             * The below block was throwing exceptions occasionally as the app was shutting down
             * we admittedly don't fully understand, so we're wrapping it in a a try/catch as
             * a quick fix.
             */
            try
            {
                Application.Current.Dispatcher.Invoke(delegate //main thread
                {
                    this.dockingGroup   = groups.dockingGroup;
                    this.snappingGroup  = groups.snappingGroup;
                    Minimize.Visibility = Visibility.Visible;
                    if (groups.dockingGroup != "")
                    {
                        DockingButton.Content    = "@";
                        DockingButton.ToolTip    = "Detach Window";
                        DockingButton.Visibility = Visibility.Visible;
                        Minimize.SetValue(Canvas.RightProperty, buttonWidth * 3);
                        DockingButton.Background = dockingButtonDockedBackground;
                        if (!groups.topRight)
                        {
                            Minimize.Visibility = Visibility.Hidden;
                        }
                    }
                    else if (groups.snappingGroup != "")
                    {
                        DockingButton.Content    = ">";
                        DockingButton.ToolTip    = "Attach Windows";
                        DockingButton.Visibility = Visibility.Visible;
                        Minimize.SetValue(Canvas.RightProperty, buttonWidth * 3);
                        DockingButton.Background = Brushes.Transparent;
                    }
                    else
                    {
                        DockingButton.Visibility = Visibility.Hidden;
                        Minimize.SetValue(Canvas.RightProperty, buttonWidth * 2);
                    }
                    Window_Size_Changed();
                });
            }
            catch (Exception)
            {
            }
        }
Beispiel #5
0
        public void T02_Multidimensional()
        {
            // test using the rosenbrock banana function, which has a long, curved, narrow valley
            RosenbrockBanana function = new RosenbrockBanana();

            double[] point = new double[2] {
                -1.2, 2
            };
            double value = Minimize.BFGS(function, point);

            Assert.AreEqual(1, point[0], 2.4e-10);
            Assert.AreEqual(1, point[0], 2.4e-10);
            Assert.AreEqual(0, value, 6.4e-20);
        }
Beispiel #6
0
        protected void onMinimized(object sender, EventArgs e)
        {
            lock (IFace.LayoutMutex) {
                if (IsNormal)
                {
                    savedBounds = this.LastPaintedSlot;
                }
                Width       = 200;
                Height      = 20;
                Resizable   = false;
                IsMinimized = true;
                NotifyValueChanged("ShowNormal", true);
                NotifyValueChanged("ShowMinimize", false);
                NotifyValueChanged("ShowMaximize", true);
            }

            Minimize.Raise(sender, e);
        }
Beispiel #7
0
        public void T01_OneDimensional()
        {
            const double Accuracy = 1.5e-7;

            // sin(x+1) + x/2 has local minima at -2/3PI-1, 4/3PI-1, 10/3PI-1, etc.
            DifferentiableFunction function   = new DifferentiableFunction(x => Math.Sin(x + 1) + x / 2, x => Math.Cos(x + 1) + 0.5);
            Func <double, double>  ndFunction = function.Evaluate; // create a version without derivative information
            // the three minima above are located between -5 and 13, so we should be able to find them with BracketInward()
            List <MinimumBracket> brackets = Minimize.BracketInward(function, -5, 13, 3).ToList();

            Assert.AreEqual(3, brackets.Count); // ensure we found them all
            List <double> minima = new List <double>();

            // for each bracket, try to find it using all available methods
            foreach (MinimumBracket bracket in brackets)
            {
                double x = Minimize.GoldenSection(function, bracket);              // first use golden section search, which is the most reliable
                Assert.AreEqual(x, Minimize.Brent(function, bracket), Accuracy);   // then make sure Brent's method gives a similar answer, both with
                Assert.AreEqual(x, Minimize.Brent(ndFunction, bracket), Accuracy); // and without the derivative
                minima.Add(x);
            }
            minima.Sort(); // then sort the results to put them in a known order and make sure they're equal to the expected values
            Assert.AreEqual(3, minima.Count);
            Assert.AreEqual(Math.PI * -2 / 3 - 1, minima[0], Accuracy);
            Assert.AreEqual(Math.PI * 4 / 3 - 1, minima[1], Accuracy);
            Assert.AreEqual(Math.PI * 10 / 3 - 1, minima[2], Accuracy);

            // now test BracketOutward
            MinimumBracket b;

            Assert.IsFalse(Minimize.BracketOutward(x => x, 0, 1, out b));  // make sure it fails with functions that have no minimum
            Assert.IsTrue(Minimize.BracketOutward(x => 5, 0, 1, out b));   // but succeeds with constant functions
            Assert.IsTrue(Minimize.BracketOutward(function, 0, 1, out b)); // and with our sample function
            // make sure it searches in a downhill direction, as designed
            Assert.AreEqual(Math.PI * -2 / 3 - 1, Minimize.GoldenSection(function, b), Accuracy);
            Assert.IsTrue(Minimize.BracketOutward(function, 1, 2, out b));
            Assert.AreEqual(Math.PI * 4 / 3 - 1, Minimize.GoldenSection(function, b), Accuracy);

            // try a function with a singularity, for kicks
            ndFunction = x => Math.Cos(x) / (x - 1);
            Assert.AreEqual(1, Minimize.GoldenSection(ndFunction, new MinimumBracket(-1, -0.1, 1)), Accuracy);
            Assert.AreEqual(1, Minimize.Brent(ndFunction, new MinimumBracket(-1, -0.1, 1)), Accuracy);
        }
Beispiel #8
0
        private async void Start(object sender, EventArgs e)
        {
            server = new ServerForm();
            enemy  = new EnemyForm(server);
            client = new ClientForm(server);

            client.Show();
            server.Show();

            StartModel.Enabled = false;



            await client.Initialize();

            Maximize.Show();
            Minimize.Show();
            StartModel.Hide();
            enemy.Show();
        }
        private void Window_Size_Changed()
        {
            int    LinkerGroupCount = LinkerGroups.Where(g => g.Value.Visibility == Visibility.Visible).Count();
            double LeftWidths       = buttonWidth + LinkerGroupCount * 12;
            double RightWidths      = buttonWidth * 3;

            if (!showLinker)
            {
                LeftWidths -= buttonWidth;
            }

            if (Emitter.Visibility == Visibility.Visible)
            {
                Emitter.SetValue(Canvas.LeftProperty, LeftWidths);
                LeftWidths += buttonWidth;
            }
            if (DockingButton.IsVisible)
            {
                RightWidths = buttonWidth * 4;
            }
            Title.SetValue(Canvas.LeftProperty, LeftWidths);
            Close.SetValue(Canvas.RightProperty, 0.0);
            Maximize.SetValue(Canvas.RightProperty, buttonWidth);
            if (DockingButton.Visibility == Visibility.Visible)
            {
                Minimize.SetValue(Canvas.RightProperty, buttonWidth * 3);
                DockingButton.SetValue(Canvas.RightProperty, buttonWidth * 2);
            }
            else
            {
                Minimize.SetValue(Canvas.RightProperty, buttonWidth * 2);
            }

            var titleWidth = Toolbar.ActualWidth - LeftWidths - RightWidths;

            if (titleWidth < 0)
            {
                titleWidth = 0;
            }
            Title.Width = titleWidth;
        }
Beispiel #10
0
        public void Dispose()
        {
            if (!_disposed)
            {
                if (CornerNW != null)
                {
                    CornerNW.Dispose();
                    CornerNW = null;
                }

                if (CornerNE != null)
                {
                    CornerNE.Dispose();
                    CornerNE = null;
                }

                if (CornerSE != null)
                {
                    CornerSE.Dispose();
                    CornerSE = null;
                }

                if (CornerSW != null)
                {
                    CornerSW.Dispose();
                    CornerSW = null;
                }

                if (BorderN != null)
                {
                    BorderN.Dispose();
                    BorderN = null;
                }

                if (BorderE != null)
                {
                    BorderE.Dispose();
                    BorderE = null;
                }

                if (BorderS != null)
                {
                    BorderS.Dispose();
                    BorderS = null;
                }

                if (BorderW != null)
                {
                    BorderW.Dispose();
                    BorderW = null;
                }

                if (Minimize != null)
                {
                    Minimize.Dispose();
                    Minimize = null;
                }

                if (Maximize != null)
                {
                    Maximize.Dispose();
                    Maximize = null;
                }

                if (Restore != null)
                {
                    Restore.Dispose();
                    Restore = null;
                }

                if (Close != null)
                {
                    Close.Dispose();
                    Close = null;
                }

                _disposed = true;
            }
        }
Beispiel #11
0
 public static void Minimizetheapp()
 {
     Minimize?.Invoke(typeof(GlobalResources), EventArgs.Empty);
 }
Beispiel #12
0
        public void T03_Constrained()
        {
            // a constrained minimization problem using a barrier function to minimize x^2 subject to x > 5
            MinimumBracket bracket = Minimize.BracketInward(new BarrierFunction(1), 5 + (5.0 / 2) * IEEE754.DoublePrecision, 100, 100).First();
            double         value;

            Assert.AreEqual(5, Minimize.Brent(new BarrierFunction(1e-10), bracket, out value), 1.2e-7);
            Assert.AreEqual(25, value, 1.2e-6);

            // test a constrained minimization problem using various methods
            ConstrainedMinimizer minimizer;

            double[] point;
            foreach (ConstraintEnforcement method in (ConstraintEnforcement[])Enum.GetValues(typeof(ConstraintEnforcement)))
            {
                // test the same problem using the ConstrainedMinimizer
                point = new double[2] {
                    5, 8
                };
                minimizer = new ConstrainedMinimizer(new ConstraintTestFunction())
                {
                    ConstraintEnforcement = method
                };
                minimizer.SetBounds(0, 1, double.PositiveInfinity);
                minimizer.SetBounds(1, 3, 9);
                value = minimizer.Minimize(point);
                switch (method)
                {
                case ConstraintEnforcement.InverseBarrier: // ~ 220 function calls and 180 gradient evaluations
                    Assert.AreEqual(9, value, 1.4e-8);
                    Assert.AreEqual(1, point[0], 2.4e-10);
                    Assert.AreEqual(3, point[1], 4.1e-10);
                    break;

                case ConstraintEnforcement.LinearPenalty: // ~ 870 function calls and 120 gradient evaluations
                    Assert.AreEqual(9, value, 4.4e-11);
                    Assert.AreEqual(1, point[0], 2.5e-12);
                    Assert.AreEqual(3, point[1], 2.5e-12);
                    break;

                case ConstraintEnforcement.LogBarrier: // ~ 140 function calls and 130 gradient evaluations
                    Assert.AreEqual(9, value, 5.1e-9);
                    Assert.AreEqual(1, point[0], 6e-12);
                    Assert.AreEqual(3, point[1], 1.7e-11);
                    break;

                case ConstraintEnforcement.QuadraticPenalty: // ~ 670 function calls and 170 gradient evaluations
                    Assert.AreEqual(9, value, 9e-9);
                    Assert.AreEqual(1, point[0], 9e-10);
                    Assert.AreEqual(3, point[1], 4e-10);
                    break;

                default: throw new NotImplementedException();
                }
            }

            // test the constrained minimizer with a tricky problem -- finding the minimum of the rosenbrock banana constrained to an
            // arbitrary line that doesn't pass through the minimum of the original problem
            minimizer = new ConstrainedMinimizer(new RosenbrockBanana());
            minimizer.AddConstraint(new LineConstraint(-1.5, -1.5, 0, 1.5, 0));
            point = new double[2] {
                -1.2, 2
            };
            value = minimizer.Minimize(point);
            Assert.AreEqual(2.4975, value, 2e-9);
            Assert.AreEqual(-0.57955689989313142185, point[0], 8e-10);
            Assert.AreEqual(0.34088620021373715629, point[1], 1e-9);
        }
        /// <summary>
        /// defines all of the actions
        /// </summary>
        public void DefineActions()
        {
            Click              click             = new Click();
            Clear              clear             = new Clear();
            Close              close             = new Close();
            Exit               exit              = new Exit();
            Next_Tab           next_tab          = new Next_Tab();
            Previous_Tab       previous_tab      = new Previous_Tab();
            WindowsCtrlTab     wtab              = new WindowsCtrlTab();
            Idle               idle              = new Idle();
            Next_Selection     nextSelection     = new Next_Selection();
            Previous_Selection previousSelection = new Previous_Selection();
            Scroll_Down        scrollDown        = new Scroll_Down();
            Scroll_Up          scrollUp          = new Scroll_Up();
            MousePress         mousePress        = new MousePress();
            MouseRelease       mouseRelease      = new MouseRelease();
            MultipleSelection  multipleSelection = new MultipleSelection();
            Maximize           maximize          = new Maximize();
            Minimize           minimize          = new Minimize();
            Lock               locking           = new Lock();
            Unlock             unlocking         = new Unlock();
            Undo               undo              = new Undo();
            Redo               redo              = new Redo();
            Open               open              = new Open();


            //defining the click actions
            QlikMove.StandardHelper.ActionCore.Action clickAction = new QlikMove.StandardHelper.ActionCore.Action(ActionName.SIMPLE_SELECTION, new ActionPart[1] {
                click
            });
            this.AddAction(clickAction);

            //defining the mouse press actions
            QlikMove.StandardHelper.ActionCore.Action mousePressedAction = new QlikMove.StandardHelper.ActionCore.Action(ActionName.MOUSE_PRESS, new ActionPart[1] {
                mousePress
            });
            this.AddAction(mousePressedAction);

            //defining the mouse release actions
            QlikMove.StandardHelper.ActionCore.Action mouseReleasedAction = new QlikMove.StandardHelper.ActionCore.Action(ActionName.MOUSE_RELEASE, new ActionPart[1] {
                mouseRelease
            });
            this.AddAction(mouseReleasedAction);


            //defining the exit action
            QlikMove.StandardHelper.ActionCore.Action exitAction = new StandardHelper.ActionCore.Action(ActionName.EXIT, new ActionPart[1] {
                exit
            });
            this.AddAction(exitAction);

            //defining the next action
            QlikMove.StandardHelper.ActionCore.Action nextAction = new StandardHelper.ActionCore.Action(ActionName.NEXT_TAB, new ActionPart[1] {
                next_tab
            });
            this.AddAction(nextAction);

            //defining the previous action
            QlikMove.StandardHelper.ActionCore.Action previousAction = new StandardHelper.ActionCore.Action(ActionName.PREVIOUS_TAB, new ActionPart[1] {
                previous_tab
            });
            this.AddAction(previousAction);

            //defining the menu action
            QlikMove.StandardHelper.ActionCore.Action tabsAction = new QlikMove.StandardHelper.ActionCore.Action(ActionName.MENU, new ActionPart[1] {
                wtab
            });
            this.AddAction(tabsAction);

            //defining the idle action
            QlikMove.StandardHelper.ActionCore.Action idleAction = new QlikMove.StandardHelper.ActionCore.Action(ActionName.IDLE, new ActionPart[1] {
                idle
            });
            this.AddAction(idleAction);

            //defining the next selection action
            QlikMove.StandardHelper.ActionCore.Action nextSelectionAction = new QlikMove.StandardHelper.ActionCore.Action(ActionName.NEXT_SELECTION, new ActionPart[1] {
                nextSelection
            });
            this.AddAction(nextSelectionAction);

            //defining the previous selection action
            QlikMove.StandardHelper.ActionCore.Action previousSelectionAction = new QlikMove.StandardHelper.ActionCore.Action(ActionName.PREVIOUS_SELECTION, new ActionPart[1] {
                previousSelection
            });
            this.AddAction(previousSelectionAction);

            //defining the scrolling down action
            QlikMove.StandardHelper.ActionCore.Action scrollDownAction = new StandardHelper.ActionCore.Action(ActionName.SCROLL_DOWN, new ActionPart[1] {
                scrollDown
            });
            this.AddAction(scrollDownAction);

            //defining the scrolling up action
            QlikMove.StandardHelper.ActionCore.Action scrollUpAction = new StandardHelper.ActionCore.Action(ActionName.SCROLL_UP, new ActionPart[1] {
                scrollUp
            });
            this.AddAction(scrollUpAction);

            //defining the multiple selection action
            QlikMove.StandardHelper.ActionCore.Action multipleSelectionAction = new StandardHelper.ActionCore.Action(ActionName.MULTIPLE_SELECTION, new ActionPart[1] {
                multipleSelection
            });
            this.AddAction(multipleSelectionAction);

            //defining the maximize action
            QlikMove.StandardHelper.ActionCore.Action maximizeAction = new StandardHelper.ActionCore.Action(ActionName.MAX, new ActionPart[1] {
                maximize
            });
            this.AddAction(maximizeAction);

            //defining the minimize action
            QlikMove.StandardHelper.ActionCore.Action minimizeAction = new StandardHelper.ActionCore.Action(ActionName.MIN, new ActionPart[1] {
                minimize
            });
            this.AddAction(minimizeAction);

            //defining the clear action
            QlikMove.StandardHelper.ActionCore.Action clearAction = new StandardHelper.ActionCore.Action(ActionName.CLEAR, new ActionPart[1] {
                clear
            });
            this.AddAction(clearAction);

            //defining the undo action
            QlikMove.StandardHelper.ActionCore.Action undoAction = new StandardHelper.ActionCore.Action(ActionName.UNDO, new ActionPart[1] {
                undo
            });
            this.AddAction(undoAction);

            //defining the redo action
            QlikMove.StandardHelper.ActionCore.Action redoAction = new StandardHelper.ActionCore.Action(ActionName.REDO, new ActionPart[1] {
                redo
            });
            this.AddAction(redoAction);

            //defining the locking action
            QlikMove.StandardHelper.ActionCore.Action lockingAction = new StandardHelper.ActionCore.Action(ActionName.LOCK, new ActionPart[1] {
                locking
            });
            this.AddAction(lockingAction);

            //defining the unlocking action
            QlikMove.StandardHelper.ActionCore.Action unlockingAction = new StandardHelper.ActionCore.Action(ActionName.UNLOCK, new ActionPart[1] {
                unlocking
            });
            this.AddAction(unlockingAction);

            //defining the close action
            QlikMove.StandardHelper.ActionCore.Action closeAction = new StandardHelper.ActionCore.Action(ActionName.CLOSE, new ActionPart[1] {
                close
            });
            this.AddAction(closeAction);

            //defining the open action
            QlikMove.StandardHelper.ActionCore.Action openAction = new StandardHelper.ActionCore.Action(ActionName.OPEN, new ActionPart[1] {
                open
            });
            this.AddAction(openAction);

            LogHelper.logInput("Actions defined", LogHelper.logType.INFO, this);
        }
Beispiel #14
0
        public static DFSM CalculateOverloadStates(IEnumerable <Function> group)
        {
            var functionGroup = group.ToList();

            // Create a set of unique parameter types.
            var uniqueTypes = functionGroup.SelectMany(method => method.Parameters)
                              .Select(p => p.Type).Distinct().ToList();

            // Consider the alphabet as sequential ordered numbers, one per type.
            var Sigma = Enumerable.Range(0, uniqueTypes.Count).Select(i => (char)i).ToArray();

            var Q = new List <string> {
                "S"
            };

            var overloadStates = Enumerable.Range(0, functionGroup.Count).Select(i => $"F{i}")
                                 .ToArray();

            Q.AddRange(overloadStates);

            var Delta = new List <Transition>();

            // Setup states and transitions.
            for (var methodIndex = 0; methodIndex < functionGroup.Count; methodIndex++)
            {
                var method   = functionGroup[methodIndex];
                var curState = "S";

                for (var paramIndex = 0; paramIndex < method.Parameters.Count; paramIndex++)
                {
                    var param     = method.Parameters[paramIndex];
                    var typeIndex = uniqueTypes.FindIndex(p => p.Equals(param.Type));

                    var isLastTransition = paramIndex == method.Parameters.Count - 1;
                    var nextState        = isLastTransition ? $"F{methodIndex}" : $"{methodIndex}_{paramIndex}";

                    if (!isLastTransition)
                    {
                        Q.Add(nextState);
                    }

                    Delta.Add(new Transition(curState, (char)typeIndex, nextState));
                    curState = nextState;
                }
            }

            var Q0 = new List <string> {
                "S"
            };
            var F = overloadStates;

            var NDFSM = new NDFSM(Q, Sigma, Delta, Q0, F);
            var DFSM  = Minimize.PowersetConstruction(NDFSM);

            // Add the zero-parameters overload manually if one exists since it got optimized out.
            var zeroParamsOverload = functionGroup.SingleOrDefault(f => f.Parameters.Count == 0);

            if (zeroParamsOverload != null)
            {
                var index = functionGroup.FindIndex(f => f == zeroParamsOverload);
                DFSM.F.Insert(index, $"F{index}");
            }

#if OPTIMIZE_STATES
            DFSM = Minimize.MinimizeDFSM(DFSM);
#endif

            // The construction step above can result in unordered final states, so re-order them to
            // make the following code generation steps easier.

            DFSM.F = DFSM.F.OrderBy(f => f).ToList();

            return(DFSM);
        }
Beispiel #15
0
 private void ExecuteMinimize(RoutedEventArgs e)
 {
     Minimize?.Invoke(this, e);
 }
 private void Min_Click(object sender, RoutedEventArgs e)
 {
     Minimize?.Invoke(this, EventArgs.Empty);
 }
Beispiel #17
0
 /// <summary>
 /// Minimizeイベントを発生させる
 /// </summary>
 /// <param name="e">イベントデータを格納しているEventArgs</param>
 protected virtual void OnMinimize(EventArgs e) => Minimize?.Invoke(this, e);