Giter Club home page Giter Club logo

Comments (4)

rhgrant10 avatar rhgrant10 commented on June 7, 2024

Sorry it has taken me so long to get back to you. An answer may not even be relevant for you at this point. Regardless, I'm not sure I understand your concern. The tour found by the ant is a closed loop so the starting coordinate seems irrelevant to me... am I missing something?

from acopy.

rhgrant10 avatar rhgrant10 commented on June 7, 2024

I'm closing this ticket for now but please feel free to re-engage on this issue.

from acopy.

shubhamwaghe avatar shubhamwaghe commented on June 7, 2024

Sure it can be closed. Back then, I was trying to solve a problem which had an analogy with TSP. I was given a starting node and had to travel all cities without returning to the starting city (Not a closed a loop like TSP) I was exploring if applying Ant Colony to my problem could be of any help. Thanks!

from acopy.

Amalgamator avatar Amalgamator commented on June 7, 2024

Actually, the pants library (former) had a nodes list and the route would always start on the node you listed first, if I remember correctly.

Here's the relevant code I used/wrote for 3D TSP:

import pants
import math

from waypoints import waypoints
#   waypoints = {"name": (x,y,z),"anothername": (x,y,z)}

nodes = []
for key, value in waypoints.items():
    nodes.append(value)

nodecount = len(nodes)

print(str(nodecount), "nodes, finding solutions")
print("...")


def euclidean2d(a, b):
    return math.sqrt(pow(a[1] - b[1], 2) + pow(a[0] - b[0], 2))


def euclidean3d(a, b):
    return math.sqrt(pow(a[1] - b[1], 2) + pow(a[0] - b[0], 2) + pow(a[2] - b[2], 2))


if len(nodes[1]) > 2:
    world = pants.World(nodes, euclidean3d)
else:
    world = pants.World(nodes, euclidean2d)

solver = pants.Solver(alpha=0.886,
                      beta=10,
                      rho=0.6,
                      elite=0.286,
                      limit=100000,
                      ant_count=nodecount,
                      Q=math.sqrt(nodecount))

solutions = solver.solutions(world)

for solution in solutions:
    j += 1
    assert solution.distance < best
    best = solution.distance

    pilgrimage = []
    for i in solution.tour:
        pilgrimage.append(list(waypoints.keys())[list(waypoints.values()).index(i)])
    # more case-specific code I won't show
for point in pilgrimage:
    print(point)

from acopy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.