示例#1
0
 def optimize(self, reference_graphs):
     """Optimize iteratively."""
     assert (self.grammar.is_fit())
     assert (self.multiobj_est.is_fit())
     seed_graph = self._init_pareto(reference_graphs)
     # iterate
     last(islice(iterate(self._update_pareto_set, seed_graph), self.n_iter))
     graphs = self.pareto_set
     return self._rank(graphs)
示例#2
0
 def iterated_neighborhood(self, graph):
     """iterated_neighborhood."""
     n = self.n_neigh_steps
     if n == 1:
         return pipe(graph, self.neighborhood, self._random_sample)
     else:
         return last(islice(iterate(self.set_neighborhood, [graph]), n + 1))
示例#3
0
def test_nth():
    l = list([1, 2, 3])
    i = iter([1, 2, 3])
    assert_that(nth(2, l)).is_equal_to(3)
    assert_that(nth(2, l)).is_equal_to(3)
    assert_that(nth(2, i)).is_equal_to(3)  #Can do only once for the iter
    assert_that(last(l)).is_equal_to(nth(len(l) - 1, l))
示例#4
0
def authors_concat_string(author, authors):
    """
    return proper authors string, dependent on number of authors (1, 2, or
    many)
    """
    nr = len(authors)
    name = author['name']
    is_last = lambda d: (last(authors) == author and "and {}".format(name)
                         ) or d
    return (nr == 1 and name)\
        or (nr == 2 and is_last(name)) \
        or is_last("{},".format(name))
示例#5
0
文件: utils.py 项目: RedHatQE/pong
def get_latest_test_run(test_run_name):
    """
    Gets the most recent TestRun based on the test_run_name

    NOTE: the test_run_name should be the name of a test run without the integer.
    For example, if your TestRun id is normally "Jenkins Run 1", then test_run_name
    should be "Jenkins Run".

    :param test_run_name: test run id string
    :return: TestRun
    """
    from pylarion.test_run import TestRun
    s = TestRun.search('"{}"'.format(test_run_name),
                       fields=["test_run_id", "created", "status"],
                       sort="created")
    current = None
    if s:
        latest = itz.last(s)
        current = TestRun(uri=latest.uri)
    return current
示例#6
0
 def sample(self, reference_graphs):
     """Optimize iteratively."""
     # setup
     #iteration_step_ = curry(self._iteration_step)(
     #    self.grammar, self.cost_estimator, self.max_neighborhood_order)
     iteration_step_ = lambda x: self._iteration_step(
         self.grammar, self.cost_estimator, self.max_neighborhood_order, x)
     state_dict = dict()
     state_dict['visited'] = set()
     n_neigh_steps = 1
     start_graphs = self.grammar.set_neighborhood(reference_graphs)
     costs = self.cost_estimator.compute(start_graphs)
     state_dict['pareto_set'] = get_pareto_set(start_graphs, costs)
     seed_graph = random.choice(state_dict['pareto_set'])
     arg = (seed_graph, state_dict, n_neigh_steps)
     # iterate
     arg = last(islice(iterate(iteration_step_, arg), self.max_n_iter))
     seed_graph, state_dict, n_neigh_steps = arg
     pareto_set_graphs = state_dict['pareto_set']
     return pareto_set_graphs
示例#7
0
def test_last():
    assert last('ABCDE') == 'E'
    assert last((3, 2, 1)) == 1
    assert isinstance(last({0: 'zero', 1: 'one'}), int)