def evalOthers(toRun, name, makeSpec, checkFunc): print(name) lineLengths = toRun.copy() gamutSizes = toRun.copy() tasks = list(itertools.product(lineLengths, gamutSizes)) results = [] print(tasks) res = [] for (length, gamut) in tasks: try: print((length, gamut)) s = cantusSpec(length, gamut, '') opt = Optimize() for c in s.constraints: opt.add(c.formula) checked, _ = timeWithTimeout(lambda: opt.check(), 10) if (checked == sat): cf = [extractPitch(opt.model(), p) for p in s.line] res += doCheck( makeSpec([ConstPitch(x) for x in cf], gamut, ''), lambda x: checkFunc(cf, x), length, gamut, name) except Exception: pass dt = str(datetime.datetime.now()) out = pd.DataFrame(columns=['length', 'gamut', 'mutations', 'time'], data=res) out.to_csv('output/checker/' + name + '/time_' + dt + '.csv')
def repairCF(cf: List[int], gamutMax): reasons = checkCF(cf) length = len(cf) cf = [ConstPitch(x) for x in cf] tCF = makeTemporalisedLine(cf, NoteLength.WHOLE) sm = makeSimMap([tCF], tCF) return repairLine(cf, cantusSpec(length, gamutMax, ''), reasons, gamutMax, sm)
def evalCF(toRun): name = 'cf' print(name) lineLengths = toRun.copy() gamutSizes = toRun.copy() tasks = list(itertools.product(lineLengths, gamutSizes)) results = [] print(tasks) res = [] for (length, gamut) in tasks: print((length, gamut)) res += doCheck(cantusSpec(length, gamut, ''), lambda x: checkCF(x), length, gamut, name) out = pd.DataFrame(columns=['length', 'gamut', 'mutations', 'time'], data=res) dt = str(datetime.datetime.now()) out.to_csv('output/checker/' + name + '/time_' + dt + '.csv')
def generateOtherLines(powersOfTwo, specMaker, name): lineLengths = powersOfTwo.copy() gamutSizes = powersOfTwo.copy() tasks = list(itertools.product(lineLengths, gamutSizes)) results = [] # (lineLength, GamutSize, time) causes = [] #(lineLength, gamutSize, result) lines = [] print(tasks) for (length, gamut) in tasks: print(length, gamut) try: cf = Generator(cantusSpec(length, gamut, '')).createNew() if cf == []: causes.append((length, gamut, 'Invalid cf')) except Exception: causes.append((length, gamut, 'Invalid cf')) continue try: g = Generator(specMaker([ConstPitch(x) for x in cf], gamut, '')) except Exception: causes.append((length, gamut, 'Invalid species')) continue i = 0 while True: if i == 5: causes.append((length, gamut, 'over5')) break i += 1 res, runtime = timeWithTimeout(lambda: g.createNew(), 10) # No more unique output for task if res == []: if i == 1: causes.append((length, gamut, 'No possible species')) else: causes.append((length, gamut, 'All outputs found')) break #timeout elif res is None: causes.append((length, gamut, 'timeout')) break else: out = (length, gamut, i, runtime) lines.append((length, gamut, res)) results.append(out) success = pd.DataFrame(columns=['length', 'gamut', 'iteration', 'times'], data=results) fails = pd.DataFrame(columns=['length', 'gamut', 'result'], data=causes) linesDF = pd.DataFrame(columns=['length', 'gamut', 'line'], data=lines) print(success) print(fails) print(lines) dt = str(datetime.datetime.now()) success.to_csv( 'output/generator/' + name + '/generate' + name + 'Success_Max:' + str(powersOfTwo[-1]) + "_Time:" + dt + '.csv', index=False, ) fails.to_csv( 'output/generator/' + name + '/generate' + name + 'Fails_Max:' + str(powersOfTwo[-1]) + "_Time:" + dt + '.csv', index=False, ) linesDF.to_csv( 'output/generator/' + name + '/generate' + name + 'Lines_Max:' + str(powersOfTwo[-1]) + '.csv', index=False, )
def generateCanti(powersOfTwo): lineLengths = powersOfTwo.copy() gamutSizes = powersOfTwo.copy() tasks = list(itertools.product(lineLengths, gamutSizes)) results = [] # (lineLength, GamutSize, time) causes = [] #(lineLength, gamutSize, result) cfs = [] #(lineLength, gamutSize, result) print(tasks) for (length, gamut) in tasks: print((length, gamut)) try: g = Generator(cantusSpec(length, gamut, '')) except Exception: causes.append((length, gamut, 'Invalid')) continue i = 0 while True: if i == 5: causes.append((length, gamut, 'over5')) break i += 1 res, runtime = timeWithTimeout(lambda: g.createNew(), 10) # No more unique output for task if res == []: if i == 1: causes.append((length, gamut, 'No possible lines')) else: causes.append((length, gamut, 'All outputs found')) break #timeout elif res is None: causes.append((length, gamut, 'timeout')) break else: out = (length, gamut, i, runtime) cfs.append((length, gamut, res)) results.append(out) success = pd.DataFrame(columns=['length', 'gamut', 'iteration', 'times'], data=results) fails = pd.DataFrame(columns=['length', 'gamut', 'result'], data=causes) lines = pd.DataFrame(columns=['length', 'gamut', 'line'], data=cfs) print(success) print(fails) print(cfs) dt = str(datetime.datetime.now()) success.to_csv( 'output/generator/cf/generateCFSuccess_Max:' + str(powersOfTwo[-1]) + "_Time:" + dt + '.csv', index=False, ) fails.to_csv( 'output/generator/cf/generateCFFails_Max:' + str(powersOfTwo[-1]) + "_Time:" + dt + '.csv', index=False, ) lines.to_csv( 'output/generator/cf/generateCFCFs_Max:' + str(powersOfTwo[-1]) + '.csv', index=False, )