code: def maximise_with_method_on_cp_domain(
      method,
      obj,
      domain,
      max_evals,
      return_history=False,
      *args,
      **kwargs,
  ):
      """A wrapper for maximising an objective on a CartesianProductDomain."""
      # pylint: disable=too-many-locals
      # pylint: disable=too-many-branches
      if method.lower().startswith(
          ("direct", "pdoo")
      ):  # ------------------------------------
          # If the domain consists entirely of Euclidean parts, use PDOO or DiRect
          return maximise_with_method_on_product_euclidean_spaces(
              method,
              obj,
              domain.list_of_domains,
              max_evals,
              return_history,
              *args,
              **kwargs,
          )
      elif (
          method.lower() == "rand"
      ):  # -------------------------------------------------------
          # Use a random optimiser
          return _rand_maximise_vectorised_objective_in_cp_domain(
              obj, domain, max_evals, return_history
          )
      elif method.lower().startswith(
          "ga"
      ):  # ------------------------------------------------
          # First decide if there is a follow up Euclidean opt method
          ga_opt_methods = method.lower().split("-")
          euc_domains = [
              dom
              for dom in domain.list_of_domains
              if dom.get_type() == "euclidean"
          ]
          if len(ga_opt_methods) == 2 and len(euc_domains) > 0:
              to_follow_up_with_euc_opt = True
              euc_opt_method = ga_opt_methods[1]
              euc_domain_idxs = [
                  idx
                  for (idx, dom) in enumerate(domain.list_of_domains)
                  if dom.get_type() == "euclidean"
              ]
          else:
              to_follow_up_with_euc_opt = False
          # Run a GA optimiser ---------------------------------------
          from .worker_manager import SyntheticWorkerManager
          from .experiment_caller import CPFunctionCaller
          from ..opt.cp_ga_optimiser import (
              cp_ga_optimiser_from_proc_args,
          )
  
          obj_in_func_caller = CPFunctionCaller(
              obj, domain, domain_orderings=None
          )
          worker_manager = SyntheticWorkerManager(
              1, time_distro="const"
          )
          (
              ga_max_val,
              ga_max_pt,
              ga_history,
          ) = cp_ga_optimiser_from_proc_args(
              obj_in_func_caller,
              domain,
              worker_manager,
              max_evals,
              mode="asy",
              options=None,
              reporter="silent",
          )
          # Finished running a GA optimiser --------------------------
          if to_follow_up_with_euc_opt:
              # If you need to do an additional optimisation on the Euclidean part, do so.
              def _swap_indices_at_point(swap_pt, orig_pt, swap_idxs):
                  """Swap indices at point swap_pt."""
                  ret = orig_pt[:]
                  for sidx, spt in zip(swap_idxs, swap_pt):
                      ret[sidx] = spt
                  return ret
  
              def _get_swapped_obj(_obj, _orig_pt, _swap_idxs):
                  """Returns an objective which swaps in new points at _swap_idxs."""
                  return lambda x: _obj(
                      _swap_indices_at_point(x, _orig_pt, _swap_idxs)
                  )
  
              swapped_obj = _get_swapped_obj(
                  obj, ga_max_pt, euc_domain_idxs
              )
              (
                  euc_max_val,
                  euc_max_pt,
              ) = maximise_with_method_on_product_euclidean_spaces(
                  euc_opt_method,
                  swapped_obj,
                  euc_domains,
                  max_evals,
                  return_history=False,
              )
              if euc_max_val > ga_max_val:
                  max_val = euc_max_val
                  history = ga_history
                  max_pt = _swap_indices_at_point(
                      euc_max_pt, ga_max_pt, euc_domain_idxs
                  )
              else:
                  max_val, max_pt, history = (
                      ga_max_val,
                      ga_max_pt,
                      ga_history,
                  )
          else:
              max_val, max_pt, history = (
                  ga_max_val,
                  ga_max_pt,
                  ga_history,
              )
          # return
          if return_history:
              return max_val, max_pt, history
          else:
              return max_val, max_pt
      else:
          raise NotImplementedError("Not implemented yet!")
  
imports: from argparse import Namespace
  import numpy
  from .cp_domain_utils import get_processed_from_raw_via_config, get_raw_from_processed_via_config, sample_from_cp_domain
  from ..utils.general_utils import map_to_bounds, flatten_list_of_lists
  from ..utils.oper_utils import direct_ft_maximise, latin_hc_sampling, pdoo_maximise, random_maximise
label_desc: Use image node_id 16 for calling a global function with example usage: maximise_with_method_on_cp_domain(method, obj, domain, max_evals, return_history) and returns: maximise_with_method_on_product_euclidean_spaces, _rand_maximise_vectorised_objective_in_cp_domain, max_val,  max_pt,  history, max_val,  max_pt, ret, function