예제 #1
0
def start_proc(dir_seed):
    print(dir_seed[1])
    rows = ROWS
    cols = COLS
    num_plant_types = PlantType().num_plant_types
    depth = num_plant_types + 3  # +1 for 'earth' type, +1 for water, +1 for health
    sector_rows = SECTOR_ROWS
    sector_cols = SECTOR_COLS
    prune_window_rows = PRUNE_WINDOW_ROWS
    prune_window_cols = PRUNE_WINDOW_COLS
    garden_step = STEP

    action_low = 0
    action_high = 1
    obs_low = 0
    obs_high = rows * cols

    garden_days = 100
    sector_obs_per_day = int(NUM_PLANTS +
                             PERCENT_NON_PLANT_CENTERS * NUM_PLANTS)
    collection_time_steps = sector_obs_per_day * garden_days  # 210 sectors observed/garden_day * 200 garden_days
    water_threshold = 1.0

    data_collection = DataCollection()
    data_collection.evaluate_policy(
        data_collection.init_env(rows, cols, depth, sector_rows, sector_cols,
                                 prune_window_rows, prune_window_cols,
                                 action_low, action_high, obs_low, obs_high,
                                 collection_time_steps, garden_step,
                                 num_plant_types, dir_seed[0], dir_seed[1]),
        analytic_policy.policy, collection_time_steps, sector_rows,
        sector_cols, prune_window_rows, prune_window_cols, garden_step,
        water_threshold, sector_obs_per_day)
예제 #2
0
    def __init__(self,
                 max_time_steps,
                 rows,
                 cols,
                 sector_rows,
                 sector_cols,
                 prune_window_rows,
                 prune_window_cols,
                 seed=None,
                 step=1,
                 dir_path="/"):
        super(SimAlphaGardenWrapper, self).__init__(max_time_steps)
        self.rows = rows
        self.cols = cols
        self.num_sectors = (rows * cols) / (sector_rows * sector_cols)
        self.sector_rows = sector_rows
        self.sector_cols = sector_cols
        self.prune_window_rows = prune_window_rows
        self.prune_window_cols = prune_window_cols
        self.step = step
        self.PlantType = PlantType()
        self.seed = seed
        self.reset()
        self.curr_action = -1

        self.config = configparser.ConfigParser()
        self.config.read('gym_config/config.ini')

        # Amount to water every square in a sector by
        self.irr_actions = {
            1: MAX_WATER_LEVEL,
        }

        self.plant_centers_original = []
        self.plant_centers = []
        self.non_plant_centers_original = []
        self.non_plant_centers = []

        self.centers_to_execute = []
        self.actions_to_execute = []

        self.plant_radii = []
        self.plant_heights = []

        self.dir_path = dir_path
