knit_graphs.artin_wale_braids.Loop_Braid_Graph module

Module containing the Loop Braid Graph class.

This module provides the Loop_Braid_Graph class which tracks crossing relationships between loops in cable knitting patterns using a directed graph structure.

class Loop_Braid_Graph[source]

Bases: object

A graph structure that tracks crossing braid edges between loops in cable patterns.

This class maintains a directed graph where nodes are loops and edges represent cable crossings between those loops. It provides methods to add crossings, query crossing relationships, and determine which loops cross with a given loop.

loop_crossing_graph

A NetworkX directed graph storing loop crossing relationships with crossing direction attributes.

Type:

DiGraph

__init__()[source]

Initialize an empty loop braid graph with no crossings.

add_crossing(left_loop, right_loop, crossing_direction)[source]

Add a crossing edge between two loops with the specified crossing direction.

Parameters:
  • left_loop (Loop) – The loop on the left side of the crossing.

  • right_loop (Loop) – The loop on the right side of the crossing.

  • crossing_direction (Crossing_Direction) – The direction of the crossing (over, under, or none) between the loops.

Return type:

None

remove_loop(loop)[source]

Removes any crossings that involve the given loop. :type loop: Loop :param loop: The loop to remove. :type loop: Loop

Return type:

None

__contains__(item)[source]

Check if a loop or loop pair is contained in the braid graph.

Parameters:

item (Loop | tuple[Loop, Loop]) – Either a single loop to check for node membership, or a tuple of loops to check for edge membership.

Returns:

True if the loop is a node in the graph (for single loop) or if there is an edge between the loops (for tuple).

Return type:

bool

left_crossing_loops(left_loop)[source]

Get all loops that cross with the given loop when it is on the left side.

Parameters:

left_loop (Loop) – The loop on the left side of potential crossings.

Returns:

List of loops that this loop crosses over on the right side. Empty list if the loop is not in the graph or has no crossings.

Return type:

list[Loop]

right_crossing_loops(right_loop)[source]

Get all loops that cross with the given loop when it is on the right side.

Parameters:

right_loop (Loop) – The loop on the right side of potential crossings.

Returns:

List of loops that cross this loop from the left side. Empty list if the loop is not in the graph or has no crossings.

Return type:

list[Loop]

get_crossing(left_loop, right_loop)[source]

Get the crossing direction between two loops, creating a no-cross edge if none exists.

If no edge exists between the loops, this method automatically adds a no-crossing edge to maintain consistency in the graph structure.

Parameters:
  • left_loop (Loop) – The loop on the left side of the crossing.

  • right_loop (Loop) – The loop on the right side of the crossing.

Returns:

The crossing direction between the left and right loop. Defaults to No_Cross if no explicit crossing was previously defined.

Return type:

Crossing_Direction