classes.init_classes(config)
        project_id_mappings = configParser.get('files', 'project_id_mappings')
        capacity = configParser.getint('valid_values', 'capacity')
        capacity_w = configParser.getint('valid_values', 'capacity_w')
        temp = configParser.getint('valid_values', 'temperature')
        iters = configParser.getint('valid_values', 'iterations')
        team_size = capacity

        # Creating the annealer with our energy and move functions.
        if mode == "cc":
                annealer = Annealer(pg.energy, pg.move)
        elif mode == "co":
                annealer = Annealer(pg.energy_co, pg.move_co)
        else:
                raise FieldError("Unknown algorithm mode")
        all_projects = util.generate_all_projects(config)

        students = util.create_students_from_input(input_file, config)
        feasibles = util.create_feasible_projects(students, all_projects)

        sol = test.do_greedy_initial_solutions(students, all_projects, annealer, project_id_mappings, config)
        use_file = False
        use_diversity = False
        if (set_output_file):
                test.manual_schedule(use_file, students, sol, feasibles,  annealer, use_diversity, input_file, temp, iters, output_file)
        else:
                test.manual_schedule(use_file, students, sol, feasibles,  annealer, use_diversity, input_file, temp, iters)

        string =  "Program completed in " + str((time.time() - start_time)/60)
        string += " minutes."
        print string
예제 #2
0
#!/usr/bin/env python

import util
import initial_solution
import numpy as np
import copy

if (__name__ == "__main__"):
    students = util.create_students_from_input('students.csv')
    print len(students)
    feasibles = util.create_feasible_projects(students, util.generate_all_projects())
    min_rank = float("inf")
    min_sol = None
    def calculate_avg_rank(solution, verbose = False):
        avgs = []
        cnt = 0
        for p in solution:
            cnt += len(p.students)
            if (verbose):
                print str(p.ID) + ":" + str([s.ID for s in p.students])
                print "Ranks:",
            rankings = [s.get_ranking(p.ID) for s in p.students]
            if (verbose):
                print rankings
            avg_rank = np.mean(rankings)
            if (verbose):
                print "Average rank: " + str(avg_rank)
            avgs.append(avg_rank)
        if (len(avgs)==0):
            raise ValueError('Tried to average slice of length 0.')
        overall_average_rank = np.mean(avgs)
    # Create config parser to get various fields.
    configParser = ConfigParser.ConfigParser()
    configFilePath = config
    configParser.read(configFilePath)

    classes.init_classes(config)
    project_id_mappings = configParser.get('files', 'project_id_mappings')
    capacity = configParser.getint('valid_values', 'capacity')
    capacity_w = configParser.getint('valid_values', 'capacity_w')
    temp = configParser.getint('valid_values', 'temperature')
    iters = configParser.getint('valid_values', 'iterations')
    team_size = capacity

    # Creating the annealer with our energy and move functions.
    annealer = Annealer(pgd.energy, pgd.move)
    all_projects = util.generate_all_projects(config)
    students = util.create_students_from_input(input_file, config)

    sol = initial_solution.random_initial_solution_for_diversity(
        students, all_projects, num_teams)

    use_diversity = True
    use_file = False
    if (set_output_file):
        test.manual_schedule(use_file, students, sol, None, annealer,
                             use_diversity, input_file, temp, iters,
                             output_file)
    else:
        test.manual_schedule(use_file, students, sol, None, annealer,
                             use_diversity, input_file, temp, iters)
		print "Please specify the number of teams to create."
		print " usage: ./diversity_main.py -i <inputfile> [-o <outputfile>] -n <numteams>"

	# Create config parser to get various fields.
	configParser = ConfigParser.ConfigParser()
	configFilePath = r'config.txt'
	configParser.read(configFilePath)

	project_id_mappings = configParser.get('files', 'project_id_mappings')
	num_MBAs = configParser.getint('valid_values', 'num_MBAs')
	num_MEngs = configParser.getint('valid_values', 'num_MEngs')
	team_size = num_MBAs + num_MEngs

	# Creating the annealer with our energy and move functions.
	annealer = Annealer(pgd.energy, pgd.move)
	all_projects = util.generate_all_projects()
	students = util.create_students_from_input(input_file)

	sol = initial_solution.random_initial_solution_for_diversity(students, all_projects, num_teams)	

	use_diversity = True
	use_file = False
	if (set_output_file):
		test.manual_schedule(use_file, students, sol, annealer, use_diversity, input_file, output_file)
	else:
		test.manual_schedule(use_file, students, sol, annealer, input_file, use_diversity)

	string =  "Program completed in " + str((time.time() - start_time)/60)
	string += " minutes."
	print string