예제 #3
0
    def __init__(self,
                 max_time_steps,
                 rows,
                 cols,
                 sector_rows,
                 sector_cols,
                 prune_window_rows,
                 prune_window_cols,
                 seed=None,
                 step=1,
                 dir_path="",
                 randomize_seed_coords=False,
                 plant_seed_config_file_path=None):
        """AlphaGarden's wrapper for Gym, inheriting basic functions from the WrapperEnv.

        Args:
            max_time_steps (int): the number of time steps a simulator runs before resetting.
            rows (int): Amount rows for the grid modeling the garden (N in paper).
            cols (int): Amount columns for the grid modeling the garden (M in paper).
            sector_rows (int): Row size of a sector.
            sector_cols (int): Column size of a sector.
            prune_window_rows (int): Row size of pruning window.
            prune_window_cols (int): Column size of pruning window
            seed (int): Value for "seeding" numpy's random state generator. NOT SEED OF PLANT.
            step (int): Distance between adjacent points in grid.
            dir_path (str): Directory location for saving experiment data.
            randomize_seed_coords (bool): Flag to randomize seed coordinates for given plant seed config file.
            plant_seed_config_file_path (str): File path for plant seed configuration.

        """
        self.max_time_steps = max_time_steps
        super(SimAlphaGardenWrapper, self).__init__(max_time_steps)
        self.rows = rows
        self.cols = cols

        #: int: Number of sectors (representing the area observable to the agent at time t) in garden.
        self.num_sectors = (rows * cols) / (sector_rows * sector_cols)

        self.sector_rows = sector_rows
        self.sector_cols = sector_cols
        self.prune_window_rows = prune_window_rows
        self.prune_window_cols = prune_window_cols
        self.step = step
        self.randomize_seed_coords = randomize_seed_coords
        self.plant_seed_config_file_path = plant_seed_config_file_path
        self.PlantType = PlantType(
        )  #: :obj:`PlantType`: Available types of Plant objects (modeled).
        self.seed = seed
        self.reset()  #: Reset simulator.

        self.curr_action = -1  #: int: Current action selected. 0 = no action, 1 = irrigation, 2 = pruning

        #: Configuration file parser for reinforcement learning with gym.
        self.config = configparser.ConfigParser()
        self.config.read('gym_config/config.ini')

        #: dict of [int,str]: Amount to water every square in a sector by.
        self.irr_actions = {
            1: MAX_WATER_LEVEL,
        }

        self.plant_centers_original = [
        ]  #: Array of [int,int]: Initial seed locations [row, col].
        self.plant_centers = [
        ]  #: Array of [int,int]: Seed locations [row, col] for sectors.
        self.non_plant_centers_original = [
        ]  #: Array of [int,int]: Initial locations without seeds [row, col].
        self.non_plant_centers = [
        ]  #: Array of [int,int]: Locations without seeds [row, col] for sectors.

        self.centers_to_execute = [
        ]  #: Array of [int,int]: Locations [row, col] where to perform actions.
        self.actions_to_execute = []  #: List of int: Actions to perform.

        self.plant_radii = [
        ]  #: List of tuples (str, float): Tuple containing plant type it's plant radius.
        self.plant_heights = [
        ]  #: List of tuples (str, float): Tuple containing plant type it's plant height.

        self.dir_path = dir_path
예제 #4
0
    plt.legend()
    plt.savefig(save_dir + 'water_use_' + str(trial) + '.png',
                bbox_inches='tight',
                pad_inches=0.02)
    plt.close()


if __name__ == '__main__':
    import os
    cpu_cores = [i for i in range(0, 80)]  # Cores (numbered 0-11)
    os.system("taskset -pc {} {}".format(",".join(str(i) for i in cpu_cores),
                                         os.getpid()))

    rows = 150
    cols = 300
    num_plant_types = PlantType().num_plant_types
    depth = num_plant_types + 3  # +1 for 'earth' type, +1 for water, +1 for health
    sector_rows = 15
    sector_cols = 30
    prune_window_rows = 5
    prune_window_cols = 5
    garden_step = 1

    action_low = 0
    action_high = 1
    obs_low = 0
    obs_high = rows * cols

    garden_days = args.days
    sector_obs_per_day = int(NUM_PLANTS +
                             PERCENT_NON_PLANT_CENTERS * NUM_PLANTS)
예제 #5
0
# INPUT {type: {(x, y), radius}, ..., {}}
real_data = {
    'borage': {
        ((2, 2), 10),
        ((5, 5), 10),
    },
    'sorrel': {
        ((8, 8), 10),
        ((11, 11), 10),
    },
}

timestep = 10

plant_type = PlantType()
plant_types = plant_type.plant_names
plant_objs = plant_type.get_plant_seeds(0,
                                        ROWS,
                                        COLS,
                                        SECTOR_ROWS,
                                        SECTOR_COLS,
                                        start_from_germination=False,
                                        existing_data=real_data,
                                        timestep=timestep)

plants = [{} for _ in range(len(plant_types))]

grid = np.empty((ROWS, COLS),
                dtype=[('water', 'f'), ('health', 'i'), ('nearby', 'O')])
grid['water'] = np.random.normal(0.4, 0.1, grid['water'].shape)