コード例 #1
0
        //Функция для высчитывания новой точки
        Coord newPoint(Coord x1, Coord x2, opt opt_A)
        {
            Matrix E    = Matrix.E(amountVar);
            Coord  grad = Coord.Gradient(y, x2, amountVar);

            if (k % amountVar == 1)
            {
                //if (k == 1)
                A = E;
            }
            else
            {
                A = opt_A(x1, x2);
            }
            p = -A * grad;
            p = p / p.Norma;
            LinearSearch f1 = new LinearSearch(x2, p, y);

            f1.Svenn(20);
            f1.Bolcano(10);
            f1.Davidon();
            alfa = f1.alfa_min;
            Coord x3 = x2 + alfa * p / p.Norma;

            return(x3);
        }
コード例 #2
0
        private int Method(opt OptBeta)
        {
            opt Beta = OptBeta;

            double[] arr_p = new double[amountVar];
            Coord    p     = new Coord(arr_p);

            p = p / p.Norma;
            k = 1;
            //Высчитываем новую точку, пока квадрат нормы градиента меньше эпсилон
            while (true)
            {
                x[k + 1] = newPoint(x[k - 1], x[k], OptBeta);
                Grad     = Coord.Gradient(y, x[k + 1], amountVar);
                // Console.WriteLine("gradNorm^2 = {0}", Grad.Norma * Grad.Norma);

                if (Grad.Norma * Grad.Norma <= Eps || k >= 300)
                {
                    min = x[k + 1];
                    break;
                }
                k++;
            }
            return(k);
        }
コード例 #3
0
        //Функция для высчитывания новой точки
        Coord newPoint(Coord x1, Coord x2, opt OptBeta)
        {
            opt Beta = OptBeta;

            Grad = Coord.Gradient(y, x2, amountVar);
            //Если k = 1, n+1, 2n+1...
            if (k % amountVar == 1)
            {
                p = -Grad;
            }
            else
            {
                double beta = Beta(x2, x1);
                p = -Grad + (beta * p);
            }
            //Запускаем линейный поиск
            p = p / p.Norma;
            LinearSearch f1 = new LinearSearch(x2, p, y);

            f1.Svenn(20);
            f1.Bolcano(20);
            f1.Davidon();
            alfa = f1.alfa_min;
            p    = p / p.Norma;
            Coord x3 = x2 + alfa * p;

            return(x3);
        }
コード例 #4
0
        //Метод переменной метрики
        public int Method(opt opt_A)
        {
            k = 1;
            Coord Grad;

            while (true)
            {
                x[k + 1] = newPoint(x[k - 1], x[k], opt_A);
                Grad     = Coord.Gradient(y, x[k + 1], amountVar);
                if (Grad.Norma <= Eps || k >= maxIter)
                {
                    min = x[k + 1];
                    break;
                }
                k++;
            }
            return(k);
        }
コード例 #5
0
        Coord newPoint(Coord x1, Coord x2, opt opt_A)
        {
            Matrix E    = Matrix.E(amountVar);
            Coord  grad = Coord.Gradient(y, x2, amountVar);

            if (k % amountVar == 1)
            {
                //if (k == 1)
                A = E;
            }
            else
            {
                A = opt_A(x1, x2);
            }
            p = -A * grad;
            LinearSearch f1 = new LinearSearch(x2, p, y);

            return(f1.M[6](50));
        }
コード例 #6
0
        //Метод сопряжённых градиентов
        public int Method(opt OptBeta)
        {
            opt Beta = OptBeta;

            double[] arr_p = new double[amountVar];
            Coord    p     = new Coord(arr_p);

            k = 1;
            //Высчитываем новую точку, пока квадрат нормы градиента меньше эпсилон
            while (true)
            {
                x[k + 1] = newPoint(x[k - 1], x[k], OptBeta);
                Grad     = Coord.Gradient(y, x[k + 1], amountVar);
                if (Grad.Norma * Grad.Norma <= Eps || k >= maxIter)
                {
                    min = x[k + 1];
                    break;
                }
                k++;
            }
            return(k);
        }
コード例 #7
0
ファイル: Args.cs プロジェクト: uilit/BuildXL
 action: opt => ParsePropertyOption(opt, CommandLineConfig.Startup.Properties)),
コード例 #8
0
ファイル: StartWindow.xaml.cs プロジェクト: riggspc/SpaceAce
        private void updateFont(opt nextOpt)
        {
            switch (curOpt)
            {
                case opt.play1:
                    this.play1.Foreground = Brushes.White;
                    break;
                case opt.play2:
                    this.play2.Foreground = Brushes.White;
                    break;
                case opt.viewHigh:
                    this.viewHigh.Foreground = Brushes.White;
                    break;
                case opt.exitGame:
                    this.exitGame.Foreground = Brushes.White;
                    break;
            }

            switch(nextOpt)
            {
                case opt.play1:
                    this.play1.Foreground = Brushes.Yellow;
                    break;
                case opt.play2:
                    this.play2.Foreground = Brushes.Yellow;
                    break;
                case opt.viewHigh:
                    this.viewHigh.Foreground = Brushes.Yellow;
                    break;
                case opt.exitGame:
                    this.exitGame.Foreground = Brushes.Yellow;
                    break;
            }

            curOpt = nextOpt;
        }
