Beispiel #1
0
    void createPlayers(bool replay)
    {
        if (showBestSolution)
        {
            if (!replay)
            {
                solution = geneticController.getSolution();
            }

            if (solution != null)
            {
                players = new List <GeneticPlayer>();
                players.Add(new GeneticPlayer(new Vector2(0, 0), this.mapModel, solution, false, solution.fitness()));
                this.GetComponent <MapGeneticView>().setPlayers(players);
            }
        }
        else
        {
            if (!replay)
            {
                List <ChromosomeSalesman> currentSolutions = geneticController.getPartialSolution();
                if (currentSolutions != null)
                {
                    solutions = currentSolutions;
                }
            }

            if (solutions != null)
            {
                float worstFitness = 0;
                foreach (ChromosomeSalesman solution in solutions)
                {
                    float fitness = solution.fitness();
                    if (fitness > worstFitness)
                    {
                        worstFitness = fitness;
                    }
                }

                players = new List <GeneticPlayer>();
                // create players
                for (int i = 0; i < solutions.Count; i++)
                {
                    players.Add(new GeneticPlayer(new Vector2(0, 0), this.mapModel, solutions[i], i == 0, worstFitness));
                }
                this.GetComponent <MapGeneticView>().setPlayers(players);
            }
        }
    }
    float worstFitness;                 // used to calculate the time for moving the players (based on the worst fitness)

    public GeneticPlayer(Vector2 position, MapGenetic map, ChromosomeSalesman solution, bool bestSolution, float worstFitness) : base(position, map)
    {
        this.solution     = solution;
        this.bestSolution = bestSolution;
        this.worstFitness = worstFitness;
    }