Beispiel #1
0
        public static IChangeCalculator BuildCalculator(ILogger?logger)
        {
            var attributeComparer  = new AttributeComparer();
            var attributeMatcher   = new AttributeEvaluator();
            var attributeProcessor = new AttributeMatchProcessor(attributeMatcher, attributeComparer, logger);

            var accessModifierChangeTable  = new AccessModifiersChangeTable();
            var accessModifiersComparer    = new AccessModifiersComparer(accessModifierChangeTable);
            var memberModifiersChangeTable = new PropertyModifiersChangeTable();
            var memberModifiersComparer    = new PropertyModifiersComparer(memberModifiersChangeTable);

            var genericTypeElementComparer = new GenericTypeElementComparer();

            var fieldModifiersChangeTable = new FieldModifiersChangeTable();
            var fieldModifiersComparer    = new FieldModifiersComparer(fieldModifiersChangeTable);
            var fieldComparer             = new FieldComparer(accessModifiersComparer, fieldModifiersComparer, attributeProcessor);
            var fieldMatcher   = new FieldEvaluator();
            var fieldProcessor = new FieldMatchProcessor(fieldMatcher, fieldComparer, logger);

            var propertyAccessorAccessModifiersChangeTable = new PropertyAccessorAccessModifiersChangeTable();
            var propertyAccessorAccessModifiersComparer    = new PropertyAccessorAccessModifiersComparer(propertyAccessorAccessModifiersChangeTable);
            var propertyAccessorComparer  = new PropertyAccessorComparer(propertyAccessorAccessModifiersComparer, attributeProcessor);
            var propertyAccessorEvaluator = new PropertyAccessorEvaluator();
            var propertyAccessorProcessor =
                new PropertyAccessorMatchProcessor(propertyAccessorEvaluator, propertyAccessorComparer, logger);
            var propertyComparer  = new PropertyComparer(accessModifiersComparer, memberModifiersComparer, propertyAccessorProcessor, attributeProcessor);
            var propertyMatcher   = new PropertyEvaluator();
            var propertyProcessor = new PropertyMatchProcessor(propertyMatcher, propertyComparer, logger);

            var methodEvaluator               = new MethodEvaluator();
            var methodModifiersChangeTable    = new MethodModifiersChangeTable();
            var methodModifiersComparer       = new MethodModifiersComparer(methodModifiersChangeTable);
            var parameterModifiersChangeTable = new ParameterModifiersChangeTable();
            var parameterModifiersComparer    = new ParameterModifiersComparer(parameterModifiersChangeTable);
            var parameterComparer             = new ParameterComparer(parameterModifiersComparer, attributeProcessor);
            var methodComparer  = new MethodComparer(accessModifiersComparer, methodModifiersComparer, genericTypeElementComparer, parameterComparer, attributeProcessor);
            var methodProcessor = new MethodMatchProcessor(methodEvaluator, methodComparer, logger);

            var classModifiersChangeTable = new ClassModifiersChangeTable();
            var classModifiersComparer    = new ClassModifiersComparer(classModifiersChangeTable);
            var classComparer             = new ClassComparer(
                accessModifiersComparer,
                classModifiersComparer,
                genericTypeElementComparer,
                fieldProcessor,
                propertyProcessor,
                methodProcessor, attributeProcessor);

            var interfaceComparer = new InterfaceComparer(
                accessModifiersComparer,
                genericTypeElementComparer,
                propertyProcessor,
                methodProcessor,
                attributeProcessor);

            var structModifiersChangeTable = new StructModifiersChangeTable();
            var structModifiersComparer    = new StructModifiersComparer(structModifiersChangeTable);
            var structComparer             = new StructComparer(
                accessModifiersComparer,
                structModifiersComparer,
                genericTypeElementComparer,
                fieldProcessor,
                propertyProcessor,
                methodProcessor,
                attributeProcessor);

            var aggregateTypeComparer = new AggregateTypeComparer(classComparer, interfaceComparer, structComparer);

            var typeEvaluator = new TypeEvaluator();
            var typeProcessor = new TypeMatchProcessor(typeEvaluator, aggregateTypeComparer, logger);

            return(new ChangeCalculator(typeProcessor, logger));
        }
Beispiel #2
0
        /// <summary>
        /// Runs an AStar search through the puzzle, looking for the solution.
        /// </summary>
        /// <returns>Node holding the solved puzzle, or nothing if puzzle not solved.</returns>
        private SliderNode AStarSolver()
        {
            // Initialize the first node for the default state, add it to found state list,
            // then push it to the stack
            var node = CurrentPuzzle.StartingNode;

            var comp = new ClassComparer();
            var heuristicList = new SortedList<int, SliderNode>(comp);

            _history.Add(node.StateS, node);
            heuristicList.Add(node.Heuristic + node.Cost, node);

            while (heuristicList.Count > 0)
            {
                // get first in stack
                var currentNode = heuristicList.First().Value;
                heuristicList.RemoveAt(0);

                // Increment for each node expanded
                NodesExpanded++;

                // Is state the goal state?
                if (currentNode.StateS.Equals(CurrentPuzzle.GoalNode.StateS)) return currentNode;

                // Get all swaps and push them to the queue
                foreach (var swapNode in currentNode.GetSuccessors())
                {
                    var key = swapNode.StateS;

                    // If key is in history and the cost in the history is larger, then reduce the cost in the history
                    //
                    if (_history.ContainsKey(key))
                    {
                        if (_history[key].Cost <= swapNode.Cost) continue;
                        _history[key].Cost = swapNode.Cost;
                        heuristicList.Add(swapNode.Heuristic + swapNode.Cost, swapNode);
                    }
                    else
                    {
                        heuristicList.Add(swapNode.Heuristic + swapNode.Cost, swapNode);
                        _history.Add(swapNode.StateS, swapNode);
                    }
                }
            }
            return null;
        }