MCPcopy Create free account
hub / github.com/anyoptimization/pymoo / eval

Method eval

pymoo/core/evaluator.py:37–96  ·  view source on GitHub ↗
(
        self,
        problem: Problem,
        pop: Population,
        skip_already_evaluated: bool | None = None,
        evaluate_values_of: list[Any] | None = None,
        count_evals: bool = True,
        **kwargs,
    )

Source from the content-addressed store, hash-verified

35 self.n_eval = 0
36
37 def eval(
38 self,
39 problem: Problem,
40 pop: Population,
41 skip_already_evaluated: bool | None = None,
42 evaluate_values_of: list[Any] | None = None,
43 count_evals: bool = True,
44 **kwargs,
45 ):
46
47 # load the default settings from the evaluator object if not already provided
48 evaluate_values_of = (
49 self.evaluate_values_of
50 if evaluate_values_of is None
51 else evaluate_values_of
52 )
53 skip_already_evaluated = (
54 self.skip_already_evaluated
55 if skip_already_evaluated is None
56 else skip_already_evaluated
57 )
58
59 # check the type of the input
60 is_individual = isinstance(pop, Individual)
61
62 # make sure the object is a population
63 if is_individual:
64 pop = Population().create(pop)
65
66 # filter the index to have individual where not all attributes have been evaluated
67 if skip_already_evaluated:
68 I = np.array( # noqa: E741
69 [
70 i
71 for i, ind in enumerate(pop)
72 if not all([e in ind.evaluated for e in evaluate_values_of])
73 ]
74 )
75
76 # if skipping is deactivated simply make the index being all individuals
77 else:
78 I = np.arange(len(pop)) # noqa: E741
79
80 # evaluate the solutions (if there are any)
81 if len(I) > 0:
82 # do the actual evaluation - call the sub-function to set the corresponding values to the population
83 self._eval(problem, pop[I], evaluate_values_of, **kwargs)
84
85 # update the function evaluation counter
86 if count_evals:
87 self.n_eval += len(I)
88
89 # allow to have a callback registered
90 if self.callback:
91 self.callback(pop)
92
93 if is_individual:
94 return pop[0]

Callers 15

test_evaluate_individualFunction · 0.95
test_evaluate_popFunction · 0.95
test_preevaluatedFunction · 0.95
nextMethod · 0.45
_setupMethod · 0.45
_advanceMethod · 0.45
_advanceMethod · 0.45
_initialize_infillMethod · 0.45
_initialize_infillMethod · 0.45
_advanceMethod · 0.45
stepMethod · 0.45

Calls 3

_evalMethod · 0.95
PopulationClass · 0.90
createMethod · 0.80

Tested by 9

test_evaluate_individualFunction · 0.76
test_evaluate_popFunction · 0.76
test_preevaluatedFunction · 0.76
test_associationFunction · 0.36
test_update_caFunction · 0.36
test_update_daFunction · 0.36
test_updateFunction · 0.36