SlideShare a Scribd company logo
1 of 28
BITS Pilani
Pilani Campus
ACI – Lab Session 2
BITS Pilani
Pilani Campus
Optimizing attributes for travel cost
Hill ClimbingAlgorithm
Autonomous car driving agent
BITS Pilani
Pilani Campus
The algorithm – Hill climbing
BITS Pilani, Pilani Campus
Hill climbing algorithm is a local search algorithm
which continuously moves in the direction of
increasing value to find the peak of the mountain
or best solution to the problem.
It terminates when it reaches a peak value where
no neighbor has a higher value.
One of the widely discussed examples of Hill
climbing algorithm is Traveling-salesman
Problem in which we need to minimize the
distance traveled by the salesman.
Hill Climbing Algorithm
BITS Pilani, Pilani Campus
Hill climbing algorithm is also called greedy local search
as it only looks to its good immediate neighbor state and
not beyond that.
Its core components include the initial state, successor
function, and objective function.
A node of hill climbing algorithm has two components which
are state and value.
Hill Climbing is mostly used when a good heuristic is
available.
In this algorithm, we don't need to maintain and handle the
search tree or graph as it only keeps a single current
state.
The limitation of Hill Climbing is that it can get stuck in
local optima, which are suboptimal solutions.
Hill Climbing Algorithm
BITS Pilani, Pilani Campus
HillClimbing(problem){
currentState = problem.startState
goal = false
while(!goal){
neighbour = highest valued successor of currentState
if neighbour.value <= currentState.value
goal = true
else
currentState = neighbour
}
}
Hill climbing - function
BITS Pilani, Pilani Campus
Limitation of hill climbing is local best solution
Hill climbing - function
BITS Pilani
Pilani Campus
The Problem
Optimizing attributes of autonomous vehicle
8
BITS Pilani, Pilani Campus
Performance measure of an automated driver
Desirable qualities include getting to the correct destination;
minimizing fuel consumption and wear and tear;
minimizing the trip time or cost; minimizing violations of traffic
laws and disturbances to other drivers; maximizing safety
and passenger comfort; maximizing profits. Obviously, some
of these goals conflict, so tradeoffs will be required.
Fuel is one of the main factors contributing to travel cost.
Fuel economy is calculated by using the formula
Average Fuel Consumption (Km/L) = Distance travelled / Litres
of fuel consumed
Travel cost depends on other attributes like speed of the
vehicle, time taken for the travel, type of roads, traffic, driving
behavior, weather, weight, air conditioning, etc.
The problem - Attributes for
fuel economy
BITS Pilani, Pilani Campus
Let us take a few of these for our sub-problem.
A few attributes that influence travel cost are:
Time to travel
Speed
Fuel consumed
Distance travelled
Optimizing these objectives is known as Multi-objective
optimization
The attributes/objectives for
optimization in the example
BITS Pilani, Pilani Campus
A problem that takes more than one objective for
optimization
The objectives can be contradicting ones
Meaning, it is desirable to increase the value of one
objective while decreasing the value of others
Solution representation and evaluation:
The objectives are represented as a vector and can be
evaluated using
– The vector as a whole
– Defining a evaluation function using the objectives
Multi-objective optimization
problem
BITS Pilani, Pilani Campus
In the current autonomous car agent problem the cost or
evaluation function is taken as follows:
Travel Cost = Time + Speed + Fuel – Distance
Here our goal is to reduce the cost. (Minimization problem)
Time travelled and fuel consumed must have lower values
for cost reduction.
Speed must be average (not less not more)
Distance travelled must be maximum to reduce the cost
Cost function / Evaluation
function
BITS Pilani, Pilani Campus
Choose the optimal attribute values to get minimum cost
Goal = 0 cost
Heuristic – Hill climbing
Choose attribute vectors (neighbors) at random (Stochastic
hill climbing)
Evaluate them
Retain the best while forgetting the less optimal values
Heuristic
BITS Pilani, Pilani Campus
Performance – Safety, time, legal drive, comfort.
– In the algorithm, reducing the cost of travel by optimizing the
attributes taken
Environment – Roads, other cars, pedestrians, road signs.
– Acceptable range of values for the attributes Time, Speed, Fuel
and Distance travelled represented as vector of combination of
these values
Actuators – Steering, accelerator, brake, signal, horn.
– Initial solution, Candidate solution, Evaluation function.
Sensors – Fuel indicator, Speedometer, Digital clock in the
display
– Candidate solution with the acceptable range of values (from the
sensors), number of iterations.
PEAS
BITS Pilani, Pilani Campus
Step 1: Evaluate the initial state, if it is goal state then
return success and Stop.
Step 2: Loop Until a solution is found or there is no new
operator left to apply.
Step 3: Select and apply an operator to the current state.
Step 4: Check new state
Step 5: Exit.
Hill climbing algorithm - Steps
BITS Pilani, Pilani Campus
Code Walk through
Stochastic hill climbing in
PYTHON
BITS Pilani, Pilani Campus
import numpy as np
import random;
#The PEAS
#Time, Speed, Fuel, Distance
#Init_solution = [10, 100, 25, 10];
#Init_solution = [2,10,5,100]
#Init_solution = [0, 0, 0, 0];
Iterations = 0
max_itr=1000 #Can be increased or decreased
Final_solution = None #Stores best of each iteration
#PEAS and the initial states
BITS Pilani, Pilani Campus
#Contains an objective vector of attributes to be optimized and
the cost associated with the objectives
class Solu_space:
def __init__(self):
self.obj_vector = None
self.cost = None
def setObj_vector(self, val):
self.obj_vector = val
def setCost(self, cost):
self.cost = cost
def getAttr(self):
return {'Time, Speed, Fuel, Distance': self.obj_vector, 'Cost':
self.cost }
#Class : Solution space
BITS Pilani, Pilani Campus
# Function for calculating the cost - The evaluation function
def calc_cost(objVector):
cost = round((objVector[0] + objVector[1] +
objVector[2] - objVector[3]),2)
#print("Cost"+str(cost))
return abs(cost)
#Function for cost evaluation
BITS Pilani, Pilani Campus
def gen_new_solution():
distance_step=0
speed_step=random.randint(10,100)
time_step=round((random.randint(1,100))/60,2)
try:
distance_step=random.randint(1,round(speed_step*time_step,2))
except:
pass
fuel_step=random.randint(1,25)
objVector=[time_step,speed_step,fuel_step,distance_step]
#print("new solution: "+str(objVector))
return objVector
#Function to generate new
solution
BITS Pilani, Pilani Campus
def Hill_Climb(objVector):
soln_space = Solu_space()
soln_space.setObj_vector(objVector)
oldCost = calc_cost(objVector);
soln_space.setCost(oldCost)
newobjVector = gen_new_solution()
newcost= calc_cost(newobjVector)
#Function Hill climb
BITS Pilani, Pilani Campus
if(newcost < oldCost):
soln_space.setObj_vector(newobjVector)
soln_space.setCost(newcost)
print(str(soln_space.getAttr()))
return soln_space.obj_vector
print(str(soln_space.getAttr()))
return soln_space.obj_vector
#Function Hill climb –
compare solution costs
BITS Pilani, Pilani Campus
def stopit():
globals()
cost=calc_cost(Final_solution)
if cost == 0:
return True
if Iterations == max_itr:
return True
else:
return False
#Function – The stopping
criterion
CALLING ALL THE DEFINED
FUNCTIONS
BITS Pilani, Pilani Campus
#Time,speed,fuel,distance
Init_soln=
[random.randint(1,10),
random.randint(1,100),
random.randint(1,25),
random.randint(1,500)]
#Generate initial solution
BITS Pilani, Pilani Campus
Final_solution= Hill_Climb(Init_solution) #Initialize variable Final_solution
print(Final_solution)
while not stopit():
solution=Final_solution
Final_solution=Hill_Climb(solution)
print("Iteration no: "+str(Iterations))
Iterations+=1
print("Solution")
print(str(Final_solution[0])+ " Hrs " +str(Final_solution[1])+ "
Km/Hr " + str(Final_solution[2]) + " Litres " +
str(Final_solution[3]) + " Kms")
print("Cost" + str(calc_cost(Final_solution)))
#Loop the Hill Climb
BITS Pilani, Pilani Campus
{'Time, Speed, Fuel, Distance': [1.3, 70, 12, 55], 'Cost': 28.3} Iteration no: 35
{'Time, Speed, Fuel, Distance': [1.3, 70, 12, 55], 'Cost': 28.3} Iteration no: 36
{'Time, Speed, Fuel, Distance': [1.3, 70, 12, 55], 'Cost': 28.3} Iteration no: 37
{'Time, Speed, Fuel, Distance': [0.13, 10, 2, 0], 'Cost': 12.13} Iteration no: 172
{'Time, Speed, Fuel, Distance': [0.13, 10, 2, 0], 'Cost': 12.13} Iteration no: 173
{'Time, Speed, Fuel, Distance': [0.13, 10, 2, 0], 'Cost': 12.13} Iteration no: 174
{'Time, Speed, Fuel, Distance': [0.13, 10, 2, 0], 'Cost': 12.13} Iteration no: 175
{'Time, Speed, Fuel, Distance': [1.5, 66, 2, 70], 'Cost': 0.5} Iteration no: 991
{'Time, Speed, Fuel, Distance': [1.5, 66, 2, 70], 'Cost': 0.5} Iteration no: 992
{'Time, Speed, Fuel, Distance': [1.5, 66, 2, 70], 'Cost': 0.5} Iteration no: 993
{'Time, Speed, Fuel, Distance': [1.5, 66, 2, 70], 'Cost': 0.5} Iteration no: 994
{'Time, Speed, Fuel, Distance': [1.5, 66, 2, 70], 'Cost': 0.5} Iteration no: 995
{'Time, Speed, Fuel, Distance': [1.5, 66, 2, 70], 'Cost': 0.5} Iteration no: 996
{'Time, Speed, Fuel,Distance': [1.5, 66, 2, 70], 'Cost': 0.5} Iteration no: 997
{'Time, Speed, Fuel, Distance': [1.5, 66, 2, 70], 'Cost': 0.5} Iteration no: 998
{'Time, Speed, Fuel, Distance': [1.5, 66, 2, 70], 'Cost': 0.5} Iteration no: 999
Solution 1.5 Hrs 66 Km/Hr 2 Litres 70 Kms Cost 0.5
Partial sample output
BITS Pilani, Pilani Campus
Add code to convert stochastic hill climb into Random
restart hill climb
Solve the problem using Simulated annealing
Implement the solution for the given problem using genetic
algorithm
That’s all for Hill Climbing
Food for thought