コード例 #9
0
ファイル: MainWindow.xaml.cs プロジェクト: riggspc/SpaceAce
        private void pause_updateFont(opt nextOpt)
        {
            switch (curOpt)
            {
                case opt.resume:
                    this.pause_resume.Foreground = Brushes.White;
                    break;
                case opt.returnToStart:
                    this.pause_returnToStart.Foreground = Brushes.White;
                    break;
                case opt.exitGame:
                    this.pause_exitGame.Foreground = Brushes.White;
                    break;
            }

            switch (nextOpt)
            {
                case opt.resume:
                    this.pause_resume.Foreground = Brushes.Yellow;
                    break;
                case opt.returnToStart:
                    this.pause_returnToStart.Foreground = Brushes.Yellow;
                    break;
                case opt.exitGame:
                    this.pause_exitGame.Foreground = Brushes.Yellow;
                    break;
            }

            curOpt = nextOpt;
        }
コード例 #10
0
        private void SeminarForm_Load(object sender, EventArgs e)
        {
            lec = (lection)((SeminarForm)sender).Tag;

            ans[] answer   = lec.ans;
            int[] rightAns = new int[5];
            int   o        = 0;

            foreach (ans a in answer)
            {
                rightAns[o] = a.num;
                o++;
            }

            //answer a = lec.answers;
            ans = rightAns;


            String[]         substrings = lec.text.Split('\n');
            HashSet <String> options    = new HashSet <string>();

            int i = 0;
            int t = 1;
            int q = 0;

            foreach (String ans in substrings)
            {
                opt      opt    = lec.opt[q];
                String[] subOpt = opt.text.Split(',');

                Label label = new Label();
                label.Text     = ans;
                label.Location = new Point(0, i);
                label.AutoSize = true;
                this.Controls.Add(label);
                int j = i + 10;

                GroupBox group = new GroupBox();
                group.Location = new Point(0, i + 10);
                group.Size     = new Size(150, 70);
                group.Name     = "opt";
                int start = 0;
                foreach (String optO in subOpt)
                {
                    RadioButton radio = new RadioButton();
                    radio.Text     = optO;
                    radio.Location = new Point(0, start);
                    radio.Name     = "radio";
                    group.Controls.Add(radio);

                    this.Controls.Add(group);
                    start += 20;
                }

                t++;
                i += 100;
                q++;
            }

            Button button = new Button();

            button.Text     = "Finish test";
            button.Name     = "finTest";
            button.AutoSize = true;
            button.Tag      = rightAns;

            button.Location = new Point(250, i + 10);
            button.Click   += new EventHandler(this.Btn_Click);
            this.Controls.Add(button);

            if (userProgress.getSeminarProgress(lec.id) == 1 || userProgress.getSeminarProgress(lec.id) == 2)
            {
                Control[] b = this.Controls.Find("finTest", false);
                b[0].Visible = false;
                List <Answer> list  = userProgress.getSeminarAnswers(lec.id);
                bool[]        wrong = getWrong(list);


                int[] right = ans;
                int   count = 0;

                int[] choosed = new int[list.Count];
                int   p       = 0;
                foreach (Answer an in list)
                {
                    choosed[p] = an.num;
                    p++;
                }

                for (int a = 0; a < 5; a++)
                {
                    if (right[a] == choosed[a])
                    {
                        wrong[a] = true;
                        count++;
                    }
                }

                isDone(count);

                Control[] groupBox  = this.Controls.Find("opt", false);
                int       countList = 0;
                foreach (Control con in groupBox)
                {
                    int       qwe   = 0;
                    Control[] radio = con.Controls.Find("radio", false);
                    foreach (Control rad in radio)
                    {
                        if (qwe + 1 == choosed[countList])
                        {
                            ((RadioButton)rad).Checked = true;

                            break;
                        }
                        else
                        {
                            qwe++;
                            continue;
                        }
                    }

                    countList++;
                }

                setOptColor(list, wrong);
            }
        }
