Implemented basic stuff
This commit is contained in:
parent
88eb6129e0
commit
e8adbeb401
@ -1,9 +1,54 @@
|
|||||||
|
import multiprocessing
|
||||||
import os
|
import os
|
||||||
|
import requests
|
||||||
|
|
||||||
|
|
||||||
|
def worker(outqueue, id):
|
||||||
|
print(f"Process {id} is preparing...")
|
||||||
|
import numpy as np
|
||||||
|
import networkx as nx
|
||||||
|
|
||||||
|
with open("/dkebab/GBA1000.txt") as f:
|
||||||
|
n = int(f.readline()) # pontok száma
|
||||||
|
m = int(f.readline()) # élek száma
|
||||||
|
A = [[0] * n for _ in range(n)] # táblázat, ahol az élek helyén 1 van, ammeg 0
|
||||||
|
for _ in range(m):
|
||||||
|
[u, v] = map(int, f.readline().split())
|
||||||
|
A[u][v] = 1
|
||||||
|
A[v][u] = 1
|
||||||
|
|
||||||
|
input_graph = nx.Graph(np.array(A))
|
||||||
|
|
||||||
|
def max_comp_size(G):
|
||||||
|
return max([len(c) for c in nx.connected_components(G)])
|
||||||
|
|
||||||
|
print(f"Process {id} is working...")
|
||||||
|
while True:
|
||||||
|
del_list = []
|
||||||
|
G = input_graph.copy()
|
||||||
|
target = len(G.nodes) / 2
|
||||||
|
while max_comp_size(G) > target:
|
||||||
|
u = np.random.choice(G.nodes)
|
||||||
|
if u not in del_list:
|
||||||
|
del_list.append(u)
|
||||||
|
G.remove_node(u)
|
||||||
|
|
||||||
|
outqueue.put(del_list)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
for i in range(os.cpu_count()):
|
target_url = os.environ['TARGET_URL']
|
||||||
print(i)
|
multiprocessing.set_start_method('spawn')
|
||||||
|
outqueue = multiprocessing.Queue()
|
||||||
|
processes = []
|
||||||
|
|
||||||
|
for id in range(os.cpu_count()):
|
||||||
|
p = multiprocessing.Process(target=worker, args=(outqueue, id))
|
||||||
|
p.start()
|
||||||
|
processes.append(p)
|
||||||
|
|
||||||
|
while True:
|
||||||
|
result = outqueue.get()
|
||||||
|
requests.post(target_url, json=result)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
Loading…
Reference in New Issue
Block a user