How to make and use the test problems

Currently supported: * ZDT Problems- ZDT1-4, ZDT6 * DTLZ Problems- DTLZ1-7

Import the test problem builder

[1]:
from desdeo_problem.testproblems.TestProblems import test_problem_builder

Use test_problem_builder to build the necessary MOProblem instance, which can be used by methods in desdeo-emo and desdeo-mcdm to solve multiobjective optimization problems

[2]:
help(test_problem_builder)
Help on function test_problem_builder in module desdeo_problem.testproblems.TestProblems:

test_problem_builder(name: str, n_of_variables: int = None, n_of_objectives: int = None) -> desdeo_problem.problem.Problem.MOProblem
    Build test problems. Currently supported: ZDT1-4, ZDT6, and DTLZ1-7.

    Args:
        name (str): Name of the problem in all caps. For example: "ZDT1", "DTLZ4", etc.
        n_of_variables (int, optional): Number of variables. Required for DTLZ problems,
            but can be skipped for ZDT problems as they only support one variable value.
        n_of_objectives (int, optional): Required for DTLZ problems,
            but can be skipped for ZDT problems as they only support one variable value.

    Raises:
        ProblemError: When one of many issues occur while building the MOProblem
            instance.

    Returns:
        MOProblem: The test problem object

[3]:
zdt1 = test_problem_builder("ZDT1")
zdt1
[3]:
<desdeo_problem.problem.Problem.MOProblem at 0x1f33b279ac8>
[4]:
dtlz3 = test_problem_builder("DTLZ3", n_of_objectives= 3, n_of_variables=20)
dtlz3
[4]:
<desdeo_problem.problem.Problem.MOProblem at 0x1f33b279208>

How to use these instances for other purposes, such as generating data:

[5]:
import numpy as np

Generate input data as desired:

[6]:
number_of_samples = 3
zdt_data = np.random.random((number_of_samples, 30))  # 30 is the number of variables in the ZDT1 problem
print(zdt_data)
[[0.9566665  0.12642707 0.75401858 0.03765694 0.01986561 0.48660617
  0.49280935 0.85344899 0.27133411 0.93323257 0.84133493 0.20475801
  0.92905088 0.06490354 0.8570188  0.83492128 0.62833644 0.99593786
  0.81635487 0.82580931 0.56251793 0.97574662 0.47558831 0.3939823
  0.27397178 0.7496003  0.04909389 0.08239682 0.34656906 0.49915204]
 [0.74919761 0.28625722 0.67908382 0.6106337  0.6950148  0.25785019
  0.61746779 0.76319615 0.89890242 0.75963628 0.98161652 0.67291301
  0.79612155 0.52273917 0.20450823 0.7952598  0.60585745 0.4121897
  0.05809478 0.34800526 0.58840432 0.18724738 0.68237086 0.61657321
  0.3096879  0.32458604 0.16036243 0.82480997 0.17956196 0.01421743]
 [0.9957692  0.19364135 0.11009589 0.63606894 0.92162454 0.95342228
  0.88665615 0.74501953 0.09816078 0.48951933 0.76896919 0.64603171
  0.90088292 0.26154581 0.91006787 0.89883207 0.45426937 0.47012129
  0.01451065 0.40256939 0.2019439  0.45817166 0.56534801 0.18641038
  0.91780371 0.19666782 0.83473067 0.15496044 0.01478023 0.85545543]]
[7]:
dtlz_data = np.random.random((number_of_samples, 20)) # We put the number of variables earlier as 20

<MOProblem object>.evaluate(data) returns a tuple containing the objective values and constraint violations

[8]:
zdt_obj_val = zdt1.evaluate(zdt_data)
zdt_obj_val
[8]:
EvaluationResults(objectives=array([[0.9566665 , 3.42361516],
       [0.74919761, 3.55955498],
       [0.9957692 , 3.31853043]]), fitness=array([[0.9566665 , 3.42361516],
       [0.74919761, 3.55955498],
       [0.9957692 , 3.31853043]]), constraints=None, uncertainity=array([[nan, nan],
       [nan, nan],
       [nan, nan]]))

There are no constraints in the zdt or dtlz problems, hence cons_val is None

[9]:
dtlz_obj_val = dtlz3.evaluate(dtlz_data)
dtlz_obj_val
[9]:
EvaluationResults(objectives=array([[1307.49928399, 1214.1266996 ,  555.10066581],
       [ 248.94975775,  162.82774202, 2199.31133262],
       [1052.58290325, 1701.71639663,  600.67385014]]), fitness=array([[1307.49928399, 1214.1266996 ,  555.10066581],
       [ 248.94975775,  162.82774202, 2199.31133262],
       [1052.58290325, 1701.71639663,  600.67385014]]), constraints=None, uncertainity=array([[nan, nan, nan],
       [nan, nan, nan],
       [nan, nan, nan]]))
[ ]: