def __init__(self,
                 validation,
                 test_days,
                 sampling_type=None):  ## sampling_type can be 'prob' or 'max'
        ur = probabilistic_rewards.uncertain_rewards(test_days)
        task_prob, self.prob, self.clusters = ur.get_probabilistic_reward_model(
        )
        self.time_int = 48
        self.int_duration = 1440 / self.time_int
        if validation == True:
            self.test_days = ur.test_days
            self.test_tasks = ur.test_tasks
            self.no_days = len(self.test_days)

            ### expected data
            # self.test_rewards = []
            # with open('/home/milan/workspace/strands_ws/src/battery_scheduler/data/exp_rewards', 'r') as f:
            #     for rew in f:
            #         self.test_rewards.append(float(rew[:-1]))

        else:
            self.no_days = 1  # no. of days to be tested, if not using validation

        self.rewards, self.cl_ids, self.act_rewards = self.get_samples(
            validation, sampling_type)
Ejemplo n.º 2
0
    def __init__(self, init_battery, init_charging, test_days, pareto_point):
        ur = probabilistic_rewards.uncertain_rewards(test_days)
        self.task_prob, self.prob, self.clusters = ur.get_probabilistic_reward_model(
        )
        self.charge_model, self.discharge_model, self.gocharge_model = get_battery_model(
        )
        self.cl_id = []
        self.sample_reward = []
        self.actual_reward = []
        self.exp_reward = []
        self.no_int = ur.no_int
        self.no_days = len(ur.test_days)
        self.horizon = 48  ## in terms of intervals
        self.no_simulations = 1
        for z in range(self.no_int * self.no_days):
            self.exp_reward.append(
                sum(self.prob[z % self.no_int] * self.clusters))
            print self.prob[z % self.no_int], self.clusters, sum(
                self.prob[z % self.no_int] * self.clusters)
        self.req_pareto_point = pareto_point

        self.main_path = roslib.packages.get_pkg_dir('battery_scheduler')
        self.path_mod = self.main_path + '/models/'
        self.path_data = self.main_path + '/data/'

        sg = generate_samples.sample_generator(True, test_days)
        self.cl_id = []
        for clid in sg.cl_ids:
            if np.isnan(clid):
                cl = None
            else:
                cl = int(clid)
            self.cl_id.append(cl)
        self.sample_reward = sg.rewards
        self.actual_reward = sg.act_rewards

        self.totalreward = np.zeros((self.no_days))
        self.init_battery = init_battery
        self.init_charging = init_charging
        self.actions = []
        self.obtained_rewards = []
        self.battery = []
        self.charging = []
        self.time = []
        self.pareto_point = []

        self.simulate()
Ejemplo n.º 3
0
    def __init__(self, init_battery, init_charging, test_days, pareto_point):
        ur = probabilistic_rewards.uncertain_rewards(test_days)
        self.task_prob, self.prob, self.clusters = ur.get_probabilistic_reward_model(
        )
        self.charge_model, self.discharge_model = get_battery_model()
        self.cl_id = []
        self.sample_reward = []
        self.actual_reward = []
        self.exp_reward = []
        self.no_int = ur.no_int
        self.no_days = len(ur.test_days)
        self.horizon = 48  ## in terms of intervals
        self.no_simulations = 1
        for z in range(self.no_int * self.no_days):
            self.exp_reward.append(
                sum(self.prob[z % self.no_int] * self.clusters))
        self.req_pareto_point = pareto_point

        self.main_path = roslib.packages.get_pkg_dir('battery_scheduler')
        self.path_rew = self.main_path + '/data/rhc2_sample_rewards'
        self.path_mod = self.main_path + '/models/'
        self.path_data = self.main_path + '/data/'

        if not os.path.isfile(self.path_rew):
            raise ValueError(
                'Sample Rewards Not Generated. Generate rewards with generate_samples.py'
            )

        with open(self.path_rew, 'r') as f:
            for line in f:
                x = line.split(' ')
                self.cl_id.append(int(float(x[0].strip())))
                self.sample_reward.append(float(x[1].strip()))
                self.actual_reward.append(float(x[2].strip()))

        self.totalreward = np.zeros((self.no_days))
        self.init_battery = init_battery
        self.init_charging = init_charging
        self.actions = []
        self.obtained_rewards = []
        self.battery = []
        self.charging = []
        self.time = []
        self.pareto_point = []
