if (not (len(project.students) == team_size)):
            project.reset()

    matched_projects = [
        project for project in feasible_projects
        if len(project.students) >= team_size
    ]

    def can_make_team_with_waiting(u_students):
        overall_number = (len(u_students) / team_size) > 0
        return overall_number

    while (len(unmatched_students) > 0):
        if (can_make_team_with_waiting(unmatched_students)):
            # Pick a random project that does not have any students on it.
            project = util.random_project(feasible_projects, matched_projects,
                                          False)
            for i in range(team_size):
                st = util.random_student_lst(unmatched_students, [], False)
                unmatched_students.remove(st)
                project.add_student(st, False)
            matched_projects.append(project)
        else:
            #pass
            feasible_projects = filter(
                lambda project: len(project.students) == team_size,
                feasible_projects)
            available_projects = feasible_projects[:]
            for student in unmatched_students:
                project = util.random_project(available_projects, [], True)
                project.add_student(student, True)
                available_projects.remove(project)
def _test_new_project(browser):

    browser_download_location_path = get_browser_download_location_path(
        browser)

    projects_page = begin(browser)
    eq(projects_page.welcome_text, 'Welcome to OpenMDAO %s' % __version__)

    # Create a project.
    projects_page, project_dict = random_project(projects_page.new_project(),
                                                 verify=True,
                                                 load_workspace=False)
    # Go back to projects page to see if it is on the list.
    assert projects_page.contains(project_dict['name'])

    # Make sure all the project meta data was saved correctly.
    edit_dialog = projects_page.edit_project(project_dict['name'])
    eq(str(edit_dialog.project_name).strip(), project_dict['name'])
    eq(str(edit_dialog.description).strip(), project_dict['description'])
    eq(str(edit_dialog.version).strip(), project_dict['version'])  # maxlength

    # Edit the project meta data
    project_dict['description'] = "pony express"
    project_dict['version'] = "23432"

    projects_page = edit_project(edit_dialog, project_dict['name'],
                                 project_dict['description'],
                                 project_dict['version'])

    # Make sure all the new project meta data was saved correctly.
    edit_dialog = projects_page.edit_project(project_dict['name'])
    eq(str(edit_dialog.project_name).strip(), project_dict['name'])
    eq(str(edit_dialog.description).strip(), project_dict['description'])
    eq(str(edit_dialog.version).strip(),
       project_dict['version'][:5])  # maxlength
    edit_dialog.cancel()

    # Export the project
    projects_page.export_project(project_dict['name'])
    project_pattern = project_dict['name'].replace(' ', '_') + '-*.proj'
    project_pattern = os.path.join(browser_download_location_path,
                                   project_pattern)
    for i in range(10):  # Give the download time to complete.
        time.sleep(1)
        project_path = glob.glob(project_pattern)
        if project_path:
            break
    else:
        assert False, 'Download of %r timed-out' % project_pattern
    assert len(project_path) == 1
    project_path = project_path[0]

    # Delete the project in preparation for reimporting
    projects_page.delete_project(project_dict['name'])

    # Make sure the project was deleted
    assert not projects_page.contains(project_dict['name'], False)

    # Import the project and give it a new name
    projects_page, project_dict = import_project(
        projects_page.import_project(),
        project_path,
        verify=True,
        load_workspace=False)
    # Go back to projects page to see if it is on the list.
    assert projects_page.contains(project_dict['name'])

    # Delete the project that was just imported
    projects_page.delete_project(project_dict['name'])

    # remove the downloaded file
    os.remove(project_path)
def _test_last_saved_metadata(browser):
    def last_saved(target):
        def wrapper(projects_page, project_name, timestamp, *args, **kargs):
            workspace_page = projects_page.open_project(project_name)
            result = target(workspace_page)

            projects_page = workspace_page.close_workspace()

            if result is False:
                last_saved = timestamp
            else:
                metadata = projects_page.get_project_metadata(project_name)
                last_saved = date_to_datetime(metadata['last_saved'])
                assert (last_saved > timestamp)

            return projects_page, project_name, last_saved

        return wrapper

    def date_to_datetime(date):
        date_regex = re.compile("(\d+)-(\d+)-(\d+)")
        time_regex = re.compile("(\d+):(\d+):(\d+)")

        match_object = date_regex.search(date)
        year = int(match_object.group(1))
        month = int(match_object.group(2))
        day = int(match_object.group(3))

        match_object = time_regex.search(date)
        hours = int(match_object.group(1))
        minutes = int(match_object.group(2))
        seconds = int(match_object.group(3))

        return datetime.datetime(year, month, day, hours, minutes, seconds)

    @last_saved
    def add_file(workspace_page):
        file_path = pkg_resources.resource_filename(
            'openmdao.gui.test.functional', 'files/simple_paraboloid.py')
        workspace_page.add_file(file_path)

    @last_saved
    def new_file(workspace_page):
        workspace_page.new_file('test_file.py')

    @last_saved
    def rename_file(workspace_page):
        workspace_page.get_files()
        workspace_page.rename_file('test_file.py', 'best_file.py')

    @last_saved
    def edit_file(workspace_page):
        if broken_chrome():
            print "Skipping testing metadata after editing file due to broken chrome driver."
            return False

        workspace_window = browser.current_window_handle

        editor_page = workspace_page.open_editor()
        editor_page.edit_file('test_file.py', dclick=False)
        editor_page.add_text_to_file('#just a comment\n')
        editor_page.save_document(check=False)

        browser.switch_to_window(workspace_window)
        port = workspace_page.port
        workspace_page = WorkspacePage.verify(browser, port)

    @last_saved
    def delete_file(workspace_page):
        workspace_page.delete_file('best_file.py')

    @last_saved
    def add_object(workspace_page):
        workspace_page.add_library_item_to_dataflow(
            "openmdao.main.assembly.Assembly", 'top')

    @last_saved
    def replace_object(workspace_page):
        workspace_page.replace_driver("top", 'SLSQPdriver')

    @last_saved
    def commit_project(workspace_page):
        top = workspace_page.get_dataflow_figure('top')
        top.remove()
        workspace_page.commit_project()

    @last_saved
    def revert_project(workspace_page):
        workspace_page.add_library_item_to_dataflow(
            "openmdao.main.assembly.Assembly", 'top')
        workspace_page = workspace_page.revert_project()

    projects_page = begin(browser)
    projects_page, project_dict = random_project(projects_page.new_project(),
                                                 verify=True,
                                                 load_workspace=False)

    project_name = project_dict['name']
    metadata = projects_page.get_project_metadata(project_name)
    created_time = date_to_datetime(metadata['created'])

    #Testing metadata for file operations
    projects_page, project_name, add_file_time = add_file(
        projects_page, project_name, created_time)
    projects_page, project_name, new_file_time = new_file(
        projects_page, project_name, add_file_time)
    projects_page, project_name, edit_file_time = edit_file(
        projects_page, project_name, new_file_time)
    projects_page, project_name, rename_file_time = rename_file(
        projects_page, project_name, edit_file_time)
    projects_page, project_name, delete_file_time = delete_file(
        projects_page, project_name, rename_file_time)

    #Testing metadata for project operations
    projects_page, project_name, add_object_time = add_object(
        projects_page, project_name, delete_file_time)
    projects_page, project_name, replace_object_time = replace_object(
        projects_page, project_name, add_object_time)
    projects_page, project_name, commit_project_time = commit_project(
        projects_page, project_name, replace_object_time)
    projects_page, project_name, revert_project_time = revert_project(
        projects_page, project_name, commit_project_time)

    projects_page.delete_project(project_name)
def move_co(state, verbose=False, super_verbose=False):
    """
                A move for conversations in the studio. There are exactly classes.number_project_rankings
                groups, so it does not make any sense to allow projects to change identity. In its place,
                this move type will swap a student that is matched with a student that is unmatched.
        """

    student_exchange_probability = 0.01

    projects = state[0]
    inv_cov_mat_tup = state[1]
    feasibles = state[2]
    students = state[3]

    if random.random() < student_exchange_probability:
        project_to_choose_from = util.random_project(projects, [], True)
        student_to_swap = util.random_student(project_to_choose_from)
        matched_students = []
        for p in projects:
            matched_students.extend(p.students)
        other = util.random_student_lst(students, matched_students, False)
        if other == None:
            pass
        else:
            project_to_choose_from.students.remove(student_to_swap)
            project_to_choose_from.students.append(other)
    else:
        project_one = util.random_project(projects, [], True)
        project_two = util.random_project(projects, [], True)

        # Guarantee that the projects are not the same.
        # Continue to swap project two until it is diff from project one.
        while project_one.ID == project_two.ID:
            project_two = util.random_project(projects, [], True)
            if super_verbose:
                print "Project one and project two are the same."

        if super_verbose:
            print "Found two different projects."

            print "First team students are " + str([s.ID for s in project_one.students])
            print "Second team students are " + str([s.ID for s in project_two.students])

            print "CLEAR: made it to pick_team"

        # Team to pick first students from
        pick_team = util.random_two_choice()

        if pick_team == 0:
            first_team = project_one
            second_team = project_two
        else:
            first_team = project_two
            second_team = project_one

        # Pick a student from the first team, and this student will be swapped.

        student_one = util.random_student(first_team)
        student_two = util.random_student(second_team)

        # NOTE: this is problematic if teams aren't full.
        # 38
        # Guarantee that the students are of the same type.
        # while (not (student_one.degree_pursuing == student_two.degree_pursuing)):
        # 	student_two = util.random_student(second_team)

        # Remove the students from their respective teams
        first_team.students.remove(student_one)
        if not (student_two in second_team.students):
            if super_verbose:
                print "Second team students is " + str([s.ID for s in second_team.students])
            error = "Student two ("
            error += str(student_two.ID)
            error += ") is not in second_team.students ("
            error += str(second_team.ID)
            error += ") "

            raise CompError(error)
        second_team.students.remove(student_two)

        first_team.students.append(student_two)
        second_team.students.append(student_one)

    if verbose:
        print "AFTER MOVE:"
        for p in projects:
            print str(p.ID) + ": " + str([s.ID for s in p.students])

    state_after_change = (projects, inv_cov_mat_tup, feasibles)

    # print energy(state_after_change)

    return projects
def move(state, verbose=False, super_verbose=False):
    """
		Makes a random change to a state.
		
		Picks two random teams, picks two random members, and performs
		a swap of these members across the teams.

                With some small probability, change a project to a completely different project instead.
		NOTE: there should be no teams of size 0 before calling the function.	
	"""
    project_exchange_probability = 0.01

    projects = state[0]
    inv_cov_mat_tup = state[1]
    feasibles = state[2]

    if random.random() < project_exchange_probability:
        project_to_swap = util.random_project(projects, [], True)
        feasible_IDs = [p.ID for p in feasibles]
        reasonable_project_IDs = list(set().union(*[set(s.project_rankings) for s in project_to_swap.students]))
        reasonable_projects = filter(lambda p: p.ID in reasonable_project_IDs, feasibles)

        def popularity(p):
            return len(filter(lambda s: s.get_ranking(p.ID) < 100, project_to_swap.students))

        reasonable_projects.sort(key=popularity, reverse=True)
        most_likely_popular = reasonable_projects[: max(10, 2 * len(projects))]
        # other = util.random_project(most_likely_popular, projects, False)
        other = util.random_project(most_likely_popular, [], True)
        while project_to_swap.ID == other.ID:
            other = util.random_project(most_likely_popular, [], True)
        if other == None:
            pass
        else:
            tmp = project_to_swap.ID
            projects.remove(project_to_swap)
            projects.append(other)
            util.safe_project_swap(project_to_swap, other)
        # print "swapping " + str(tmp) + " for " + str(other.ID)
        # print "Project IDs in swap move is " + str([p.ID for p in projects])
    else:
        project_one = util.random_project(projects, [], True)
        project_two = util.random_project(projects, [], True)

        # Guarantee that the projects are not the same.
        # Continue to swap project two until it is diff from project one.
        while project_one.ID == project_two.ID:
            project_two = util.random_project(projects, [], True)
            if super_verbose:
                print "Project one and project two are the same."

        if super_verbose:
            print "Found two different projects."

            print "First team students are " + str([s.ID for s in project_one.students])
            print "Second team students are " + str([s.ID for s in project_two.students])

            print "CLEAR: made it to pick_team"

        # Team to pick first students from
        pick_team = util.random_two_choice()

        if pick_team == 0:
            first_team = project_one
            second_team = project_two
        else:
            first_team = project_two
            second_team = project_one

        # Pick a student from the first team, and this student will be swapped.

        student_one = util.random_student(first_team)
        student_two = util.random_student(second_team)

        # NOTE: this is problematic if teams aren't full.
        # 38
        # Guarantee that the students are of the same type.
        # while (not (student_one.degree_pursuing == student_two.degree_pursuing)):
        # 	student_two = util.random_student(second_team)

        # Remove the students from their respective teams
        first_team.students.remove(student_one)
        if not (student_two in second_team.students):
            if super_verbose:
                print "Second team students is " + str([s.ID for s in second_team.students])
            error = "Student two ("
            error += str(student_two.ID)
            error += ") is not in second_team.students ("
            error += str(second_team.ID)
            error += ") "

            raise CompError(error)
        second_team.students.remove(student_two)

        first_team.students.append(student_two)
        second_team.students.append(student_one)

    if verbose:
        print "AFTER MOVE:"
        for p in projects:
            print str(p.ID) + ": " + str([s.ID for s in p.students])

            # state_after_change = (projects, inv_cov_mat_tup, feasibles)

            # print energy(state_after_change)

    return projects
