• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Nearest greedy

Nur Azriati Mat

New Member
hello,
i have a coding for nearest greedy but i have a problem.. in this problem the salesman have to start at node 1 and going back to node 1 at last. Before going back to node 1, the salesman have to visit 2.

Example: 1>4>3>5>6>2>1

My problem is i don't know how to code for if i have to visit node 2 before going back to node 1 at the end.Here, i also have attached my excel workbook..

Hopefully, anyone can help me.. Thanks in advance :)
 

Attachments

  • NGM_VBA.xls
    39.5 KB · Views: 8
Hi Nur ,

Is this is a specific requirement , or do you want to extend this to start from any node and end at any node ? What I mean is , will you always want to start at node A , traverse all the nodes , then visit node G before returning to node A ?

Your workbook mentions nodes A , B , C ,... ; does your node 1 in your post correspond to node A in the workbook , node 2 in your post correspond to node G in the workbook ?

Once you have uploaded a file , please make all references to data within the workbook.

Narayan
 
Actually 1>4>3>5>6>2>1 is just an example. Based on my problem, there are 2 condition that have to fulfilled:

i. Start from node A and return back to node A as basic (already done with the code)
ii. Before going back to node A at the end, i have to visit node B (i don't know how to code)
 
Hi Nur ,

If you say that node 1 is A , and node 2 is B , can you specify the entire route that you want the salesman to take ?

At present the route is :

A -> G -> J -> C -> B -> E -> D -> F -> H -> I -> K -> L -> A

Narayan
 
Hi Nur ,

Does this mean that this is a fixed route ? If so , then why do you need VBA ?

If you specify this as the route , then the distances travelled will be known from the table , and the total distance travelled can be obtained. You can use Excel formulae to derive the distances.

Narayan
 
Yes, the problem can be solve using excel formula to obtain the distance. But, this doesn't meet the requirement. my project have to solve the problem by using VBA. The given code is a basic process for nearest greedy which is start from node A and end at node A as basic as i attached before. My problem is i could not meet the 2nd requirement which is have to visit node B before going back to node A.

A -> G -> J -> C -> B -> E -> D -> F -> H -> I -> K -> L -> A (this is for 1st requirement: start and end at node A)

A > G > J > C > E > D > F > H > I > K > L > B >A ( this is the answer for 2nd requirement that i have to fulfilled: must visit node B before returned back to node A)

i don't know how to code in order to get the 2nd answer to meet the requirement.
I hope you can understand my problem.
 
Hi Narayank,

Just wondering, do you use shortest path algorithm from A to B or just basically look for nearest position from A (as long as it is not B), then look for another nearest position and so on.

I always find path finding algorithm interesting.
 
Hi ,

Sorry but the algorithm was already present in the uploaded file ; I have merely changed it so that OP's requirement has been met.

The original algorithm was looking at the nearest neighbour , according to which node B would have been traversed somewhere in the middle of the route ; since OP wanted that node B should be the penultimate node , I included the check ( node <> B ) within the loop ; then cutting the route one short of the final node , which in our case was the starting node A , node B has been inserted along with the distances between the earlier node and node B , and node B and node A.

Narayan
 
Back
Top