<jupyter_start><jupyter_text>Todo 1. add the pyga to the main python code 2. read failure link3. convert ga solution to the failure link index for aug value<jupyter_code>import numpy as np
from geneticalgorithm import geneticalgorithm as ga
import subprocess
np.__version__
# import numpy as np
# from geneticalgorithm import geneticalgorithm as ga
# import subprocess
# program='c:/GitCodes/LinJuanJuan/x64/Release/NetworkResilience.exe'
# aug = "15 2 8 12 7"
# excute = program + " " + aug
# print(excute)
# p = subprocess.Popen(excute,
#                      shell=True,
#                      stdout=subprocess.PIPE,
#                      stderr=subprocess.STDOUT,
#                      close_fds=True,
#                      encoding='utf-8')
# strval = p.communicate()[0]
# # print(p.communicate()[0])
# print (strval)
# sv = strval.split(sep='\n')
# print("final")
# print("size = {0}".format(len(sv)))
# print(sv[-1])<jupyter_output><empty_output><jupyter_text>the code is create to use ga package to solve the problem<jupyter_code>def f(X):
    dp = {}
    for i in range(0,len(X)):
        key =str(i)
        dp[key] = X[i]
    print("------------")
    sd = sorted(dp.items(),key=lambda d:d[1])
    print(sd)
    print("------------")
    # print the sol in file
    aug = ""
    for e in range(0,len(sd)-1):
        aug = aug + str(sd[e][0])+" "
    aug = aug + str(sd[-1][0])
    aug = "15 2 8 12 7"
    program='c:/GitCodes/LinJuanJuan/x64/Release/NetworkResilience.exe'
    # print(aug)
    excute = program + " " + aug
    print(excute)
    p = subprocess.Popen(excute,
                     shell=True,
                     stdout=subprocess.PIPE,
                     stderr=subprocess.STDOUT,
                     close_fds=True,
                     encoding='utf-8')
    # print(float(p.communicate()[0]))
    strval = p.communicate()[0]
    sv = strval.split(sep='\n')
    print(sv[-1])
    # input()
    res = float(sv[-1])
    # print(res)
    # return np.sum(X)
    return res
NumOfLinks = 5
varbound=np.array([[0,1]]*NumOfLinks)
#TODO: Read number of failure links

algorithm_param = {'max_num_iteration': 2,\
                   'population_size':4,\
                   'mutation_probability':0.1,\
                   'elit_ratio': 0.01,\
                   'crossover_probability': 0.5,\
                   'parents_portion': 0.3,\
                   'crossover_type':'uniform',\
                   'max_iteration_without_improv':None,
                   'random_seed':1}

model=ga(function=f,\
            dimension=NumOfLinks,\
            variable_type='real',\
            variable_boundaries=varbound,\
            algorithm_parameters=algorithm_param)

model.run()
algorithm_param = {'max_num_iteration': 2,\
                   'population_size':4,\
                   'mutation_probability':0.1,\
                   'elit_ratio': 0.01,\
                   'crossover_probability': 0.5,\
                   'parents_portion': 0.3,\
                   'crossover_type':'uniform',\
                   'max_iteration_without_improv':None,
                   'random_seed':10}

model=ga(function=f,\
            dimension=NumOfLinks,\
            variable_type='real',\
            variable_boundaries=varbound,\
            algorithm_parameters=algorithm_param)

model.run()
algorithm_param = {'max_num_iteration': 2,\
                   'population_size':4,\
                   'mutation_probability':0.1,\
                   'elit_ratio': 0.01,\
                   'crossover_probability': 0.5,\
                   'parents_portion': 0.3,\
                   'crossover_type':'uniform',\
                   'max_iteration_without_improv':None,
                   'random_seed':1}

model=ga(function=f,\
            dimension=NumOfLinks,\
            variable_type='real',\
            variable_boundaries=varbound,\
            algorithm_parameters=algorithm_param)

model.run()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13647894469812277, 'fraction_numerical': 0.0197869101978691, 'mean_word_length': 1.9447348767737118, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '594441', 'license': 'MIT', 'n_tokens_mistral': 1305, 'n_tokens_neox': 1205, 'n_words': 223, 'path': 'Script/pyGa.ipynb', 'repo_name': 'hkujy/LinJuanJuan', 'size': '3942'}