當前位置: 首頁>>代碼示例>>Python>>正文


Python Result.print_nicely方法代碼示例

本文整理匯總了Python中result.Result.print_nicely方法的典型用法代碼示例。如果您正苦於以下問題:Python Result.print_nicely方法的具體用法?Python Result.print_nicely怎麽用?Python Result.print_nicely使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在result.Result的用法示例。


在下文中一共展示了Result.print_nicely方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: execute

# 需要導入模塊: from result import Result [as 別名]
# 或者: from result.Result import print_nicely [as 別名]
def execute(prefs, print_output=True, recursion_limit=10000):
	# adjust the system's recursion call depth limit
	# system default is 1000
	sys.setrecursionlimit(recursion_limit)

	# SETUP --> CREATE PERSON OBJECTS
	Person.setup(prefs)

	if print_output:
		print("Starting Preference Matrix -- Phase 0 Complete:")
		pprint.pprint(Person.prefsMatrix('current'))

	# PHASE 1

	#core of phase 1 --> everybody proposes to their top choice
	for person in Person.ppl.values():
		# before proposing, we need to make sure everybody hasn't rejected them yet!
		# this would happen iff everybody else has already received better offers...
		if len(person.current_prefs) > 0:       
			person.propose_to(person.current_prefs[0])  # propose to your top choice

	if print_output:
		print("Phase 1 Complete:")
		pprint.pprint(Person.prefsMatrix('current'))

	# does anybody have an empty column at the end of phase one?
	has_empty_column_after_phase_one = Person.empty_column()
	print("Empty column --> " + str(has_empty_column_after_phase_one))

	# PHASE 2

	#find the initial person with a second column
	current_person = Person.find_person_with_second_column()    

	num_rotations = 1    # number of rotations so far...

	# while we still have a person with a second column
	while current_person: 

		# grab their second choice preference
		current_pref = current_person.current_prefs[1]

		# and cross off that person's last preference.... 
		# which kicks off the rotation
		current_pref.cross_off(current_pref.current_prefs[-1])

		if print_output:
			print("Rotating around person " + current_person.name + 
				", with preference " + current_pref.name)
			print("Rotation #" + str(num_rotations) + ":")

			num_rotations = num_rotations + 1
			pprint.pprint(Person.prefsMatrix('current'))	

		# find another person to work with... if there is one
		current_person = Person.find_person_with_second_column()

	if print_output:
		print("Phase 2 Complete:")
		pprint.pprint(Person.prefsMatrix('current'))

		print("\nRESULTS:\n")

	# who wasn't matched?
	ppl_without_match = Person.who_wasnt_matched()
	stable = False

	#if everybody was matched, was the match stable?
	if len(ppl_without_match) == 0:
		stable = Person.was_the_match_stable()

	# grab the corresponding result object
	result = Result(Person.ppl,ppl_without_match,stable,Person.prefsMatrix("initial"))

	if print_output:
		result.print_nicely()

	# HYPOTHESIS: if there is not an empty column at the end of phase one,
	# there should be a stable match --> but this is currently NOT the case
	# if (not stable) and (not has_empty_column_after_phase_one):
		# raise Exception("The match was unstable, yet there was not an empty column at the end of phase one.")

	return result
開發者ID:charlierproctor,項目名稱:matching_algorithm,代碼行數:85,代碼來源:matchmaker.py


注:本文中的result.Result.print_nicely方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。