Пример #1
0
 def add_wire(self, board, direction, styles=None):
     self._add_path([
         "board %d %s" % (board.id, Diagram.DIRECTION_POSTFIX[direction]),
         "board %d %s" %
         (board.follow_wire(direction).id,
          Diagram.DIRECTION_POSTFIX[topology.opposite(direction)])
     ], styles)
Пример #2
0
def generate_wiring_instructions(boards, socket_names):
	# Instructions for wiring systems up
	
	out = ""
	
	b2c = dict(boards)
	
	wires = []
	for board, source_coord in cabinet_torus:
		for direction in [NORTH, EAST, SOUTH_WEST]:
			target_coord = b2c[board.follow_wire(direction)]
			
			source = tuple(list(source_coord) + [socket_names[direction]])
			target = tuple(list(target_coord) + [socket_names[topology.opposite(direction)]])
			
			# List wires in bottom-left to top-right order
			wires.append(tuple(sorted([source,target])))
	
	# (cabinet,rack) -> [wire,...]
	wires_between_slots = defaultdict(list)
	# (cabinet) -> [wire,...]
	wires_between_racks = defaultdict(list)
	# [wire,...]
	wires_between_cabinets = []
	
	for source, target in wires:
		if source[0:2] == target[0:2]:
			# Same cabinet and rack
			wires_between_slots[(source[0:2])].append((source,target))
		elif source[0] == target[0]:
			# Same cabinet
			wires_between_racks[source[0]].append((source,target))
		else:
			# Different cabinet
			wires_between_cabinets.append((source,target))
	
	# Within-rack wires
	out += r"\subsection{Wires Within Racks}"
	for cabinet_num in range(num_cabinets):
		for rack_num in range(num_racks_per_cabinet):
			out += r"\subsubsection{Cabinet %d, Rack %d}"%(cabinet_num, rack_num)
			out += generate_wiring_list(wires_between_slots[(cabinet_num,rack_num)])
	
	# Within-cabinet wires
	if wires_between_racks:
		out += r"\newpage\subsection{Wires Within Cabinets}"
		for cabinet_num in range(num_cabinets):
			out += r"\subsubsection{Cabinet %d}"%(cabinet_num)
			out += generate_wiring_list(wires_between_racks[(cabinet_num)])
	
	# Global wires
	if wires_between_cabinets:
		out += r"\newpage\subsection{Wires Between Cabinets}"
		out += generate_wiring_list(wires_between_cabinets)
	
	return out
Пример #3
0
def get_relative_wires(boards, direction):
	"""
	Returns a list of (coord, wire_relative_target) tuples where coord is a
	coordinate of a board and wire_relative_target is the coordinate relative to
	coord of the wire going in direction from coord.
	"""
	
	b2c = dict(boards)
	
	out = []
	
	for board, coord in boards:
		out.append((coord, b2c[board.follow_wire(direction)] - coord))
	
	return out
Пример #4
0
def calculate_wire_cabinet_stats(boards):
	"""
	Calculate stats about how often wires leave their own cabinet
	"""
	# Counters
	stats = [
		#              In-Rack  Between Racks  Between Cabinets
		(NORTH      , [0,       0,             0]),
		(EAST       , [0,       0,             0]),
		(SOUTH_WEST , [0,       0,             0]),
	]
	
	b2c = dict(boards)
	
	for board, coord in cabinet_torus:
		for direction, counters in stats:
			source = b2c[board]
			target = b2c[board.follow_wire(direction)]
			cabinets, racks, slots = abs(target - source)
			
			if cabinets > 0:
				counters[0] += 1
			elif racks > 0:
				counters[1] += 1
			elif slots > 0:
				counters[2] += 1
			else:
				assert(False)
	
	wire_cabinet_stats = "\n".join(
		"%s & %d & %d & %d & %d \\\\"%(
			DIRECTION_NAMES[direction],
			sum(counters),
			counters[2], counters[1], counters[0],
		)
		for direction, counters in stats
	)
		
	total_wire_cabinet_stats = "Total & %d & %d & %d & %d \\\\\n"%(
			sum(sum(counters) for (d,counters) in stats),
			sum(counters[2] for (d,counters) in stats),
			sum(counters[1] for (d,counters) in stats),
			sum(counters[0] for (d,counters) in stats),
		)
	
	return wire_cabinet_stats, total_wire_cabinet_stats
Пример #5
0
    def add_curved_wire(self, board, direction, styles=None):
        offset = {
            topology.NORTH: (0, 1, 0),
            topology.SOUTH: (0, -1, 0),
            topology.NORTH_EAST: (0, 0, -1),
            topology.SOUTH_WEST: (0, 0, 1),
            topology.EAST: (1, 0, 0),
            topology.WEST: (-1, 0, 0),
        }[direction]
        self.path_definitions += r"""
			\draw [%s] [hexagon coords]
				(%s) ..
				  controls +(%d,%d,%d)
				       and +(%d,%d,%d)
				.. (%s)
				;
		""" % (",".join(styles), "board %d %s" %
         (board.id, Diagram.DIRECTION_POSTFIX[direction]), offset[0],
         offset[1], offset[2], -offset[0], -offset[1], -offset[2],
         "board %d %s" %
         (board.follow_wire(direction).id,
          Diagram.DIRECTION_POSTFIX[topology.opposite(direction)])) + "\n"
Пример #6
0
import diagram

from model import board
from model import transforms
from model import topology

d = diagram.Diagram()

# Create a small system of boards on a hexagonal coordinate system
boards = board.create_torus(4,4)

# Create a dictionary which maps boards to coordinates to use for labelling
# boards in the diagram.
board2coord = dict(boards)

# Draw the boards on the diagram as a hexagons
for board, coords in boards:
	d.add_board_hexagon(board, coords)
	
	# Draw only long wires
	for direction, colour in ( (topology.NORTH,      "red")
	                         , (topology.NORTH_EAST, "green")
	                         , (topology.EAST,       "blue")):
		if sum(map(abs, board2coord[board.follow_wire(direction)] - board2coord[board])) > 2:
			d.add_wire(board, direction, [colour])

# Output the TikZ code for the diagram
print r"\begin{tikzpicture}[thick]"
print d.get_tikz()
print r"\end{tikzpicture}"
Пример #7
0
from model import transforms
from model import topology

d = diagram.Diagram()

# Create a small system of boards on a hexagonal coordinate system
boards = board.create_torus(4, 4)

# Create a dictionary which maps boards to coordinates to use for labelling
# boards in the diagram.
board2coord = dict(boards)

# Draw the boards on the diagram as a hexagons
for board, coords in boards:
    d.add_board_hexagon(board, coords)

    # Draw only long wires
    for direction, colour in ((topology.NORTH, "red"),
                              (topology.NORTH_EAST, "green"), (topology.EAST,
                                                               "blue")):
        if sum(
                map(
                    abs, board2coord[board.follow_wire(direction)] -
                    board2coord[board])) > 2:
            d.add_wire(board, direction, [colour])

# Output the TikZ code for the diagram
print r"\begin{tikzpicture}[thick]"
print d.get_tikz()
print r"\end{tikzpicture}"