Example #1
0
    def __init__(self, options):
        self.options = DotDict(options)
        self.options.ENV_ENCODING = [('s', Squid), ('X', Obstacle)]
        self.options.save_history_for = [Squid]
        super().__init__(self.options)

        self.agent_status = {}
        self.agent_U_and_pi = {}
Example #2
0
    def __init__(self, options=None, name='noname'):
        options = options or {}
        self.options = DotDict(options)

        self.things = []
        self.agents = []
        self.actions = None
        self.rewards = None
        self.__name__ = name
        self.observers = defaultdict(list)
        self.non_spatials = {}  # indexed with time

        # These needs to be set in the subclass when rendering in the browser
        self.wss = None
        self.world = None
        self.wss_cfg = None
Example #3
0
    def __init__(self, options=None):
        options = options or {}
        super().__init__(options)
        options = self.options

        self.width = options.width or 10
        self.height = options.height or 10
        self.thing_counter = 0

        self.ENV_ENCODING = options.ENV_ENCODING or []

        # Sets iteration start and end (no walls).
        self.x_start, self.y_start = (0, 0)
        self.x_end, self.y_end = (self.width, self.height)

        if options.terrain:
            self.width = len(options.terrain[0])
            self.height = len(options.terrain)
            self.x_end, self.y_end = (self.width, self.height)

        # build world from things and terrain
        if options.things:
            self.add_things(options.things)

        #self.save_history_for = options.save_history_for or []

        #self.environment_history = {}
        #for cls in self.save_history_for:
        #    self.environment_history[cls] = []

        # setup rendering in browser if options are there
        if options.wss:
            self.wss = options.wss
            self.wss_cfg = DotDict(options.wss_cfg)

            self.options.wss_cfg['terrain'] = '\n'.join(self.options.terrain)

            self.build_world()
            if self.world:
                self.options.wss_cfg['terrain'] = '\n'.join(self.world)

            self.wss.send_init(self.options.wss_cfg)
Example #4
0
OPTIONS = DotDict({
    'output_path': get_output_dir(file=__file__),
    'terrain': terrain.split('\n'),
    'things': things.split('\n'),
    'exogenous_things': exogenous_things.split('\n'),
    'exogenous_things_prob': 0.1,
    'objectives': {
        'energy': 1.0,
        'water': 1.0
    },
    'rewards': {
        None: {
            Energy: {
                'energy': 1.0,
                'water': -0.001
            },
            Water: {
                'energy': -0.001,
                'water': 1.0
            },
            None: {
                'energy': -0.001,
                'water': -0.001
            }
        }
    },
    'wss_cfg': {
        'numTilesPerSquare': (1, 1),
        'drawGrid': True,
        'randomTerrain': 0,
        'agents': {
            'grid_agent': {
                'name': 'G',
                'pos': agent_start_pos,
                'hidden': False
            }
        }
    }
})
Example #5
0
OPTIONS = DotDict({
    'terrain': terrain.split('\n'),
    'things': things.split('\n'),
    'exogenous_things': exogenous_things.split('\n'),
    'exogenous_things_prob': 0.01,
    'objectives': {
        'energy': 1
    },
    'reward': {
        'eat_and_forward': {
            Squid: {
                'energy': 0.1
            },
            None: {
                'energy': -0.05
            }
        },
        'forward': {
            None: {
                'energy': -0.001
            }
        },
        'dive_and_forward': {
            None: {
                'energy': -0.002
            }
        },
        'up_and_forward': {
            None: {
                'energy': -0.002
            }
        },
        'sing': {
            None: {
                'energy': -0.001
            }
        },
    },
    'agents': {
        'mom': {
            'sensors': [(Squid, 's')],
            'motors': [('eat_and_forward', ['eat', 'forward']),
                       ('forward', ['forward']),
                       ('dive_and_forward', ['down', 'forward']),
                       ('up_and_forward', ['up', 'forward']),
                       ('sing', ['sing'])],
        },
        'calf': {
            'sensors': [(Squid, 's'), (Sing, 'S')],
            'motors': [('eat_and_forward', ['eat', 'forward']),
                       ('forward', ['forward']),
                       ('dive_and_forward', ['down', 'forward']),
                       ('up_and_forward', ['up', 'forward'])],
        }
    },
    'wss_cfg': {
        'numTilesPerSquare': (1, 1),
        'drawGrid': True,
        'randomTerrain': 0,
        'agents': {
            'mom': {
                'name': 'M',
                'pos': mom_start_pos,
                'hidden': False
            },
            'calf': {
                'name': 'c',
                'pos': calf_start_pos,
                'hidden': False
            }
        }
    }
})
Example #6
0
from gzutils.gzutils import DotDict
from agents import Agent, Thing, Direction, NonSpatial, XYEnvironment

MOVES = [(1, 0), (-1, 0)]

OPTIONS = DotDict({
    'terrain': 'DDDDD',
    'wss_cfg': {
        'numTilesPerSquare': (1, 1),
        'drawGrid': True,
        'randomTerrain': 0,
        'agents': {
            'Test': {
                'name': 'T',
                'pos': (0,0),
                'hidden': False
            } 
        }
    }
})

# Classes
# =======

class World(XYEnvironment):
    def __init__(self, options):
        super().__init__(options)

    def calc_performance(self, _, _2):
        pass
Example #7
0
MOVES = [(0, -1), (0, 1)]

fido_start_pos = (0, 0)
dido_start_pos = (0, 0)

OPTIONS = DotDict({
    'terrain': 'G\nG\nG\nG\nG\nG\nG\nG\nG\nG'.split('\n'),
    'wss_cfg': {
        'numTilesPerSquare': (1, 1),
        'drawGrid': True,
        'randomTerrain': 0,
        'agents': {
            'fido': {
                'name': 'F',
                'pos': fido_start_pos,
                'hidden': False
            },
            'dido': {
                'name': 'D',
                'pos': dido_start_pos,
                'hidden': False
            }
        }
    }
})



# Classes
# ========
Example #8
0
 def __init__(self, options):
     self.options = DotDict(options)
     self.ENV_ENCODING = [('s', Squid), ('X', Obstacle)]
     self.save_history_for = [Squid]
     super().__init__(options)
Example #9
0
OPTIONS = DotDict({
    'output_path': get_output_dir(file=__file__),
    'terrain': terrain.split('\n'),
    'things': things.split('\n'),
    'exogenous_things': exogenous_things.split('\n'),
    'exogenous_things_prob': 0.05,
    'objectives': {
        'energy': 1.0
    },
    'rewards': {
        'sing_eat_and_forward': {
            Squid: {
                'energy': 0.5
            },
            None: {
                'energy': -0.02
            }
        },
        'eat_and_forward': {
            Squid: {
                'energy': 0.5
            },
            None: {
                'energy': -0.02
            }
        },
        'dive_and_forward': {
            None: {
                'energy': -0.02
            }
        },
        'up_and_forward': {
            None: {
                'energy': -0.01
            }
        },
        'forward': {
            None: {
                'energy': -0.01
            }
        },
        None: {
            None: {
                'energy': 0.0
            }
        },
    },
    'wss_cfg': {
        'numTilesPerSquare': (1, 1),
        'drawGrid': True,
        'randomTerrain': 0,
        'agents': {
            'mom': {
                'name': 'M',
                'pos': mom_start_pos,
                'hidden': False
            },
            'calf': {
                'name': 'c',
                'pos': calf_start_pos,
                'hidden': False
            }
        }
    }
})