예제 #1
0
def main():
    parser = argparse.ArgumentParser()

    parser.add_argument('--config_json',
                        help='location of json configuration',
                        default='config.json')
    options = vars(parser.parse_args())
    config_json = read_config(options['config_json'])

    #url = 'https://api.openweathermap.org/data/2.5/weather?zip={}&appid={}'.format(options['zip'], options['owmkey'])
    #r = requests.get(url)
    ticks_per_quarter = config_json['midi']['ticks_per_quarter']
    midi_output = midi.Midi(ticks_per_quarter)
    trk_chk = midi.Midi.TrackChunk(ticks_per_quarter)

    # result sequence is a list containing a single list containing the resulting measures from the algorithm
    result_sequence = genetic.run(config_json)

    for measure in result_sequence[0]:
        print("Result measure: {}".format(measure))
        for note in measure.notes:
            note_length_ticks = int(ticks_per_quarter * note.note_len * 4)
            trk_chk.add_event(1, 0, note.midi_num, 96, 0)
            trk_chk.add_event(0, 0, note.midi_num, 0, note_length_ticks)
    midi_output.chunks.append(trk_chk)
    midi_output.write_to_file(config_json['midi']['output'])
예제 #2
0
def main():
    """Run imported algorithms and show statistics."""
    if OMIT_OUTPUT:
        sys.stdout = open(os.devnull, 'w')

    genetic_time, lcv_time, mrv_time, ph_time = [], [], [], []

    for _ in range(NO_OF_TESTS):
        now = time.time()
        genetic.run()
        genetic_time.append(time.time() - now)

        now = time.time()
        least_constraining_value.run()
        lcv_time.append(time.time() - now)

        now = time.time()
        minimum_remaining_values.run()
        mrv_time.append(time.time() - now)

        now = time.time()
        power_heuristic.run()
        ph_time.append(time.time() - now)

    if OMIT_OUTPUT:
        sys.stdout = sys.__stdout__

    algorithms = [
        'Genetic', 'Least constraining value', 'Minimum remaining values',
        'Power heuristic'
    ]
    stats = [genetic_time, lcv_time, mrv_time, ph_time]

    for name, t in zip(algorithms, stats):
        avg_time = round(sum(t) / NO_OF_TESTS * 1000, ACCURACY)
        print(f"Statistics for {name} algorithm: {avg_time} ms.")
예제 #3
0
파일: run.py 프로젝트: bd-git/YahooFantasy
def test(stat,time):
    mystats = team.calcTeamStats(mystarters, stat, players, time)
    head = team.statidHeader(stat)
    t1,f1=genetic.run(mystarters,TeamsToInclude=[0,MYTEAMID],StatsToMaximize=stat,
                        TimeFrame=time, Population=1000, Generations=60)
    print('\n\n\n\n\n\n\n')

    [print(head[i],mystats[i]) for i in range(len(head))]
    print()

    gastats = team.calcTeamStats(t1, stat, players, time)
    [print(head[i],gastats[i]) for i in range(len(head))]

    m = set(mystarters)
    g = set(t1)

    k = m&g
    d = m-g
    u = g-m

    print('\nKeep:')
    for x in k:
      p = players[x]
      print(p['stats_percentown'],p['stats_percentowndelta'],p['player_name'],p['position_eligible'])
    print('\nDrop:')
    for x in d:
      p = players[x]
      print(p['stats_percentown'],p['stats_percentowndelta'],p['player_name'],p['position_eligible'])
    print('\nPickup:')
    for x in u:
      p = players[x]
      print(p['stats_percentown'],p['stats_percentowndelta'],p['player_name'],p['position_eligible'])

    mystats = team.calcTeamStats(mystarters, st, players, time)
    gastats = team.calcTeamStats(t1, st, players, time)
    print (gastats)
    print (mystats)
    print (len(mystats))
    print ( sum( [a/b for a,b in zip(gastats,mystats)] ) )
예제 #4
0
def initialize():
    preamble()
    generate_detectors()
    initialize_state()
    genetic.run()
예제 #5
0
def initialize():
    preamble()
    generate_detectors()
    initialize_state()
    genetic.run()