Question: Hello, I need help with the following task in PYTHON. The optimization algorithms that need to be tested are: Random Search Hill Climb Iterated local
Hello,
I need help with the following task in PYTHON. The optimization algorithms that need to be
tested are:
Random Search
Hill Climb
Iterated local search
Simulated Annealing
Objective: Find the maximum value of where
Constraints: The solution must be subject to the hard constraints:
and zinR
You should explain the approach taken, submitting all programming code that is used
provide comments to code, or a description of the code, where appropriate to demonstrate
you understand the code used.
Equation in Python:
math. exp math math math math math
math. math math math
math
Examples of algorithms in Python:
#Random Search
import random
import numpy
import math
def fx:
f xxxxxx #Change this for each question
return f
xbest random.uniform
fbest fxbest
steps
for i in rangesteps:
xnew random.uniform #new random solution
fnew fxnew
if fnew fbest:
xbest xnew
fbest fnew
print xbest xbest, 'fbest', fbest,
# Perform a hillclimb
def fx:
f xxxxxx #Change this for each question
return f
xbest random.uniform
fbest fxbest
steps
for i in rangesteps:
xnew xbest random.gauss #Hill climb step
fnew fxnew
if fnew fbest:
xbest xnew
fbest fnew
printxbest xbest, 'fbest', fbest
# Perform a Iterated Local Search ILS
# The function to optimise
def fx:
f xxxxxx #Change this for each question
return f
# Create a random initial solution, with fbest: # if new solution is better than best solution, update best solution.
xbest xnew
fbest fnew
# Continue ILS Loop Check best solution against overall optimal solution
if fbest fopt: # if new solution is better than best solution, update best solution.
xopt xbest
fopt fbest
# Carry out a big step
xbest xopt random.gauss #step size here should be small, here
### print best solution
printxopt xopt, 'fopt', fopt
# Simulated Annealing
def fx:
f xxxxxx #Change this for each question
return f
xbest random.uniform
fbest fxbest
steps
for i in rangesteps:
Tisteps #Tempertaure function
xnew xbest random.gauss
fnew fxnew
if fnew fbest:
xbest xnew
fbest fnew
elif random.random math.expfnewfbestT: #Accept worse solutions?
xbest xnew
fbest fnew
print xbest xbest, 'fbest', fbest,
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