More Related Content

Similar to ACI-LabSession2A-HillClimbing-TravelOptimization.pptx

Standoutfromthe crowds
Standoutfromthe crowdsStandoutfromthe crowds
Standoutfromthe crowdsMohammed Awad
 
Fleet management in Oracle Transport Management(otm)
Fleet management in Oracle Transport Management(otm)Fleet management in Oracle Transport Management(otm)
Fleet management in Oracle Transport Management(otm)Satyam Rai
 
Vpriv Ready
Vpriv ReadyVpriv Ready
Vpriv ReadyLangLin
 
Passenger forecasting at KLM
Passenger forecasting at KLMPassenger forecasting at KLM
Passenger forecasting at KLMBigData Republic
 
IRJET-Survey on Simulation of Self-Driving Cars using Supervised and Reinforc...
IRJET-Survey on Simulation of Self-Driving Cars using Supervised and Reinforc...IRJET-Survey on Simulation of Self-Driving Cars using Supervised and Reinforc...
IRJET-Survey on Simulation of Self-Driving Cars using Supervised and Reinforc...IRJET Journal
 
C ost+behaviour+estimation
C ost+behaviour+estimationC ost+behaviour+estimation
C ost+behaviour+estimationKhalid Aziz
 
Well Architected: Cost Optimization
Well Architected: Cost Optimization Well Architected: Cost Optimization
Well Architected: Cost Optimization Amazon Web Services
 
