[go: up one dir, main page]

0% found this document useful (0 votes)
51 views4 pages

Question: Devise A Hill Climbing Search Based Approach To Solve N-City Tsps. You Must de Ne All Req..

Uploaded by

Malik Asad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views4 pages

Question: Devise A Hill Climbing Search Based Approach To Solve N-City Tsps. You Must de Ne All Req..

Uploaded by

Malik Asad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Alert when this question is answered

× Download the Chegg Study App GE T


★★★★★ (80K+)

  Textbook Solutions Expert Q&A Practice 

home / study / engineering / computer science / computer science questions and answers / devise a...
Find solutions for your homework

Question:   Devise a hill climbing search based approach to


solve N-city TSPs. You must de ne all req...

Devise a hill climbing search based approach to solve N-city TSPs. You must de ne all required elements to
be able to implement the hill climbing search as indicated in the pseudocode of this algorithm including
the state description (representation of the problem), the initial state, the successor function and applicable
actions, the goal test or the goal state, and the heuristic function h. Strive for an evaluation or heuristic
function de nition that facilitates optimal solutions. Describe the pseudocode for the hill climbing
algorithm adapted for the TSP. There is no need to implement the search algorithm.

2 Comments

Expert Answer

rrrRnnm
answered this

Function HILL-CLIMBING(Problem) returns a solution state


Inputs: Problem, problem
Local variables: Current, a node
Next, a node
Current = MAKE-NODE(INITIAL-STATE[Problem])
Loop do
Next = a highest-valued successor of Current
If VALUE[Next] < VALUE[Current] then return Current
Current = Next
End

The Hill Climbing algorithm is great for nding local optima and works by changing a small part of the
current state to get a better (in this case, shorter) path.
implement the small changes to nd a better solution is up to us. Let's say we want to simply switch two
nodes and only keep the result if it's better than your current solution.

**swaps two cities in the tour and returns the


* change in cost of the tour
* @param tour the current tour
* @param tourIndexA the position of the city to swap
* @param tourIndexB the other position to swap
* @param distances the symmetric distance matrix
* @return the change in cost, negative indicating a
* shorter new tour, and positive indicating an increase
* in tour length
*/
public double swap(int[] tour, int tourIndexA,
int tourIndexB, double[][] distances)
{
return 0;
}

Just swapping the second town with some other town gives us the following:

# rst iteration
start: ABCDEFGA
next: ACBDEFGA, ADCBEFGA, AECDBFGA, AFCDEBGA, AGCDEFBA

# second iteration
start: ADCBEFGA
next: ACDBEFGA, ABCDEFGA, AECBDFGA, AFCBEDGA, AGCBEFDA

/**performs a hill climbing algorithm on the TSP with


* random restart
* @param tour where the best solution will be stored.
* Initially the contents of this array are unspeci ed,
* but it does include enough storage to keep the resulting
* approximated optimal tour.
* @param distances the symmetric distance matrix
* @param restarts the number of times to start at a
* new random solution
* @param seed the seed for the random restart
* @return the cost of the approximated optimal tour
*/
public double getBestTour(int[] tour,
double[][] distances, int restarts,
int seed)
{
//must use random to create new randomly ordered tours
Random random=new Random(seed);

for(int i=0; i<restarts; i++)


{
randomizeTour(tour, random);
//put code here
}

return 0;
}

we would want to check the tness of each of these possibilities and keep the best one. Then reiterate
until none of the next possibilities are better than your current state. We'll want to continually use the same
algorithm for each iteration.
we can switch the second city on the rst iteration, the third on the second, the fourth on the third, etc. but
make sure we loop back around and continue this style of swapping and don't stop when we reach the
end.

0 Comments

Was this answer helpful? 1

0
Up next for you in Computer Science

Question 3: Calendar USE C++ PLEASE


Application (write code in //forward declaring all
c++) In this program, you classes to deal with
will develop a calendar circular dependencies. c…
application that can See more quest
display the full calendar for subjects you s
for any month of any year
and allow the user to add

See answer See answer

Questions viewed by other students

?nformed search method – Hill Climbing Search to solve the 8-queens problem with c++
See answer 100% (1 rating)

please do question a,b,c,d


See answer 100% (1 rating)

Show more 

COMPANY

LEGAL & POLICIES

CHEGG PRODUCTS AND SERVICES


CHEGG NETWORK

CUSTOMER SERVICE

© 2003-2021 Chegg Inc. All rights reserved.

You might also like