Objective Maximisation

ENTMOOT supports both minimisation and maximisation of objective functions. This notebook defines a concave function, that has a maximum at (1, 1).

[1]:
from entmoot import Enting, ProblemConfig, PyomoOptimizer
import numpy as np
[2]:
# define a maximisation problem
def eval_simple_max_testfunc(X):
    x = np.array(X)
    y = - np.sum((x - np.ones_like(x)) ** 2, axis=1)
    return y.reshape(-1, 1)

def build_simple_max_problem(problem_config: ProblemConfig):
    problem_config.add_feature("real", (0.0, 2.0), name="x1")
    problem_config.add_feature("real", (0.0, 2.0), name="x2")
    problem_config.add_max_objective()
[3]:
# define problem
problem_config = ProblemConfig(rnd_seed=73)
# number of objectives
build_simple_max_problem(problem_config)
# sample data
rnd_sample = problem_config.get_rnd_sample_list(num_samples=200)
testfunc_evals = eval_simple_max_testfunc(rnd_sample)

params = {"unc_params": {"dist_metric": "l1", "acq_sense": "penalty"}}
enting = Enting(problem_config, params=params)
enting.fit(rnd_sample, testfunc_evals)
[10]:
params_pyomo = {"solver_name": "gurobi_direct"}
opt_pyo = PyomoOptimizer(problem_config, params=params_pyomo)

res_pyo = opt_pyo.solve(enting)
res_pyo
WARNING: The gurobipy module (an optional Pyomo dependency) failed to import:
NameError: name 'GurobiDirect' is not defined
---------------------------------------------------------------------------
ApplicationError                          Traceback (most recent call last)
Cell In[10], line 4
      1 params_pyomo = {"solver_name": "gurobi_direct"}
      2 opt_pyo = PyomoOptimizer(problem_config, params=params_pyomo)
----> 4 res_pyo = opt_pyo.solve(enting)
      5 res_pyo

File ~\phd\entmoot\entmoot\optimizers\pyomo_opt.py:104, in PyomoOptimizer.solve(self, tree_model, model_core, weights)
    102 # Solve optimization model
    103 verbose = self._params.get("verbose", True)
--> 104 opt.solve(opt_model, tee=verbose)
    106 # update current solution
    107 self._curr_sol, self._active_leaves = self._get_sol(opt_model)

File c:\Users\tobyb\phd\phdvenv\lib\site-packages\pyomo\solvers\plugins\solvers\direct_solver.py:75, in DirectSolver.solve(self, *args, **kwds)
     72 def solve(self, *args, **kwds):
     73     """Solve the problem"""
---> 75     self.available(exception_flag=True)
     76     #
     77     # If the inputs are models, then validate that they have been
     78     # constructed! Collect suffix names to try and import from solution.
     79     #
     80     _model = None

File c:\Users\tobyb\phd\phdvenv\lib\site-packages\pyomo\solvers\plugins\solvers\gurobi_direct.py:215, in GurobiDirect.available(self, exception_flag)
    213     if exception_flag:
    214         gurobipy.log_import_warning(logger=__name__)
--> 215         raise ApplicationError(
    216             "No Python bindings available for %s solver plugin" % (type(self),)
    217         )
    218     return False
    220 # Ensure environment is started to check for a valid license

ApplicationError: No Python bindings available for <class 'pyomo.solvers.plugins.solvers.gurobi_direct.GurobiDirect'> solver plugin
[ ]: