示例#1
0
def tmy_step_to_OOMDP(current_step_data, tracker, solpos, old_tilt, albedo):
    '''
    Creates OOMDP state from TMY data.
    '''

    #time since epoch in sec
    last_unix = current_step_data.index.view('int64')
    #time of day
    hour = current_step_data.index.hour

    sun_attributes = {'apparent_zenith': float(solpos['apparent_zenith']), 'azimuth': float(solpos['azimuth'])}
    env_attributes = {'DHI': float(current_step_data['DHI']), 'GHI': float(current_step_data['GHI']), 'DNI':float(current_step_data['DNI']), 'Wspd':float(current_step_data['Wspd']), 'DryBulb': float(current_step_data['DryBulb']), 'TotCld':float(current_step_data['TotCld']), 'OpqCld':float(current_step_data['OpqCld']),
                        'albedo':albedo,  'datetime':last_unix, 'hour':hour}

    angle_pos = pvlib.tracking.singleaxis(solpos['apparent_zenith'], solpos['azimuth'], backtrack=False)

    surface_tilt = angle_pos['tracker_theta']
    # print(surface_tilt)
    if np.isnan(surface_tilt[0]):
        #TODO: fix this wrt hour
        surface_tilt = tracker.fallback_angle if hour > 12 else -tracker.fallback_angle

    tracker_attributes = {'tracker_theta':surface_tilt, 'prev_angle':old_tilt}

    sun_obj = OOMDPObject(sun_attributes, name="sun")
    env_obj = OOMDPObject(env_attributes, name="env")
    tracker_obj = OOMDPObject(tracker_attributes, name="tracker")

    #passing list of objects for class!
    objects = {'sun':[sun_obj], 'env':[env_obj], 'tracker':[tracker_obj]}
    return OOMDPState(objects)
    def __init__(self,
                 width,
                 height,
                 agent,
                 walls,
                 goals,
                 crumbs,
                 slip_prob=0,
                 gamma=0.99,
                 step_cost=0,
                 weights=None,
                 env_code=None,
                 sample_rate=5):
        self.env_code = env_code
        self.height = height
        self.width = width
        if weights is not None:
            self.weights = weights
        else:
            # use true weighting over reward variables (on the goal with the passenger, on a toll, on a traffic cell)
            self.weights = np.array([[2, -0.4, -0.5]])

        # objects that belong in the state (changing)
        agent_obj = OOMDPObject(attributes=agent, name="agent")
        agent_exit = {"x": 100, "y": 100}
        crumb_objs = self._make_oomdp_objs_from_list_of_dict(crumbs, "crumb")
        crumb_objs_exit = self._make_oomdp_objs_from_list_of_dict(
            crumbs, "crumb")

        # objects that belong to the MDP (static)
        wall_objs = self._make_oomdp_objs_from_list_of_dict(walls, "wall")
        self.walls = wall_objs
        goal_objs = self._make_oomdp_objs_from_list_of_dict(goals, "goal")
        self.goals = goal_objs
        self.slip_prob = slip_prob

        init_state = self._create_state(agent_obj, crumb_objs)
        self.exit_state = self._create_state(
            OOMDPObject(attributes=agent_exit, name="agent_exit"),
            crumb_objs_exit)
        self.exit_state.set_terminal(True)
        self.exit_state.set_goal(False)
        OOMDP.__init__(self,
                       CookieCrumbOOMDP.ACTIONS,
                       self._cookie_crumb_transition_func,
                       self._cookie_crumb_reward_func,
                       init_state=init_state,
                       gamma=gamma,
                       step_cost=step_cost,
                       sample_rate=sample_rate)
    def __init__(self,
                 width,
                 height,
                 agent,
                 walls,
                 goal,
                 skateboard,
                 slip_prob=0,
                 gamma=0.99,
                 step_cost=0,
                 weights=None,
                 env_code=None,
                 sample_rate=5):
        self.env_code = env_code
        self.height = height
        self.width = width
        if weights is not None:
            self.weights = weights
        else:
            self.weights = np.array([[2, -0.4, -0.5]])

        # objects that belong in the state (changing)
        agent_obj = OOMDPObject(attributes=agent, name="agent")
        agent_exit = {"x": 100, "y": 100}
        skateboard_objs = self._make_oomdp_objs_from_list_of_dict(
            skateboard, "skateboard")
        skateboard_objs_exit = self._make_oomdp_objs_from_list_of_dict(
            skateboard, "skateboard")

        # objects that belong to the MDP (static)
        wall_objs = self._make_oomdp_objs_from_list_of_dict(walls, "wall")
        self.walls = wall_objs
        self.goal = goal
        self.slip_prob = slip_prob

        init_state = self._create_state(agent_obj, skateboard_objs)
        self.exit_state = self._create_state(
            OOMDPObject(attributes=agent_exit, name="agent_exit"),
            skateboard_objs_exit)
        self.exit_state.set_terminal(True)
        self.exit_state.set_goal(False)
        OOMDP.__init__(self,
                       SkateboardOOMDP.ACTIONS,
                       self._skateboard_transition_func,
                       self._skateboard_reward_func,
                       init_state=init_state,
                       gamma=gamma,
                       step_cost=step_cost,
                       sample_rate=sample_rate)
示例#4
0
    def map_state(self, l0_state):
        '''
        Args:
            l0_state (OOMDPState): L0 Taxi State
        Returns:
            projected_state (TaxiL1State): Mapping of state into L1 space
        '''
        agent = l0_state.get_first_obj_of_class('agent')
        passenger = l0_state.get_first_obj_of_class('passenger')
        agent_location = agent['x'], agent['y']
        passenger_location = passenger['x'], passenger['y']
        destination = passenger['dest_x'], passenger['dest_y']
        agent_color = self.l0_domain.color_for_location(agent_location)
        passenger_color = self.l0_domain.color_for_location(passenger_location)
        passenger_dest_color = self.l0_domain.color_for_location(destination)

        agent_dict = {
            'current_color': agent_color,
            'has_passenger': agent['has_passenger']
        }
        passengers = [{
            'current_color': passenger_color,
            'dest_color': passenger_dest_color
        }]
        agent_obj = OOMDPObject(attributes=agent_dict, name='agent')
        passenger_objs = self.l0_domain._make_oomdp_objs_from_list_of_dict(
            passengers, 'passenger')

        return TaxiL1State(agent_obj, passenger_objs[0])
示例#5
0
    def __init__(self,
                 width,
                 height,
                 agent,
                 walls,
                 passengers,
                 goal_loc=None,
                 slip_prob=0,
                 gamma=0.99):
        self.height = height
        self.width = width

        agent_obj = OOMDPObject(attributes=agent, name="agent")
        wall_objs = self._make_oomdp_objs_from_list_of_dict(walls, "wall")
        pass_objs = self._make_oomdp_objs_from_list_of_dict(
            passengers, "passenger")
        init_state = self._create_state(agent_obj, wall_objs, pass_objs)

        self.goal_location = goal_loc
        self.terminal_func = taxi_helpers.is_taxi_terminal_state if goal_loc is None else self._navigation_terminal_func
        rf = self._taxi_reward_func if goal_loc is None else self._navigation_reward_func

        OOMDP.__init__(self,
                       TaxiOOMDP.ACTIONS,
                       self._taxi_transition_func,
                       rf,
                       init_state=init_state,
                       gamma=gamma)

        self.slip_prob = slip_prob
示例#6
0
    def __init__(self,
                 width,
                 height,
                 agent,
                 blocks,
                 lavas,
                 gamma=0.99,
                 slip_prob=0.0,
                 name="trench"):
        self.height = height
        self.width = width
        self.name = name

        agent_obj = OOMDPObject(attributes=agent, name="agent")
        block_objs = self._make_oomdp_objs_from_list_of_dict(blocks, "block")
        lava_objs = self._make_oomdp_objs_from_list_of_dict(lavas, "lava")

        init_state = self._create_state(agent_obj, block_objs, lava_objs)
        OOMDP.__init__(self,
                       TrenchOOMDP.ACTIONS,
                       self._trench_transition_func,
                       self._trench_reward_func,
                       init_state=init_state,
                       gamma=gamma)
        self.slip_prob = slip_prob
示例#7
0
    def _create_init_state(self, height, width, agent, walls, blocks, exit):
        '''
        Args:
            height (int)
            width (int)
            agent (dict)
            walls (list of dicts)
            blocks (list of dicts)
            exit (dict)

        Returns:
            (OOMDP State)
        '''

        self.objects = {c: [] for c in BlockDudeOOMDP.CLASSES}

        # Make agent.
        agent_attributes = {}
        for attr in agent.keys():
            agent_attributes[attr] = agent[attr]
        agent = OOMDPObject(attributes=agent_attributes, name="agent")
        self.objects["agent"].append(agent)

        # Make walls.
        for w in walls:
            wall_attributes = {}
            for attr in w:
                wall_attributes[attr] = w[attr]
            wall = OOMDPObject(attributes=wall_attributes, name="wall")
            self.objects["wall"].append(wall)

        # Make passengers.
        for b in blocks:
            passenger_attributes = {}
            for attr in p:
                passenger_attributes[attr] = p[attr]
            block = OOMDPObject(attributes=passenger_attributes, name="block")
            self.objects["block"].append(block)

        # Make exit.
        exit_attributes = {}
        for attr in exit.keys():
            exit_attributes[attr] = exit[attr]
        exit = OOMDPObject(attributes=exit_attributes, name="exit")
        self.objects["exit"].append(exit)

        return BlockDudeState(self.objects)
示例#8
0
 def _get_default_panel_obj_list(self):
     panels = []
     for i in xrange(self.sqrt_num_panels**2):
         # Make panel object.
         panel_attributes = {}
         panel_attributes["angle_ew"] = 0.0
         panel_attributes["angle_ns"] = 0.0
         panel = OOMDPObject(attributes=panel_attributes, name="panel_" + str(i))
         panels.append(panel)
     return panels
示例#9
0
    def __init__(self, width, height, agent, walls, passengers, slip_prob=0, gamma=0.99):
        self.height = height
        self.width = width

        agent_obj = OOMDPObject(attributes=agent, name="agent")
        wall_objs = self._make_oomdp_objs_from_list_of_dict(walls, "wall")
        pass_objs = self._make_oomdp_objs_from_list_of_dict(passengers, "passenger")

        init_state = self._create_state(agent_obj, wall_objs, pass_objs)
        OOMDP.__init__(self, TaxiOOMDP.ACTIONS, self._taxi_transition_func, self._taxi_reward_func, init_state=init_state, gamma=gamma)
        self.slip_prob = slip_prob
示例#10
0
    def __init__(self,
                 width,
                 height,
                 agent,
                 walls,
                 passengers,
                 slip_prob=0,
                 gamma=0.99,
                 weights=None):
        self.height = height
        self.width = width
        if weights is not None:
            self.weights = weights
        else:
            # use true weighting over reward variables (on the goal with the passenger, on a toll, on a traffic cell)
            self.weights = np.array([[10, 0, -1]])

        agent_obj = OOMDPObject(attributes=agent, name="agent")
        agent_exit = {"x": 100, "y": 100, "has_passenger": 0}
        wall_objs = self._make_oomdp_objs_from_list_of_dict(walls, "wall")
        pass_objs = self._make_oomdp_objs_from_list_of_dict(
            passengers, "passenger")
        pass_objs_exit = self._make_oomdp_objs_from_list_of_dict(
            passengers, "passenger")
        self.walls = wall_objs

        self.exit_state = self._create_state(
            OOMDPObject(attributes=agent_exit, name="agent_exit"),
            pass_objs_exit)
        self.exit_state.set_terminal(True)
        self.exit_state.set_goal(False)

        init_state = self._create_state(agent_obj, pass_objs)
        OOMDP.__init__(self,
                       TaxiOOMDP.ACTIONS,
                       self._taxi_transition_func,
                       self._taxi_reward_func,
                       init_state=init_state,
                       gamma=gamma,
                       sample_rate=1)
        self.slip_prob = slip_prob
示例#11
0
 def create_goal_state(cls, dest_color):
     goal_agent = {'current_color': dest_color, 'has_passenger': 0}
     goal_passengers = [{
         'current_color': dest_color,
         'dest_color': dest_color
     }]
     goal_agent_obj = OOMDPObject(attributes=goal_agent, name='agent')
     goal_passenger_objs = OOMDP._make_oomdp_objs_from_list_of_dict(
         goal_passengers, 'passenger')
     return TaxiL1OOMDP._create_state(goal_agent_obj,
                                      goal_passenger_objs,
                                      is_terminal=True)
示例#12
0
    def _create_state(self, angle_ew, angle_ns, pixels, time):
        '''
		Creates an OOMDP state from the provided panel angle, time, and image.
		Image is a flattened array of image pixels, provided by _capture_img
		'''

        self.objects = {attr: [] for attr in ArduinoOOMDP.CLASSES}

        panel_attributes = {'angle_ew': angle_ew, 'angle_ns': angle_ns}
        panel = OOMDPObject(attributes=panel_attributes, name='panel')
        self.objects["panel"].append(panel)  #it's a list!

        # Sun.
        sun_attributes = {}
        sun_angle_AZ = sh._compute_sun_azimuth(self.latitude_deg,
                                               self.longitude_deg, time)
        sun_angle_ALT = sh._compute_sun_altitude(self.latitude_deg,
                                                 self.longitude_deg, time)

        #NOTE: providing sun angle AND image
        sun_attributes["angle_AZ"] = sun_angle_AZ
        sun_attributes["angle_ALT"] = sun_angle_ALT

        if pixels:
            for idx, pix in enumerate(pixels):
                sun_attributes['pix' + str(idx)] = pix

        sun = OOMDPObject(attributes=sun_attributes, name="sun")
        self.objects["sun"].append(sun)

        return SolarOOMDPState(self.objects,
                               date_time=time,
                               longitude=self.longitude_deg,
                               latitude=self.latitude_deg,
                               sun_angle_AZ=sun_angle_AZ,
                               sun_angle_ALT=sun_angle_ALT)
示例#13
0
    def _make_oomdp_objs_from_list_of_dict(cls, list_of_attr_dicts, name):
        '''
        Ags:
            list_of_attr_dicts (list of dict)
            name (str): Class of the object.

        Returns:
            (list of OOMDPObject)
        '''
        objects = []

        for attr_dict in list_of_attr_dicts:
            next_obj = OOMDPObject(attributes=attr_dict, name=name)
            objects.append(next_obj)

        return objects
示例#14
0
    def _create_state(self, panels, time):
        '''
        Args:
            panels (list): Contains attribute dictionaries for panel objects.
            time (datetime)

        Returns:
            (SolarOOMDPState)
        '''
        self.objects = {attr: [] for attr in SolarOOMDP.CLASSES}
        self.objects["panel"] = panels

        # Sun.
        sun_attributes = {}
        sun_angle_AZ = sh._compute_sun_azimuth(self.latitude_deg,
                                               self.longitude_deg, time)
        sun_angle_ALT = sh._compute_sun_altitude(self.latitude_deg,
                                                 self.longitude_deg, time)

        # Image stuff.
        if self.image_mode:
            # Grab image relative to first image for now.
            bounded_panel_angle_ew = max(min(panels[0]["angle_ew"], 90), -90)
            bounded_panel_angle_ns = max(min(panels[0]["angle_ns"], 90), -90)
            # Set attributes as pixels.
            image = self._create_sun_image(sun_angle_AZ, sun_angle_ALT,
                                           bounded_panel_angle_ns,
                                           bounded_panel_angle_ew)
            for i in range(self.img_dims):
                for j in range(self.img_dims):
                    idx = i * self.img_dims + j
                    sun_attributes['pix' + str(idx)] = image[i][j]
        else:
            sun_attributes["angle_AZ"] = sun_angle_AZ
            sun_attributes["angle_ALT"] = sun_angle_ALT

        sun = OOMDPObject(attributes=sun_attributes, name="sun")
        self.objects["sun"].append(sun)

        return SolarOOMDPState(self.objects,
                               date_time=time,
                               longitude=self.longitude_deg,
                               latitude=self.latitude_deg,
                               sun_angle_AZ=sun_angle_AZ,
                               sun_angle_ALT=sun_angle_ALT)
示例#15
0
    def __init__(self,
                 agent_color='red',
                 passenger_color='blue',
                 passenger_dest_color='green'):
        agent = {'current_color': agent_color, 'has_passenger': 0}
        passengers = [{
            'current_color': passenger_color,
            'dest_color': passenger_dest_color
        }]

        agent_obj = OOMDPObject(attributes=agent, name='agent')
        passenger_objs = self._make_oomdp_objs_from_list_of_dict(
            passengers, 'passenger')

        init_state = TaxiL1OOMDP._create_state(agent_obj, passenger_objs)

        self.goal_state = TaxiL1OOMDP.create_goal_state(passenger_dest_color)
        self.terminal_func = lambda state: state == self.goal_state

        OOMDP.__init__(self, TaxiL1OOMDP.ACTIONS, self._transition_func,
                       self._reward_func, init_state)
示例#16
0
    def _create_moved_panel(self, state, action, panel_index):
        panel_angle_ew = state.get_panel_angle_ew(panel_index=panel_index)
        panel_angle_ns = state.get_panel_angle_ns(panel_index=panel_index)

        # Compute new angles
        ew_step, ns_step = {"panel_forward_ew": (self.panel_step, 0),
                            "panel_forward_ns": (0, self.panel_step),
                            "panel_back_ew": (-self.panel_step, 0),
                            "panel_back_ns": (0, self.panel_step),
                            "do_nothing": (0, 0)}[action]
        new_panel_angle_ew, new_panel_angle_ns = panel_angle_ew + ew_step, panel_angle_ns + ns_step
        bounded_panel_angle_ew = max(min(new_panel_angle_ew, 70), -70)
        bounded_panel_angle_ns = max(min(new_panel_angle_ns, 70), -70)

        # Make panel object.
        panel_attributes = {}
        panel_attributes["angle_ew"] = bounded_panel_angle_ew
        panel_attributes["angle_ns"] = bounded_panel_angle_ns
        panel = OOMDPObject(attributes=panel_attributes, name="panel_" + str(panel_index))

        return panel
