Пример #1
0
        /// <summary>
        /// Executes one step from model
        /// </summary>
        public UiDescription ExecuteStep(UiDescription userData)
        {
            if (_currentStepIndex == 0)
                IsEnd = false;

            var data = new UiDescription();
            if (Steps == null || Steps.Count == 0)
            {
                IsEnd = true;
                return data;
            }

            var currentStep = Steps[_currentStepIndex];
            try
            {
                data = currentStep(userData);
            }
            catch (NoSuchDataException exception)
            {
                throw new InvalidModelException(exception.Message);
            }
            _currentStepIndex++;

            if (_currentStepIndex == Steps.Count)
            {
                IsEnd = true;
                _currentStepIndex = 0;
            }
            return data;
        }
        private UiDescription CutoffAddingStep(UiDescription userData)
        {
            SetNextStep(NextWeakenedProblemSolvingStep);

            var sLabel = _gomoryFirst.GetFreeBasisVariableLabel(_currentSimplexTable);
            var cutoff = _gomoryFirst.MakeCutoff(_currentSimplexTable,
                                                 ((StepVariants)userData["creativeVar"].Value).Variants.ElementAt(0),
                                                 InitialProblem);
            var prevSimplexTable = _currentSimplexTable;
            _currentSimplexTable = _gomoryFirst.AddCutoff(_currentSimplexTable, sLabel, cutoff);

            var tableSettings = new SimplexTableViewSettings
            {
                RowCount = _currentSimplexTable.RowsCount,
                Variables = new List<string>(_currentSimplexTable.Variables)
            };

            return new UiDescription
                       {
                           {"SimplexTableView", "prevTable", prevSimplexTable},
                           {"Label", "lab1", "Відсічення:"},
                           {"LimitationsArea", "limSystem", userData["limSystem"].Value},
                           {"Label", "lab2", "Нова симплекс-таблиця:"},
                           {"SimplexTableView", "table", "", _currentSimplexTable, true, true, tableSettings}
                       };
        }
 public UiDescription Design(IEnumerable<IModel> models)
 {
     var data = new UiDescription();
     foreach (var model in models)
         data.Add("DataRadioButton", model.GetDescription(), model.GetDescription(), false);
     return data;
 }
Пример #4
0
        private UiDescription Question1(UiDescription userData)
        {
            const string question = "Какой класс является базовым для всех классов в С#?";
            const string rightAnswer = "Object";
            var wrongAnswers = new List<string> { "Int16", "Type", "Нету общего базового класса" };

            return Question(question, rightAnswer, wrongAnswers);
        }
Пример #5
0
        //===================================================================================
        private UiDescription Question0(UiDescription userData)
        {
            IsEnd = false;
            const string question = "Сколько будет 2 + 2 * 2";
            const string rightAnswer = "6";
            var wrongAnswers = new List<string> { "8", "4", "Невозможно посчитать" };

            return Question(question, rightAnswer, wrongAnswers);
        }
Пример #6
0
 private UiDescription Step1(UiDescription userData)
 {
     _a = int.Parse((string)userData["a"].Value);
     return new UiDescription
                {
                    {"SignedTextBox", "a", "First num:", _a.ToString(CultureInfo.InvariantCulture)},
                    {"Label", "multOperator", "*", "*"},
                    {"SignedTextBox", "b", "Enter second num:", string.Empty, true}
                };
 }
 protected override UiDescription GetNextStepData(UiDescription previousStepData)
 {
     var nextStepData = base.GetNextStepData(previousStepData);
     foreach (var dataItem in nextStepData)
     {
         dataItem.CheckRequired = false;
         dataItem.Editable = dataItem.Value == null || IsValueEmptyString(dataItem.Value);
     }
     return nextStepData;
 }
Пример #8
0
 private UiDescription Step2(UiDescription userData)
 {
     _b = int.Parse((string)userData["b"].Value);
     return new UiDescription
                {
                    {"SignedTextBox", "a", "First num:", _a.ToString(CultureInfo.InvariantCulture)},
                    {"Label", "multOperator", "*", "*"},
                    {"SignedTextBox", "b", "Second num:", _b.ToString(CultureInfo.InvariantCulture)},
                    {"Label", "equalsOperator", "=", "="},
                    {"SignedTextBox", "result", "Enter result:", (_a*_b).ToString(CultureInfo.InvariantCulture), true, true}
                };
 }
        public UiDescription GetUserData()
        {
            var data = new UiDescription();

            foreach (Control control in form1.Controls)
            {
                Data cData = GetControlData(control);
                if (cData == null)
                    continue;
                data.Add(cData);
            }
            return data;
        }
