Ejemplo 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;
        }
Ejemplo n.º 2
0
        public ActionResult Edit(InstanceModel instance, IEnumerable<ParamEntity> strategyParams)
        {
            instance.StrategyParams = strategyParams.ToList();

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

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

            else
            {
                return _Edit(instance);
            }

        }
Ejemplo n.º 3
0
        public ActionResult Edit(int instanceId = 0)
        {
            InitializeLists();
            InstanceModel model = null;

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

            return View("Edit", model);
        }
Ejemplo n.º 4
0
        private void LoadNavigationProperties(InstanceModel 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);

            //if (model.Selection == null && model.SelectionId.HasValue)
            //    model.Selection = selectionService.GetById(model.SelectionId.Value);

        }
Ejemplo n.º 5
0
        /// <summary>
        /// Редактирование стратегии
        /// </summary>
        /// <param name="instanceId">Если 0 - создание нвого варианта</param>
        /// <returns></returns>
        private ActionResult _Edit(InstanceModel model)
        {
            InitializeLists();

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

            return View("Edit", model);

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

            return View(model);
        }