Пример #1
0
        public void Create(LaboratoryWorkModel laboratoryWorkModel, string userName, List <IFormFile> files)
        {
            LaboratoryWork laboratoryWork = _mapper.Map <LaboratoryWork>(laboratoryWorkModel);

            laboratoryWork.User = _userService.GetUser(userName);
            foreach (var item in files)
            {
                if (item.Length > 0)
                {
                    var stream = _streamFetcher.GetArray(item);
                    var file   = new File
                    {
                        Content        = _encoder.Encode(stream),
                        Name           = item.FileName,
                        LaboratoryWork = laboratoryWork
                    };
                    laboratoryWork.Files.Add(file);
                }
            }
            Dictionary <LaboratoryWork, List <Similarity> > similarities = _plagiarismDetector.FindAndSaveSimilarities(laboratoryWork);
            decimal plagiarismValue = _plagiarismDetector.CalculatePlagiarism(similarities);

            laboratoryWork.Similarity = plagiarismValue;
            _unitOfWork.LaboratoryWorkRepository.Insert(laboratoryWork);
            _unitOfWork.Save();
        }
Пример #2
0
 /// <summary>
 /// Конструктор класса, для задания начальных параметров.
 /// </summary>
 public ClassicOptimizationMethod(Delegate function, Vectors vector)
 {
     this.function = function;
     x             = new Vectors(vector);
     A             = new Matrix(x.Size);
     getAlpha      = new LaboratoryWork(function, x.Size);
 }
Пример #3
0
        public async Task <IActionResult> Create([FromBody] LaboratoryWorkDTO model)
        {
            var laboratoryWork =
                new LaboratoryWork {
                TemplateLaboratoryWorkId = model.TemplateLaboratoryWorkId == -1 ? null : model.TemplateLaboratoryWorkId, ThemeId = model.ThemeId, Name = model.Name, Description = model.Description, Evaluation = model.Evaluation, DisciplineCipher = model.DisciplineCipher, UserId = model.UserId, Constraints = model.Constraints
            };

            // тема ЛР будет перезаписывать тему шаблона

            /*if (laboratoryWork.TemplateLaboratoryWorkId != null &&
             *  laboratoryWork.ThemeId != _db.TemplateLaboratoryWorks.FirstOrDefault(x => x.TemplateLaboratoryWorkId == laboratoryWork.TemplateLaboratoryWorkId).ThemeId)
             * {
             *  return BadRequest("Темы лабораторный работы не принадлежит теме шаблона");
             * }*/

            try
            {
                await _db.LaboratoryWorks.AddAsync(laboratoryWork);

                await _db.SaveChangesAsync();
            }
            catch (DbUpdateException e)
            {
                await Response.WriteAsync(e.InnerException.Message);

                return(BadRequest(e.InnerException.Message));
            }
            return(Ok(model));
        }
Пример #4
0
        public async Task <ActionResult <LaboratoryWorkDTO> > PostLaboratoryWork(CreateLaboratoryWorkDTO laboratoryWorkDto)
        {
            LaboratoryWork newLaboratoryWork = new LaboratoryWork(Guid.NewGuid(), laboratoryWorkDto.Name, new Guid(User.Identity.Name), laboratoryWorkDto.DisciplineId);

            try
            {
                await _context.AddAsync(newLaboratoryWork);

                await _context.SaveChangesAsync();

                return(newLaboratoryWork.ToLaboratoryWorkDto());
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                return(StatusCode(500));
            }
        }
Пример #5
0
 protected override bool ComponentPredicate(LaboratoryWork laboratoryWork, string nameComponent)
 => JsonConvert.DeserializeObject <Constrains>(laboratoryWork.Constraints).Checker == nameComponent;
Пример #6
0
 protected abstract bool ComponentPredicate(LaboratoryWork laboratoryWork, string nameComponent);