R, Scikit-Learn and Apache Spark ML - What difference does it make?
R, Scikit-Learn and Apache Spark ML - What difference does it make?R, Scikit-Learn and Apache Spark ML - What difference does it make?
R, Scikit-Learn and Apache Spark ML - What difference does it make?Villu Ruusmann
 
A Linear Programming Solution To The Gate Assignment Problem At Airport Termi...
A Linear Programming Solution To The Gate Assignment Problem At Airport Termi...A Linear Programming Solution To The Gate Assignment Problem At Airport Termi...
A Linear Programming Solution To The Gate Assignment Problem At Airport Termi...Hannah Baker
 
IDDFS ALGORITHM in artificial intelligence
IDDFS ALGORITHM in artificial intelligenceIDDFS ALGORITHM in artificial intelligence
IDDFS ALGORITHM in artificial intelligencePenielAnkomah1
 
How Vnomics built a "Digital Twin" for Commercial Trucking
How Vnomics built a "Digital Twin" for Commercial TruckingHow Vnomics built a "Digital Twin" for Commercial Trucking
How Vnomics built a "Digital Twin" for Commercial TruckingLloyd Palum
 
Deepak-Computational Advertising-The LinkedIn Way
Deepak-Computational Advertising-The LinkedIn WayDeepak-Computational Advertising-The LinkedIn Way
Deepak-Computational Advertising-The LinkedIn Wayyingfeng
 
Case Study for Plant Layout :: A modern analysis
Case Study for Plant Layout :: A modern analysisCase Study for Plant Layout :: A modern analysis
Case Study for Plant Layout :: A modern analysisSarang Bhutada
 

Similar to ACI-LabSession2A-HillClimbing-TravelOptimization.pptx (20)

Chap005 abc
Chap005 abcChap005 abc
Chap005 abc
 
Standoutfromthe crowds
Standoutfromthe crowdsStandoutfromthe crowds
Standoutfromthe crowds
 
Profit maximization
Profit maximizationProfit maximization
Profit maximization
 