コード例 #11
0
        private void updateFont(opt nextOpt)
        {
            switch (curOpt)
            {
                case opt.returnStart:
                    this.returnStart.Foreground = Brushes.White;
                    break;
                case opt.clearScores:
                    this.clearScores.Foreground = Brushes.White;
                    break;
                case opt.confirmNo:
                    this.confirmNo.Foreground = Brushes.White;
                    break;
                case opt.confirmYes:
                    this.confirmYes.Foreground = Brushes.White;
                    break;
            }

            switch (nextOpt)
            {
                case opt.returnStart:
                    this.returnStart.Foreground = Brushes.Yellow;
                    break;
                case opt.clearScores:
                    this.clearScores.Foreground = Brushes.Yellow;
                    break;
                case opt.confirmNo:
                    this.confirmNo.Foreground = Brushes.Yellow;
                    break;
                case opt.confirmYes:
                    this.confirmYes.Foreground = Brushes.Yellow;
                    break;
            }

            curOpt = nextOpt;
        }
コード例 #12
0
ファイル: SetupWindow.xaml.cs プロジェクト: riggspc/SpaceAce
        private void updateFont(opt nextOpt)
        {
            if (curOpt != nextOpt)
            {
                switch (curOpt)
                {
                    case opt.diff:
                        this.Diff_Opt.Foreground = Brushes.White;
                        this.DiffArrL.Visibility = Visibility.Collapsed;
                        this.DiffArrR.Visibility = Visibility.Collapsed;
                        break;
                    case opt.p1:
                        this.P1_Opt.Foreground = Brushes.White;
                        this.P1ArrL.Visibility = Visibility.Collapsed;
                        this.P1ArrR.Visibility = Visibility.Collapsed;
                        break;
                    case opt.p2:
                        this.P2_Opt.Foreground = Brushes.White;
                        this.P2ArrL.Visibility = Visibility.Collapsed;
                        this.P2ArrR.Visibility = Visibility.Collapsed;
                        break;
                    case opt.startGame:
                        this.StartGame.Foreground = Brushes.White;
                        break;
                    case opt.returnToStart:
                        this.ReturnToStart.Foreground = Brushes.White;
                        break;
                }

                curOpt = nextOpt;
            }
            else
            {
                switch (curOpt)
                {
                    case opt.diff:
                        this.Diff_Opt.Text = diffString[(int) diff];
                        break;
                    case opt.p1:
                        this.P1_Opt.Text = inputOptString[(int) p1_in];
                        break;
                    case opt.p2:
                        this.P2_Opt.Text = inputOptString[(int)p2_in];
                        break;
                }
            }

            switch (nextOpt)
            {
                case opt.diff:
                    this.Diff_Opt.Foreground = Brushes.Yellow;
                    if(diff > Difficulty.easy)
                        this.DiffArrL.Visibility = Visibility.Visible;
                    else
                        this.DiffArrL.Visibility = Visibility.Collapsed;
                    if (diff < Difficulty.hard)
                        this.DiffArrR.Visibility = Visibility.Visible;
                    else
                        this.DiffArrR.Visibility = Visibility.Collapsed;
                    break;
                case opt.p1:
                    this.P1_Opt.Foreground = Brushes.Yellow;
                    if(p1_in > InputType.joy)
                        this.P1ArrL.Visibility = Visibility.Visible;
                    else
                        this.P1ArrL.Visibility = Visibility.Collapsed;
                    if(p1_in < InputType.arrows)
                        this.P1ArrR.Visibility = Visibility.Visible;
                    else
                        this.P1ArrR.Visibility = Visibility.Collapsed;
                    break;
                case opt.p2:
                    this.P2_Opt.Foreground = Brushes.Yellow;
                    if (p2_in > InputType.joy)
                        this.P2ArrL.Visibility = Visibility.Visible;
                    else
                        this.P2ArrL.Visibility = Visibility.Collapsed;
                    if (p2_in < InputType.arrows)
                        this.P2ArrR.Visibility = Visibility.Visible;
                    else
                        this.P2ArrR.Visibility = Visibility.Collapsed;
                    break;
                case opt.startGame:
                    this.StartGame.Foreground = Brushes.Yellow;
                    break;
                case opt.returnToStart:
                    this.ReturnToStart.Foreground = Brushes.Yellow;
                    break;
            }
        }
コード例 #13
0
 AddMappingOperationOptionsItems(opt, parameters);
