Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 576317
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:02:04+00:00 2026-05-13T14:02:04+00:00

Guys I have asked this question before but did not receive a single comment

  • 0

Guys I have asked this question before but did not receive a single comment or answer

I want to simulate a search algorithm on a power law graph and want to visually see the algorithm move from one node to another on the graph. How do I do that?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T14:02:04+00:00Added an answer on May 13, 2026 at 2:02 pm

    You can adapt this completely different code I happen to have written for Find the most points enclosed in a fixed size circle 🙂

    The useful bit is:

    It uses the basic windowing system tkinter to create a frame containing a canvas; it then does some algorithm, calling it’s own ‘draw()‘ to change the canvas and then ‘update()‘ to redraw the screen, with a delay. From seeing how easy it is to chart in tkinter, you can perhaps move on to interactive versions etc.

    import random, math, time
    from Tkinter import * # our UI
    
    def sqr(x):
        return x*x
    
    class Point:
        def __init__(self,x,y):
            self.x = float(x)
            self.y = float(y)
            self.left = 0
            self.right = []
        def __repr__(self):
            return "("+str(self.x)+","+str(self.y)+")"
        def distance(self,other):
            return math.sqrt(sqr(self.x-other.x)+sqr(self.y-other.y))
    
    def equidist(left,right,dist):
        u = (right.x-left.x)
        v = (right.y-left.y)
        if 0 != u:
            r = math.sqrt(sqr(dist)-((sqr(u)+sqr(v))/4.))
            theta = math.atan(v/u)
            x = left.x+(u/2)-(r*math.sin(theta))
            if x < left.x:
                x = left.x+(u/2)+(r*math.sin(theta))
                y = left.y+(v/2)-(r*math.cos(theta))
            else:
                y = left.y+(v/2)+(r*math.cos(theta))
        else:
            theta = math.asin(v/(2*dist))
            x = left.x-(dist*math.cos(theta))
            y = left.y + (v/2)
        return Point(x,y)
    
    class Vis:
        def __init__(self):
            self.frame = Frame(root)
            self.canvas = Canvas(self.frame,bg="white",width=width,height=height)
            self.canvas.pack()
            self.frame.pack()
            self.run()
        def run(self):
            self.count_calc0 = 0
            self.count_calc1 = 0
            self.count_calc2 = 0
            self.count_calc3 = 0
            self.count_calc4 = 0
            self.count_calc5 = 0
            self.prev_x = 0
            self.best = -1
            self.best_centre = []
            for self.sweep in xrange(0,len(points)):
                self.count_calc0 += 1
                if len(points[self.sweep].right) <= self.best:
                    break
                self.calc(points[self.sweep])
            self.sweep = len(points) # so that draw() stops highlighting it
            print "BEST",self.best+1, self.best_centre # count left-most point too
            print "counts",self.count_calc0, self.count_calc1,self.count_calc2,self.count_calc3,self.count_calc4,self.count_calc5
            self.draw()
        def calc(self,p):
            for self.right in p.right:
                self.count_calc1 += 1
                if (self.right.left + len(self.right.right)) < self.best:
                    # this can never help us
                    continue
                self.count_calc2 += 1
                self.centre = equidist(p,self.right,radius)
                assert abs(self.centre.distance(p)-self.centre.distance(self.right)) < 1
                count = 0
                for p2 in p.right:
                    self.count_calc3 += 1
                    if self.centre.distance(p2) <= radius:
                        count += 1
                if self.best < count:
                    self.count_calc4 += 4
                    self.best = count
                    self.best_centre = [self.centre]
                elif self.best == count:
                    self.count_calc5 += 5
                    self.best_centre.append(self.centre)
                self.draw()
                self.frame.update()
                time.sleep(0.1)
        def draw(self):
            self.canvas.delete(ALL)
            # draw best circle
            for best in self.best_centre:
                self.canvas.create_oval(best.x-radius,best.y-radius,\
                    best.x+radius+1,best.y+radius+1,fill="red",\
                    outline="red")
            # draw current circle
            if self.sweep < len(points):
                self.canvas.create_oval(self.centre.x-radius,self.centre.y-radius,\
                    self.centre.x+radius+1,self.centre.y+radius+1,fill="pink",\
                    outline="pink")
            # draw all the connections
            for p in points:
                for p2 in p.right:
                    self.canvas.create_line(p.x,p.y,p2.x,p2.y,fill="lightGray")
            # plot visited points
            for i in xrange(0,self.sweep):
                p = points[i]
                self.canvas.create_line(p.x-2,p.y,p.x+3,p.y,fill="blue")
                self.canvas.create_line(p.x,p.y-2,p.x,p.y+3,fill="blue")
            # plot current point
            if self.sweep < len(points):
                p = points[self.sweep]
                self.canvas.create_line(p.x-2,p.y,p.x+3,p.y,fill="red")
                self.canvas.create_line(p.x,p.y-2,p.x,p.y+3,fill="red")
                self.canvas.create_line(p.x,p.y,self.right.x,self.right.y,fill="red")
                self.canvas.create_line(p.x,p.y,self.centre.x,self.centre.y,fill="cyan")
                self.canvas.create_line(self.right.x,self.right.y,self.centre.x,self.centre.y,fill="cyan")
            # plot unvisited points
            for i in xrange(self.sweep+1,len(points)):
                p = points[i]
                self.canvas.create_line(p.x-2,p.y,p.x+3,p.y,fill="green")
                self.canvas.create_line(p.x,p.y-2,p.x,p.y+3,fill="green")
    
    radius = 60
    diameter = radius*2
    width = 800
    height = 600
    
    points = []
    
    # make some points
    for i in xrange(0,100):
        points.append(Point(random.randrange(width),random.randrange(height)))
    
    # sort points for find-the-right sweep
    points.sort(lambda a, b: int(a.x)-int(b.x))
    
    # work out those points to the right of each point
    for i in xrange(0,len(points)):
        p = points[i]
        for j in xrange(i+1,len(points)):
            p2 = points[j]
            if p2.x > (p.x+diameter):
                break
            if (abs(p.y-p2.y) <= diameter) and \
                p.distance(p2) < diameter:
                p.right.append(p2)
                p2.left += 1
    
    # sort points in potential order for sweep, point with most right first
    points.sort(lambda a, b: len(b.right)-len(a.right))
    
    # debug
    for p in points:
        print p, p.left, p.right
    
    # show it
    root = Tk()
    vis = Vis()
    root.mainloop()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question I have asked before and just got answer that there is an
So I asked something similar yesterday and did receive an answer to my question,
Hi guys I wrote this code and i have two errors. Invalid rank specifier:
Problem solved: Thanks guys, see my answer below. I have a website running in
I have a classifieds website, and I just asked a question regarding if I
When reading about SQL Injection and XSS i was wondering if you guys have
How have you guys handled working with jQuery includes <script type=text/javascript src=jquery.js></script> in Asp.Net
Have you guys had any experiences (positive or negative) by placing your source code/solution
Have you guys and gals got any tips or hacks for making the most
Ok guys just a small game: I have some specifications for a project. At

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.