Fleet management in Oracle Transport Management(otm)
Fleet management in Oracle Transport Management(otm)Fleet management in Oracle Transport Management(otm)
Fleet management in Oracle Transport Management(otm)
 
Vpriv Ready
Vpriv ReadyVpriv Ready
Vpriv Ready
 
Cost Optimization at Scale
Cost Optimization at ScaleCost Optimization at Scale
Cost Optimization at Scale
 
Passenger forecasting at KLM
Passenger forecasting at KLMPassenger forecasting at KLM
Passenger forecasting at KLM
 
IRJET-Survey on Simulation of Self-Driving Cars using Supervised and Reinforc...
IRJET-Survey on Simulation of Self-Driving Cars using Supervised and Reinforc...IRJET-Survey on Simulation of Self-Driving Cars using Supervised and Reinforc...
IRJET-Survey on Simulation of Self-Driving Cars using Supervised and Reinforc...
 
Filling the gap
Filling the gapFilling the gap
Filling the gap
 
PPT on PM_Unit 1 .pptx.
PPT                  on PM_Unit 1 .pptx.PPT                  on PM_Unit 1 .pptx.
PPT on PM_Unit 1 .pptx.
 
C ost+behaviour+estimation
C ost+behaviour+estimationC ost+behaviour+estimation
C ost+behaviour+estimation
 
Well Architected: Cost Optimization
Well Architected: Cost Optimization Well Architected: Cost Optimization
Well Architected: Cost Optimization
 
R, Scikit-Learn and Apache Spark ML - What difference does it make?
R, Scikit-Learn and Apache Spark ML - What difference does it make?R, Scikit-Learn and Apache Spark ML - What difference does it make?
R, Scikit-Learn and Apache Spark ML - What difference does it make?
 
A Linear Programming Solution To The Gate Assignment Problem At Airport Termi...
A Linear Programming Solution To The Gate Assignment Problem At Airport Termi...A Linear Programming Solution To The Gate Assignment Problem At Airport Termi...
A Linear Programming Solution To The Gate Assignment Problem At Airport Termi...
 
Cost behavior
Cost behaviorCost behavior
Cost behavior
 
IDDFS ALGORITHM in artificial intelligence
IDDFS ALGORITHM in artificial intelligenceIDDFS ALGORITHM in artificial intelligence
IDDFS ALGORITHM in artificial intelligence
 
20181221 q-trader
20181221 q-trader20181221 q-trader
20181221 q-trader
 
How Vnomics built a "Digital Twin" for Commercial Trucking
How Vnomics built a "Digital Twin" for Commercial TruckingHow Vnomics built a "Digital Twin" for Commercial Trucking
How Vnomics built a "Digital Twin" for Commercial Trucking
 
Deepak-Computational Advertising-The LinkedIn Way
Deepak-Computational Advertising-The LinkedIn WayDeepak-Computational Advertising-The LinkedIn Way
Deepak-Computational Advertising-The LinkedIn Way
 
Case Study for Plant Layout :: A modern analysis
Case Study for Plant Layout :: A modern analysisCase Study for Plant Layout :: A modern analysis
Case Study for Plant Layout :: A modern analysis
 

More from ssuser1eba67

ACI-Webinar-3-MinMaxAlphaBetaPruning-TicTacToe.pptx
ACI-Webinar-3-MinMaxAlphaBetaPruning-TicTacToe.pptxACI-Webinar-3-MinMaxAlphaBetaPruning-TicTacToe.pptx
ACI-Webinar-3-MinMaxAlphaBetaPruning-TicTacToe.pptxssuser1eba67
 
ISM_Session_5 _ 23rd and 24th December.pptx
ISM_Session_5 _ 23rd and 24th December.pptxISM_Session_5 _ 23rd and 24th December.pptx
ISM_Session_5 _ 23rd and 24th December.pptxssuser1eba67
 
mi al material ISM_Session_4 _ 16th and 17th December (2).pptx
mi al material ISM_Session_4 _ 16th and 17th December (2).pptxmi al material ISM_Session_4 _ 16th and 17th December (2).pptx
mi al material ISM_Session_4 _ 16th and 17th December (2).pptxssuser1eba67
 
final uniform_search_Uninformed Search.pptx
final uniform_search_Uninformed Search.pptxfinal uniform_search_Uninformed Search.pptx
final uniform_search_Uninformed Search.pptxssuser1eba67
 
Salesforce Billing SessionS 1,2,3 AUX.pptx
Salesforce Billing SessionS 1,2,3 AUX.pptxSalesforce Billing SessionS 1,2,3 AUX.pptx
Salesforce Billing SessionS 1,2,3 AUX.pptxssuser1eba67
 