示例#17
0
    def _create_moved_panel(self, state, action, panel_index):
        '''
        Args;
            state (State)
            action (str)
            panel_index (int)

        Returns:
            (OOMDPObject): The panel object, moved according to @action.
        '''
        panel_angle_ew = state.get_panel_angle_ew(panel_index=panel_index)
        panel_angle_ns = state.get_panel_angle_ns(panel_index=panel_index)

        if "," in action:
            # Bandit action.
            ns_act, ew_act = action.split(",")
            bounded_panel_angle_ew = max(min(int(ew_act), 90), -90)
            bounded_panel_angle_ns = max(min(int(ns_act), 90), -90)
        else:
            # Compute new angles
            ew_step, ns_step = {
                "panel_forward_ew": (self.panel_step, 0),
                "panel_forward_ns": (0, self.panel_step),
                "panel_back_ew": (-self.panel_step, 0),
                "panel_back_ns": (0, -self.panel_step),
                "do_nothing": (0, 0)
            }[action]
            new_panel_angle_ew, new_panel_angle_ns = panel_angle_ew + ew_step, panel_angle_ns + ns_step
            bounded_panel_angle_ew = max(min(new_panel_angle_ew, 90), -90)
            bounded_panel_angle_ns = max(min(new_panel_angle_ns, 90), -90)

        # Make panel object.
        panel_attributes = {}
        panel_attributes["angle_ew"] = bounded_panel_angle_ew
        panel_attributes["angle_ns"] = bounded_panel_angle_ns
        panel = OOMDPObject(attributes=panel_attributes,
                            name="panel_" + str(panel_index))

        return panel
示例#18
0
    def __init__(self,
                 width,
                 height,
                 agent,
                 walls,
                 passengers,
                 tolls,
                 traffic,
                 fuel_stations,
                 slip_prob=0,
                 gamma=0.99,
                 step_cost=0,
                 weights=None,
                 env_code=None,
                 sample_rate=5):
        self.env_code = env_code
        self.height = height
        self.width = width
        if weights is not None:
            self.weights = weights
        else:
            # use true weighting over reward variables (on the goal with the passenger, on a toll, on a traffic cell)
            self.weights = np.array([[2, -0.4, -0.5]])

        # objects that belong in the state (changing)
        agent_obj = OOMDPObject(attributes=agent, name="agent")
        agent_exit = {"x": 100, "y": 100, "has_passenger": 0}
        pass_objs = self._make_oomdp_objs_from_list_of_dict(
            passengers, "passenger")
        pass_objs_exit = self._make_oomdp_objs_from_list_of_dict(
            passengers, "passenger")

        # objects that belong to the MDP (static)
        wall_objs = self._make_oomdp_objs_from_list_of_dict(walls, "wall")
        toll_objs = self._make_oomdp_objs_from_list_of_dict(tolls, "toll")
        traffic_objs = self._make_oomdp_objs_from_list_of_dict(
            traffic, "traffic")
        fuel_station_objs = self._make_oomdp_objs_from_list_of_dict(
            fuel_stations, "fuel_station")
        self.tolls = toll_objs
        self.traffic_cells = traffic_objs
        self.walls = wall_objs
        self.fuel_stations = fuel_station_objs
        self.slip_prob = slip_prob

        init_state = self._create_state(agent_obj, pass_objs)
        self.exit_state = self._create_state(
            OOMDPObject(attributes=agent_exit, name="agent_exit"),
            pass_objs_exit)
        self.exit_state.set_terminal(True)
        self.exit_state.set_goal(False)
        if init_state.track_fuel():
            OOMDP.__init__(self,
                           AugmentedTaxiOOMDP.AUGMENTED_ACTIONS,
                           self._taxi_transition_func,
                           self._taxi_reward_func,
                           init_state=init_state,
                           gamma=gamma,
                           step_cost=step_cost,
                           sample_rate=sample_rate)
        else:
            OOMDP.__init__(self,
                           AugmentedTaxiOOMDP.BASE_ACTIONS,
                           self._taxi_transition_func,
                           self._taxi_reward_func,
                           init_state=init_state,
                           gamma=gamma,
                           step_cost=step_cost,
                           sample_rate=sample_rate)