Пример #10
0
        private UiDescription Question2(UiDescription userData)
        {
            const string question = "Что делает оператор % в С#?";
            const string rightAnswer = "Возвращает остаток от деления";
            var wrongAnswers = new List<string>
                                   {
                                       "Возвращает процентное соотношение двух операндов",
                                       "Форматирует значения разных типов в строку",
                                       "Переводит дробное число в проценты"
                                   };

            return Question(question, rightAnswer, wrongAnswers);
        }
        //----------------------------------------------------------------
        /// <summary>
        /// Executes one step from model
        /// </summary>
        public new UiDescription ExecuteStep(UiDescription userData)
        {
            var data = new UiDescription();

            if (IsEnd) return data;

            var currentStep = Steps[0];
            try
            {
                data = currentStep(userData);
            }
            catch (NoSuchDataException exception)
            {
                throw new InvalidModelException(exception.Message);
            }
            return data;
        }
Пример #12
0
        protected override UiDescription GetNextStepData(UiDescription previousStepData)
        {
            var nextStepData = new UiDescription();
            var shouldShowHistory = false;

            while (!shouldShowHistory && !CurrentModel.IsEnd)
            {
                _stepNumber++;
                nextStepData = base.GetNextStepData(previousStepData);

                foreach (var dataItem in previousStepData)
                {
                    if (SolvingHistory.Contains(dataItem.Name)) continue;

                    dataItem.Editable = false;
                    dataItem.Name = "Step" + _stepNumber + "-" + dataItem.Name;
                    SolvingHistory.Add(dataItem);
                }

                foreach (var dataItem in nextStepData)
                {
                    dataItem.CheckRequired = false;
                    var itemShouldBeShown = RequiresUserInteraction(dataItem);
                    dataItem.Editable = itemShouldBeShown;

                    if (itemShouldBeShown)
                        shouldShowHistory = true;
                }

                if (!shouldShowHistory)
                    previousStepData = new UiDescription {nextStepData};
            }

            var history = new UiDescription { SolvingHistory, nextStepData };

            if (CurrentModel.IsEnd)
                SolvingHistory.Clear();

            return history;
        }
Пример #13
0
        private static UiDescription Question(string question, string rightAnswer, IEnumerable<string> wrongAnsers)
        {
            var data = new UiDescription();
            var tmp = new UiDescription();

            var qData = new UiDescriptionItem
            {
                Name = "question",
                ControlType = "Label",
                Value = question
            };
            data.Add(qData);

            var rData = new UiDescriptionItem
            {
                Name = rightAnswer,
                Text = rightAnswer,
                ControlType = "DataRadioButton",
                Value = true,
                CheckRequired = true
            };
            data.Add(rData);

            foreach (var wAnswer in wrongAnsers)
            {
                var wData = new UiDescriptionItem
                {
                    Name = wAnswer,
                    Text = wAnswer,
                    ControlType = "DataRadioButton",
                    Value = false,
                    CheckRequired = true
                };
                tmp.Add(wData);
            }
            foreach (var dataItem in tmp)
                data.Add(dataItem);
            return data;
        }
Пример #14
0
 protected virtual UiDescription GetNextStepData(UiDescription previousStepData)
 {
     return _models[_currentModel].ExecuteStep(previousStepData);
 }
Пример #15
0
 private UiDescription Step0(UiDescription userData)
 {
     return new UiDescription { { "SignedTextBox", "a", "Enter first num:", string.Empty, true, false } };
 }
 /// <summary>
 /// Gets entered by user informaition from form
 /// </summary>
 /// <returns></returns>
 public UiDescription GetUserData()
 {
     var data = new UiDescription();
     foreach (Control control in UserControls)
     {
         var dataControl = GetDataControl(control);
         data.Add(dataControl.ControlType, dataControl.ControlName, dataControl.Value);
     }
     return data;
 }
Пример #17
0
 private bool CheckData(UiDescription data)
 {
     var notMatchedValues = new List<string>();
     foreach (var checkDataElem in _dataToCheck)
         foreach (var userDataElem in data)
         {
             if (checkDataElem.Name != userDataElem.Name) continue;
             var isEqual = true;
             try
             {
                 isEqual = checkDataElem.Value is IEnumerable
                            ? CompareCollections(checkDataElem.Value, userDataElem.Value)
                            : ((IComparable)checkDataElem.Value).CompareTo(userDataElem.Value) == 0;
             }
             catch (ArgumentException)
             {
                 notMatchedValues.Add(checkDataElem.Name);
             }
             if (isEqual == false) return false;
         }
     if (notMatchedValues.Count != 0)
         throw new NotMatchedValuesException(notMatchedValues);
     return true;
 }
        private UiDescription VariablesWithoutZeroLimitationsChanging(UiDescription userData)
        {
            var prevProblem = CurrentProblem;
            CurrentProblem = _simplex.ReplaceVariablesWithoutZeroConstraints(CurrentProblem);

            SetNextStep(NormalizeActionChoiceStep);

            return new UiDescription
                       {
                           {"LppView", "LPP", "", prevProblem},
                           {"Label", "lab", null, "Enter changed LPP:"},
                           {"LppView", "ChangedLPP", "", CurrentProblem, true, true}
                       };
        }
