code: def define_sub_network_cycle_constraints( subnetwork, snapshots, passive_branch_p, attribute):
      
  
      sub_network_cycle_constraints = {}
      sub_network_cycle_index = []
  
      matrix = subnetwork.C.tocsc()
      branches = subnetwork.branches()
  
      for col_j in range( matrix.shape[1] ):
          cycle_is = matrix.getcol(col_j).nonzero()[0]
  
          if len(cycle_is) == 0: continue
  
          sub_network_cycle_index.append((subnetwork.name, col_j))
  
  
          branch_idx_attributes = []
  
          for cycle_i in cycle_is:
              branch_idx = branches.index[cycle_i]
              attribute_value = 1e5 * branches.at[ branch_idx, attribute] * subnetwork.C[ cycle_i, col_j]
              branch_idx_attributes.append( (branch_idx, attribute_value))
  
          for snapshot in snapshots:
              expression_list = [ (attribute_value,
                                   passive_branch_p[branch_idx[0], branch_idx[1], snapshot]) for (branch_idx, attribute_value) in branch_idx_attributes]
  
              lhs = LExpression(expression_list)
              sub_network_cycle_constraints[subnetwork.name,col_j,snapshot] = LConstraint(lhs,"==",LExpression())
  
      return( sub_network_cycle_index, sub_network_cycle_constraints)
docs: Constructs cycle_constraints for a particular subnetwork