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() sg = generate_samples.sample_generator(True, test_days) self.test_rewards = sg.act_rewards self.battery = [] self.charging = [] self.action = [] self.obtained_reward = [] self.time = [] self.simulate()
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()
with open(self.path_data + fname, 'w') as f: f.write('Pareto Point: {0}\n'.format(pareto_point)) f.write( 'time battery charging action obtained_reward match_reward actual_reward exp_reward\n' ) for t, b, ch, a, obr, mr, ar, er in zip( self.time, self.battery, self.charging, self.actions, self.obtained_rewards, self.sample_reward, self.actual_reward, self.exp_reward): f.write('{0} {1} {2} {3} {4} {5} {6} {7}\n'.format( t, b, ch, a, obr, mr, ar, er)) if __name__ == '__main__': sg = generate_samples.sample_generator(True, [date(2017, 10, 1)]) rewards = sg.rewards cl_id = sg.cl_ids act_rewards = sg.act_rewards # exp_rewards = sg.exp_rewards #path = roslib.packages.get_pkg_dir('battery_scheduler') + '/data/sample_rewards' path = '/home/milan/workspace/strands_ws/src/battery_scheduler/data/bcth_pareto_sample_rewards' with open(path, 'w') as f: for r, c, a_r in zip(rewards, cl_id, act_rewards): #, exp_rewards): f.write('{0} {1} {2} '.format(c, r, a_r)) f.write('\n') np.random.seed(0) fhc = FiniteHorizonControl(70, 1, [date(2017, 10, 1)], 'oct1') fhc.simulate(1)
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__': no_int = 48 sg = generate_samples.sample_generator( True, [date(2017, 11, 10), date(2017, 10, 19), date(2017, 9, 28)]) rewards = sg.rewards cl_id = sg.cl_ids act_rewards = sg.act_rewards path = roslib.packages.get_pkg_dir( 'battery_scheduler') + '/data/rbc2_sample_rewards' with open(path, 'w') as f: for r, c, a_r in zip(rewards, cl_id, act_rewards): f.write('{0} {1} {2} '.format(c, r, a_r)) f.write('\n') np.random.seed(0) f_name = 'rbc2_10111910289_70b_1' rbc2 = RuleBasedControl(70, 1)