Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: regarding the Frontier object #2

Open
BradKML opened this issue Apr 7, 2021 · 1 comment
Open

Question: regarding the Frontier object #2

BradKML opened this issue Apr 7, 2021 · 1 comment

Comments

@BradKML
Copy link

BradKML commented Apr 7, 2021

  1. How are the "internal" and "perimeter" used?
  2. How does one do a BFS with multiple users as the source nodes, but no end nodes to speak of? How does one prevent getting the same data of user Z twice from Twitter when users X and Y both follow user Z?
  3. Tweepy's Authorization does not have to be this complex https://docs.tweepy.org/en/latest/auth_tutorial.html
@BradKML
Copy link
Author

BradKML commented Apr 13, 2021

Requesting code checks for this object

import typing
from typing import List # can't do List[UserType] ATM

UserType = [int, str]

class MultiFront():
    
    def __init__(self, sources:List[int], expander):
        
        self.sources = sources # list of nodes
        self.expander = expander # expansion function, based on API
        
        self.frontlines = {user: Frontier(user, lambda n: self.sus_expander(n)) for user in sources}
        self.node_table = {} # needed to prevent repeated API calls
        
        self.counter = 0

    def sus_expander(self,user:UserType):
        if user in self.node_table:
            return self.node_table[user] # dump to the saved API data
        else:
            expansion_result = self.expander(user) # get the API data
            self.node_table[user] = expansion_result # save the downloaded API call
            return expansion_result
    
    def expand_perimeter(self):
        # expand for each frontier
        self.counter += 1 # needed for the addition of new users
        return set().union(*[self.frontlines[user].expand_perimeter() for user in self.frontlines])
    
    def is_on_perimeter(self, user_id:UserType):
        # checks all perimeters in each frontier
        return set().union(*[self.frontlines[user].is_on_perimeter(user_id) for user in self.frontlines])
    
    def covered_all(self):
        # will return 0 if all nodes are covered
        return sum([self.frontlines[user].covered_all() for user in self.frontlines])

    def get_distance(self, user_id:UserType):
        # gets the shortest distance between n and the source node
        return min([self.frontlines[user].get_parent(user_id) for user in self.frontlines])
    
    def add_user(self, source):
        # needed for adding new BFS items
        self.sources += [source]
        self.frontliners[source] = Frontier(source, self.sus_expander)
        for i in range(counter):
            self.frontliners[source].expand_perimeter()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant