| Total Complexity | 4 | 
| Total Lines | 28 | 
| Duplicated Lines | 0 % | 
| Changes | 0 | ||
| 1 | from ._result import Result | ||
| 2 | |||
| 3 | |||
| 4 | class ObjectiveAdapter: | ||
| 5 | """Maps *pos* → (score, metrics, params).""" | ||
| 6 | |||
| 7 | def __init__(self, conv, objective): | ||
| 8 | self._conv = conv | ||
| 9 | self._objective = objective # user callable | ||
| 10 | |||
| 11 | def _call_objective(self, pos): | ||
| 12 | """Run the underlying objective and normalise outputs.""" | ||
| 13 | params = self._conv.value2para(self._conv.position2value(pos)) | ||
| 14 | out = self._objective(params) | ||
| 15 | |||
| 16 | if isinstance(out, tuple): | ||
| 17 | score, metrics = out | ||
| 18 | else: | ||
| 19 |             score, metrics = float(out), {} | ||
| 20 | |||
| 21 | result = Result(score, metrics) | ||
| 22 | |||
| 23 | return result, params | ||
| 24 | |||
| 25 | # keep one public entry point so subclasses can override cleanly | ||
| 26 | def __call__(self, pos): | ||
| 27 | return self._call_objective(pos) | ||
| 28 |