Пример #7
0
        private void Сalculate_Click(object sender, EventArgs e)
        {
            button1_Click(new object(), new EventArgs());

            eps = Convert.ToDouble(Fault.Text);
            m   = Convert.ToInt16(Limitation.Text);
            string[] NewPoint;            // Значение вектора
            if (StartingPoint.Text != "") // Если введено значение для вектора то задать
            {
                NewPoint = StartingPoint.Text.Split(' ');
                for (int i = 0; i < NewPoint.Length; i++)
                {
                    x[i] = Convert.ToDouble(NewPoint[i]);
                }
            }
            LaboratoryWork lab3 = new LaboratoryWork(function, x.Size, maxK, mineps); // Создание класса для поиска альфа
            Alpha          getAlpha;                                                  // Метод одномерного поиска

            #region Выбор метода одномерного поиска
            switch (DimensionalMethods.SelectedIndex)
            {
            case 0: getAlpha = lab3.getAlphaBolzanoDavidon; break;

            case 1: getAlpha = lab3.getAlphaDihotomy; break;

            case 2: getAlpha = lab3.getAlphaZS1; break;

            case 3: getAlpha = lab3.getAlphaZS2; break;

            case 4: getAlpha = lab3.getAlphaCubic; break;

            case 5: getAlpha = lab3.getAlphaPauell; break;

            case 6: getAlpha = lab3.getAlphaBolzano; break;

            default: getAlpha = null; break;
            }
            #endregion
            startpoint = x; // Вектор хранящий значение стартовых точек
            minimum    = x; // Вектор хранящий значение минимума
            #region Выбор метода многомерного поиска
            if (ThemeName.SelectedIndex == 0)
            {
                switch (MethodName.SelectedIndex)
                {
                case 0: minimum = NewtonOptimizationMethods.NewtonRaphson(getAlpha); break;

                case 1: minimum = NewtonOptimizationMethods.NewtonControlStep(getAlpha); break;

                case 2: minimum = NewtonOptimizationMethods.NewtonConstHessian(getAlpha); break;
                }
            }

            if (ThemeName.SelectedIndex == 1)
            {
                VariableMetricMethods MetricMethod = new VariableMetricMethods();
                switch (MethodName.SelectedIndex)
                {
                case 0: minimum = MetricMethod.QuasiNewton(getAlpha, MetricMethod.DFP); break;

                case 1: minimum = MetricMethod.QuasiNewton(getAlpha, MetricMethod.BFSH); break;

                case 2: minimum = MetricMethod.QuasiNewton(getAlpha, MetricMethod.BFGSH); break;

                case 3: minimum = MetricMethod.QuasiNewton(getAlpha, MetricMethod.MK); break;

                case 4: minimum = MetricMethod.QuasiNewton(getAlpha, MetricMethod.Broiden); break;

                case 5: minimum = MetricMethod.QuasiNewton(getAlpha, MetricMethod.Pirson_2); break;

                case 6: minimum = MetricMethod.QuasiNewton(getAlpha, MetricMethod.Pirson_3); break;

                case 7: minimum = MetricMethod.QuasiNewton(getAlpha, MetricMethod.PZ); break;
                }
            }

            if (ThemeName.SelectedIndex == 2)
            {
                switch (MethodName.SelectedIndex)
                {
                case 0: minimum = new ConjugateGradientMethods().getOptimize(getAlpha, ConjugateGradientMethods.betaDaniel); break;

                case 1: minimum = new ConjugateGradientMethods().getOptimize(getAlpha, ConjugateGradientMethods.betaPhitchersRivers); break;

                case 2: minimum = new ConjugateGradientMethods().getOptimize(getAlpha, ConjugateGradientMethods.betaPolakRiber); break;

                case 3: minimum = new ConjugateGradientMethods().getOptimize(getAlpha, ConjugateGradientMethods.betaDikson); break;
                }
            }
            #endregion

            Result.Text  = "Начальная точка: [ " + startpoint.ToString() + " ]" + Environment.NewLine;
            Result.Text += "Найденный минимум: [ " + minimum.ToString() + " ]" + Environment.NewLine;
            Result.Text += "Количество итераций: " + k;

            x    = null;
            lab3 = null;
        }
        public Dictionary <LaboratoryWork, List <Similarity> > FindAndSaveSimilarities(LaboratoryWork laboratoryWork)
        {
            Dictionary <LaboratoryWork, List <Similarity> > laboratorySimilarities = new Dictionary <LaboratoryWork, List <Similarity> >();

            foreach (File sourceFile in laboratoryWork.Files)
            {
                var dmp = new diff_match_patch();
                foreach (LaboratoryWork anotherLaboratory in _context.LaboratoryWork.ToList())
                {
                    List <Similarity> similarities = new List <Similarity>();
                    foreach (File file in anotherLaboratory.Files)
                    {
                        var     diffs       = dmp.diff_main(file.Content, sourceFile.Content);
                        var     countEquals = CountEquals(diffs);
                        decimal similarity  = (countEquals / (decimal)Math.Max(sourceFile.Content.Length, file.Content.Length));
                        if (similarity >= (decimal)0.6)
                        {
                            Similarity s = new Similarity {
                                SimilarityToId = file.Id, Value = similarity, File = sourceFile
                            };
                            sourceFile.Similarities.Add(s);
                            similarities.Add(s);
                        }
                    }
                    if (!laboratorySimilarities.TryAdd(anotherLaboratory, similarities))
                    {
                        similarities.AddRange(laboratorySimilarities[anotherLaboratory]);
                        laboratorySimilarities[anotherLaboratory] = similarities;
                    }
                }
            }

            return(laboratorySimilarities);
        }