Пример #19
0
 //=====================================================================================
 private UiDescription Step0(UiDescription userData)
 {
     var data = new UiDescription { { "SignedTextBox", "a", "Enter first num:", string.Empty, true } };
     return data;
 }
        private UiDescription SolvingElementChoosingStep(UiDescription userData)
        {
            SetNextStep(MakeNextSimplexTableStep);

            var solvingElement = _simplex.GetSolvingElement(CurrentSimplexTable);
            var varsString = string.Empty;
            var variableCount = CurrentSimplexTable.Variables.Count;
            for (var i = 0; i < variableCount; i++)
                varsString += CurrentSimplexTable.Variables.ElementAt(i) + (i == variableCount - 1 ? "" : "|");
            var cellVariable = new StepVariants(new[] { CurrentSimplexTable.GetVariable(solvingElement.CellIndex) });
            var rowVariable = new StepVariants(new[] { CurrentSimplexTable.GetBasisVariableLabel(solvingElement.RowIndex) });

            return new UiDescription
                       {
                           {"SimplexTableView", "table", "", CurrentSimplexTable},
                           {"Label", "lab1", "Виберіть змінну, яка вводиться в базис:"},
                           {"StepsContainer", "cellVar", varsString, cellVariable, true, true},
                           {"Label", "lab2", "Виберіть змінну, яка виводиться з базису:"},
                           {"StepsContainer", "rowVar", varsString, rowVariable, true, true}
                       };
        }
        private UiDescription MakeNextSimplexTableStep(UiDescription userData)
        {
            SetNextStep(IsEndStep);

            var prevTable = CurrentSimplexTable;

            var solvingElement = _simplex.GetSolvingElement(CurrentSimplexTable);
            var cellVariable = new StepVariants(new[] { CurrentSimplexTable.GetVariable(solvingElement.CellIndex) });
            var rowVariable = new StepVariants(new[] { CurrentSimplexTable.GetBasisVariableLabel(solvingElement.RowIndex) });

            CurrentSimplexTable = _simplex.NextSimplexTable(CurrentSimplexTable, solvingElement);

            var tableSettings = new SimplexTableViewSettings
            {
                RowCount = CurrentSimplexTable.RowsCount,
                Variables = new List<string>(CurrentSimplexTable.Variables)
            };

            return new UiDescription
                       {
                           {"TargetFunctionBox", "targetFunction", CurrentProblem.TargetFunction},
                           {"SimplexTableView", "prevTable", prevTable},
                           {
                               "Label", "lab2",
                               "Нова симплекс-таблиця(" + cellVariable.Variants.ElementAt(0) + " вводиться в базис, " +
                                    rowVariable.Variants.ElementAt(0) + " - виводиться)."},
                           {"SimplexTableView", "table", "", CurrentSimplexTable, true, true, tableSettings}
                       };
        }
        private UiDescription NormalizedProblemResultEnteringStep(UiDescription userData)
        {
            SetNextStep(InitialProblemResultEnteringStep);

            var result = _simplex.GetNormalizedProblemResult(CurrentSimplexTable, CurrentProblem);

            return new UiDescription
                       {
                           {"Label", "lab1", "Ф-ція цілі допоміжної задачі:"},
                           {"TargetFunctionBox", "targetFunction", CurrentProblem.TargetFunction},
                           {"SimplexTableView", "table", CurrentSimplexTable},
                           {"Label", "lab2", "Введіть результат розв’язку допоміжної задачі:"},
                           {"LppResultView", "result", "", result, true, true, CurrentProblem.TargetFunctionArguments}
                       };
        }
        private UiDescription SolveOrNormalizeChoiceStep(UiDescription userData)
        {
            CurrentProblem = new LppForSimplexMethod(((LinearProgrammingProblem)userData["LPP"].Value));

            //CurrentProblem = _simplex.Normalize(CurrentProblem);
            //CurrentSimplexTable = _simplex.MakeFirstSimplexTable(CurrentProblem);
            //CurrentSimplexTable = _simplex.Solve(CurrentSimplexTable);
            //return NormalizedProblemResultEnteringStep(userData);

            var nextStep = SolveOrNormalizing();
            SetNextStep(nextStep == SolveLabel ? (Step)MakeFirstSimplexTableStep : NormalizeActionChoiceStep);
            return new UiDescription
                       {
                           {"LppView", "LPP", "", CurrentProblem, false, false},
                           {"Label", "lab", null, "Виберіть наступний крок:", false, false},
                           {"StepsContainer", "NextSteps", SolveOrNormalizeVariants, new StepVariants(new[] {nextStep}), true, true}
                       };
        }
        private UiDescription NormalizeActionChoiceStep(UiDescription userData)
        {
            var nextStep = NextStepOfNormalizing();
            SetNextStepOfNormalizing(nextStep);

            return new UiDescription
                       {
                           {"LppView", "LPP", "", CurrentProblem},
                           {"Label", "lab", null, "Виберіть наступний крок:"},
                           {"StepsContainer", "NextSteps", GetAllNormalizeActions(),
                                      new StepVariants(GetPosibleNormalizeActions(nextStep).Split(new[] {'|'})), true, true}
                       };
        }
        private UiDescription MoreThanOrEqualsZeroLimitationsChanging(UiDescription userData)
        {
            var value = CurrentProblem;
            CurrentProblem = _simplex.ChangeMoreThanZeroConstraints(CurrentProblem);

            SetNextStep(NormalizeActionChoiceStep);

            return new UiDescription
                       {
                           {"LppView", "LPP", "", value},
                           {"Label", "lab", null, "Enter changed limitations system:"},
                           {"LimitationsArea", "LimSystem", "", CurrentProblem.GetAllConstraints(), true, true}
                       };
        }
        private UiDescription IsEndStep(UiDescription userData)
        {
            SetNextStep(_solveActionsSteps[IsEndRightVariant]);

            var nextStepRightVariant = new StepVariants(new[] { _solveActionsLabels[IsEndRightVariant] });

            return new UiDescription
                       {
                           {"SimplexTableView", "table", "", CurrentSimplexTable},
                           {"Label", "lab1", "Подальші дії?"},
                           {"StepsContainer", "variants", IsEndAllVariants, nextStepRightVariant, true, true}
                       };
        }
        private UiDescription InitialStep(UiDescription userData)
        {
            SetNextStep(SolveOrNormalizeChoiceStep);

            return new UiDescription
                       {
                           {"Label", "lab1", "", "Введіть задачу лінійного програмування:"},
                           {"LppView", "LPP", "", null, true},
                       };
        }
        private UiDescription TargetChanging(UiDescription userData)
        {
            var value = CurrentProblem;
            CurrentProblem = _simplex.TargetToMinimize(CurrentProblem);

            SetNextStep(NormalizeActionChoiceStep);

            return new UiDescription
                       {
                           {"LppView", "LPP", "", value},
                           {"Label", "lab", null, "Enter changed target function:"},
                           {"TargetFunctionBox", "TargetFunc", "", CurrentProblem.TargetFunction, true, true}
                       };
        }
        private UiDescription MoreOrEqualsAndEqualsLimitationsChanging(UiDescription userData)
        {
            var prevProblem = CurrentProblem;
            CurrentProblem = _simplex.ChangeMoreThanAndEqualConstraints(CurrentProblem);

            SetNextStep(NormalizeActionChoiceStep);

            return new UiDescription
                       {
                           {"LppView", "LPP", "", prevProblem},
                           {"Label", "lab", null, "Введіть змінену задачу:"},
                           {"LppView", "ChangedLPP", "", CurrentProblem, true, true}
                       };
        }
        private UiDescription MakeFirstSimplexTableStep(UiDescription userData)
        {
            CurrentSimplexTable = _simplex.MakeFirstSimplexTable(CurrentProblem);
            CurrentSimplexTable = _simplex.CalculateRatings(CurrentSimplexTable);

            SetNextStep(IsEndStep);

            var tableSettings = new SimplexTableViewSettings
            {
                RowCount = CurrentSimplexTable.RowsCount,
                Variables = new List<string>(CurrentSimplexTable.Variables)
            };

            return new UiDescription
                       {
                           {"LppView", "normalizedLpp", CurrentProblem},
                           {"Label", "lab1", "Заповніть першу симплекс-таблицю та підрахуйте оцінки."},
                           {"SimplexTableView", "table", "", CurrentSimplexTable, true, true, tableSettings}
                       };
        }