from graphfile import GraphFile


# Load manufacturing paths paths
# ==============================
paths = GraphFile("data/manufacturing_paths.txt").read_paths_with_count()
number_of_manufactured_items = sum(paths.values())

# Load edges
# ==========
edges = GraphFile("data/manufacturing_edges.txt").read_edges_from_file()

# Filter out edges that only serve a handfull of items
# ====================================================
threshold = 0.001 * number_of_manufactured_items
edges_to_remove = [k for k,v in edges.items() if v < threshold]
edges_to_remove = set(edges_to_remove)

# Clean manufacturing paths
# =========================
clean_paths = {}
for k,v in paths.items():
    e = [(i,j) for (i,j) in zip(k, k[1:])]
    e = set(e)
    if len(edges_to_remove.intersection(e)) == 0:
        clean_paths[k] = clean_paths.get(k, 0) + v

# Get clean edges
# ===============
clean_edges = {}
for k,v in clean_paths.items():
    # full_path = "/mnt/irisgpfs/users/yomar/manufacturing_entropy_article/"
    filename_paths = "data/clean_manufacturing_paths.txt"
    # filename_paths = full_path + filename_paths
    filename_edges = "data/clean_manufacturing_edges.txt"
    # filename_edges = full_path + filename_edges
    edges = GraphFile(filename_edges).read_edges_from_file()
    paths = GraphFile(filename_paths).read_paths_with_count()

    # =========================================================================
    # CALCULATE ENTROPY
    # =========================================================================
    if method == 1:
        # Method 1: binary, directed graph with self-loops on all nodes
        # Due to computation issues, this is deployed in an HPC!!!
        # =============================================================
        edges = {k: 1 for k, v in edges.items()}
        G = Graph(edges)

        nodes = G.nodes
        for n in G.nodes:
            G.addEdge(n, n, 1)

        # Check that all edges have a value of 1
        assert len(set(G.edges.values())) == 1

        print("\nNumber of nodes: ", len(G.nodes))
        print("Number of edges: ", len(G.edges.keys()))

        print("Binary, directed graph with self-loops on all nodes\n")
        pool = multiprocessing.Pool()
        start = datetime.datetime.now()
# Yamila Mariel Omar
# Date of original code: 9th February 2021
# Date of code last modification: 9th February 2021

from graphviz import Digraph
import sys
sys.path.append('..')

from graphfile import GraphFile
from graph import Graph

# Load edges
# ==========
filename = "data/F2.txt"
edges = GraphFile(filename).read_edges_from_file()
total_items = sum([v for k, v in edges.items() if "source" in k])
edges = {k: v / total_items for k, v in edges.items()}

G = Graph(edges)

# Get node list
# =============
nodes = G.nodes

# Nodes positions in plot
# =======================
positions = {
    'source': "0,9!",
    '24': "-1,8!",
    '25': "1,8!",
    '26': "-1,7!",
示例#4
0
    # ======================================
    filename_paths = "data/clean_manufacturing_paths.txt"
    filename_edges = "data/clean_manufacturing_edges.txt"
    edges = GraphFile(filename_edges).read_edges_from_file()
    paths = GraphFile(filename_paths).read_paths_with_count()

    # Generate graph from clean edges
    # ===============================
    edges = add_self_loops(paths, edges)
    G = Graph(edges)

    # ==========================================================================
    # Get frequency of n in paths
    # ==========================================================================
    freq_n_in_paths = {n: 0 for n in G.nodes}
    for p, v in paths.items():
        for n in p:
            freq_n_in_paths[n] += v

    number_of_paths = sum(list(paths.values()))
    freq_n_in_paths = {
        k: v / number_of_paths
        for k, v in freq_n_in_paths.items()
    }

    # Make plot
    # =========
    x = list(freq_n_in_paths.keys())
    x.sort()
    freq = [freq_n_in_paths[n] for n in x]