Exemplo n.º 1
0
        public TargetOptimizationCenter(GWActionExecuter <PositionData, ActionData> actionExecuter, IEnumerable <GWActionFinder <PositionData, ActionData> > actionFinders, IEnumerable <GWActionEvaluator <PositionData, ActionData> > actionEvaluators, GWPositionEvaluator <PositionData, ActionData> endPositionEvaluator, GWProgressEstimator <PositionData> progressEstimator, GWPositionCategorizer <PositionData, ActionData> positionCategorizer, GWActionCategorizer <PositionData, ActionData> actionCategorizer, CategoryEvaluator <PositionData, ActionData, CheckPointType> categoryEvaluationLogic, CancelCriteria cancelCriteria, string id, TargetOptCenterParams optCenterParams, PositionGuide <PositionData> areaGuide, MandatoryActionExecuter <PositionData, ActionData, CheckPointType> mandatoryActionExecuter, RunnerPool <PositionData, ActionData, CheckPointType> runnerPool) : base()
        {
            MandatoryActionExecuter = mandatoryActionExecuter;
            AreaGuide             = areaGuide;
            Id                    = id;
            ProgressEstimator     = progressEstimator;
            PositionCategorizer   = positionCategorizer;
            CancelCriteria        = cancelCriteria;
            TargetOptCenterParams = optCenterParams;

            EndPositionEvaluator    = endPositionEvaluator;
            CategoryEvaluationLogic = categoryEvaluationLogic;

            Pool = runnerPool;
            Pool.OnEndpositionDiscovered = (item) => EndPositionDiscovered(item.Position);
        }
Exemplo n.º 2
0
        //public static IOptimizationCenter<PositionData, ActionData> PhalanxCenter<PositionData, ActionData>(int phalanxSize, int resultsSize, double[] feedBack, GWActionExecuter<PositionData, ActionData> actionExecuter, IEnumerable<GWActionFinder<PositionData, ActionData>> actionFinders, IEnumerable<GWActionEvaluator<PositionData, ActionData>> actionEvaluators, IEnumerable<GWPositionEvaluator<PositionData, ActionData>> endPositionEvaluators)
        //     where PositionData : Cloneable<PositionData>
        //{
        //    var phalanxCenter = new GWPhalanxOptimizationCenter<PositionData, ActionData>(phalanxSize, resultsSize, feedBack, actionExecuter, actionFinders, actionEvaluators, endPositionEvaluators);

        //    return phalanxCenter;
        //}
        public static ITargetOptCenter <PositionData, ActionData, CheckPointType> TargetOptimizationCenter <PositionData, ActionData, CheckPointType>(GWActionExecuter <PositionData, ActionData> actionExecuter, IEnumerable <GWActionFinder <PositionData, ActionData> > actionFinders, IEnumerable <GWActionEvaluator <PositionData, ActionData> > actionEvaluators, GWPositionEvaluator <PositionData, ActionData> endPositionEvaluator, GWProgressEstimator <PositionData> progressEstimator, GWPositionCategorizer <PositionData, ActionData> positionCategorizer, GWActionCategorizer <PositionData, ActionData> actionCategorizer, CategoryEvaluator <PositionData, ActionData, CheckPointType> categoryEvaluationLogic, CancelCriteria cancelCriteria, string id, TargetOptCenterParams optCenterParams, PositionGuide <PositionData> areaGuide, MandatoryActionExecuter <PositionData, ActionData, CheckPointType> mandatoryActionExecuter, RunnerPool <PositionData, ActionData, CheckPointType> runnerPool)
            where PositionData : BasePositionData <PositionData, ActionData, CheckPointType>, Cloneable <PositionData>, IHasFingerprint
            where ActionData : BaseActionData <PositionData, ActionData, CheckPointType>
            where CheckPointType : CheckPoint <PositionData>
        {
            var optCenter = new TargetOptimizationCenter <PositionData, ActionData, CheckPointType>(actionExecuter, actionFinders, actionEvaluators, endPositionEvaluator, progressEstimator, positionCategorizer, actionCategorizer, categoryEvaluationLogic, cancelCriteria, id, optCenterParams, areaGuide, mandatoryActionExecuter, runnerPool);

            return(optCenter);
        }
Exemplo n.º 3
0
        public void RunUntilMeetTargetOrEnd(PartialTarget <PositionData>[] targets, CancelCriteria criteria, int maxSteps = 0)
        {
            //Position.Data.NextCheckPoint = NextCheckPoint;
            //LastCrossroad = new GWCrossroad<PositionData, ActionData>(Position);
            int stepsDone = 0;

            while (true)
            {
                //var fallbackDone = false;
                var currentTargetsReached = new bool[targets.Length];
                for (int i = 0; i < targets.Length; i++)
                {
                    currentTargetsReached[i] = targets[i].ReachTarget(Position);
                }

                var options = new List <GWAction <PositionData, ActionData> >();
                foreach (var actionFinder in ActionHandling.ActionFinders)
                {
                    // filter actions that have been researched
                    var newOptions = actionFinder.FindActions(Position);
                    options.AddRange(newOptions);
                    //options.AddRange(newOptions.Where(a => !Position.Data.ActionsTried.Contains(a.Data.FingerPrint)));
                }
                if (HasMoved)
                {
                    options = (options.Where(op => op.HasImpactOnTarget)).ToList();
                }
                //TODO: filter double actions (from several actionFinders)
                if (options.NullOrEmpty())
                {   //no more options that help reach a target, can stop searching
                    break;
                }

                //categorize actions
                //var optionCategories = options.Split(action => ActionHandling.ActionCategorizer.Categorize(action)).ToArray();


                if (options.NullOrEmpty())
                {   //no more options that help reach a target, can stop searching
                    break;
                }

                //choose by multievaluation:
                ChosenAction = MultiEvaluation.Do(options, ActionHandling.ActionEvaluators, Weights, 1, MultiEvaluationOptions).First();


                PreSolution.Position = ActionHandling.ActionExecuter.CreateNewPosition(ChosenAction);
                HasMoved             = true;
                stepsDone++;

                //check if new target is reached
                bool newTargetReached = false;
                for (int i = 0; i < targets.Length; i++)
                {
                    var targetReached = targets[i].ReachTarget(Position);
                    if (currentTargetsReached[i] != targetReached)
                    {
                        currentTargetsReached[i] = targetReached;
                        newTargetReached         = true;
                    }
                }
                if (targets.All(t => t.ReachTarget(Position) || t.IsOptional))
                {
                    Position.IsEndPosition = true;
                    OnTargetReached(this);
                    if (criteria == CancelCriteria.TargetsReached)
                    {
                        break;
                    }
                }
                if (newTargetReached)
                {
                    OnTargetReached(this);
                    if (criteria == CancelCriteria.TargetsReached)
                    {
                        break;
                    }
                }

                if (criteria == CancelCriteria.MaxSteps && stepsDone >= maxSteps)
                {
                    break;
                }
            }
            //Score = Position.Data.NextCheckPoint.Score(Position.Data);
        }