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

Grid Zone #37

Open
6 tasks
SeanMcOwen opened this issue Jul 3, 2024 · 3 comments
Open
6 tasks

Grid Zone #37

SeanMcOwen opened this issue Jul 3, 2024 · 3 comments
Labels

Comments

@SeanMcOwen
Copy link
Collaborator

The grid zone can either be an entity or type

Either way the following would be some of the tasks associated:

  • Define out grid zone as either a type or entity in the math spec
  • Add a global state variable for zones
  • Add implementations of the zones, if it is an entity maybe make a class which gets instantiated
  • Determine if there should be a state preparation function which initializes the zones. If we go with entity representations then it might be nice to consider the nuance of it. For example the parameter could be grid_x and grid_y and the state prep function which then convert these (much more compact) params into the exact entities. This is a minor nuance but it does make it easier in the future to parameter sweep so that we can compare 5x5 grid to 10x10 grid instead of class representation in the params which would be trying to compare list A to list B and probably require post-processing to make a legible version.
  • Determine way to represent the directed graph
  • Consider if it is better to, instead of using a list of zones approach, to have one large entity that acts as the controller for all zones and keeps things like the mapping of weights, etc in it

From the notebook:

  • The city is modeled as a grid of zones, represented as nodes in a directed graph. Roads between zones are represented as edges with associated weights.
  • Each zone tracks the length of its queue, which indicates the congestion level.
@SeanMcOwen SeanMcOwen added the DIPR label Jul 3, 2024
@SeanMcOwen
Copy link
Collaborator Author

Right now after reading the implementation it is probably closest to being Grid as a state variable of one entity which has local state as well as a type of zone, although because it has some state that gets updated I wonder if it should also be an entity in which case the local state for grid would reference the Zone local state such as List[Zone]

@SeanMcOwen
Copy link
Collaborator Author

These MSML issues also may be blocking/I can possibly prioritize when we do this

  1. Entity Implementations MSML#426
  2. Add something that allows global state to reference local states as variables such as doing List[LocalState] MSML#153

If we want to fast track these both it may be worth it for me to do a working session/proposal sheet and get some opinions on what is the cleanest representation

@SeanMcOwen
Copy link
Collaborator Author

SeanMcOwen commented Jul 4, 2024

Code that was in DIPR:

class Grid:
def init(self, width=4, height=4, min_weight=1, max_weight=10, alpha=0.9):
self.width = width
self.height = height
self.min_weight = min_weight
self.max_weight = max_weight
self.alpha = alpha
self.graph = nx.DiGraph()
self.zones = {}
self.queues = defaultdict(int)
self.priorities = defaultdict(int)
self.create_graph()
self.create_zones()
self.precompute_shortest_paths()

  def create_graph(self):
      for i in range(self.width):
          for j in range(self.height):
              self.graph.add_node((i, j))
      for i in range(self.width):
          for j in range(self.height - 1):
              weight_1 = random.randint(self.min_weight, self.max_weight)
              weight_2 = random.randint(self.min_weight, self.max_weight)
              self.graph.add_edge((i, j), (i, j + 1), weight=weight_1)
              self.graph.add_edge((i, j + 1), (i, j), weight=weight_2)
              weight_3 = random.randint(self.min_weight, self.max_weight)
              weight_4 = random.randint(self.min_weight, self.max_weight)
              self.graph.add_edge((j, i), (j + 1, i), weight=weight_3)
              self.graph.add_edge((j + 1, i), (j, i), weight=weight_4)

  def create_zones(self):
      self.zones = {(i, j): Zone(i, j) for i in range(self.width) for j in range(self.height)}

  def precompute_shortest_paths(self):
      self.shortest_paths = dict(nx.all_pairs_dijkstra_path_length(self.graph, weight='weight'))

  def update_priorities(self):
      for node in self.graph.nodes:
          self.priorities[node] = self.alpha * self.priorities[node] + self.queues[node]      

class Zone:
def init(self, x, y):
self.x = x
self.y = y
self.name = f"Zone ({x},{y})"
self.queue_length = 0

  def __str__(self):
      return f"Zone ({self.x},{self.y})"

  def update_queue(self, length):
      self.queue_length = length

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

No branches or pull requests

1 participant