print(f"Loop {counter} of {total_count}")
            counter += 1
            # build problem
            var_names = ["x" + str(i + 1) for i in range(n_var)]
            obj_names = ["f" + str(i + 1) for i in range(n_obj)]
            prob = wfg_problem(
                name=problem_name, n_of_objectives=n_obj, n_of_variables=n_var
            )
            variables = variable_builder(
                names=var_names,
                initial_values=prob.lower,
                lower_bounds=prob.lower,
                upper_bounds=prob.upper,
            )
            objective = VectorObjective(name=obj_names, evaluator=prob.eval)
            problem = MOProblem([objective], variables, None)
            problem.ideal = prob.ideal
            problem.nadir = (
                abs(np.random.normal(size=n_obj, scale=0.15)) + 1
            ) * prob.nadir

            true_nadir = prob.nadir

            scalar = asf(ideal=problem.ideal, nadir=true_nadir)

            # a posteriori
            a_post_rvea = RVEA(
                problem=problem, interact=False, n_gen_per_iter=gen, n_iterations=4
            )
            a_post_nsga = NSGAIII(
                problem=problem, interact=False, n_gen_per_iter=gen, n_iterations=4
Beispiel #2
0
        return (x[0] + x[1]) - 0.5

    f1 = _ScalarObjective(name="f1", evaluator=f_1)
    f2 = _ScalarObjective(name="f2", evaluator=f_2)
    f3 = _ScalarObjective(name="f3", evaluator=f_3)
    f4 = _ScalarObjective(name="f4", evaluator=f_4)
    f5 = _ScalarObjective(name="f5", evaluator=f_5)
    varsl = variable_builder(
        ["x_1", "x_2"],
        initial_values=[0.5, 0.5],
        lower_bounds=[0.3, 0.3],
        upper_bounds=[1.0, 1.0],
    )
    c1 = ScalarConstraint("c1", 2, 5, evaluator=c_1)
    problem = MOProblem(variables=varsl,
                        objectives=[f1, f2, f3, f4, f5],
                        constraints=[c1])

    method = NIMBUS(problem, scalar_method="scipy_de")
    reqs = method.request_classification()[0]

    response = {}
    response["classifications"] = ["<", "<=", "=", ">=", "0"]
    response["levels"] = [-6, -3, -5, 8, 0.349]
    response["number_of_solutions"] = 3
    reqs.response = response
    res_1 = method.iterate(reqs)[0]
    res_1.response = {"indices": []}

    res_2 = method.iterate(res_1)[0]
    response = {}
Beispiel #3
0
    objkaikki = VectorObjective("obj", objectives)

    # variables
    var_names = ["x1", "x2"
                 ]  # Make sure that the variable names are meaningful to you.

    initial_values = np.array([0.5, 0.5])
    lower_bounds = [0.3, 0.3]
    upper_bounds = [1.0, 1.0]
    bounds = np.stack((lower_bounds, upper_bounds))
    variables = variable_builder(var_names, initial_values, lower_bounds,
                                 upper_bounds)

    # problem
    prob = MOProblem(objectives=[obj1, obj2, obj3, obj4],
                     variables=variables)  # objectives "seperately"

    # solved in Nautilus.py
    ideal = np.array([-6.34, -3.44487179, -7.5, 0])
    nadir = np.array([-4.751, -2.86054116, -0.32111111, 9.70666666])

    # start solving
    method = ReferencePointMethod(problem=prob, ideal=ideal, nadir=nadir)

    # Pareto optimal solution: [-6.30, -3.26, -2.60, 3.63]

    print("Let's start solving\n")
    req = method.start()
    rp = np.array([-5.0, -3.0, -3.0, 5.0])
    req.response = {
        "reference_point": rp,
def test_problem_builder(name: str,
                         n_of_variables: int = None,
                         n_of_objectives: int = None) -> 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
    """
    problems = {
        "ZDT1": zdt.ZDT1,
        "ZDT2": zdt.ZDT2,
        "ZDT3": zdt.ZDT3,
        "ZDT4": zdt.ZDT4,
        "ZDT5": zdt.ZDT5,
        "ZDT6": zdt.ZDT6,
        "DTLZ1": dtlz.DTLZ1,
        "DTLZ2": dtlz.DTLZ2,
        "DTLZ3": dtlz.DTLZ3,
        "DTLZ4": dtlz.DTLZ4,
        "DTLZ5": dtlz.DTLZ5,
        "DTLZ6": dtlz.DTLZ6,
        "DTLZ7": dtlz.DTLZ7,
    }
    num_var = {"ZDT1": 30, "ZDT2": 30, "ZDT3": 30, "ZDT4": 10, "ZDT6": 10}
    if not (name in problems.keys()):
        msg = (
            "Specified Problem not yet supported.\n The supported problems are:"
            + str(problems.keys()))
        raise ProblemError(msg)
    if "ZDT" in name:
        if n_of_variables is None:
            n_of_variables = num_var[name]
        if n_of_objectives is None:
            n_of_objectives = 2
        if not (n_of_variables == num_var[name]):
            msg = (name + " problem has been limited to " +
                   str(num_var[name]) +
                   " variables. Number of variables recieved = " +
                   str(n_of_variables))
            raise ProblemError(msg)
        if not (n_of_objectives == 2):
            msg = ("ZDT problems can only have 2 objectives. " +
                   "Number of objectives recieved = " + str(n_of_objectives))
            raise ProblemError(msg)
        obj_func = problems[name]()
    elif "DTLZ" in name:
        if (n_of_variables is None) or (n_of_objectives is None):
            msg = ("Please provide both number of variables and objectives" +
                   " for the DTLZ problems")
            raise ProblemError(msg)
        obj_func = problems[name](n_of_objectives, n_of_variables)
    else:
        msg = "How did you end up here?"
        raise ProblemError(msg)
    lower_limits = obj_func.min_bounds
    upper_limits = obj_func.max_bounds
    var_names = ["x" + str(i + 1) for i in range(n_of_variables)]
    obj_names = ["f" + str(i + 1) for i in range(n_of_objectives)]
    variables = variable_builder(
        names=var_names,
        initial_values=lower_limits,
        lower_bounds=lower_limits,
        upper_bounds=upper_limits,
    )

    # Because optproblems can only handle one objective at a time
    def modified_obj_func(x):
        if isinstance(x, list):
            if len(x) == n_of_variables:
                return [obj_func(x)]
            elif len(x[0]) == n_of_variables:
                return list(map(obj_func, x))
        else:
            if x.ndim == 1:
                return [obj_func(x)]
            elif x.ndim == 2:
                return list(map(obj_func, x))
        raise TypeError("Unforseen problem, contact developer")

    objective = VectorObjective(name=obj_names, evaluator=modified_obj_func)
    problem = MOProblem([objective], variables, None)
    return problem
    # define the variables, bounds -5 <= x_1 and x_2 <= 5
    varsl = variable_builder(["x_1", "x_2", "x_3"],
                             initial_values=[0.5, 0.5, 0.5],
                             lower_bounds=[-5, -5, -5],
                             upper_bounds=[5, 5, 5])

    # define constraints
    def c_1(x, f=None):
        x = x.squeeze()
        # x_1 < 2
        return x[0] + 2

    # name of constraints, num variables, num objectives, evaluator
    c1 = ScalarConstraint("c1", len(varsl), len(objl), evaluator=c_1)

    problem = MOProblem(variables=varsl, objectives=objl, constraints=[c1])

    max_bool = list(
        map(lambda x: True if x < 0 else False, problem._max_multiplier))
    max_multiplier = problem._max_multiplier

    # define ideal and nadir
    ideal = max_multiplier * np.array([-15, 15, 15])
    nadir = max_multiplier * np.array([15, -15, -15])

    problem.ideal = ideal
    problem.nadir = nadir

    # GLOBAL
    global method
    method = NIMBUS(problem, scalar_method="scipy_de")
Beispiel #6
0

f1 = _ScalarObjective(name="f1", evaluator=f_1, maximize=[True])
f2 = _ScalarObjective(name="f2", evaluator=f_2, maximize=[True])
f3 = _ScalarObjective(name="f3", evaluator=f_3, maximize=[True])
f4 = _ScalarObjective(name="f4", evaluator=f_4)
f5 = _ScalarObjective(name="f5", evaluator=f_5)

varsl = variable_builder(
    ["x_1", "x_2"],
    initial_values=[0.5, 0.5],
    lower_bounds=[0.3, 0.3],
    upper_bounds=[1.0, 1.0],
)

problem = MOProblem(variables=varsl, objectives=[f1, f2, f3, f4, f5])

evolver = RVEA(problem, interact=True, n_iterations=10, n_gen_per_iter=100)

_, pref = evolver.iterate()
n_iteration = 1

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.bind(("10.0.2.15", 5005))
# sock.bind(("127.0.0.1", 5005))
sock.listen(1)

print("Waiting for ComVis to connect...")
connection, client_addr = sock.accept()

print("Connection estabilished!")
Beispiel #7
0
        lower_bounds=[-5, -5, -5],
        upper_bounds=[5, 5, 5],
    )

    f1 = _ScalarObjective(name="f1", evaluator=f_1)
    f2 = _ScalarObjective(name="f2", evaluator=f_2)

    #For AI_DM ranges are always defined as IDEAL, NADIR.
    f1_range = [-20, -14]
    f2_range = [-14, 0.5]
    x1 = np.linspace(min(f1_range), max(f1_range), 1000)
    x2 = np.linspace(min(f2_range), max(f2_range), 1000)
    y = np.linspace(0, 0, 1000)

    problem = MOProblem(variables=varsl,
                        objectives=[f1, f2],
                        ideal=np.array([-20, -12]),
                        nadir=np.array([-14, 0.5]))

    from desdeo_mcdm.interactive.NIMBUS import NIMBUS
    from scipy.optimize import minimize, differential_evolution

    scalar_method = ScalarMethod(
        lambda x, _, **y: differential_evolution(x, **y),
        use_scipy=True,
        method_args={
            "polish": True,
            "disp": True
        })

    method = NIMBUS(problem, scalar_method)
Beispiel #8
0
    return -0.5 + (x[:, 0] - 0.5)**2 + (x[:, 1] - 0.5)**2


list_vars = variable_builder(["x", "y"],
                             initial_values=[0, 0],
                             lower_bounds=[0, 0],
                             upper_bounds=[np.pi, np.pi])

f1 = _ScalarObjective(name="f1", evaluator=f_1)
f2 = _ScalarObjective(name="f2", evaluator=f_2)

c1 = ScalarConstraint("c1", 2, 2, c_1)
c2 = ScalarConstraint("c2", 2, 2, c_2)

problem = MOProblem(variables=list_vars,
                    objectives=[f1, f2],
                    constraints=[c1, c2])

evolver = RVEA(problem)
"""
figure = animate_init_(evolver.population.objectives, filename="MOPC4.html")
"""
while evolver.continue_evolution():
    evolver.iterate()
    """figure = animate_next_(
        evolver.population.objectives,
        figure,
        filename="MOPC4.html",
        generation=evolver._iteration_counter,
    )
"""