Package com.heatonresearch.aifh.examples.capstone.alife.milestone1

Examples of com.heatonresearch.aifh.examples.capstone.alife.milestone1.DisplayPlant


        for (int i = 0; i < 100; i++) {
            physics.runPhysics(universe);
            growth.runGrowth(universe, bestGenome.getData());
        }

        this.display = new DisplayPlant();
        this.display.setUniverse(this.universe);
        this.getContentPane().add(this.display);

        setSize(PlantUniverse.UNIVERSE_WIDTH * 5, PlantUniverse.UNIVERSE_HEIGHT * 5);

 
View Full Code Here


        this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

        this.universe = new PlantUniverse();
        this.universe.reset();

        this.display = new DisplayPlant();
        this.display.setUniverse(this.universe);
        this.getContentPane().add(this.display);

        setSize(PlantUniverse.UNIVERSE_WIDTH * 5, PlantUniverse.UNIVERSE_HEIGHT * 5);

 
View Full Code Here

        genetic.addOperation(0.9, new Splice(PlantUniverse.GENOME_SIZE / 3));
        genetic.addOperation(0.1, new MutatePerturb(0.1));

        // Display

        this.universe = new PlantUniverse();
        this.universe.reset();


        DoubleArrayGenome bestGenome = (DoubleArrayGenome) genetic.getBestGenome();
        PlantPhysics physics = new PlantPhysics();
View Full Code Here

     * {@inheritDoc}
     */
    @Override
    public double calculateScore(final MLMethod algo) {
        DoubleArrayGenome genome = (DoubleArrayGenome) algo;
        PlantUniverse universe = new PlantUniverse();
        universe.reset();
        PlantPhysics physics = new PlantPhysics();
        PlantGrowth growth = new PlantGrowth();

        // Run the generations.
        for (int i = 0; i < PlantUniverse.EVALUATION_CYCLES; i++) {
            physics.runPhysics(universe);
            growth.runGrowth(universe, genome.getData());
        }

        // Count the amount of green.
        int count = 0;
        double sum = 0;
        for (int row = 0; row < PlantUniverse.UNIVERSE_HEIGHT; row++) {
            for (int col = 0; col < PlantUniverse.UNIVERSE_WIDTH; col++) {
                PlantUniverseCell cell = universe.getCell(row, col);
                if (cell.isAlive()) {
                    if (row >= PlantUniverse.GROUND_LINE) {
                        sum += 0.5;
                    } else {
                        sum += cell.getLeafyness();
View Full Code Here

     * Constructor.
     */
    public Milestone2Main() {
        this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

        this.universe = new PlantUniverse();
        this.universe.reset();

        this.display = new DisplayPlant();
        this.display.setUniverse(this.universe);
        this.getContentPane().add(this.display);
View Full Code Here

            }
        }

        for (int row = 0; row < PlantUniverse.UNIVERSE_HEIGHT; row++) {
            for (int col = 0; col < PlantUniverse.UNIVERSE_WIDTH; col++) {
                PlantUniverseCell cell = universe.getCell(row, col);

                // see if we want to change the composition
                if (row < PlantUniverse.GROUND_LINE) {
                    double[] cellVec = universe.getCellInfoVector(row, col);
                    double d1 = dist.calculate(cellVec, 0, genome, 0, PlantUniverse.CELL_VECTOR_LENGTH);
                    double d2 = dist.calculate(cellVec, 0, genome, PlantUniverse.CELL_VECTOR_LENGTH, PlantUniverse.CELL_VECTOR_LENGTH);

                    if (d1 < d2) {
                        cell.setLeafyness(cell.getLeafyness() * PlantUniverse.STEM_TRANSITION);
                    }
                }

                // Evaluate growth into each neighbor cell
                if (universe.canGrow(row, col)) {
                    evaluateNeighbors(universe, row, col, genome, allowRoot, allowSurface);
                }
            }
        }

        // Copy the new composition back to the universe
        for (int row = 0; row < PlantUniverse.UNIVERSE_HEIGHT; row++) {
            for (int col = 0; col < PlantUniverse.UNIVERSE_WIDTH; col++) {
                PlantUniverseCell cell = universe.getCell(row, col);

                if (this.newComposition[row][col]) {
                    if (row >= PlantUniverse.GROUND_LINE) {
                        // Roots are always 100% stem for transfer.
                        cell.setLeafyness(0);
                    } else {
                        cell.setLeafyness(1.0);
                    }
                    cell.setEnergy(1.0);
                    cell.setNourishment(1.0);
                }
            }
        }
    }
View Full Code Here

                } else {
                    // no decay until otherwise calculated
                    decay = 1;
                }

                PlantUniverseCell cell = universe.getCell(row, col);
                cell.setCalculatedSunlight(sunlight[col]);

                // Collect resources for live cells
                if (cell.isAlive()) {
                    // Live cells cause the sunlight to decay (shade)
                    decay *= PlantUniverse.DECAY * cell.getLeafyness();

                    // Set the energy based on sunlight level and composition of the live cell
                    double myEnergy = cell.getCalculatedSunlight() * cell.getLeafyness();
                    double transEnergy = universe.calculateTransferEnergy(row, col) * (1.0 - cell.getLeafyness());
                    double e = Math.max(myEnergy, transEnergy);
                    e = Math.max(PlantUniverse.MIN_LIVING_ENERGY, e);
                    cell.setEnergy(e);
                }

                sunlight[col] *= decay;

            }
View Full Code Here

                } else {
                    // no decay until otherwise calculated
                    decay = 1;
                }

                PlantUniverseCell cell = universe.getCell(row, col);
                cell.setCalculatedWater(waterTable[col]);

                // Collect resources for live cells
                if (cell.isAlive()) {
                    // Live cells cause the water to decay (roots collect)
                    decay *= PlantUniverse.DECAY;

                    // Set the energy based on sunlight level and composition of the live cell
                    double myWater = cell.getCalculatedWater() * cell.getLeafyness();
                    double transWater = universe.calculateTransferNourishment(row, col) * (1.0 - cell.getLeafyness());
                    double n = Math.max(myWater, transWater);
                    n = Math.max(PlantUniverse.MIN_LIVING_ENERGY, n);
                    cell.setNourishment(n);

                    // update the root and surface counts
                    if (row >= PlantUniverse.GROUND_LINE) {
                        rootCount += cell.getNourishment();
                    } else {
                        surfaceCount += cell.getLeafyness();
                    }
                }

                waterTable[col] *= decay;

View Full Code Here

        // Count the amount of green.
        int count = 0;
        double sum = 0;
        for (int row = 0; row < PlantUniverse.UNIVERSE_HEIGHT; row++) {
            for (int col = 0; col < PlantUniverse.UNIVERSE_WIDTH; col++) {
                PlantUniverseCell cell = universe.getCell(row, col);
                if (cell.isAlive()) {
                    if (row >= PlantUniverse.GROUND_LINE) {
                        sum += 0.5;
                    } else {
                        sum += cell.getLeafyness();
                    }
                }
                count++;
            }
        }
View Full Code Here

TOP

Related Classes of com.heatonresearch.aifh.examples.capstone.alife.milestone1.DisplayPlant

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.