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 f(x,y,z), where
f(x,y,z)=esin(40z)+sin(60cos(z))+esin(50x)
+sin(60ey)+sin(70sin(x))+sin(sin(80y))
-sin(10(x+y))+x2+y2+z2100
Constraints: The solution must be subject to the (hard) constraints:
0x,y,z5, and ,x,y,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 *sin(40**z))+ math *sin(60** math *cos(z))+ math *exp( math *sin(50**x))
+ math. sin(60**math*exp(y))+ math sin(70**math*sin(x))+ math *sin( math *sin(80**y))
- math sin(10**(x+y))+x****2+y****2+z****2100
Examples of algorithms in Python:
#Random Search
import random
import numpy
import math
def f(x):
f =-x**6+28*x**5-307*x**4+1660*x**3-4564*x**2+5872*x +2688 #Change this for each question
return f
xbest = random.uniform(0,10)
fbest = f(xbest)
steps =100
for i in range(1,steps):
xnew = random.uniform(0,10) #new random solution
fnew = f(xnew)
if fnew > fbest:
xbest = xnew
fbest = fnew
print ('xbest', xbest, 'fbest', fbest,)
# Perform a hill-climb
def f(x):
f =-x**6+28*x**5-307*x**4+1660*x**3-4564*x**2+5872*x +2688 #Change this for each question
return f
xbest = random.uniform(0,10)
fbest = f(xbest)
steps =100
for i in range(1,steps):
xnew = xbest + random.gauss(0,0.1) #Hill climb step
fnew = f(xnew)
if fnew > fbest:
xbest = xnew
fbest = fnew
print('xbest', xbest, 'fbest', fbest)
# Perform a Iterated Local Search (ILS)
# The function to optimise
def f(x):
f =-x**6+28*x**5-307*x**4+1660*x**3-4564*x**2+5872*x +2688 #Change this for each question
return f
# Create a random initial solution, with 0 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(0,1) #step size here should be small, 1 here
### print best solution
print('xopt', xopt, 'fopt', fopt)
# Simulated Annealing
def f(x):
f =-x**6+28*x**5-307*x**4+1660*x**3-4564*x**2+5872*x +2688 #Change this for each question
return f
xbest = random.uniform(0,10)
fbest = f(xbest)
steps =200
for i in range(1,steps):
T=5*(1-i/steps) #Tempertaure function
xnew = xbest + random.gauss(0,0.1)
fnew = f(xnew)
if fnew > fbest:
xbest = xnew
fbest = fnew
elif random.random() math.exp((fnew-fbest)/T): #Accept worse solutions?
xbest = xnew
fbest = fnew
print ('xbest', xbest, 'fbest', fbest,)
Hello, I need help with the following task in

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Accounting Questions!