Python Forum

Full Version: I have problem with ACO, I want to always start in the first city and end in the last
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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]