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


Python algorithm.Algorithm類代碼示例

本文整理匯總了Python中algorithm.Algorithm的典型用法代碼示例。如果您正苦於以下問題:Python Algorithm類的具體用法?Python Algorithm怎麽用?Python Algorithm使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


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

示例1: __init__

	def __init__(self, g):
		Algorithm.__init__(self, g)
		self.REPAIR_PERIOD=20*self.MSG_PERIOD
		self.RETRY_PERIOD=self.REPAIR_PERIOD
		self.tables={}
		#init tables
		self.repair()
開發者ID:gpleiss,項目名稱:OlinMeshNetwork,代碼行數:7,代碼來源:BATMANalgorithm.py

示例2: repair

	def repair(self):
		transmissions=len(self.g.nodes()) #All the hellos.
		for n in self.g.nodes():
			if self.old_g.nodes().count(n)>0:
				new_neighborhood=self.g.neighbors(n)
				old_neighborhood=self.old_g.neighbors(n)
				transmittedLSA=False
				for neighbor in new_neighborhood:
					if old_neighborhood.count(neighbor)==0:
						(f,t)=Algorithm.util_flood(self.g,n)
						transmissions+=t
						transmittedLSA=True
						break
				if transmittedLSA:
					break
				for neighbor in old_neighborhood:
					if new_neighborhood.count(neighbor)==0:
						(f,t)=Algorithm.util_flood(self.g,n)
						transmissions+=t
						break
			else:
				(f,t)=Algorithm.util_flood(self.g, n)
				transmissions+=t
		self.old_g=copy.deepcopy(self.g)
		return transmissions
			
開發者ID:gpleiss,項目名稱:OlinMeshNetwork,代碼行數:25,代碼來源:GLSRalgorithm.py

示例3: __init__

	def __init__ (self, num_players, horizon=100):
		Algorithm.__init__(self, num_players)
		# Y[i,j] is the proportion of games player i beat over player j
		# N[i,j] is the number of games i and j have played against each other
		self.Y = np.zeros((num_players, num_players))
		self.N = np.zeros((num_players, num_players))
		self.T = horizon
		self.ranking_procedure = Copeland(num_players, self.Y)
開發者ID:keeganryan,項目名稱:urban-bassoon,代碼行數:8,代碼來源:Naive_RankEL_Algorithm.py

示例4: __init__

 def __init__(self, memory_size, selection_method):
     # Los bloques adyacentes a un bloque vacio siempre estan llenos
     # Los bloques adyacentes a un bloque lleno pueden estar vacios o llenos
     
     Algorithm.__init__(self, memory_size)
     self.selection_method = selection_method # Seleccion de bloque vacio (Primer ajuste, mejor ajuste o peor ajuste)
     self.full             = {} # Mapeo de bloques llenos: PCB -> Bloque
     self.empty            = [Block(0, memory_size - 1)] # Lista de bloques vacios
開發者ID:Alejandro-Merlo,項目名稱:Sistemas-Operativos,代碼行數:8,代碼來源:mvt.py

示例5: __init__

	def __init__(self, g):
		'''
		Constructor
		'''
		Algorithm.__init__(self, g)
		self.tables = {}		
		#init tables
		for node in self.g.nodes():
			self.tables[node]={}
開發者ID:gpleiss,項目名稱:OlinMeshNetwork,代碼行數:9,代碼來源:OWNalgorithm.py

示例6: parse_file

def parse_file(fp):
    #Check if file validates and the content
    if validate_file(fp):
        lines = fp.read().replace('\n', '')
        if validate_contents(lines):
            #do JSON stuff, bonus points right here
            pass
        else:
            parse_text = Algorithm(lines)
            return parse_text.determine_language()
開發者ID:jghyllebert,項目名稱:determine-language,代碼行數:10,代碼來源:parse_messages.py

示例7: test_segments

	def test_segments(self):
		point_array = [
			Point(19, 42), 
			Point(34, 5), 
			Point(66, 66), 
			Point(49, 86)
		]
		algo = Algorithm(point_array)
		algo.stack = point_array
		seg_list = algo.segments()

		self.assertEqual(str(seg_list[0]), str(Segment(Point(19, 42), Point(34, 5))))
開發者ID:tks2103,項目名稱:Graham_Scan,代碼行數:12,代碼來源:test_algorithm.py

示例8: test_output_polar

	def test_output_polar(self):

		point_array = [
			Point(19.2486849886, 42.0138353124), 
			Point(34.6545353825, 5.95845608147), 
			Point(66.6014654767, 66.0841191785), 
			Point(49.1321252346, 86.6154463314)
		]
		algo = Algorithm(point_array)
		polar_list = algo.polar_angle_sort(Point(34.6545353825, 5.95845608147))

		self.assertEqual(str(polar_list[0]), str(Point(34.6545353825, 5.95845608147)))
開發者ID:tks2103,項目名稱:Graham_Scan,代碼行數:12,代碼來源:test_algorithm.py

示例9: LanguageTest

class LanguageTest(unittest.TestCase):

    def setUp(self):
        self.message = "Dit is een fijn bericht"
        self.algorithm = Algorithm(self.message)

    def test_algorithm(self):
        """
        Only test for words that are 4 characters or more
        """
        self.assertEqual(self.algorithm._determine_keywords(), ['fijn', 'bericht'])

    def test_determine_language(self):
        self.assertEqual(self.algorithm.determine_language(), 'nl')
開發者ID:jghyllebert,項目名稱:determine-language,代碼行數:14,代碼來源:test_algorithm.py

示例10: __init__

 def __init__(self):
     Algorithm.__init__(self)
     self.digits = '123456789'
     self.rows = 'ABCDEFGHI'
     self.cols = self.digits
     self.squares = self.cross(self.rows, self.cols)
     self.unitlist = ([self.cross(self.rows, col) for col in self.cols] +
                      [self.cross(row, self.cols) for row in self.rows] +
                      [self.cross(row_square, col_square) for row_square in ('ABC','DEF','GHI')
                      for col_square in ('123','456','789')])
     self.units = dict((square, [un for un in self.unitlist if square in un])
                       for square in self.squares)
     self.peers = dict((square, set(sum(self.units[square],[]))-set([square]))
                       for square in self.squares)
開發者ID:rsanchezG,項目名稱:sudokuB-1,代碼行數:14,代碼來源:norvig_algorithm.py

示例11: test_polar_angle

	def test_polar_angle(self):
		point_array = [Point(1, 1), Point(2, 2), Point(2, 3), Point(2, 1)]
		algo = Algorithm(point_array)
		polar_list = algo.polar_angle_sort(Point(1,1))


		self.assertEqual(str(polar_list[0]), str(Point(1, 1)))
		self.assertEqual(str(polar_list[1]), str(Point(2, 1)))
		self.assertEqual(str(polar_list[-1]), str(Point(2, 3)))

		point_array = [Point(1, 1), Point(0, 2), Point(2, 3), Point(2, 1)]
		algo = Algorithm(point_array)
		polar_list = algo.polar_angle_sort(Point(1,1))

		self.assertEqual(str(polar_list[-1]), str(Point(0,2)))
開發者ID:tks2103,項目名稱:Graham_Scan,代碼行數:15,代碼來源:test_algorithm.py

示例12: __init__

	def __init__(self, num_players, ranking_procedure=Copeland, alpha=0.51, horizon=100):
		Algorithm.__init__(self, num_players)
		# W[i,j] is the proportion of games player i beat over player j
		# U[i,j] is the upper confidence interval
		self.W = np.zeros((num_players, num_players))
		self.U = np.zeros((num_players, num_players))
		self.Y = np.zeros((num_players, num_players))
		self.N = np.zeros((num_players, num_players))
		self.T = horizon # Horizon
		assert(alpha > 0.5)
		self.alpha = alpha
		self.ranking = list(range(num_players))
		np.random.shuffle(self.ranking)
		
		self.ranking_procedure = ranking_procedure(num_players, self.Y)
開發者ID:keeganryan,項目名稱:urban-bassoon,代碼行數:15,代碼來源:RUCB_Algorithm.py

示例13: __init__

	def __init__(self, title):
		
		gtk.Window.__init__(self, title=title)
		self.set_size_request(0, 600)
		self.set_resizable(False)
		self.set_border_width(5)
		self.connect('delete-event', gtk.main_quit)

		self.algorithm = Algorithm()

		self.file_type = 'fasta'
		self.first_seq = ""
		self.second_seq = ""

		self.main_box = gtk.Box(spacing=5, orientation=gtk.Orientation.VERTICAL)
		self.add(self.main_box)

		self.add_logo()
		self.add_file_type_radio_buttons()

		self.add_first_squence_widgets()
		self.main_box.pack_start(gtk.Label(), False, False, 0)
		self.add_second_squence_widgets()

		self.add_controls_buttons()
開發者ID:muhammedeltabakh,項目名稱:SEQUENCE-X-SEQUENCE,代碼行數:25,代碼來源:gui.py

示例14: __init__

    def __init__(self, **kwargs):
        """Takes configuration in kwargs.
        """
        #: An Aspen :class:`~aspen.request_processor.RequestProcessor` instance.
        self.request_processor = RequestProcessor(**kwargs)

        pando_chain = Algorithm.from_dotted_name("pando.state_chain")
        pando_chain.functions = [getattr(f, "placeholder_for", f) for f in pando_chain.functions]
        #: The chain of functions used to process an HTTP request, imported from
        #: :mod:`pando.state_chain`.
        self.state_chain = pando_chain

        # copy aspen's config variables, for backward compatibility
        extra = "typecasters renderer_factories default_renderers_by_media_type"
        for key in list(ASPEN_KNOBS) + extra.split():
            self.__dict__[key] = self.request_processor.__dict__[key]

        # load our own config variables
        configure(KNOBS, self.__dict__, "PANDO_", kwargs)

        # add ourself to the initial context of simplates
        self.request_processor.simplate_defaults.initial_context["website"] = self

        # load bodyparsers
        #: Mapping of content types to parsing functions.
        self.body_parsers = {
            "application/x-www-form-urlencoded": body_parsers.formdata,
            "multipart/form-data": body_parsers.formdata,
            self.media_type_json: body_parsers.jsondata,
        }
開發者ID:AspenWeb,項目名稱:pando.py,代碼行數:30,代碼來源:website.py

示例15: initializeAlgorithm

    def initializeAlgorithm(populatinSize, dataLength, iterationsNumber, mutationRate, crossoverRate):

        chromosomeDataFactory = ChromosomeDataFactory()
        chromosomeDataFactory.dataLength = dataLength

        chromosomeFactory = ChromosomeFactory()
        chromosomeFactory.chromosomeDataFactory = chromosomeDataFactory
        chromosomeFactory.crossoverRate = crossoverRate
        chromosomeFactory.mutationRate = mutationRate

        populationFactory = PopulationFactory()
        populationFactory.chromosomeFactory = chromosomeFactory
        populationFactory.populationSize = populatinSize

        algorithm = Algorithm()
        algorithm.population = populationFactory.create()
        algorithm.numberOfIterations = iterationsNumber

        return algorithm
開發者ID:skltl,項目名稱:ubiquitous-duck,代碼行數:19,代碼來源:initializer.py


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