Skip to content

Instantly share code, notes, and snippets.

@vappiah
Created March 26, 2022 10:05
Show Gist options
  • Save vappiah/930200b4933fb540053374a589b012ed to your computer and use it in GitHub Desktop.
Save vappiah/930200b4933fb540053374a589b012ed to your computer and use it in GitHub Desktop.
This script finds the the clique with the clique with the largest weight
import matplotlib.pyplot as plt
import numpy as np
import networkx as nx
nodes = ["1", "2", "3", "4", "5"]
P = nx.Graph()
P.add_nodes_from(nodes)
weighted_edges = [
("1", "2", 0.11),
("1", "3", 3.1),
("1", "5", 2.25),
("4", "5", 0.25),
("2", "5", 0.2),
("2", "4", 0.22),
("2", "3", 0.2),
]
P.add_weighted_edges_from(weighted_edges)
#set up the graph layout
pos = nx.spring_layout(P, seed=1) # Add the seed here
labels = nx.get_edge_attributes(P, "weight")
nx.draw(P, pos=pos, with_labels=True) # add the position argument
# get edge labels
edge_labels = dict(
[
(
(u, v),
d["weight"],
)
for u, v, d in P.edges(data=True)
]
)
nx.draw_networkx_edge_labels(P, pos, edge_labels=edge_labels, font_weight="normal")
max_weight_clique=nx.max_weight_clique(P)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment