Package: pyIpnHeuristic
PyIpnHeuristicpyIpnHeuristic is a pure Python implementation of some heuristic algorithms for the National
Polytechnic Institute of Mexico. For more information on pyIpnHeuristic, visit the GitHub project pagepyIpnHeuristicPip Installpip install pyIpnHeuristicBenchmarkBenchmark problems were taken fromLiang et al. 2006.
Check out the benchmarkdocfor a deatiled description.Import benchmark problems as follows:# Import the benchmark problem methods# get_pg01, get_pg02, get_pg03, get_pg04, get_pg05,# get_pg06, get_pg07, get_pg08, get_pg09, get_pg10,# get_pg11, get_pg12, get_pg13, get_pg14, get_pg15,# get_pg16, get_pg17, get_pg18, get_pg19, get_pg20,# get_pg21, get_pg22, get_pg23, get_pg24frompyIpnHeuristic.benchmarkimportget_pg01# get_pg[*problem]() returns problem parameters as:#    {#        objective_function": <class 'function'>,#        "gx": [<class 'function'>, <class 'function'>, ...], # Soft Restrictions#        "hx": [<class 'function'>, <class 'function'>, ...], # Hard Restrictions#        "ranges": [[inf(x1), sup(x1)], ..., [inf(xd), sup(xd)]], # List of Ranges for each variable#        "markdown": "PROBLEM X", # Markdown Problem description#        "x": x_best, # Best values#        "fx": fx_best # Best solution value#    }problem=get_pg01()objective_function=problem.get("objective_function")gx=problem.get("gx")hx=problem.get("hx")ranges=problem.get("ranges")markdown=problem.get("markdown")x_best=problem.get("x")fx_best=problem.get("fx")Released AlgorithmsHarmony SearchfrompyIpnHeuristic.harmonySearchimportHarmonySearchharmonySearch=HarmonySearch(objective_function,# e.g, def f(*x): return x[0]**2 + x[1] **2soft_constrains=g,# e.g, [def g(*x): return x[0], def g(*x): return x[0]**2]hard_constrains=h,# e.g, [def h(*x): return x[1], def h(*x): return x[1]**2]ranges=ranges,# e.g, [[0, 1], [0, 1]]population_size=population_size,# e.g, 4smooth=False,# If True, hard restrictions will be treated as soft restrictionsepsilon=10**-4,# If smmooth is True, then h(x) = 0 --> |h(x)| - epsilon <= 0# Harmony Search Parametershcmr=hcmr,par=par,alpha=alpha)harmonySearch.search(iterations=T,# Number of iterations to be madesave_history=True# Save the results for each iteration. Default False)Modified Harmony SearchfrompyIpnHeuristic.modifiedHarmonySearchimportModifiedHarmonySearchharmonySearch=ModifiedHarmonySearch(objective_function,# e.g, def f(*x): return x[0]**2 + x[1] **2soft_constrains=g,# e.g, [def g(*x): return x[0], def g(*x): return x[0]**2]hard_constrains=h,# e.g, [def h(*x): return x[1], def h(*x): return x[1]**2]ranges=ranges,# e.g, [[0, 1], [0, 1]]population_size=population_size,# e.g, 4smooth=False,# If True, hard restrictions will be treated as soft restrictionsepsilon=10**-4,# If smmooth is True, then h(x) = 0 --> |h(x)| - epsilon <= 0# Harmony Search Parametershcmr=hcmr,par=par,alpha=alpha)harmonySearch.search(iterations=T,# Number of iterations to be madesave_history=True# Save the results for each iteration. Default False)Differential Evolution:DE/rand/1/ binDE/best/1DE/current-to-best/1DE/best/2DE/rand/2frompyIpnHeuristic.differentialEvolutionimportDifferentialEvolutiondifferentialEvolution=DifferentialEvolution(objective_function,# e.g, def f(*x): return x[0]**2 + x[1] **2soft_constrains=g,# e.g, [def g(*x): return x[0], def g(*x): return x[0]**2]hard_constrains=h,# e.g, [def h(*x): return x[1], def h(*x): return x[1]**2]ranges=ranges,# e.g, [[0, 1], [0, 1]]population_size=population_size,# e.g, 4smooth=False,# If True, hard restrictions will be treated as soft restrictionsepsilon=10**-4,# If smooth is True, then h(x) = 0 --> |h(x)| - epsilon <= 0# Differential Evolution Parameterstype=de_type,# Types: "rand-1", "best-1", "current-to-best-1", "best-2, "rand-2", default: "rand-1"f=0.9,cr=0.05,)differentialEvolution.search(iterations=T,# Number of iterations to be madesave_history=True# Save the results for each iteration. Default False)Particle Swarm OptimizationfrompyIpnHeuristic.particleSwarmOptimizationimportParticleSwarmOptimizationparticleSwarmOptimization=ParticleSwarmOptimization(objective_function,# e.g, def f(*x): return x[0]**2 + x[1] **2soft_constrains=g,# e.g, [def g(*x): return x[0], def g(*x): return x[0]**2]hard_constrains=h,# e.g, [def h(*x): return x[1], def h(*x): return x[1]**2]ranges=ranges,# e.g, [[0, 1], [0, 1]]population_size=population_size,# e.g, 4smooth=False,# If True, hard restrictions will be treated as soft restrictionsepsilon=10**-4,# If smmooth is True, then h(x) = 0 --> |h(x)| - epsilon <= 0# Particle Swarm Parametersw=0.3,c1=0.1,c2=1.9)particleSwarmOptimization.search(iterations=T,# Number of iterations to be madesave_history=True# Save the results for each iteration. Default False)Artificial Bee ColonyfrompyIpnHeuristic.artificialBeeColonyimportArtificialBeeColonyartificialBeeColony=ArtificialBeeColony(objective_function,# e.g, def f(*x): return x[0]**2 + x[1] **2soft_constrains=g,# e.g, [def g(*x): return x[0], def g(*x): return x[0]**2]hard_constrains=h,# e.g, [def h(*x): return x[1], def h(*x): return x[1]**2]ranges=ranges,# e.g, [[0, 1], [0, 1]]population_size=population_size,# e.g, 4smooth=False,# If True, hard restrictions will be treated as soft restrictionsepsilon=10**-4,# If smmooth is True, then h(x) = 0 --> |h(x)| - epsilon <= 0# Artificial Bee Colony Parametersmr=0.3,max_trials=3,)artificialBeeColony.search(iterations=T,# Number of iterations to be madesave_history=True# Save the results for each iteration. Default False)