def greedy_hueristics(filepath, comp_filename, load_file_name, start_range, contingency_range, blackout_criterion, system_name, p_budget, s_budget, sub_name, protected_substation): import time import maptest_testing import maptest_testing_subs import static_attack_subs_support # import maptest_testing_trimmed import trimmed_list tot_exe_time_start = time.time() temp_max_loadloss = 0 worst_case_outage = [] worst_case_sub = [] loadloss_gain = 0 for sub_budget in range(0, s_budget): if (worst_case_sub == []): subs_config_dict = maptest_testing.maptest14bus_test_system( comp_filename, start_range, contingency_range, sub_name, protected_substation) else: subs_config_dict = trimmed_list.maptest14bus_test_system( comp_filename, start_range, contingency_range, worst_case_sub, sub_name, protected_substation) subs_config_dict_keys = subs_config_dict.keys() for i in range(0, len(subs_config_dict)): # print subs_config_dict_keys[i]; temp_comp_list = subs_config_dict[subs_config_dict_keys[i]] # print temp_comp_list temp_subs_elements = maptest_testing_subs.maptest14bus_test_system( temp_comp_list, start_range, contingency_range) max_load_loss_outage, max_loadloss = static_attack_subs_support.greedy_hueristics( filepath, temp_subs_elements, load_file_name, start_range, contingency_range, blackout_criterion, system_name, p_budget) if (max_loadloss > temp_max_loadloss): temp_max_loadloss = max_loadloss worst_case_outage = max_load_loss_outage worst_case_sub = subs_config_dict_keys[i] if sub_budget == 0: worst_case_sub = tuple([worst_case_sub]) else: worst_case_sub = worst_case_sub # print worst_case_sub; if ((loadloss_gain - temp_max_loadloss) == 0): break else: loadloss_gain = temp_max_loadloss tot_exe_time_end = time.time() tot_exe_time = (tot_exe_time_end - tot_exe_time_start) print '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@' print 'Worst case outage: %s' % worst_case_outage print 'Worst case loadloss: %s' % temp_max_loadloss print 'Worst case substation: {0}'.format(worst_case_sub) print 'Total execution time in seconds: %s' % tot_exe_time print '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@' return worst_case_outage, temp_max_loadloss, worst_case_sub
def greedy_hueristics(filepath, comp_filename, load_file_name, start_range, contingency_range, blackout_criterion, system_name, p_budget): import cascade_algorithm import maptest_new_outage_list import cascade_algorithm_reduced_outages import time import maptest_testing import maptest_testing_subs import static_attack_subs_support # tot_exe_time_start = time.time() temp_max_loadloss = 0 worst_case_outage = [] worst_case_sub = [] budget = 0 # max_loadloss = 0; subs_config_dict = maptest_testing.maptest14bus_test_system( comp_filename, start_range, contingency_range) # print subs_config_dict # print len(subs_config_dict) # temp_comp_list = subs_config_dict['S9'] # print temp_comp_list # temp_subs_elements = maptest_testing_subs.maptest14bus_test_system(temp_comp_list, start_range, contingency_range); # print temp_subs_elements subs_config_dict_keys = subs_config_dict.keys() for i in range(0, len(subs_config_dict)): print subs_config_dict_keys[i] temp_comp_list = subs_config_dict[subs_config_dict_keys[i]] print temp_comp_list # if (len(temp_comp_list) <= p_budget): # budget = len(temp_comp_list); # else: # budget = p_budget; temp_subs_elements = maptest_testing_subs.maptest14bus_test_system( temp_comp_list, start_range, contingency_range) max_load_loss_outage, max_loadloss = static_attack_subs_support.greedy_hueristics( filepath, temp_subs_elements, load_file_name, start_range, contingency_range, blackout_criterion, system_name, p_budget) if (max_loadloss > temp_max_loadloss): temp_max_loadloss = max_loadloss worst_case_outage = max_load_loss_outage worst_case_sub = subs_config_dict_keys[i] print '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@' print 'Worst case outage: %s' % worst_case_outage print 'Worst case loadloss: %s' % temp_max_loadloss print 'Worst case substation: %s' % worst_case_sub # print 'Total execution time in seconds: %s' %tot_exe_time print '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@'
def greedy_hueristics(filepath, comp_filename, load_file_name, start_range, contingency_range, blackout_criterion, system_name, p_budget, s_budget, sub_name): # Importing necessary method and libraries import time import maptest_testing_defense_substations1_v1_support import maptest_testing_subs import static_attack_subs_support import trimmed_list_defense_substations1_v1_support tot_exe_time_start = time.time() # Initializing method variables temp_max_loadloss = 0 worst_case_outage = [] worst_case_sub = [] loadloss_gain = 0 # Identifying the worst case attack depending upon the budget constraints for sub_budget in range(0, s_budget): # Sending the entire attack space if nothing is attacked if (worst_case_sub == []): subs_config_dict = maptest_testing_defense_substations1_v1_support.maptest14bus_test_system( comp_filename, start_range, contingency_range, sub_name) else: # generating a new attack space if certain points are already attacked in the system subs_config_dict = trimmed_list_defense_substations1_v1_support.maptest14bus_test_system( comp_filename, start_range, contingency_range, worst_case_sub, sub_name) subs_config_dict_keys = subs_config_dict.keys() # Checking which points gives the maximum damage for i in range(0, len(subs_config_dict)): temp_comp_list = subs_config_dict[subs_config_dict_keys[i]] temp_subs_elements = maptest_testing_subs.maptest14bus_test_system( temp_comp_list, start_range, contingency_range) max_load_loss_outage, max_loadloss = static_attack_subs_support.greedy_hueristics( filepath, temp_subs_elements, load_file_name, start_range, contingency_range, blackout_criterion, system_name, p_budget) # Updates the solution with the maximum damage point if (max_loadloss > temp_max_loadloss): temp_max_loadloss = max_loadloss worst_case_outage = max_load_loss_outage worst_case_sub = subs_config_dict_keys[i] if sub_budget == 0: worst_case_sub = tuple([worst_case_sub]) else: worst_case_sub = worst_case_sub # If no improvent in damage is observed for 2 consecutive iterations then algorithm is terminated if ((loadloss_gain - temp_max_loadloss) == 0): break else: loadloss_gain = temp_max_loadloss tot_exe_time_end = time.time() tot_exe_time = (tot_exe_time_end - tot_exe_time_start) # Outputing the details on the console print '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@' print 'Worst case outage: %s' % worst_case_outage print 'Worst case loadloss: %s' % temp_max_loadloss print 'Worst case substation: {0}'.format(worst_case_sub) print 'Total execution time in seconds: %s' % tot_exe_time print '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@' return worst_case_outage, worst_case_sub, temp_max_loadloss
def greedy_hueristics(filepath, comp_filename, load_file_name, start_range, contingency_range, blackout_criterion, system_name, p_budget, s_budget): # ----------------------------------------------------------------------------------------------------------------------------------- # Importing supporting methods # ----------------------------------------------------------------------------------------------------------------------------------- import time import maptest_testing import maptest_testing_subs import static_attack_subs_support # import maptest_testing_trimmed import trimmed_list # ----------------------------------------------------------------------------------------------------------------------------------- # Initializing the method variables # ----------------------------------------------------------------------------------------------------------------------------------- tot_exe_time_start = time.time() # Starting the timer temp_max_loadloss = 0; worst_case_outage = []; worst_case_sub = []; loadloss_gain = 0; # ----------------------------------------------------------------------------------------------------------------------------------- for sub_budget in range(0, s_budget): # This loop runs for the value of s_budget and identifies the substations that maximizes the system damage # ----------------------------------------------------------------------------------------------------------------------------------- # Attack Space generation # ----------------------------------------------------------------------------------------------------------------------------------- if (worst_case_sub == []): subs_config_dict = maptest_testing.maptest14bus_test_system(comp_filename, start_range, contingency_range); # Depending upon the value of worst_case_sub, appropriate method is called. The inputs to both these methods maptest_testing, else: # trimmed_list are the comp_filename. Both of them returns a dictionary with substations as the keys and transmission lines subs_config_dict = trimmed_list.maptest14bus_test_system(comp_filename, start_range, contingency_range, worst_case_sub); # associated with the respective protection assemblies as values which are then further used as attack points. subs_config_dict_keys = subs_config_dict.keys(); # ----------------------------------------------------------------------------------------------------------------------------------- # Finding the maximum load loss causing trasmission lines/protection assemblies # ----------------------------------------------------------------------------------------------------------------------------------- for i in range (0, len(subs_config_dict)): print subs_config_dict_keys[i]; temp_comp_list = subs_config_dict[subs_config_dict_keys[i]]; # Identifies the transmission lines that are present in the respective substations print temp_comp_list temp_subs_elements = maptest_testing_subs.maptest14bus_test_system(temp_comp_list, start_range, contingency_range); # Converts temp_comp_list into the required input format for the static_attack_subs_support method using maptest_testing_subs max_load_loss_outage, max_loadloss = static_attack_subs_support.greedy_hueristics(filepath, temp_subs_elements, load_file_name, start_range, contingency_range, blackout_criterion, system_name, p_budget); # Calls the method static_attack_subs_support for computing the worst case load loss caused by the transmission lines/protection assemblies # ----------------------------------------------------------------------------------------------------------------------------------- # Updating the solution # ----------------------------------------------------------------------------------------------------------------------------------- # as per the budget constraints. The method returns the maximum load loss max_loadloss and corresponding transmission line max_load_loss_outage. if (max_loadloss > temp_max_loadloss): # Checks if the current system damage is more than any previous damage temp_max_loadloss = max_loadloss; # Updates load loss/damage worst_case_outage = max_load_loss_outage; # Updates transmission line worst_case_sub = subs_config_dict_keys[i]; # Updates Substations if sub_budget == 0: worst_case_sub = tuple([worst_case_sub]); else: worst_case_sub = worst_case_sub; # print worst_case_sub; if ((loadloss_gain - temp_max_loadloss) == 0): # Checks if there is a change in the solution for consecutive iterations. If not, the algorithm is terminated break; else: loadloss_gain = temp_max_loadloss; # Updates the change in damage tot_exe_time_end = time.time() # Stopping the timer tot_exe_time = (tot_exe_time_end - tot_exe_time_start) # Computes the actual run time of the algorithm # ----------------------------------------------------------------------------------------------------------------------------------- # Prints the outputs on the console # ----------------------------------------------------------------------------------------------------------------------------------- print '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@' print 'Worst case outage: %s' %worst_case_outage print 'Worst case loadloss: %s' %temp_max_loadloss print 'Worst case substation: {0}'.format(worst_case_sub) print 'Total execution time in seconds: %s' %tot_exe_time print '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@'
def greedy_hueristics(filepath, comp_filename, load_file_name, start_range, contingency_range, blackout_criterion, system_name, p_budget, s_budget): # Importing the supporitng methods and initializing the method variables import time import maptest_testing_subs_v2 import maptest_testing_subs import static_attack_subs_support import trimmed_list_subs_v2 tot_exe_time_start = time.time() temp_max_loadloss = 0 worst_case_outage = [] worst_case_sub = [] loadloss_gain = 0 # Running the attack identification method to identify the worst case attack using susbtation config. for sub_budget in range(0, s_budget): if (worst_case_sub == []): # Identifies the entire attack space subs_config_dict = maptest_testing_subs_v2.maptest14bus_test_system( comp_filename, start_range, contingency_range) else: # Itentifies the updated attack surface subs_config_dict = trimmed_list_subs_v2.maptest14bus_test_system( comp_filename, start_range, contingency_range, worst_case_sub) subs_config_dict_keys = subs_config_dict.keys() # Identify the components in the respective susbtations that maximize the system damage as per the budget constraints for i in range(0, len(subs_config_dict)): print subs_config_dict_keys[i] temp_comp_list = subs_config_dict[subs_config_dict_keys[i]] print temp_comp_list temp_subs_elements = maptest_testing_subs.maptest14bus_test_system( temp_comp_list, start_range, contingency_range) max_load_loss_outage, max_loadloss = static_attack_subs_support.greedy_hueristics( filepath, temp_subs_elements, load_file_name, start_range, contingency_range, blackout_criterion, system_name, p_budget) # Updates the solution if damage is maximized if (max_loadloss > temp_max_loadloss): temp_max_loadloss = max_loadloss worst_case_outage = max_load_loss_outage worst_case_sub = subs_config_dict_keys[i] if sub_budget == 0: worst_case_sub = tuple([worst_case_sub]) else: worst_case_sub = worst_case_sub # Terminates the algortihm when no further improvement is observed if ((loadloss_gain - temp_max_loadloss) == 0): break else: loadloss_gain = temp_max_loadloss tot_exe_time_end = time.time() tot_exe_time = (tot_exe_time_end - tot_exe_time_start) # Prints on the console print '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@' print 'Worst case outage: %s' % worst_case_outage print 'Worst case loadloss: %s' % temp_max_loadloss print 'Worst case substation: {0}'.format(worst_case_sub) print 'Total execution time in seconds: %s' % tot_exe_time print '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@' return worst_case_outage, temp_max_loadloss, worst_case_sub