当前位置: 首页>>代码示例>>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;未经允许,请勿转载。