Salesforce Billing Invoice session 6,7,8.pptx
Salesforce Billing Invoice session 6,7,8.pptxSalesforce Billing Invoice session 6,7,8.pptx
Salesforce Billing Invoice session 6,7,8.pptxssuser1eba67
 
SALEFORCE BILLING MILESTONE.pptx
SALEFORCE BILLING MILESTONE.pptxSALEFORCE BILLING MILESTONE.pptx
SALEFORCE BILLING MILESTONE.pptxssuser1eba67
 
Salesforce CPQ_Sessoin 5,6.pptx
Salesforce CPQ_Sessoin 5,6.pptxSalesforce CPQ_Sessoin 5,6.pptx
Salesforce CPQ_Sessoin 5,6.pptxssuser1eba67
 
Salesforce CPQ updated 1.pptx
Salesforce CPQ updated 1.pptxSalesforce CPQ updated 1.pptx
Salesforce CPQ updated 1.pptxssuser1eba67
 
Salesforce CPQ_Sessoin 5,6.pptx
Salesforce CPQ_Sessoin 5,6.pptxSalesforce CPQ_Sessoin 5,6.pptx
Salesforce CPQ_Sessoin 5,6.pptxssuser1eba67
 
Presentation1.pptx
Presentation1.pptxPresentation1.pptx
Presentation1.pptxssuser1eba67
 
Salesforce CPQ_Sessoin123.pptx
Salesforce CPQ_Sessoin123.pptxSalesforce CPQ_Sessoin123.pptx
Salesforce CPQ_Sessoin123.pptxssuser1eba67
 
Salesforce CPQ_Sessoin 3,4.pptx
Salesforce CPQ_Sessoin 3,4.pptxSalesforce CPQ_Sessoin 3,4.pptx
Salesforce CPQ_Sessoin 3,4.pptxssuser1eba67
 
Salesforce CPQ updated 1.pptx
Salesforce CPQ updated 1.pptxSalesforce CPQ updated 1.pptx
Salesforce CPQ updated 1.pptxssuser1eba67
 
Salesforce Billing overview_VARA.pptx
Salesforce Billing overview_VARA.pptxSalesforce Billing overview_VARA.pptx
Salesforce Billing overview_VARA.pptxssuser1eba67
 
PPT_Machine learning approach to Renewable Energy systems.pptx
PPT_Machine learning approach to Renewable Energy systems.pptxPPT_Machine learning approach to Renewable Energy systems.pptx
PPT_Machine learning approach to Renewable Energy systems.pptxssuser1eba67
 
TRAINING VARAPRASAD (1).pptx
TRAINING VARAPRASAD (1).pptxTRAINING VARAPRASAD (1).pptx
TRAINING VARAPRASAD (1).pptxssuser1eba67
 
diseases of omentum mesentry retroperitoneum.pptx
diseases of omentum mesentry retroperitoneum.pptxdiseases of omentum mesentry retroperitoneum.pptx
diseases of omentum mesentry retroperitoneum.pptxssuser1eba67
 
AppBuilderSet1_26th sep.pptx
AppBuilderSet1_26th sep.pptxAppBuilderSet1_26th sep.pptx
AppBuilderSet1_26th sep.pptxssuser1eba67
 
20MBMB11PPT_Machine learning approach to Predict solar photovoltaic (2).pptx
20MBMB11PPT_Machine learning approach to Predict solar photovoltaic (2).pptx20MBMB11PPT_Machine learning approach to Predict solar photovoltaic (2).pptx
20MBMB11PPT_Machine learning approach to Predict solar photovoltaic (2).pptxssuser1eba67
 

More from ssuser1eba67 (20)

ACI-Webinar-3-MinMaxAlphaBetaPruning-TicTacToe.pptx
ACI-Webinar-3-MinMaxAlphaBetaPruning-TicTacToe.pptxACI-Webinar-3-MinMaxAlphaBetaPruning-TicTacToe.pptx
ACI-Webinar-3-MinMaxAlphaBetaPruning-TicTacToe.pptx
 
ISM_Session_5 _ 23rd and 24th December.pptx
ISM_Session_5 _ 23rd and 24th December.pptxISM_Session_5 _ 23rd and 24th December.pptx
ISM_Session_5 _ 23rd and 24th December.pptx
 
mi al material ISM_Session_4 _ 16th and 17th December (2).pptx
mi al material ISM_Session_4 _ 16th and 17th December (2).pptxmi al material ISM_Session_4 _ 16th and 17th December (2).pptx
mi al material ISM_Session_4 _ 16th and 17th December (2).pptx
 
final uniform_search_Uninformed Search.pptx
final uniform_search_Uninformed Search.pptxfinal uniform_search_Uninformed Search.pptx
final uniform_search_Uninformed Search.pptx
 