Ejemplo n.º 4
0
    def __init__(self, init_battery, init_charging, test_days, plan_id):
        ur = probabilistic_rewards.uncertain_rewards(test_days)
        self.task_prob, self.prob, self.clusters = ur.get_probabilistic_reward_model(
        )
        self.charge_model, self.discharge_model = get_battery_model()
        self.cl_id = []
        self.sample_reward = []
        self.actual_reward = []
        self.exp_reward = []
        self.no_int = ur.no_int
        self.no_days = len(ur.test_days)
        self.no_simulations = 1
        for z in range(self.no_int * self.no_days):
            self.exp_reward.append(
                sum(self.prob[z % self.no_int] * self.clusters))

        #######################SPECIFY LOCATION ######################
        self.main_path = '/home/milan/workspace/strands_ws/src/battery_scheduler'
        self.path_rew = self.main_path + '/data/bcth_pareto_sample_rewards'
        self.path_mod = self.main_path + '/models/'
        self.path_data = self.main_path + '/data/'

        if not os.path.isfile(self.path_rew):
            raise ValueError(
                'Sample Rewards Not Generated. Generate rewards with generate_samples.py'
            )

        with open(self.path_rew, 'r') as f:
            for line in f:
                x = line.split(' ')
                self.cl_id.append(int(float(x[0].strip())))
                self.sample_reward.append(float(x[1].strip()))
                self.actual_reward.append(float(x[2].strip()))

        self.avg_totalreward = np.zeros((self.no_days))
        self.init_battery = init_battery
        self.init_charging = init_charging
        self.actions = []
        self.obtained_rewards = []
        self.battery = []
        self.charging = []
        self.time = []
        self.plan_id = plan_id
Ejemplo n.º 5
0
    def __init__(self, init_battery, init_charging, test_days):
        self.current_battery = init_battery
        self.current_charging = init_charging
        self.charge_model, self.discharge_model = get_battery_model()
        ur = probabilistic_rewards.uncertain_rewards(test_days)
        self.task_prob, prob, clusters = ur.get_probabilistic_reward_model()
        self.threshold = np.mean(clusters)
        # self.threshold = 8000

        self.test_rewards = []
        with open(
                roslib.packages.get_pkg_dir('battery_scheduler') +
                '/data/rbc4_sample_rewards', 'r') as f:
            for line in f:
                self.test_rewards.append(float(line.split(' ')[2].strip()))

        self.battery = []
        self.charging = []
        self.action = []
        self.obtained_reward = []
        self.time = []
Ejemplo n.º 6
0
    def get_rewards_from_plan(self, fname):
        print 'Reading Plan...'
        file_name = roslib.packages.get_pkg_dir(
            'battery_scheduler') + '/data/' + fname
        rewards_obtained = []
        with open(file_name, 'r') as f:
            for line in f:
                if 'time' not in line:
                    s = line.split(' ')
                    rewards_obtained.append(float(s[4]))
        return rewards_obtained


if __name__ == '__main__':

    pr = probabilistic_rewards.uncertain_rewards([])
    probt, probm, rew_cl = pr.get_probabilistic_reward_model()
    threshold = np.mean(rew_cl)

    rbc3 = RuleBasedControl(70, 1, [
        datetime(2017, 10, 10),
        datetime(2017, 10, 11),
        datetime(2017, 10, 12)
    ], threshold)
    rbc3.get_plan('rbc3_101011101210_1')

    np.random.seed(1)
    rbc3 = RuleBasedControl(70, 1, [
        datetime(2017, 10, 10),
        datetime(2017, 10, 11),
        datetime(2017, 10, 12)