Пример #1
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);
        }
Пример #2
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;
            }
        }
Пример #3
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);
        }