Beispiel #6
0
def move(state, verbose=False, super_verbose=False):
    '''
		Makes a random change to a state.
		
		Picks two random teams, picks two random members, and performs
		a swap of these members across the teams.

                With some small probability, change a project to a completely different project instead.
		NOTE: there should be no teams of size 0 before calling the function.	
	'''
    project_exchange_probability = 0.01

    projects = state[0]
    inv_cov_mat_tup = state[1]
    feasibles = state[2]

    if random.random() < project_exchange_probability:
        project_to_swap = util.random_project(projects, [], True)
        feasible_IDs = [p.ID for p in feasibles]
        reasonable_project_IDs = list(set().union(
            *[set(s.project_rankings) for s in project_to_swap.students]))
        reasonable_projects = filter(lambda p: p.ID in reasonable_project_IDs,
                                     feasibles)

        def popularity(p):
            return len(
                filter(lambda s: s.get_ranking(p.ID) < 100,
                       project_to_swap.students))

        reasonable_projects.sort(key=popularity, reverse=True)
        most_likely_popular = reasonable_projects[:max(10, 2 * len(projects))]
        #other = util.random_project(most_likely_popular, projects, False)
        other = util.random_project(most_likely_popular, [], True)
        while (project_to_swap.ID == other.ID):
            other = util.random_project(most_likely_popular, [], True)
        if other == None:
            pass
        else:
            tmp = project_to_swap.ID
            projects.remove(project_to_swap)
            projects.append(other)
            util.safe_project_swap(project_to_swap, other)
        # print "swapping " + str(tmp) + " for " + str(other.ID)
        #print "Project IDs in swap move is " + str([p.ID for p in projects])
    else:
        project_one = util.random_project(projects, [], True)
        project_two = util.random_project(projects, [], True)

        # Guarantee that the projects are not the same.
        # Continue to swap project two until it is diff from project one.
        while (project_one.ID == project_two.ID):
            project_two = util.random_project(projects, [], True)
            if (super_verbose):
                print "Project one and project two are the same."

        if (super_verbose):
            print "Found two different projects."

            print "First team students are " + str(
                [s.ID for s in project_one.students])
            print "Second team students are " + str(
                [s.ID for s in project_two.students])

            print "CLEAR: made it to pick_team"

        # Team to pick first students from
        pick_team = util.random_two_choice()

        if (pick_team == 0):
            first_team = project_one
            second_team = project_two
        else:
            first_team = project_two
            second_team = project_one

        # Pick a student from the first team, and this student will be swapped.

        student_one = util.random_student(first_team)
        student_two = util.random_student(second_team)

        # NOTE: this is problematic if teams aren't full.
        # 38
        # Guarantee that the students are of the same type.
        # while (not (student_one.degree_pursuing == student_two.degree_pursuing)):
        #	student_two = util.random_student(second_team)

        # Remove the students from their respective teams
        first_team.students.remove(student_one)
        if (not (student_two in second_team.students)):
            if (super_verbose):
                print "Second team students is " + str(
                    [s.ID for s in second_team.students])
            error = "Student two ("
            error += str(student_two.ID)
            error += ") is not in second_team.students ("
            error += str(second_team.ID)
            error += ") "

            raise CompError(error)
        second_team.students.remove(student_two)

        first_team.students.append(student_two)
        second_team.students.append(student_one)

    if (verbose):
        print "AFTER MOVE:"
        for p in projects:
            print str(p.ID) + ": " + str([s.ID for s in p.students])

    #state_after_change = (projects, inv_cov_mat_tup, feasibles)

    #print energy(state_after_change)

    return projects
	# If there are any teams that are not full, remove all students from them.
	for project in feasible_projects:
		if (not(len(project.students) == team_size)):
			project.students = []

	matched_projects = [project for project in feasible_projects if len(project.students) >= team_size]
	
	def can_make_team_with_waiting(u_students):
                overall_number = (len(u_students)/ team_size) > 0
		return overall_number
	
	while (len(unmatched_students) > 0):
		if (can_make_team_with_waiting(unmatched_students)):
			# Pick a random project that does not have any students on it. 
			project = util.random_project(feasible_projects, matched_projects, False)
                        for i in range(team_size):
                                st = util.random_student_lst(unmatched_students, [], False)
                                unmatched_students.remove(st)
                                project.students.append(st)
			matched_projects.append(project)
		else:
			#pass
			feasible_projects = filter(lambda project: len(project.students) == team_size, feasible_projects)
			available_projects = feasible_projects[:]
			for student in unmatched_students:
				project = util.random_project(available_projects, [], True)
				project.add_student(student, True)
				available_projects.remove(project)
			unmatched_students = []
	
Beispiel #8
0
def move_co(state, verbose=False, super_verbose=False):
    '''
                A move for conversations in the studio. There are exactly classes.number_project_rankings
                groups, so it does not make any sense to allow projects to change identity. In its place,
                this move type will swap a student that is matched with a student that is unmatched.
        '''

    student_exchange_probability = 0.01

    projects = state[0]
    inv_cov_mat_tup = state[1]
    feasibles = state[2]
    students = state[3]

    if random.random() < student_exchange_probability:
        project_to_choose_from = util.random_project(projects, [], True)
        student_to_swap = util.random_student(project_to_choose_from)
        matched_students = []
        for p in projects:
            matched_students.extend(p.students)
        other = util.random_student_lst(students, matched_students, False)
        if other == None:
            pass
        else:
            project_to_choose_from.students.remove(student_to_swap)
            project_to_choose_from.students.append(other)
    else:
        project_one = util.random_project(projects, [], True)
        project_two = util.random_project(projects, [], True)

        # Guarantee that the projects are not the same.
        # Continue to swap project two until it is diff from project one.
        while (project_one.ID == project_two.ID):
            project_two = util.random_project(projects, [], True)
            if (super_verbose):
                print "Project one and project two are the same."

        if (super_verbose):
            print "Found two different projects."

            print "First team students are " + str(
                [s.ID for s in project_one.students])
            print "Second team students are " + str(
                [s.ID for s in project_two.students])

            print "CLEAR: made it to pick_team"

        # Team to pick first students from
        pick_team = util.random_two_choice()

        if (pick_team == 0):
            first_team = project_one
            second_team = project_two
        else:
            first_team = project_two
            second_team = project_one

        # Pick a student from the first team, and this student will be swapped.

        student_one = util.random_student(first_team)
        student_two = util.random_student(second_team)

        # NOTE: this is problematic if teams aren't full.
        # 38
        # Guarantee that the students are of the same type.
        # while (not (student_one.degree_pursuing == student_two.degree_pursuing)):
        #	student_two = util.random_student(second_team)

        # Remove the students from their respective teams
        first_team.students.remove(student_one)
        if (not (student_two in second_team.students)):
            if (super_verbose):
                print "Second team students is " + str(
                    [s.ID for s in second_team.students])
            error = "Student two ("
            error += str(student_two.ID)
            error += ") is not in second_team.students ("
            error += str(second_team.ID)
            error += ") "

            raise CompError(error)
        second_team.students.remove(student_two)

        first_team.students.append(student_two)
        second_team.students.append(student_one)

    if (verbose):
        print "AFTER MOVE:"
        for p in projects:
            print str(p.ID) + ": " + str([s.ID for s in p.students])

    state_after_change = (projects, inv_cov_mat_tup, feasibles)

    #print energy(state_after_change)

    return projects
