Last active
January 19, 2023 09:00
-
-
Save jaromil/e1e34b9407910501edaff7413bfd6fc3 to your computer and use it in GitHub Desktop.
REA graph dataset generator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import networkx as nx | |
import random | |
# Set the number of resources, events, and agents | |
num_resources = 80 | |
num_events = 30 | |
num_agents = 10 | |
# Initialize the graph | |
G = nx.Graph() | |
# Add the nodes to the graph, representing resources, events, and agents | |
G.add_nodes_from(["resource_{}".format(i) for i in range(num_resources)]) | |
G.add_nodes_from(["event_{}".format(i) for i in range(num_events)]) | |
G.add_nodes_from(["agent_{}".format(i) for i in range(num_agents)]) | |
# Generate random edges between resources and events, indicating that the resource is used in the event | |
for i in range(num_resources): | |
for j in range(num_events): | |
if random.random() < 0.5: # Set the probability of an edge being added | |
G.add_edge("resource_{}".format(i), "event_{}".format(j)) | |
# Generate random edges between events and agents, indicating that the agent is involved in the event | |
for i in range(num_events): | |
for j in range(num_agents): | |
if random.random() < 0.5: # Set the probability of an edge being added | |
G.add_edge("event_{}".format(i), "agent_{}".format(j)) | |
# Print out the number of nodes and edges in the graph | |
print("Number of nodes: {}".format(G.number_of_nodes())) | |
print("Number of edges: {}".format(G.number_of_edges())) | |
# nx.draw(G) | |
#nx.drawing.write_dot(G, "example.dot") | |
nx.drawing.nx_pydot.write_dot(G, "example.dot") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment