Esempio n. 1
0
    def _reward_func(self, state, action):
        '''
        Args:
            state (OOMDP State)
            action (str)

        Returns
            (float)
        '''

        # Both altitude_deg and azimuth_deg are in degrees.
        sun_altitude_deg = sh._compute_sun_altitude(self.latitude_deg, self.longitude_deg, self.time)
        sun_azimuth_deg = sh._compute_sun_azimuth(self.latitude_deg, self.longitude_deg, self.time)

        # Panel stuff
        panel_ns_deg = state.get_panel_angle_ew()
        panel_ew_deg = state.get_panel_angle_ns()

        if action is "optimal":
            # Compute optimal reward.
            reward = self._compute_optimal_reward(sun_altitude_deg, sun_azimuth_deg)

        else:
            flux = self._compute_flux(sun_altitude_deg, sun_azimuth_deg, panel_ns_deg, panel_ew_deg)
            
            # Compute electrical power output of panel for given flux.
            power = self.panel.get_power(flux)

            # Convert timestep to seconds.
            energy = power*self.timestep*60 # Joules
            cost = 0 # in Joules

            #print panel_ew_deg, panel_ns_deg

            # Get cost of motion.
            if "ew" in action:
                cost = self.panel.get_rotation_energy_for_axis('ew', np.radians(panel_ew_deg), np.radians(self.panel_step))
            elif "ns" in action:
                cost = self.panel.get_rotation_energy_for_axis('ns', np.radians(panel_ns_deg), np.radians(self.panel_step))


            #print "energy: {} cost:{} ".format(energy, cost)
            #print "cost: {}".format(cost)

            reward = energy - cost

            # print reward, energy, cost, action

        return (reward) / 1000000.0 # Convert Watts to Megawatts
Esempio n. 2
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)
Esempio n. 3
0
    def _reward_func(self, state, action):
        '''
        Args:
            state (OOMDP State)
            action (str)

        Returns
            (float)
        '''

        # Both altitude_deg and azimuth_deg are in degrees.
        sun_altitude_deg = sh._compute_sun_altitude(self.latitude_deg, self.longitude_deg, self.get_local_time())
        sun_azimuth_deg = sh._compute_sun_azimuth(self.latitude_deg, self.longitude_deg, self.get_local_time())

        # Panel stuff
        panel_ew_deg = state.get_panel_angle_ew()
        panel_ns_deg = state.get_panel_angle_ns()

        if action is "optimal":
            # Compute optimal reward.
            flux = self._compute_optimal_reward(sun_altitude_deg, sun_azimuth_deg)
            # Compute electrical power output of panel for given flux.
            power = self.panel.get_power(flux)

            # Convert timestep to seconds.
            reward = power * self.timestep * 60 # Joules

        else:
            if "energy" in self.name_ext:
                flux, r_d, r_f, r_r = self._compute_flux(sun_altitude_deg, sun_azimuth_deg, panel_ns_deg, panel_ew_deg, breakdown=True)
            
                p_d, p_f, p_r = self.panel.get_power(r_d), self.panel.get_power(r_f), self.panel.get_power(r_r)
                e_d, e_f, e_r = p_d * self.timestep * 60, p_f * self.timestep * 60, p_r * self.timestep * 60
            else:
                flux = self._compute_flux(sun_altitude_deg, sun_azimuth_deg, panel_ns_deg, panel_ew_deg)

            # Compute electrical power output of panel for given flux.
            power = self.panel.get_power(flux)

            # Convert timestep to seconds.
            energy = power * self.timestep * 60 # Joules
            cost = 0 # in Joules

            # Get cost of motion.
            if "ew" in action:
                cost = self.panel.get_rotation_energy_for_axis('ew', np.radians(panel_ew_deg), np.radians(self.panel_step))
            elif "ns" in action:
                cost = self.panel.get_rotation_energy_for_axis('ns', np.radians(panel_ns_deg), np.radians(self.panel_step))

            reward = energy - cost

            # sh._write_datum_to_file(str(self), agent, r_d, "direct")
            # sh._write_datum_to_file(str(self), agent, r_f, "diffuse")
            # sh._write_datum_to_file(str(self), agent, r_r, "reflective")

        reward = (reward) / 1000000.0 # Convert Watts to Megawatts

        if "energy" in self.name_ext:
            e_d, e_f, e_r = e_d / 1000000.0, e_f / 1000000.0, e_r / 1000000.0
            return reward, e_d, e_f, e_r

        return reward