Пример #1
0
        public InspirationalBranch CreateRandomNode()
        {
            var newNode = new InspirationalBranch(solver);

            newNode.Inspirational = solver.AvailableInspirationals[solver.RandomHelper.GetShort(solver.AvailableInspirationals.Length)];

            return(newNode);
        }
Пример #2
0
        public Organism(Solver solver, Problem problem)
        {
            this.solver  = solver;
            this.problem = problem;

            root = new InspirationalBranch(solver)
            {
                LeftNode = new InspirationalBranch(solver), RightNode = new InspirationalBranch(solver)
            };
            lastEvaluation = new EvaluationState();
            Solution       = Evaluate(root, lastEvaluation, problem);
        }
Пример #3
0
        private void TraverseNode(InspirationalBranch part, List <InspirationalBranch> nodes)
        {
            nodes.Add(part);

            if (part.LeftNode != null)
            {
                TraverseNode(part.LeftNode, nodes);
            }

            if (part.RightNode != null)
            {
                TraverseNode(part.RightNode, nodes);
            }
        }
Пример #4
0
        public InspirationalBranch Clone(Solver solver)
        {
            InspirationalBranch clone = new InspirationalBranch(solver);

            clone.Inspirational = Inspirational;

            if (LeftNode != null)
            {
                clone.LeftNode = LeftNode.Clone(solver);
            }
            if (RightNode != null)
            {
                clone.RightNode = RightNode.Clone(solver);
            }

            return(clone);
        }
Пример #5
0
        public void Tick()
        {
            InspirationalBranch clone = null;

            clone = (InspirationalBranch)root.Clone(solver);
            clone.Mutate();

            var stateNew = new EvaluationState();

            var newResult = Evaluate(clone, stateNew, problem);

            if (newResult.CostTotal < Solution.CostTotal || solver.RandomHelper.Mutate(10))
            {
                root           = clone;
                Solution       = newResult;
                lastEvaluation = stateNew;

                cachedNames = null;
            }
        }
Пример #6
0
        private static SolutionInformation Evaluate(InspirationalBranch root, EvaluationState state, Problem problem)
        {
            root.Evaluate(state);

            var cost = new SolutionInformation();

            // Add the total inspiration cost
            cost.InspirationTotal += state.Inspiration;
            cost.DiffTotal        += state.Diff;

            // Add extra cost for incomplete solutions
            foreach (var needed in problem.Proficiencies)
            {
                cost.IncompletenessPenalty += Math.Max(0d, needed.Value - state.GetValue(needed.Key)) * 1000;
            }

            cost.CostTotal = cost.InspirationTotal + cost.IncompletenessPenalty;

            return(cost);
        }