Python Forum
I have problem with ACO, I want to always start in the first city and end in the last
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I have problem with ACO, I want to always start in the first city and end in the last
#1
I want to always start with city number: 0(I did it in pos=0) and always end with city number: 9(last city. I have problem with that).
def ac_one(pop):
    lm=10**10
    global fero2
    fero2=np.array([[0. for _ in range(n)] for _ in range(n)])
    for mr in range(pop):
        print()
        print("ant number: ",mr)
        print()
        pos=0
        route=[pos]
        print(pos)
        to_v=[i for i in range(0,pos)]+[i for i in range(pos+1,n)]
        print(to_v)
        
        for k in range(n-1):
            pos=ac_next(pos,to_v)
            route.append(pos)
            to_v.remove(pos)
            print(pos)
            print(to_v)
               
        print(route)
        
        lr=len_path(route)
        print("Current length:",lr)
        if lr<lm:
            lm=lr
            r_opt=route
        print("Shortest length:",lm)    
            
    for i in range(n-1):
        fero2[r_opt[i],r_opt[i+1]]=fero2[r_opt[i],r_opt[i+1]]+sc/lm
        fero2[r_opt[i+1],r_opt[i]]=fero2[r_opt[i+1],r_opt[i]]+sc/lm         
          
    return lm, r_opt
opt=ac_one(3)
[Image: 5vo1i9z96vd61.png?width=296&format=png&a...fc9603879b]
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  naming entities(city abbreviations) tirumalaramakrishna 1 1,234 May-06-2022, 11:22 AM
Last Post: jefsummers
  pytz: get integer utc offset from Olsen region/city h4tt3n 2 5,209 Jul-30-2020, 06:43 AM
Last Post: h4tt3n
  code for finding a cables crossed the bondary of the city spider_pytthon 8 3,542 Dec-24-2019, 07:23 AM
Last Post: spider_pytthon
  Problem: Once I cancel the process my program will start working! Hadad 0 1,642 Jul-24-2019, 04:09 PM
Last Post: Hadad
  How to start with this easy problem? Fran 8 4,143 Sep-11-2018, 09:04 AM
Last Post: Fran
  What's the difference b/w assigning start=None and start=" " Madara 1 2,308 Aug-06-2018, 08:23 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020