A practical Network Coding and Routing Scheme based on Maximum Flow Combination



Download 1.23 Mb.
Page13/19
Date02.05.2018
Size1.23 Mb.
#47331
1   ...   9   10   11   12   13   14   15   16   ...   19

Flow Chart of Program


The proposed approach is performed by a set of algorithms which are implemented in a program. The program loads the input file and constructs a coding and routing scheme for the network corresponding to the input file. The program also provides coding node number and link number as well as other statistics. The work flow of the program is shown in Figure 19..



  1. Work Flow Chart of Implementation
    1. Code Examples

      1. Codes for Drawing Figures


The python code for drawing a single max flow is listed below. One directed Dot graph is initialized with pydot module in line 2. One edge is created by specifying two nodes’ name in line 8. From line 9 to 14, the properties of the edge are specified by the “set” methods. Finally, the edge is added to the graph in line 15. Similar, the nodes are added in line 17-23. The jpeg file is created by calling dot program in the end.

  1. def draw_flows(net, flow, flow_index, n):

  1. # initialize graph

  2. graph = pydot.Dot(graph_type='digraph')

  3. # add edges

  4. for i in range(n):

  5. for j in range(n):

  6. if net[i][j] > 0:

  7. edge=pydot.Edge(str(i), str(j))

  8. edge.set_colorscheme(colorscheme)

  9. edge.set_style("bold")

  10. edge.set_fontname(edge_font_name)

  11. edge.set_label(str(flow[i][j]))

  12. if flow[i][j] > 0:

  13. edge.set_color(str(flow_index+1))

  14. graph.add_edge(edge)

  15. # Add nodes

  16. for i in range(n):

  17. node = pydot.Node(str(i))

  18. node.set_shape("doublecircle")

  19. node.set_style("filled")

  20. node.set_colorscheme(colorscheme)

  21. node.set_color(str(T.index(i)+1))

  22. graph.add_node(node)

  23. graph.write_jpeg('output.jpg', prog='dot')
      1. Code for Topological Sorting


In the implementation of the topological sort, there is one new array D introduced to maintain the in degree for each node. Initially, D[i] is the total number of incoming edges of node i. During the sort progress, when edge > is removed from the graph, the in degree for node j i.e. D[j] is to deduct by one. To check if one node i has no incoming edge, check if D[i] equals to 0, e.g. line 21.


  1. def topologicial_sorting(graph):

  1. global s, n

  2. # Empty list that will contain the sorted elements

  3. L = []

  4. # Set of all nodes with no incoming edges

  5. S =[s]

  6. # In Degree of each node

  7. D = [0 for i in range(n)]

  8. for i in range(n):

  9. for j in range(n):

  10. if graph[i][j]:

  11. D[j] += 1

  12. # Topologicial sort

  13. while S:

  14. i = S.pop(0)

  15. L.append(i)

  16. for j in range(n):

  17. if graph[i][j]:

  18. D[j] -= 1

  19. # if there is no incoming edge of node j

  20. if D[j]==0:

  21. S.append(j)

  22. if max(D):

  23. print "Warning: this is CYCLIC graph"

  24. exit()

  25. return L


  1. Download 1.23 Mb.

    Share with your friends:
1   ...   9   10   11   12   13   14   15   16   ...   19




The database is protected by copyright ©ininet.org 2024
send message

    Main page