Salesforce Billing SessionS 1,2,3 AUX.pptx
Salesforce Billing SessionS 1,2,3 AUX.pptxSalesforce Billing SessionS 1,2,3 AUX.pptx
Salesforce Billing SessionS 1,2,3 AUX.pptx
 
Salesforce Billing Invoice session 6,7,8.pptx
Salesforce Billing Invoice session 6,7,8.pptxSalesforce Billing Invoice session 6,7,8.pptx
Salesforce Billing Invoice session 6,7,8.pptx
 
SALEFORCE BILLING MILESTONE.pptx
SALEFORCE BILLING MILESTONE.pptxSALEFORCE BILLING MILESTONE.pptx
SALEFORCE BILLING MILESTONE.pptx
 
Salesforce CPQ_Sessoin 5,6.pptx
Salesforce CPQ_Sessoin 5,6.pptxSalesforce CPQ_Sessoin 5,6.pptx
Salesforce CPQ_Sessoin 5,6.pptx
 
Salesforce CPQ updated 1.pptx
Salesforce CPQ updated 1.pptxSalesforce CPQ updated 1.pptx
Salesforce CPQ updated 1.pptx
 
Salesforce CPQ_Sessoin 5,6.pptx
Salesforce CPQ_Sessoin 5,6.pptxSalesforce CPQ_Sessoin 5,6.pptx
Salesforce CPQ_Sessoin 5,6.pptx
 
Presentation1.pptx
Presentation1.pptxPresentation1.pptx
Presentation1.pptx
 
Salesforce CPQ_Sessoin123.pptx
Salesforce CPQ_Sessoin123.pptxSalesforce CPQ_Sessoin123.pptx
Salesforce CPQ_Sessoin123.pptx
 
Salesforce CPQ_Sessoin 3,4.pptx
Salesforce CPQ_Sessoin 3,4.pptxSalesforce CPQ_Sessoin 3,4.pptx
Salesforce CPQ_Sessoin 3,4.pptx
 
Salesforce CPQ updated 1.pptx
Salesforce CPQ updated 1.pptxSalesforce CPQ updated 1.pptx
Salesforce CPQ updated 1.pptx
 
Salesforce Billing overview_VARA.pptx
Salesforce Billing overview_VARA.pptxSalesforce Billing overview_VARA.pptx
Salesforce Billing overview_VARA.pptx
 
PPT_Machine learning approach to Renewable Energy systems.pptx
PPT_Machine learning approach to Renewable Energy systems.pptxPPT_Machine learning approach to Renewable Energy systems.pptx
PPT_Machine learning approach to Renewable Energy systems.pptx
 
TRAINING VARAPRASAD (1).pptx
TRAINING VARAPRASAD (1).pptxTRAINING VARAPRASAD (1).pptx
TRAINING VARAPRASAD (1).pptx
 
diseases of omentum mesentry retroperitoneum.pptx
diseases of omentum mesentry retroperitoneum.pptxdiseases of omentum mesentry retroperitoneum.pptx
diseases of omentum mesentry retroperitoneum.pptx
 
AppBuilderSet1_26th sep.pptx
AppBuilderSet1_26th sep.pptxAppBuilderSet1_26th sep.pptx
AppBuilderSet1_26th sep.pptx
 
20MBMB11PPT_Machine learning approach to Predict solar photovoltaic (2).pptx
20MBMB11PPT_Machine learning approach to Predict solar photovoltaic (2).pptx20MBMB11PPT_Machine learning approach to Predict solar photovoltaic (2).pptx
20MBMB11PPT_Machine learning approach to Predict solar photovoltaic (2).pptx
 

Recently uploaded

Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentInMediaRes1
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 

Recently uploaded (20)

Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media Component
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 

