本文整理汇总了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()
示例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
示例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)
示例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
示例5: __init__
def __init__(self, g):
'''
Constructor
'''
Algorithm.__init__(self, g)
self.tables = {}
#init tables
for node in self.g.nodes():
self.tables[node]={}
示例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()
示例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))))
示例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)))
示例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')
示例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)
示例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)))
示例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)
示例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()
示例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,
}
示例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