initial stuff done
This commit is contained in:
parent
84f25c698c
commit
aed7f80c42
11
.drone.yml
Normal file
11
.drone.yml
Normal file
@ -0,0 +1,11 @@
|
||||
kind: pipeline
|
||||
type: docker
|
||||
name: default
|
||||
|
||||
steps:
|
||||
- name: run_tournament
|
||||
image: "python:3.8"
|
||||
commands:
|
||||
- pip3 install -r requirements.txt
|
||||
- python3 destroy_p3.py -g GBA1000.txt > gba1000d.txt
|
||||
- python3 analyse_p3.py -g GBA1000.txt -d gba1000d.txt
|
@ -3,37 +3,35 @@ import networkx as nx
|
||||
import argparse
|
||||
import sys
|
||||
|
||||
parser=argparse.ArgumentParser(description='')
|
||||
parser = argparse.ArgumentParser(description='')
|
||||
parser.add_argument('-g', '--graph', dest='graph', action='store', default=None)
|
||||
parser.add_argument('-d', '--destroy', dest='destroy', action='store', default=None)
|
||||
parser.add_argument('-n', '--node', dest='isnode', action='store_const', const=False, default = True)
|
||||
args=parser.parse_args()
|
||||
parser.add_argument('-n', '--node', dest='isnode', action='store_const', const=False, default=True)
|
||||
args = parser.parse_args()
|
||||
|
||||
if not args.graph or not args.destroy:
|
||||
print >> sys.stderr, 'need graph and destroylist as argument -g and/or -m'
|
||||
exit()
|
||||
sys.stderr.write('need graph and destroylist as argument -g and/or -m')
|
||||
exit(1)
|
||||
|
||||
D=[]
|
||||
D = []
|
||||
with open(args.destroy) as inf:
|
||||
for line in inf:
|
||||
D.append(int(line))
|
||||
|
||||
|
||||
|
||||
with open(args.graph) as ing:
|
||||
n=int(ing.readline())
|
||||
m=int(ing.readline())
|
||||
A=[[0]*n for _ in range(n)]
|
||||
n = int(ing.readline())
|
||||
m = int(ing.readline())
|
||||
A = [[0] * n for _ in range(n)]
|
||||
for _ in range(m):
|
||||
if not args.isnode:
|
||||
if _ in D:
|
||||
continue
|
||||
[u,v]=map(int, ing.readline().split())
|
||||
[u, v] = map(int, ing.readline().split())
|
||||
if args.isnode:
|
||||
if u in D or v in D:
|
||||
continue
|
||||
A[u][v]=1
|
||||
A[v][u]=1
|
||||
G=nx.Graph(np.array(A))
|
||||
A[u][v] = 1
|
||||
A[v][u] = 1
|
||||
G = nx.Graph(np.array(A))
|
||||
|
||||
print (len(D), [len(c) for c in sorted(nx.connected_components(G), key=len, reverse=True)] )
|
||||
print(len(D), [len(c) for c in sorted(nx.connected_components(G), key=len, reverse=True)])
|
||||
|
@ -2,40 +2,43 @@ import numpy as np
|
||||
import networkx as nx
|
||||
import argparse
|
||||
|
||||
parser=argparse.ArgumentParser(description='')
|
||||
parser = argparse.ArgumentParser(description='')
|
||||
parser.add_argument('-g', '--graph', dest='graph', action='store', default=None)
|
||||
args=parser.parse_args()
|
||||
args = parser.parse_args()
|
||||
|
||||
if not args.graph:
|
||||
print ("need a graph as input")
|
||||
print("need a graph as input")
|
||||
exit()
|
||||
|
||||
|
||||
def read_graph(graph_file):
|
||||
with open(graph_file) as f:
|
||||
n=int(f.readline())
|
||||
m=int(f.readline())
|
||||
A=[[0]*n for _ in range(n)]
|
||||
n = int(f.readline())
|
||||
m = int(f.readline())
|
||||
A = [[0] * n for _ in range(n)]
|
||||
for _ in range(m):
|
||||
[u,v]=map(int, f.readline().split())
|
||||
A[u][v]=1
|
||||
A[v][u]=1
|
||||
G=nx.Graph(np.array(A))
|
||||
[u, v] = map(int, f.readline().split())
|
||||
A[u][v] = 1
|
||||
A[v][u] = 1
|
||||
G = nx.Graph(np.array(A))
|
||||
return G
|
||||
|
||||
|
||||
def max_comp_size(G):
|
||||
return max([len(c) for c in nx.connected_components(G)])
|
||||
|
||||
del_list=[]
|
||||
G=read_graph(args.graph)
|
||||
n=len(G.nodes)
|
||||
while max_comp_size(G) > n/2:
|
||||
u=np.random.choice(G.nodes)
|
||||
|
||||
del_list = []
|
||||
G = read_graph(args.graph)
|
||||
n = len(G.nodes)
|
||||
while max_comp_size(G) > n / 2:
|
||||
u = np.random.choice(G.nodes)
|
||||
if u not in del_list:
|
||||
del_list.append(u)
|
||||
G.remove_node(u)
|
||||
|
||||
#print len(del_list), del_list
|
||||
# print len(del_list), del_list
|
||||
|
||||
|
||||
for u in del_list:
|
||||
print (u)
|
||||
print(u)
|
||||
|
2
requirements.txt
Normal file
2
requirements.txt
Normal file
@ -0,0 +1,2 @@
|
||||
numpy
|
||||
networkx
|
Loading…
Reference in New Issue
Block a user