Skip to main content

pyIpnHeuristic is a pure Python implementation of some heuristic algorithms

Project description

PyIpnHeuristic

pyIpnHeuristic 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 page pyIpnHeuristic

Pip Install

pip install pyIpnHeuristic

Benchmark

Benchmark problems were taken from Liang et al. 2006. Check out the benchmark doc for 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_pg24
from pyIpnHeuristic.benchmark import get_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 Algorithms

  • Harmony Search
from pyIpnHeuristic.harmonySearch import HarmonySearch
    
harmonySearch = HarmonySearch(
    objective_function, # e.g, def f(*x): return x[0]**2 + x[1] **2
    soft_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, 4
    smooth=False, # If True, hard restrictions will be treated as soft restrictions
    epsilon=10**-4, # If smmooth is True, then h(x) = 0 --> |h(x)| - epsilon <= 0
    # Harmony Search Parameters
    hcmr=hcmr,
    par=par,
    alpha=alpha
)

harmonySearch.search(
    iterations=T, # Number of iterations to be made
    save_history=True # Save the results for each iteration. Default False
)
  • Modified Harmony Search
from pyIpnHeuristic.modifiedHarmonySearch import ModifiedHarmonySearch
    
harmonySearch = ModifiedHarmonySearch(
    objective_function, # e.g, def f(*x): return x[0]**2 + x[1] **2
    soft_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, 4
    smooth=False, # If True, hard restrictions will be treated as soft restrictions
    epsilon=10**-4, # If smmooth is True, then h(x) = 0 --> |h(x)| - epsilon <= 0
    # Harmony Search Parameters
    hcmr=hcmr,
    par=par,
    alpha=alpha
)

harmonySearch.search(
    iterations=T, # Number of iterations to be made
    save_history=True # Save the results for each iteration. Default False
)
  • Differential Evolution:
    • DE/rand/1/ bin
    • DE/best/1
    • DE/current-to-best/1
    • DE/best/2
    • DE/rand/2
from pyIpnHeuristic.differentialEvolution import DifferentialEvolution

differentialEvolution = DifferentialEvolution(
    objective_function, # e.g, def f(*x): return x[0]**2 + x[1] **2
    soft_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, 4
    smooth=False, # If True, hard restrictions will be treated as soft restrictions
    epsilon=10**-4, # If smooth is True, then h(x) = 0 --> |h(x)| - epsilon <= 0
    # Differential Evolution Parameters
    type=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 made
    save_history=True # Save the results for each iteration. Default False
)
  • Particle Swarm Optimization
from pyIpnHeuristic.particleSwarmOptimization import ParticleSwarmOptimization

particleSwarmOptimization = ParticleSwarmOptimization(
    objective_function, # e.g, def f(*x): return x[0]**2 + x[1] **2
    soft_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, 4
    smooth=False, # If True, hard restrictions will be treated as soft restrictions
    epsilon=10**-4, # If smmooth is True, then h(x) = 0 --> |h(x)| - epsilon <= 0
    # Particle Swarm Parameters
    w=0.3,
    c1=0.1,
    c2=1.9
)

particleSwarmOptimization.search(
    iterations=T, # Number of iterations to be made
    save_history=True # Save the results for each iteration. Default False
)
  • Artificial Bee Colony
from pyIpnHeuristic.artificialBeeColony import ArtificialBeeColony

artificialBeeColony = ArtificialBeeColony(
    objective_function, # e.g, def f(*x): return x[0]**2 + x[1] **2
    soft_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, 4
    smooth=False, # If True, hard restrictions will be treated as soft restrictions
    epsilon=10**-4, # If smmooth is True, then h(x) = 0 --> |h(x)| - epsilon <= 0
    # Artificial Bee Colony Parameters
    mr=0.3,
    max_trials=3,
)

artificialBeeColony.search(
    iterations=T, # Number of iterations to be made
    save_history=True # Save the results for each iteration. Default False
)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyIpnHeuristic-2.0.0.tar.gz (24.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyIpnHeuristic-2.0.0-py3-none-any.whl (24.7 kB view details)

Uploaded Python 3

File details

Details for the file pyIpnHeuristic-2.0.0.tar.gz.

File metadata

  • Download URL: pyIpnHeuristic-2.0.0.tar.gz
  • Upload date:
  • Size: 24.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.10

File hashes

Hashes for pyIpnHeuristic-2.0.0.tar.gz
Algorithm Hash digest
SHA256 670a8eff904823f7223710cf1509fba0509adf6e8655e4fc6f58ec2b2403eedf
MD5 9978183ca7282f570b5a54993bca3217
BLAKE2b-256 9d165748bc8e989817ef0155356f6ce6c5d03c65c925a44d7ce3c8e13fecff1e

See more details on using hashes here.

File details

Details for the file pyIpnHeuristic-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: pyIpnHeuristic-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 24.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.10

File hashes

Hashes for pyIpnHeuristic-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f591fabc1e7cf02702e5cb9acca765c43b3d8ae6dc8123a888fd0e1e07d90255
MD5 934cf86e472ea0b07ef803217d973ac9
BLAKE2b-256 84914d4282dd1e0aee3d8eb47153371118e69bcc98e332c5ee732ce63107a62d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page