def _test_last_saved_metadata(browser):

    def last_saved(target):
        def wrapper(projects_page, project_name, timestamp, *args, **kargs):
            workspace_page = projects_page.open_project(project_name)
            result = target(workspace_page)

            projects_page = workspace_page.close_workspace()

            if result is False:
                last_saved = timestamp
            else:
                metadata = projects_page.get_project_metadata(project_name)
                last_saved = date_to_datetime(metadata['last_saved'])
                assert(last_saved > timestamp)

            return projects_page, project_name, last_saved

        return wrapper

    def date_to_datetime(date):
        date_regex = re.compile("(\d+)-(\d+)-(\d+)")
        time_regex = re.compile("(\d+):(\d+):(\d+)")

        match_object = date_regex.search(date)
        year  = int(match_object.group(1))
        month = int(match_object.group(2))
        day   = int(match_object.group(3))

        match_object = time_regex.search(date)
        hours   = int(match_object.group(1))
        minutes = int(match_object.group(2))
        seconds = int(match_object.group(3))

        return datetime.datetime(year, month, day, hours, minutes, seconds)

    @last_saved
    def add_file(workspace_page):
        file_path = pkg_resources.resource_filename('openmdao.gui.test.functional', 'files/simple_paraboloid.py')
        workspace_page.add_file(file_path)

    @last_saved
    def new_file(workspace_page):
        workspace_page.new_file('test_file.py')

    @last_saved
    def rename_file(workspace_page):
        workspace_page.get_files()
        workspace_page.rename_file('test_file.py', 'best_file.py')

    @last_saved
    def edit_file(workspace_page):
        if broken_chrome():
            print "Skipping testing metadata after editing file due to broken chrome driver."
            return False

        workspace_window = browser.current_window_handle

        editor_page = workspace_page.open_editor()
        editor_page.edit_file('test_file.py', dclick=False)
        editor_page.add_text_to_file('#just a comment\n')
        editor_page.save_document(check=False)

        browser.switch_to_window(workspace_window)
        port = workspace_page.port
        workspace_page = WorkspacePage.verify(browser, port)

    @last_saved
    def delete_file(workspace_page):
        workspace_page.delete_file('best_file.py')

    @last_saved
    def add_object(workspace_page):
        workspace_page.add_library_item_to_dataflow("openmdao.main.assembly.Assembly", 'top')

    @last_saved
    def replace_object(workspace_page):
        workspace_page.replace_driver("top", 'SLSQPdriver')

    @last_saved
    def commit_project(workspace_page):
        top = workspace_page.get_dataflow_figure('top')
        top.remove()
        workspace_page.commit_project()

    @last_saved
    def revert_project(workspace_page):
        workspace_page.add_library_item_to_dataflow("openmdao.main.assembly.Assembly", 'top')
        workspace_page = workspace_page.revert_project()


    projects_page = begin(browser)
    projects_page, project_dict = random_project(projects_page.new_project(),
                                                 verify=True, load_workspace=False)

    project_name = project_dict['name']
    metadata = projects_page.get_project_metadata(project_name)
    created_time = date_to_datetime(metadata['created'])

    #Testing metadata for file operations
    projects_page, project_name, add_file_time       = add_file(projects_page, project_name, created_time)
    projects_page, project_name, new_file_time       = new_file(projects_page, project_name, add_file_time)
    projects_page, project_name, edit_file_time      = edit_file(projects_page, project_name, new_file_time)
    projects_page, project_name, rename_file_time    = rename_file(projects_page, project_name, edit_file_time)
    projects_page, project_name, delete_file_time    = delete_file(projects_page, project_name, rename_file_time)

    #Testing metadata for project operations
    projects_page, project_name, add_object_time     = add_object(projects_page, project_name, delete_file_time)
    projects_page, project_name, replace_object_time = replace_object(projects_page, project_name, add_object_time)
    projects_page, project_name, commit_project_time = commit_project(projects_page, project_name, replace_object_time)
    projects_page, project_name, revert_project_time = revert_project(projects_page, project_name, commit_project_time)

    projects_page.delete_project(project_name)