ACI-LabSession2A-HillClimbing-TravelOptimization.pptx

  • 1. BITS Pilani Pilani Campus ACI – Lab Session 2
  • 2. BITS Pilani Pilani Campus Optimizing attributes for travel cost Hill ClimbingAlgorithm Autonomous car driving agent
  • 3. BITS Pilani Pilani Campus The algorithm – Hill climbing
  • 4. BITS Pilani, Pilani Campus Hill climbing algorithm is a local search algorithm which continuously moves in the direction of increasing value to find the peak of the mountain or best solution to the problem. It terminates when it reaches a peak value where no neighbor has a higher value. One of the widely discussed examples of Hill climbing algorithm is Traveling-salesman Problem in which we need to minimize the distance traveled by the salesman. Hill Climbing Algorithm
  • 5. BITS Pilani, Pilani Campus Hill climbing algorithm is also called greedy local search as it only looks to its good immediate neighbor state and not beyond that. Its core components include the initial state, successor function, and objective function. A node of hill climbing algorithm has two components which are state and value. Hill Climbing is mostly used when a good heuristic is available. In this algorithm, we don't need to maintain and handle the search tree or graph as it only keeps a single current state. The limitation of Hill Climbing is that it can get stuck in local optima, which are suboptimal solutions. Hill Climbing Algorithm
  • 6. BITS Pilani, Pilani Campus HillClimbing(problem){ currentState = problem.startState goal = false while(!goal){ neighbour = highest valued successor of currentState if neighbour.value <= currentState.value goal = true else currentState = neighbour } } Hill climbing - function
  • 7. BITS Pilani, Pilani Campus Limitation of hill climbing is local best solution Hill climbing - function
  • 8. BITS Pilani Pilani Campus The Problem Optimizing attributes of autonomous vehicle 8
  • 9. BITS Pilani, Pilani Campus Performance measure of an automated driver Desirable qualities include getting to the correct destination; minimizing fuel consumption and wear and tear; minimizing the trip time or cost; minimizing violations of traffic laws and disturbances to other drivers; maximizing safety and passenger comfort; maximizing profits. Obviously, some of these goals conflict, so tradeoffs will be required. Fuel is one of the main factors contributing to travel cost. Fuel economy is calculated by using the formula Average Fuel Consumption (Km/L) = Distance travelled / Litres of fuel consumed Travel cost depends on other attributes like speed of the vehicle, time taken for the travel, type of roads, traffic, driving behavior, weather, weight, air conditioning, etc. The problem - Attributes for fuel economy
  • 10. BITS Pilani, Pilani Campus Let us take a few of these for our sub-problem. A few attributes that influence travel cost are: Time to travel Speed Fuel consumed Distance travelled Optimizing these objectives is known as Multi-objective optimization The attributes/objectives for optimization in the example
  • 11. BITS Pilani, Pilani Campus A problem that takes more than one objective for optimization The objectives can be contradicting ones Meaning, it is desirable to increase the value of one objective while decreasing the value of others Solution representation and evaluation: The objectives are represented as a vector and can be evaluated using – The vector as a whole – Defining a evaluation function using the objectives Multi-objective optimization problem
  • 12. BITS Pilani, Pilani Campus In the current autonomous car agent problem the cost or evaluation function is taken as follows: Travel Cost = Time + Speed + Fuel – Distance Here our goal is to reduce the cost. (Minimization problem) Time travelled and fuel consumed must have lower values for cost reduction. Speed must be average (not less not more) Distance travelled must be maximum to reduce the cost Cost function / Evaluation function
  • 13. BITS Pilani, Pilani Campus Choose the optimal attribute values to get minimum cost Goal = 0 cost Heuristic – Hill climbing Choose attribute vectors (neighbors) at random (Stochastic hill climbing) Evaluate them Retain the best while forgetting the less optimal values Heuristic
  • 14. BITS Pilani, Pilani Campus Performance – Safety, time, legal drive, comfort. – In the algorithm, reducing the cost of travel by optimizing the attributes taken Environment – Roads, other cars, pedestrians, road signs. – Acceptable range of values for the attributes Time, Speed, Fuel and Distance travelled represented as vector of combination of these values Actuators – Steering, accelerator, brake, signal, horn. – Initial solution, Candidate solution, Evaluation function. Sensors – Fuel indicator, Speedometer, Digital clock in the display – Candidate solution with the acceptable range of values (from the sensors), number of iterations. PEAS
  • 15. BITS Pilani, Pilani Campus Step 1: Evaluate the initial state, if it is goal state then return success and Stop. Step 2: Loop Until a solution is found or there is no new operator left to apply. Step 3: Select and apply an operator to the current state. Step 4: Check new state Step 5: Exit. Hill climbing algorithm - Steps
  • 16. BITS Pilani, Pilani Campus Code Walk through Stochastic hill climbing in PYTHON
  • 17. BITS Pilani, Pilani Campus import numpy as np import random; #The PEAS #Time, Speed, Fuel, Distance #Init_solution = [10, 100, 25, 10]; #Init_solution = [2,10,5,100] #Init_solution = [0, 0, 0, 0]; Iterations = 0 max_itr=1000 #Can be increased or decreased Final_solution = None #Stores best of each iteration #PEAS and the initial states
  • 18. BITS Pilani, Pilani Campus #Contains an objective vector of attributes to be optimized and the cost associated with the objectives class Solu_space: def __init__(self): self.obj_vector = None self.cost = None def setObj_vector(self, val): self.obj_vector = val def setCost(self, cost): self.cost = cost def getAttr(self): return {'Time, Speed, Fuel, Distance': self.obj_vector, 'Cost': self.cost } #Class : Solution space
  • 19. BITS Pilani, Pilani Campus # Function for calculating the cost - The evaluation function def calc_cost(objVector): cost = round((objVector[0] + objVector[1] + objVector[2] - objVector[3]),2) #print("Cost"+str(cost)) return abs(cost) #Function for cost evaluation
  • 20. BITS Pilani, Pilani Campus def gen_new_solution(): distance_step=0 speed_step=random.randint(10,100) time_step=round((random.randint(1,100))/60,2) try: distance_step=random.randint(1,round(speed_step*time_step,2)) except: pass fuel_step=random.randint(1,25) objVector=[time_step,speed_step,fuel_step,distance_step] #print("new solution: "+str(objVector)) return objVector #Function to generate new solution
  • 21. BITS Pilani, Pilani Campus def Hill_Climb(objVector): soln_space = Solu_space() soln_space.setObj_vector(objVector) oldCost = calc_cost(objVector); soln_space.setCost(oldCost) newobjVector = gen_new_solution() newcost= calc_cost(newobjVector) #Function Hill climb
  • 22. BITS Pilani, Pilani Campus if(newcost < oldCost): soln_space.setObj_vector(newobjVector) soln_space.setCost(newcost) print(str(soln_space.getAttr())) return soln_space.obj_vector print(str(soln_space.getAttr())) return soln_space.obj_vector #Function Hill climb – compare solution costs
  • 23. BITS Pilani, Pilani Campus def stopit(): globals() cost=calc_cost(Final_solution) if cost == 0: return True if Iterations == max_itr: return True else: return False #Function – The stopping criterion
  • 24. CALLING ALL THE DEFINED FUNCTIONS
  • 25. BITS Pilani, Pilani Campus #Time,speed,fuel,distance Init_soln= [random.randint(1,10), random.randint(1,100), random.randint(1,25), random.randint(1,500)] #Generate initial solution
  • 26. BITS Pilani, Pilani Campus Final_solution= Hill_Climb(Init_solution) #Initialize variable Final_solution print(Final_solution) while not stopit(): solution=Final_solution Final_solution=Hill_Climb(solution) print("Iteration no: "+str(Iterations)) Iterations+=1 print("Solution") print(str(Final_solution[0])+ " Hrs " +str(Final_solution[1])+ " Km/Hr " + str(Final_solution[2]) + " Litres " + str(Final_solution[3]) + " Kms") print("Cost" + str(calc_cost(Final_solution))) #Loop the Hill Climb
  • 27. BITS Pilani, Pilani Campus {'Time, Speed, Fuel, Distance': [1.3, 70, 12, 55], 'Cost': 28.3} Iteration no: 35 {'Time, Speed, Fuel, Distance': [1.3, 70, 12, 55], 'Cost': 28.3} Iteration no: 36 {'Time, Speed, Fuel, Distance': [1.3, 70, 12, 55], 'Cost': 28.3} Iteration no: 37 {'Time, Speed, Fuel, Distance': [0.13, 10, 2, 0], 'Cost': 12.13} Iteration no: 172 {'Time, Speed, Fuel, Distance': [0.13, 10, 2, 0], 'Cost': 12.13} Iteration no: 173 {'Time, Speed, Fuel, Distance': [0.13, 10, 2, 0], 'Cost': 12.13} Iteration no: 174 {'Time, Speed, Fuel, Distance': [0.13, 10, 2, 0], 'Cost': 12.13} Iteration no: 175 {'Time, Speed, Fuel, Distance': [1.5, 66, 2, 70], 'Cost': 0.5} Iteration no: 991 {'Time, Speed, Fuel, Distance': [1.5, 66, 2, 70], 'Cost': 0.5} Iteration no: 992 {'Time, Speed, Fuel, Distance': [1.5, 66, 2, 70], 'Cost': 0.5} Iteration no: 993 {'Time, Speed, Fuel, Distance': [1.5, 66, 2, 70], 'Cost': 0.5} Iteration no: 994 {'Time, Speed, Fuel, Distance': [1.5, 66, 2, 70], 'Cost': 0.5} Iteration no: 995 {'Time, Speed, Fuel, Distance': [1.5, 66, 2, 70], 'Cost': 0.5} Iteration no: 996 {'Time, Speed, Fuel,Distance': [1.5, 66, 2, 70], 'Cost': 0.5} Iteration no: 997 {'Time, Speed, Fuel, Distance': [1.5, 66, 2, 70], 'Cost': 0.5} Iteration no: 998 {'Time, Speed, Fuel, Distance': [1.5, 66, 2, 70], 'Cost': 0.5} Iteration no: 999 Solution 1.5 Hrs 66 Km/Hr 2 Litres 70 Kms Cost 0.5 Partial sample output
  • 28. BITS Pilani, Pilani Campus Add code to convert stochastic hill climb into Random restart hill climb Solve the problem using Simulated annealing Implement the solution for the given problem using genetic algorithm That’s all for Hill Climbing Food for thought