コード例 #14
0
        public static void makePopup(UserInterface ui, opt[] options, String title = "Hey! Listen!", ConfirmDelegate action = null)
        {
            Manager manager = ui.game.Manager;
            bool confirmed = false;
            object[] answer = new object[options.Length];

            bool[] answered = new bool[options.Length];
            ConfirmDelegate emptyDelegate = delegate{ return true;};
            action = action ?? emptyDelegate;
            Dialog window = new Dialog(manager);
            window.Text = title;
            window.Init();
            window.ShowModal();
            window.Caption.Text = "";
            window.Description.Text = "";
            window.Width = 200;
            window.Height = 200;
            window.SetPosition(20, OrbIt.ScreenHeight / 4);
            int heightCounter = window.Caption.Top;
            int i = 0;

            Button btnOk = new Button(manager);
            btnOk.Top = window.Description.Top + window.Description.Height;
            btnOk.Anchor = Anchors.Top;
            btnOk.Parent = window;
            btnOk.Text = "Ok";
            btnOk.Left = btnOk.Left = window.Width / 2 - btnOk.Width / 2;
            btnOk.Init();

            foreach (opt opt in options)
            {
                if (opt.type.In(OptType.info,OptType.prompt))
                {
                    Label info = new Label(manager);
                    info.Init();
                    info.Parent = window;
                    info.Left = VertPadding;
                    info.Width = window.Width - VertPadding * 5;
                    string message = ((string)opt.content).wordWrap(MAX_CHARS_PER_LINE);
                    info.Text = message;
                    info.Height = (info.Text.Count(x => x == '\n')+1) * info.Height;
                    info.Top = heightCounter; heightCounter += info.Height + VertPadding;
                }
                if (opt.type == OptType.dropDown)
                {
                    ComboBox cbBox = new ComboBox(manager);
                    cbBox.Init();
                    cbBox.Parent = window;
                    cbBox.MaxItems = 20; // TODO : ERROR?
                    cbBox.Width = window.Width - VertPadding * 5;
                    cbBox.Left = VertPadding;
                    cbBox.Top = heightCounter; heightCounter += cbBox.Height + VertPadding;
                    ObservableCollection<object> q = (ObservableCollection<object>)opt.content;
                    foreach (object o in q) cbBox.Items.Add(o);
                    q.CollectionChanged += delegate(object s, NotifyCollectionChangedEventArgs e) { cbBox.Items.syncToOCDelegate(e); };
                    int qq = i; answer[qq] = null;
                    cbBox.ItemIndexChanged += delegate {  answer[qq] = (cbBox.Items.ElementAt(cbBox.ItemIndex)); };
                    cbBox.ItemIndexChanged += opt.action;
                }
                if (opt.type == OptType.textBox)
                {
                    TextBox tbName = new TextBox(manager);
                    tbName.Init();
                    tbName.Parent = window;
                    tbName.Width = window.Width - VertPadding * 5;
                    tbName.Left = VertPadding;
                    tbName.Top = heightCounter; heightCounter += tbName.Height + VertPadding;
                    int qq = i; answer[qq] = null;
                    tbName.TextChanged += delegate { answer[qq] = tbName.Text; };
                    tbName.KeyUp += delegate(object sender, KeyEventArgs e)
                    {
                        if (e.Key == Keys.Enter)
                        { confirmed = true; if (action(true, answer)) window.Close(); }
                    };
                    tbName.TextChanged += opt.action;
                }

                if (opt.type == OptType.radialButton)
                {
                    GroupPanel gp = new GroupPanel(manager);
                    gp.Init();
                    gp.Parent = window;
                    gp.Width = window.Width - VertPadding * 5;
                    gp.Left = VertPadding;
                    int qq = i; answer[qq] = -1;
                    for (int j = 0; j < ((string[])opt.content).Length; j++)
                    {
                        RadioButton rb = new RadioButton(manager);
                        rb.Init();
                        rb.Parent = gp;
                        rb.Text = (string)opt.content;
                        int jj = j;
                        rb.Click += delegate { answer[qq] = jj; };
                        rb.Click += opt.action;
                    }
                    gp.Top = heightCounter; heightCounter += gp.Height + VertPadding;
                }
                if (opt.type == OptType.checkBox)
                {
                    CheckBox cb = new CheckBox(manager);
                    cb.Init();
                    cb.Parent = window;
                    cb.Width = window.Width - VertPadding * 5;
                    cb.Left = VertPadding;
                    cb.Top = heightCounter; heightCounter += cb.Height + VertPadding;
                    int qq = i; answer[qq] = false;
                    cb.Text = (string)opt.content;
                    cb.Click += delegate { answer[qq] = cb.Checked; };
                    cb.Click += opt.action;
                }
                i++;
            }
            if (options.Any<opt>(x => x.type != OptType.info))
            {
                btnOk.Left = VertPadding;
                Button btnCancel = new Button(manager);
                btnCancel.Init();
                btnCancel.Parent = window;
                btnCancel.Top = heightCounter;
                btnCancel.Text = "Cancel";
                btnCancel.Left = VertPadding * 2 + btnOk.Width;
                btnCancel.Click += delegate { window.Close(); action(false, answer); };
            }

            btnOk.Click += delegate {
                confirmed = true;
                window.Close(ModalResult.Cancel);
                bool res = action(true, answer);
                if (!res)
                {
                    window.Show();
                };
            };
            btnOk.Top = heightCounter;
            window.Closing += delegate { if (confirmed == false) action(false, answer); };
            window.Height = (btnOk.Top) + 70;
            manager.Add(window);
        }