def _test_new_project(browser):

    browser_download_location_path = get_browser_download_location_path(browser)

    projects_page = begin(browser)
    eq(projects_page.welcome_text, 'Welcome to OpenMDAO %s' % __version__)

    # Create a project.
    projects_page, project_dict = random_project(projects_page.new_project(),
                                                 verify=True, load_workspace=False)
    # Go back to projects page to see if it is on the list.
    assert projects_page.contains(project_dict['name'])

    # Make sure all the project meta data was saved correctly.
    edit_dialog = projects_page.edit_project(project_dict['name'])
    eq(str(edit_dialog.project_name).strip(), project_dict['name'])
    eq(str(edit_dialog.description).strip(), project_dict['description'])
    eq(str(edit_dialog.version).strip(), project_dict['version'])  # maxlength

    # Edit the project meta data
    project_dict['description'] = "pony express"
    project_dict['version'] = "23432"

    projects_page = edit_project(edit_dialog,
                         project_dict['name'],
                         project_dict['description'],
                         project_dict['version'])

    # Make sure all the new project meta data was saved correctly.
    edit_dialog = projects_page.edit_project(project_dict['name'])
    eq(str(edit_dialog.project_name).strip(), project_dict['name'])
    eq(str(edit_dialog.description).strip(), project_dict['description'])
    eq(str(edit_dialog.version).strip(), project_dict['version'][:5])  # maxlength
    edit_dialog.cancel()

    # Export the project
    projects_page.export_project(project_dict['name'])
    project_pattern = project_dict['name'].replace(' ', '_') + '-*.proj'
    project_pattern = os.path.join(browser_download_location_path,
                                   project_pattern)
    for i in range(10):  # Give the download time to complete.
        time.sleep(1)
        project_path = glob.glob(project_pattern)
        if project_path:
            break
    else:
        assert False, 'Download of %r timed-out' % project_pattern
    assert len(project_path) == 1
    project_path = project_path[0]

    # Delete the project in preparation for reimporting
    projects_page.delete_project(project_dict['name'])

    # Make sure the project was deleted
    assert not projects_page.contains(project_dict['name'], False)

    # Import the project and give it a new name
    projects_page, project_dict = import_project(projects_page.import_project(),
                                                 project_path, verify=True,
                                                 load_workspace=False)
    # Go back to projects page to see if it is on the list.
    assert projects_page.contains(project_dict['name'])

    # Delete the project that was just imported
    projects_page.delete_project(project_dict['name'])

    # remove the downloaded file
    os.remove(project_path)
def move(state, verbose = True, super_verbose = False):
	'''
		Makes a random change to a state.
		
		Picks two random teams, picks two random members, and performs
		a swap of these members across the teams.
		
		NOTE: there should be no teams of size 0 before calling the function.	
	'''
	projects = state[0]
	inv_cov_mat_tup = state[1]

	project_one = util.random_project(projects, [], True)
	project_two = util.random_project(projects, [], True)


	# Guarantee that the projects are not the same.
	# Continue to swap project two until it is diff from project one.
	while (project_one.ID == project_two.ID):
		project_two = util.random_project(projects, [], True)
		if (super_verbose):
			print "Project one and project two are the same."

	if (super_verbose):
		print "Found two different projects."

		print "First team students are " + str([s.ID for s in project_one.students])
		print "Second team students are " + str([s.ID for s in project_two.students])

		print "CLEAR: made it to pick_team"

	# Team to pick first students from 
	pick_team = util.random_two_choice()

	if (pick_team == 0):
		first_team = project_one
		second_team = project_two
	else:
		first_team = project_two
		second_team = project_one

	# Pick a student from the first team, and this student will be swapped.

	student_one = util.random_student(first_team)
	student_two = util.random_student(second_team)

	# NOTE: this is problematic if teams aren't full.
	# Guarantee that the students are of the same type.
	while (not (student_one.degree_pursuing == student_two.degree_pursuing)):
		student_two = util.random_student(second_team)

	# Remove the students from their respective teams
	first_team.students.remove(student_one)
	if (not(student_two in second_team.students)):
		if (super_verbose):
			print "Second team students is " + str([s.ID for s in second_team.students])
		error = "Student two ("
		error += str(student_two.ID)
		error += ") is not in second_team.students ("
		error += str(second_team.ID)
		error += ") "
		
		raise CompError(error)
	second_team.students.remove(student_two)

	first_team.students.append(student_two)
	second_team.students.append(student_one)

	if (verbose):
		print "AFTER MOVE:"
		for p in projects:
		 	print str(p.ID) + ": " + str([s.ID for s in p.students])

	state_after_change = (projects, inv_cov_mat_tup)

	print energy(state_after_change)

	return projects
Beispiel #12
0
def move(state, verbose = False, super_verbose = False):
	'''
		Makes a random change to a state.
		
		Picks two random teams, picks two random members, and performs
		a swap of these members across the teams.
		
		NOTE: there should be no teams of size 0 before calling the function.	
	'''
	projects = state[0]
	inv_cov_mat_tup = state[1]

	project_one = util.random_project(projects, [], True)
	project_two = util.random_project(projects, [], True)


	# Guarantee that the projects are not the same.
	# Continue to swap project two until it is diff from project one.
	while (project_one.ID == project_two.ID):
		project_two = util.random_project(projects, [], True)
		if (super_verbose):
			print "Project one and project two are the same."

	if (super_verbose):
		print "Found two different projects."

		print "First team students are " + str([s.ID for s in project_one.students])
		print "Second team students are " + str([s.ID for s in project_two.students])

		print "CLEAR: made it to pick_team"

	# Team to pick first students from 
	pick_team = util.random_two_choice()

	if (pick_team == 0):
		first_team = project_one
		second_team = project_two
	else:
		first_team = project_two
		second_team = project_one

	# Pick a student from the first team, and this student will be swapped.

	student_one = util.random_student(first_team)
	student_two = util.random_student(second_team)

        # Remove the students from their respective teams
	first_team.students.remove(student_one)
	if (not(student_two in second_team.students)):
		if (super_verbose):
			print "Second team students is " + str([s.ID for s in second_team.students])
		error = "Student two ("
		error += str(student_two.ID)
		error += ") is not in second_team.students ("
		error += str(second_team.ID)
		error += ") "
		
		raise CompError(error)
	second_team.students.remove(student_two)

	first_team.students.append(student_two)
	second_team.students.append(student_one)

	if (verbose):
		print "AFTER MOVE:"
		for p in projects:
		 	print str(p.ID) + ": " + str([s.ID for s in p.students])

        #state_after_change = (projects, inv_cov_mat_tup)

	#print energy(state_after_change)

	return projects