Esempio n. 1
0
        /// <summary>
        /// Случайно генерирует начальную популяцию. Количество особей равно сумме диапазона всех параметров * на мощность
        /// </summary>
        /// <param name="selection"></param>
        /// <param name="multiplier">Мощность</param>
        /// <returns></returns>
        public static List<InstanceModel> CreateFirstGeneration(SelectionModel selection, int multiplier = 1)
        {
            List<InstanceModel> res = new List<InstanceModel>();

            List<ParamSelection> integralParams = selection.SelectionParams.Where(p => p.ValueMin.IsIntegral() && (dynamic)p.ValueMax > (dynamic)p.ValueMin).ToList();
            List<ParamEntity> otherParams = selection.SelectionParams.Where(p => !p.ValueMin.IsIntegral()).Select(p => {
                var param = new ParamEntity { FieldValue = p.ValueMin };
                param.CopyObject(p);
                return param;
            }
            ).ToList();

            //заполняеем всеми возможными значениями
            var fieldResults = integralParams.AsParallel()
                .Select(p => new KeyValuePair<string, IEnumerable<int>>(p.FieldName, (IEnumerable<int>)Enumerable.Range(0, (dynamic)p.ValueMax - (dynamic)p.ValueMin + 1)));

            foreach (KeyValuePair<string, IEnumerable<int>> pair in fieldResults)
            {
                for (int j = 0; j < multiplier; j++)
                {
                    foreach (int i in pair.Value)
                    {
                        InstanceModel newInstance = new InstanceModel();
                        newInstance.CopyObject(selection);
                        newInstance.SelectionId = selection.Id;
                        
                        newInstance.StrategyParams.AddRange(otherParams);

                        foreach (ParamSelection paramSelection in integralParams)
                        {
                            ParamEntity newParam = new ParamEntity();
                            newParam.CopyObject(paramSelection);
                            if (paramSelection.FieldName == pair.Key)
                            {
                                // Сохраним у значения исходный тип
                                newParam.FieldValue = Convert.ChangeType((dynamic)paramSelection.ValueMin + i, Type.GetType(paramSelection.TypeName));
                            }
                            else
                            {
                                Random rnd = new Random();
                                newParam.FieldValue = Convert.ChangeType(rnd.Next(paramSelection.ValueMin.ToIntSave(), paramSelection.ValueMax.ToIntSave()), Type.GetType(paramSelection.TypeName));
                            }

                            newInstance.StrategyParams.Add(newParam);

                        }

                        res.Add(newInstance);
                    }
                }
            }

            return res;
        }
Esempio n. 2
0
        public ActionResult Edit(SelectionModel selection, IEnumerable<ParamSelection> strategyParams)
        {
            selection.SelectionParams = strategyParams.ToList();

            if (ModelState.IsValid)
            {
                //Сохранение
                selectionService.Save(selection);

                TempData["message"] = String.Format("Сохранены изменения в селекции: {0}", selection.Name);
                return RedirectToAction("Index");
            }

            else
            {
                return _Edit(selection);
            }

        }
Esempio n. 3
0
        public ActionResult Edit(int instanceId = 0)
        {
            InitializeLists();
            SelectionModel model = null;

            if (instanceId != 0)
            {
                model = selectionService.GetById(instanceId, true);
                if (model == null)
                {
                    TempData["error"] = String.Format("Экземпляр селекции \"{0}\"  не найден!", instanceId);
                    return RedirectToAction("Index");
                }
            }
            else
                model = new SelectionModel();

            return View("Edit", model);
        }
Esempio n. 4
0
        public void LoadNavigationProperties(SelectionModel model)
        {
            if (model.StrategyInfo == null && model.StrategyInfoId != 0)
                model.StrategyInfo = strategyInfoRepository.GetById(model.StrategyInfoId);

            if (model.Ticker == null && model.TickerId != 0)
                model.Ticker = tickerRepository.GetById(model.TickerId);

            if (model.TimeFrame == null && model.TimeFrameId != 0)
                model.TimeFrame = timeFrameRepository.GetById(model.TimeFrameId);
        }
Esempio n. 5
0
        /// <summary>
        /// Редактирование стратегии
        /// </summary>
        /// <param name="instanceId">Если 0 - создание нвого варианта</param>
        /// <returns></returns>
        private ActionResult _Edit(SelectionModel model)
        {
            InitializeLists();

            LoadNavigationProperties(model);
            model.SelectionParams = StrategyHelper.GetEntityParams(model.StrategyInfo, model.SelectionParams).ToList();

            return View("Edit", model);

        }
Esempio n. 6
0
        public ActionResult Details(int instanceId)
        {
            SelectionModel model = new SelectionModel();
            if (instanceId != 0)
            {
                model = selectionService.GetById(instanceId, true);
                if (model == null)
                {
                    TempData["error"] = String.Format("Экземпляр селекции \"{0}\"  не найден!", instanceId);
                    return RedirectToAction("Index");
                }
            }

            return View(model);
        }