def run(N, A, Mg, Mb, Mt, S): nseed(S) rseed(S) grafo = ugraph(N) grafo.addedges(Mg+Mb+Mt) grafo.shuffle() #Attrazioni attr = sample(xrange(1, N), A) #Lista degli archi archi = list(grafo) shuffle(archi) #Collegamenti gratuiti gratis = archi[:Mg] archi = archi[Mg:] shuffle(archi) #Collegamenti bus bus = archi[:Mb] archi = archi[Mb:] shuffle(archi) #Collegamenti traghetto trag = archi del archi print N, A, Mg, Mb, Mt for x in attr: print x for x in gratis: print x[0], x[1] for x in bus: print x[0], x[1] for x in trag: print x[0], x[1]
def run(N, M, P, Q, C, S): global randseq nseed(S) rseed(S) last = 0 randseq = [] for i in xrange(M + 1): last += randint(1, 10) randseq += [last] shuffle(randseq) #print N, M, P, Q, C, S origM = M M -= 2 * (P + Q) e = eso(M, P, Q) seqs = [flatten(e)] for i in xrange(N - 1): if randint(0, N) < C: e = eso(M, P, Q) else: e = gen_equiv(e) seqs += [flatten(e)] seqs = list(set(seqs)) shuffle(seqs) print len(seqs), origM for i in xrange(len(seqs)): print "%s" % seqs[i]
def run(N, S, M, A): nseed(S) rseed(S) print N # Decide quali elementi saranno presi, in modo che 1 sia nel # periodo o nell'antiperiodo numeri = range(1, N) shuffle(numeri) numeri = [0] + numeri # Crea un array di base che contiene numeri brutti per le # posizioni che non saranno mai raggiunte salti = [] for i in xrange(N): salti.append(randint(0, N - 1)) # Modifica alcuni numeri in modo che venga compiuto il percorso # voluto for i in xrange(A + M - 1): dist = numeri[i + 1] - numeri[i] if dist < 0: dist += N salti[numeri[i]] = dist dist = numeri[A] - numeri[A + M - 1] if dist < 0: dist += N salti[numeri[A + M - 1]] = dist print " ".join(map(str, salti))
def __init__(self, *, kernel='RBFKernel', likelihood='GaussianLikelihood', optimizer='Adam', mll='ExactMarginalLogLikelihood', ard_option=True, ker_conf=dict(), opt_conf=dict(), mll_conf=dict(), random_state=None): if isinstance(random_state, int): seed(random_state) nseed(random_state) manual_seed(random_state) self.device = check_device() self._kernel = kernel self._likelihood = likelihood self._optimizer = optimizer self._mll = mll self.ard_option = ard_option self.epoch = 0 self.model = None # 空のmodelを作成しないとloadできない self.mll = None # 空のmodelを作成しないとloadできない self.optimizer = None # 空のmodelを作成しないとloadできない self._ker_conf = ker_conf self._opt_conf = opt_conf self._mll_conf = mll_conf self.loss = []
def run(N, A, Mg, Mb, Mt, S): nseed(S) rseed(S) grafo = ugraph(N) grafo.addedges(Mg + Mb + Mt) grafo.shuffle() #Attrazioni attr = sample(xrange(1, N), A) #Lista degli archi archi = list(grafo) shuffle(archi) #Collegamenti gratuiti gratis = archi[:Mg] archi = archi[Mg:] shuffle(archi) #Collegamenti bus bus = archi[:Mb] archi = archi[Mb:] shuffle(archi) #Collegamenti traghetto trag = archi del archi print N, A, Mg, Mb, Mt for x in attr: print x for x in gratis: print x[0], x[1] for x in bus: print x[0], x[1] for x in trag: print x[0], x[1]
def run(N, ST, D, S): nseed(S) rseed(S) transitions = [] characters = [0 for _ in xrange(N)] for i in xrange(N - 1, 0, -1): min_delta = -i max_delta = N - 1 - i good_characters = [] for j, t in enumerate(transitions): if min(t) >= min_delta and max(t) <= max_delta: good_characters += [j] choice = randint(0, len(good_characters) + 1) if choice == len(good_characters): # Aggiungi un nuovo elemento. transitions.append([ randint(max(min_delta, -D), min(max_delta, D)) for _ in xrange(ST) ]) characters[i] = len(transitions) - 1 else: characters[i] = good_characters[choice] characters[0] = randint(0, len(transitions)) C = len(transitions) print N, ST, C for cur_st in range(0, ST): for cur_c in range(0, C): print cur_st, cur_c, randint(0, ST), transitions[cur_c][cur_st] for i in xrange(0, N): print characters[i]
def run_hard(N, M, X0, X1, P, Seed): """ N: numero segmenti M: numero fontane X0: inizio linea X1: fine linea P: lunghezza percentuale del salto """ nseed(Seed) rseed(Seed) fountains, segments = line_test(N/3, M/3, X0, X1, randbetween(X0, X1), randbetween(1, MAXX), P) fountains2, segments2 = line_test(N/3-1, M/3, X0, X1, segments[-1][0], randbetween(1, MAXX), P) fountains3, segments3 = line_test(N/3-1, M/3, X0, X1, segments2[-1][0], randbetween(1, MAXX), P) F = fountains|fountains2|fountains3 S = segments+segments2+segments3 print len(S)-1, len(F) for s in S: print s[0], s[1] for f in F: print f[0], f[1]
def run(N, M, S): nseed(S) rseed(S) edges = [] start = 0 cur = start # Inizia con un super-ciclo, tanto per farlo connesso for i in xrange(0, N): edges.append((i, (i + 1) % N)) # E poi tutto il resto, a caso for i in xrange(N, M - 1): next = randrange(0, N) while next == cur: next = randrange(0, N) edges.append((cur, next)) cur = next edges.append((cur, 0)) # Genera una permutazione dei vertici perm = range(N) shuffle(perm) print N, M for edge in edges: print perm[edge[0]], perm[edge[1]]
def run_line(N, M, X0, X1, P, Seed): """ N: numero segmenti M: numero fontane X0: inizio linea X1: fine linea P: lunghezza percentuale del salto """ nseed(Seed) rseed(Seed) y = randbetween(1, MAXX) fountains = set((randbetween(X0, X1), y) for i in xrange(M)) while len(fountains)<M: fountains |= set((randbetween(X0, X1), y) for i in xrange(M-len(fountains))) print N, M xi = randbetween(X0, X1) print xi, y for i in xrange(N): l1 = xi - X0 l2 = X1 - xi f = random() if f < float(l1)/(l1+l2): d = int(float(l1 * P)/100) xi = randbetween(X0, xi - d - 1) else: d = int(float(l2 * P)/100) xi = randbetween(X1, xi + d + 1) print xi, y for f in fountains: print f[0], f[1]
def run(N, S, M, A): nseed(S) rseed(S) print N # Decide quali elementi saranno presi, in modo che 1 sia nel # periodo o nell'antiperiodo numeri = range(1, N) shuffle(numeri) numeri = [0] + numeri # Crea un array di base che contiene numeri brutti per le # posizioni che non saranno mai raggiunte salti = [] for i in xrange(N): salti.append(randint(0, N-1)) # Modifica alcuni numeri in modo che venga compiuto il percorso # voluto for i in xrange(A+M-1): dist = numeri[i+1] - numeri[i] if dist < 0: dist += N salti[numeri[i]] = dist dist = numeri[A] - numeri[A+M-1] if dist < 0: dist += N salti[numeri[A+M-1]] = dist print " ".join(map(str, salti))
def run(N, M, P, Q, C, S): global randseq nseed(S) rseed(S) last = 0 randseq = [] for i in xrange(M+1): last += randint(1,10) randseq += [last] shuffle( randseq ) #print N, M, P, Q, C, S origM = M M -= 2*(P+Q) e = eso(M, P, Q) seqs = [flatten(e)] for i in xrange( N-1 ): if randint(0,N) < C: e = eso(M, P, Q) else: e = gen_equiv( e ) seqs += [flatten(e)] seqs = list(set(seqs)) shuffle( seqs ) print len(seqs), origM for i in xrange(len(seqs)): print "%s" % seqs[i]
def run(N, M, S): nseed(S) rseed(S) edges = set() start = randrange(0, N) cur = start # Inizia con un super-ciclo, tanto per farlo connesso for i in xrange(0, N): edges.add((i, (i+1)%N)) # E poi tutto il resto, a caso for i in xrange(N, M): next = randrange(0, N) while next == cur or is_in(edges, (cur, next)) or (i == M-1 and next == start): next = randrange(0, N) edges.add((cur, next)) cur = next stop = cur # Genera una permutazione dei vertici perm = range(N) shuffle(perm) print N, M, perm[start]+1, perm[stop]+1 for edge in edges: if randint(0, 1) == 0: print perm[edge[0]]+1, perm[edge[1]]+1 else: print perm[edge[1]]+1, perm[edge[0]]+1
def run(N, M, S): nseed(S) rseed(S) edges = set() start = randrange(0, N) cur = start # Inizia con un super-ciclo, tanto per farlo connesso for i in xrange(0, N): edges.add((i, (i + 1) % N)) # E poi tutto il resto, a caso for i in xrange(N, M): next = randrange(0, N) while next == cur or is_in(edges, (cur, next)) or (i == M - 1 and next == start): next = randrange(0, N) edges.add((cur, next)) cur = next stop = cur # Genera una permutazione dei vertici perm = range(N) shuffle(perm) print N, M, perm[start] + 1, perm[stop] + 1 for edge in edges: if randint(0, 1) == 0: print perm[edge[0]] + 1, perm[edge[1]] + 1 else: print perm[edge[1]] + 1, perm[edge[0]] + 1
def run_line(N, M, X0, X1, P, Seed): """ N: numero segmenti M: numero fontane X0: inizio linea X1: fine linea P: lunghezza percentuale del salto """ nseed(Seed) rseed(Seed) y = randbetween(1, MAXX) fountains = set((randbetween(X0, X1), y) for i in xrange(M)) while len(fountains) < M: fountains |= set( (randbetween(X0, X1), y) for i in xrange(M - len(fountains))) print N, M xi = randbetween(X0, X1) print xi, y for i in xrange(N): l1 = xi - X0 l2 = X1 - xi f = random() if f < float(l1) / (l1 + l2): d = int(float(l1 * P) / 100) xi = randbetween(X0, xi - d - 1) else: d = int(float(l2 * P) / 100) xi = randbetween(X1, xi + d + 1) print xi, y for f in fountains: print f[0], f[1]
def run_hard(N, M, X0, X1, P, Seed): """ N: numero segmenti M: numero fontane X0: inizio linea X1: fine linea P: lunghezza percentuale del salto """ nseed(Seed) rseed(Seed) fountains, segments = line_test(N / 3, M / 3, X0, X1, randbetween(X0, X1), randbetween(1, MAXX), P) fountains2, segments2 = line_test(N / 3 - 1, M / 3, X0, X1, segments[-1][0], randbetween(1, MAXX), P) fountains3, segments3 = line_test(N / 3 - 1, M / 3, X0, X1, segments2[-1][0], randbetween(1, MAXX), P) F = fountains | fountains2 | fountains3 S = segments + segments2 + segments3 print len(S) - 1, len(F) for s in S: print s[0], s[1] for f in F: print f[0], f[1]
def run_random(N, S): """Genera una stringa completamente casuale. """ nseed(S) rseed(S) print N print "".join(map(lambda x: choice("qwertyuiopasdfghjklzxcvbnm"), range(N)))
def run(N, M, T, S): nseed(S) rseed(S) if T == 0: g = graph.dgraph(N) else: g = graph.dag(N) g.addedges(M) g.shuffle() print g
def run(N, S, P, T, X, Y, K, Seed): nseed(Seed) rseed(Seed) piano_stazioni = [randint(N) for i in xrange(P)] piano_stazioni.sort() piano_stazioni.reverse() stazioni=set() rect=[randint(X)+1,randint(X-1)+1,randint(Y)+1,randint(Y-1)+1] if rect[1] >= rect[0]: rect[1] += 1 if rect[3] >= rect[2]: rect[3] += 1 new=[randint(X)+1,randint(Y)+1] if K == 2: new=[rect[0],rect[2]] direction = randint(2) vertices = [[new[0], new[1]]] for i in xrange(N): old=list(new) direction = direction if (randint(4) == 0 and K != 2) else 1-direction if direction == 0: new[0]=randcentered(1,X,old[0] + (2*randint(2)-1)*(T*P/N)) if old[0] <= new[0]: new[0] += 1 if K == 2: new[0] = rect[0] if old[0] == rect[1] else rect[1] else: new[1]=randcentered(1,Y,old[1] + (2*randint(2)-1)*(T*P/N)) if old[1] <= new[1]: new[1] += 1 if K == 2: new[1] = rect[2] if old[1] == rect[3] else rect[3] vertices += [[ new[0], new[1]]] while (len(piano_stazioni) > 0 and piano_stazioni[-1] == i): piano_stazioni.pop() stazione_corrente = (randbetween(old[0],new[0]),randbetween(old[1],new[1])) for r in xrange(TRIES): if stazione_corrente in stazioni: stazione_corrente = (randbetween(old[0],new[0]),randbetween(old[1],new[1])) stazioni.add(stazione_corrente) for i in xrange(S-len(stazioni)): stazione_corrente = (randint(X)+1,randint(Y)+1) for r in xrange(TRIES): if stazione_corrente in stazioni: stazione_corrente = (randint(X)+1,randint(Y)+1) stazioni.add(stazione_corrente) stazioni = list(stazioni) print N, len(stazioni) for v in vertices: print v[0], v[1] shuffle(stazioni) for s in stazioni: print s[0], s[1]
def run(N, M, S): nseed(S) rseed(S) print N, M partenza=range(1,N+1) shuffle(partenza) for i in partenza: print i for i in range(M): idx=randint(1,N) print partenza[idx], partenza[idx-1] t=partenza[idx]; partenza[idx]=partenza[idx-1] partenza[idx-1]=t
def run(K, N, C, S): nseed(S) rseed(S) print K print N l = genera(0, K, C) l1 = [] for i in xrange(N-C): j = randint(0, len(l)) l1 += [genint(l[j][0], l[j][1]+1)] l = l+l1 shuffle(l) for x, y in l: print x, y
def run(K, N, C, S): nseed(S) rseed(S) print K print N l = genera(0, K, C) l1 = [] for i in xrange(N - C): j = randint(0, len(l)) l1 += [genint(l[j][0], l[j][1] + 1)] l = l + l1 shuffle(l) for x, y in l: print x, y
def run(N, M, S): nseed(S) rseed(S) print N, M partenza = range(1, N + 1) shuffle(partenza) for i in partenza: print i for i in range(M): idx = randint(1, N) print partenza[idx], partenza[idx - 1] t = partenza[idx] partenza[idx] = partenza[idx - 1] partenza[idx - 1] = t
def run(T, K, N, C, S): nseed(S); rseed(S) print(T) print(K) print(N) if C > 0: l = covering_family(0,K,N,C) else: l = covering_family(0, K//2-randint(K//5), N//2, max(1,N//4)) l += covering_family(K//2+randint(K//5),K,(N+1)//2,max(1,N//4)) shuffle(l) assert len(l) == N for x, y in l: assert 0 <= x <= y < K print(x, y)
def __init__(self): """ Initializes the class. """ self.Helpers = Helpers("Data", False) self.dim = self.Helpers.confs["qnn"]["data"]["dim"] self.dir_train = self.Helpers.confs["qnn"]["data"]["dir_train"] self.seed = self.Helpers.confs["qnn"]["data"]["seed"] nseed(self.seed) rseed(self.seed) self.data = [] self.labels = [] self.paths = [] self.Helpers.logger.info("Data Helper Class initialization complete.")
def color_structures(fruiting_structures, mtg, scene): import matplotlib.pyplot as plt from openalea.plantgl.all import Material, Shape from random import randint, seed from numpy.random import seed as nseed seed(0) nseed(0) nbcolors = len(sum([inflos for inflos, gus in fruiting_structures], [])) #len(fruiting_structures) _colors = plt.get_cmap('jet', nbcolors) colors = lambda x: _colors(x) structures = dict() idmap = mtg.property('_axial_id') print('determine colors') colindex = determine_colorindex(fruiting_structures, mtg, scene) print(colindex) allinflos = [ lid for vid, lid in list(idmap.items()) if mtg.label(vid) == 'Inflorescence' ] for inflos, gus in fruiting_structures: i = colindex.pop(0) col = colors(i) mat = Material([int(c * 100) for c in col[:3]], 2) for j in inflos: structures[idmap[j]] = mat for j in gus: structures[idmap[j]] = mat print(col, inflos) definfmat = Material((50, 50, 50)) for inf in allinflos: if not inf in structures: structures[inf] = definfmat defmat = Material((0, 0, 0)) print('compute colored scene') nscene = Scene([ Shape(sh.geometry, structures.get(sh.id, defmat), sh.id, sh.parentId) for sh in scene ]) return nscene Viewer.display(nsc)
def run(N, R, S): nseed(S) rseed(S) print N out = []; new = randint(0,7) for i in range(R): old = new new = randint(0,7) if random() < 0.5: out.append([old,new]) else: out.append([new,old]) for i in range(R+1,N+1): out.append([randint(0,7),randint(0,7)]) shuffle(out) for i in out: print i[0], i[1]
def run(N, M, K, W, S): nseed(S) rseed(S) def wh(): return randint(1,W+1) out = ugraph(N,type='tree',w=wh) out.addedges(M-N+1) out.shuffle() air = sample( range(1,N+1), K ) C = randint(1, K) if len(air) > 1: while air[C] == 1: C = randint(1, K) print N, M, air[C], K for i in range(K): print air[i], print s = split(str(out), '\n') print join(s[1:-1], '\n')
def run_con_fibstr_cattiva(N, S): """Genera una stringa di Fibonacci e ci mette attorno roba casuale usando gli stessi due simboli. """ nseed(S) rseed(S) print N alphabet = set("qwertyuiopasdfghjklzxcvbnm") x = choice(list(alphabet)) alphabet.remove(x) y = choice(list(alphabet)) fibs = fibonacci(N) fiblen = randrange(3, len(fibs)) before = randint(0, N - fibs[fiblen]) after = N - fibs[fiblen] - before print "".join(map(lambda z: choice([x, y]), range(before))) + \ genera_fibstr(x, y, fiblen) + \ "".join(map(lambda z: choice([x, y]), range(after)))
def run_con_fibstr_cattiva(N, S): """Genera una stringa di Fibonacci e ci mette attorno roba casuale usando gli stessi due simboli. """ nseed(S) rseed(S) print N alphabet = set("qwertyuiopasdfghjklzxcvbnm") x = choice(list(alphabet)) alphabet.remove(x) y = choice(list(alphabet)) fibs = fibonacci(N) fiblen = randrange(3, len(fibs)) before = randint(0, N-fibs[fiblen]) after = N-fibs[fiblen]-before print "".join(map(lambda z: choice([x, y]), range(before))) + \ genera_fibstr(x, y, fiblen) + \ "".join(map(lambda z: choice([x, y]), range(after)))
def run(N, M, K, W, S): nseed(S) rseed(S) def wh(): return randint(1, W + 1) out = ugraph(N, type='tree', w=wh) out.addedges(M - N + 1) out.shuffle() air = sample(range(1, N + 1), K) C = randint(1, K) if len(air) > 1: while air[C] == 1: C = randint(1, K) print N, M, air[C], K for i in range(K): print air[i], print s = split(str(out), '\n') print join(s[1:-1], '\n')
def run(N, L, S): nseed(S) rseed(S) out = [] #Numero di indicazioni per ogni nazione indic_nazioni = list(multinomial(L - N, [1. / N] * N)) for i in range(len(indic_nazioni)): indic_nazioni[i] += 1 #Numero di ragazzi in ogni nazione ragazzi = [0] * N for i in range(N): for j in range(indic_nazioni[i]): temp = randint(1, MAXR / indic_nazioni[i]) ragazzi[i] += temp out.append("{0} {1}".format(i, temp if random() > .93 else temp - 1)) shuffle(out) print N, L for x in ragazzi: print x for x in out: print x
def run(N, L, S): nseed(S) rseed(S) risolvi = random() > 0.5 print "risolvi:", risolvi print N, L out = [] #Numero di indicazioni per ogni nazione indic_nazioni = list(multinomial(L-N, [1./N]*N)) for i in range(len(indic_nazioni)): indic_nazioni[i] += 1 #Numero di ragazzi in ogni nazione ragazzi = [0]*N for i in range(N): for j in range(indic_nazioni[i]): temp = randint(1, MAXR/indic_nazioni[i]); ragazzi[i] += temp out.append("{0} {1}".format(i, temp if (risolvi or (random() > .85)) else temp-1)) shuffle(out) for x in ragazzi: print x for x in out: print x
def run(R, C, S): nseed(S) rseed(S) #True se la parola e' presente risolvi = random() > 0.5 #La matrice con le lettere matr = [] for i in xrange(R): temp = [] for j in xrange(C): temp.append(choice(uppercase)) matr.append(temp) lung_parola = randint((R+C)/10+2, R+C if risolvi else (R+C)/2) parola = "" posr, posc = 0, 0 for i in xrange(lung_parola): parola += matr[posr][posc] if random() > 0.5: if posr < R-1: posr += 1 else: posc += 1 else: if posc < C-1: posc += 1 else: posr += 1 if not risolvi: for i in xrange(randint(0, (R+C)/2-2)): parola += choice(uppercase) print parola for i in xrange(R): temp = "" for j in xrange(C): temp += matr[i][j] print temp
def run(R, C, T, S): nseed(S) rseed(S) #La matrice con le lettere matr = [] for i in xrange(R): temp = [] for j in xrange(C): temp.append(choice(uppercase)) matr.append(temp) lung_parola = randint((R + C) / 10 + 2, R + C if T == 1 else (R + C) / 2) parola = "" posr, posc = 0, 0 for i in xrange(lung_parola): parola += matr[posr][posc] if random() > 0.5: if posr < R - 1: posr += 1 else: posc += 1 else: if posc < C - 1: posc += 1 else: posr += 1 if T == 0: for i in xrange(randint(0, (R + C) / 2 - 2)): parola += choice(uppercase) print R, C print parola for i in xrange(R): temp = "" for j in xrange(C): temp += matr[i][j] print temp
def run(N, S, P, T, X, Y, K, Seed): nseed(Seed) rseed(Seed) piano_stazioni = [randint(N) for i in xrange(P)] piano_stazioni.sort() piano_stazioni.reverse() stazioni = set() rect = [ randint(X) + 1, randint(X - 1) + 1, randint(Y) + 1, randint(Y - 1) + 1 ] if rect[1] >= rect[0]: rect[1] += 1 if rect[3] >= rect[2]: rect[3] += 1 new = [randint(X) + 1, randint(Y) + 1] if K == 2: new = [rect[0], rect[2]] direction = randint(2) vertices = [[new[0], new[1]]] for i in xrange(N): old = list(new) direction = direction if (randint(4) == 0 and K != 2) else 1 - direction if direction == 0: new[0] = randcentered(1, X, old[0] + (2 * randint(2) - 1) * (T * P / N)) if old[0] <= new[0]: new[0] += 1 if K == 2: new[0] = rect[0] if old[0] == rect[1] else rect[1] else: new[1] = randcentered(1, Y, old[1] + (2 * randint(2) - 1) * (T * P / N)) if old[1] <= new[1]: new[1] += 1 if K == 2: new[1] = rect[2] if old[1] == rect[3] else rect[3] vertices += [[new[0], new[1]]] while (len(piano_stazioni) > 0 and piano_stazioni[-1] == i): piano_stazioni.pop() stazione_corrente = (randbetween(old[0], new[0]), randbetween(old[1], new[1])) for r in xrange(TRIES): if stazione_corrente in stazioni: stazione_corrente = (randbetween(old[0], new[0]), randbetween(old[1], new[1])) stazioni.add(stazione_corrente) for i in xrange(S - len(stazioni)): stazione_corrente = (randint(X) + 1, randint(Y) + 1) for r in xrange(TRIES): if stazione_corrente in stazioni: stazione_corrente = (randint(X) + 1, randint(Y) + 1) stazioni.add(stazione_corrente) stazioni = list(stazioni) print N, len(stazioni) for v in vertices: print v[0], v[1] shuffle(stazioni) for s in stazioni: print s[0], s[1]
Parametri: * N (numero) * S (seed) Constraint: * 1 <= N <= %d """ % (MAXN) def run(N): print N print " ".join(map(str, [randint(-70, 99) for i in xrange(0, N * N)])) if __name__ == "__main__": if len(argv) != 3: print usage exit(1) N, S = map(int, argv[1:]) assert (1 <= N <= MAXN) # su seed non positivo copia un input di esempio dal .tex if S <= 0: print extract_input()[-S], exit(0) nseed(S) rseed(S) run(N)
def run(N, L, S): rseed(S) nseed(S) grafo = [[] for i in range(N)] def cerchizazione(load, nodi): grafo_nodi = [set() for i in nodi] size = len(nodi) for i in range(len(nodi)): grafo_nodi[i].add((i + 1) % len(nodi)) nuovi = int(load * (len(nodi) * len(nodi) - 2 * len(nodi))) while size != nuovi + len(nodi): a = randint(0, len(nodi)) b = randint(0, len(nodi)) while a == b or b in grafo_nodi[a]: a = randint(0, len(nodi)) b = randint(0, len(nodi)) grafo_nodi[a].add(b) size += 1 for nodo in range(len(grafo_nodi)): for vicino in grafo_nodi[nodo]: grafo[nodi[nodo][0]].append(nodi[vicino][1]) #cerchizazione(0.5,[[i,i] for i in range(N)]) nodi = [[i, i] for i in range(N)] shuffle(nodi) while len(nodi) != 1: x = randint(2, len(nodi) + 1) if randint(0, 2): nuovo_nodo = [nodi[len(nodi) - x][0], nodi[len(nodi) - 1][1]] else: nuovo_nodo = nodi[len(nodi) - 1] sub_nodo = [] #print nodi for i in range(x): sub_nodo.append(nodi.pop()) #print x #print sub_nodo #print nuovo_nodo cerchizazione(L, sub_nodo) nodi.insert(0, nuovo_nodo) # filtro per archi doppi out_grafo = [[] for i in range(N)] for nodo in range(len(grafo)): for arco in grafo[nodo]: if nodo in grafo[arco] and nodo > arco: continue out_grafo[nodo].append(arco) M = 0 for x in out_grafo: M += len(x) print "%d %d" % (N, M) start = randint(1, N + 1) end = randint(1, N + 1) while start == end: end = randint(1, N + 1) print "%d %d" % (start, end) for nodo in range(len(out_grafo)): for arco in out_grafo[nodo]: print "%d %d %d" % (nodo + 1, arco + 1, randint(1, 1001))
for u in range(len(X)): X_elite[u] = np.array(X[u])[rlist] Y_elite = np.array(Y)[rlist] Z_elite = np.array(indexer)[rlist] trX, trY, trZ = upsampling(X_elite, Y_elite, Z_elite) testlist = list(fset) testlist.remove(8) testlist.remove(26) valid = valid_generation(testlist, only_se=None) validX, validY, _ = upsampling(valid[0], valid[1], valid[1]) valid = tuple([validX, validY]) reset_keras(model) nseed(seed) tf.random.set_seed(seed) model, idcode = keras_setup() model.load_weights(initial_weightsave) starttime = time.time() current_acc = -np.inf cnt = 0 s_loss = [] s_acc = [] sval_loss = [] sval_acc = [] grade_acc = 0.6 while current_acc < acc_thr and cnt < 500: # 0.93: # 목표 최대 정확도, epoch limit if (cnt > maxepoch/epochs) or \ (current_acc < 0.70 and cnt > 300/epochs) or (current_acc < 0.51 and cnt > 100/epochs):
""" from random import randint as random_int, seed as rseed from numpy.random import binomial, normal, seed as nseed, uniform from collections import Counter import tqdm import sys, getopt from time import sleep import json import fcntl from multiprocessing import Pool, cpu_count, Value, Lock from ctypes import c_int32 import os # Setting random seeds rseed(0) nseed(0) # Variable for regitering progress bar status counter = Value(c_int32) counter_lock = Lock() class IoTDevice: def __init__(self, malicious, eval_time, periodicity_error, malicious_frequency_multiplier): self.malicious = malicious if malicious: self.period = self.legacy_period / malicious_frequency_multiplier class ManufacturingCell(IoTDevice): period = legacy_period = 50
division_points.sort() partition = [ division_points[i+1] - division_points[i] for i in xrange(M) ] for L in partition: interval = fill_interval(L,H) for a in interval: print a, if __name__ == "__main__": if len(argv) != 5: print usage exit(1) N, H, M, S = map(int, argv[1:]) # Finche' generiamo elementi distinti, non ha senso avere L<3. assert (1 <= N <= MAXN) assert (1 <= H <= MAXH) # su seed non positivo copia un input di esempio dal .tex if S <= 0: print extract_input(cmsbooklet=True)[-S], exit(0) nseed(S) rseed(S) run(N,H,M)
chars = '.*' for i in range(R): print ''.join(choice(chars) for j in range(S)) def copy(FILENAME): os.system("zcat " + FILENAME) if __name__ == "__main__": if len(argv) == 5: R, S, K, SEED = map(int, argv[1:]) # su seed non positivo copia un input di esempio dal .tex if SEED <= 0: print extract_input()[-SEED], exit(0) assert (3 <= R <= MAXR) assert (3 <= S <= MAXS) assert (3 <= K <= MAXK) nseed(SEED) rseed(SEED) run(R, S, K) exit(0) if len(argv) == 2: FILENAME = argv[1] copy(FILENAME) exit(0) print usage exit(1)