Esempio n. 1
0
def test_running_NNAUTILUS():
    method = NNAUTILUS(
        PreGeneratedProblem(
            filename=os.path.join(example_path, "AuxiliaryServices.csv")
        ),
        PointSearch,
    )
    vals = run(method, [-43000, 2, -60], 6)
    assert len(vals) == 6
Esempio n. 2
0
def test_running_NIMBUS():
    vals = []
    method = NIMBUS(
        PreGeneratedProblem(
            filename=os.path.join(example_path, "AuxiliaryServices.csv")),
        PointSearch)

    run1 = run(
        method,
        NIMBUSClassification(method.problem, [("<", None), (">=", 1),
                                              ("<", None)]))
    assert run1[0][1] < 1
    assert len(run1) == 2

    # When using point search, there should not be better solutions when projected
    cls = []
    for v in run1[0]:
        cls.append(("<=", v))
    run2 = run(method, NIMBUSClassification(method.problem, cls))

    assert np.isclose(run1[0], run2[1]).all()  # pylint: disable=E1101
Esempio n. 3
0
def test_point_search():
    method = NIMBUS(
        PreGeneratedProblem(
            filename=os.path.join(example_path, "AuxiliaryServices.csv")
        ),
        PointSearch,
    )

    run1 = run(
        method, NIMBUSClassification(method, [("<", None), (">=", 1), ("<", None)])
    )

    assert run1.objective_vars[0][1] >= 1
    assert len(run1.items) == 4

    # When using point search, there should not be better solutions when projected
    cls = []
    for v in run1.objective_vars[0]:
        cls.append(("<=", v))
    run2 = run(method, NIMBUSClassification(method, cls))

    assert np.isclose(
        run1.objective_vars[0], run2.objective_vars[1]
    ).all()  # pylint: disable=E1101
Esempio n. 4
0
import sys, os

example_path = os.path.dirname(os.path.realpath(__file__))
sys.path.append(os.path.join(example_path, ".."))

from desdeo.utils import tui

from desdeo.method.NAUTILUS import NAUTILUSv1, ENAUTILUS

from desdeo.optimization.OptimizationMethod import PointSearch
from desdeo.problem.Problem import PreGeneratedProblem

if __name__ == '__main__':
    # SciPy breaks box constraints
    method = ENAUTILUS(
        PreGeneratedProblem(
            filename=os.path.join(example_path, "AuxiliaryServices.csv")),
        PointSearch)
    zh = tui.iter_enautilus(method)
    ci = method.current_iter

    if ci > 0:
        if zh is None:
            fh = zh = method.problem.nadir
            fh_lo = method.problem.ideal

        else:
            zh = method.zh_prev
            fh_lo = method.fh_lo_prev
            fh = method.nsPoint_prev
        method = NAUTILUSv1(
            PreGeneratedProblem(
Esempio n. 5
0
def main(logfile=False):
    """ Solve River Pollution problem with NAUTILUS V1 and E-NAUTILUS Methods
    """

    # Duplicate output to log file

    class NAUTILUSOptionValidator(Validator):
        def validate(self, document):
            if document.text not in "ao":
                raise ValidationError(
                    message=
                    "Please select a for apriori or o for optimization option",
                    cursor_position=0,
                )

    if logfile:
        Tee(logfile)
    first = True
    current_iter = 0
    while first or current_iter:
        # SciPy breaks box constraints

        nautilus_v1 = NAUTILUSv1(RiverPollution(), SciPyDE)
        if not first:
            nautilus_v1.current_iter = current_iter
        first = False
        nadir = nautilus_v1.problem.nadir
        ideal = nautilus_v1.problem.ideal

        solution = tui.iter_nautilus(nautilus_v1)

        current_iter = nautilus_v1.current_iter

        # TODO: Move to tui module
        method_e = None
        if current_iter > 0:
            option = _prompt_wrapper(
                "select a for apriori or o for optimization option: ",
                default="o",
                validator=NAUTILUSOptionValidator(),
            )
            if option.lower() == "a":
                wi = _prompt_wrapper(
                    "Number of PO solutions (10 or 20): ",
                    default="20",
                    validator=tui.NumberValidator(),
                )
                weights = WEIGHTS[wi]

                factory = IterationPointFactory(
                    SciPyDE(NautilusAchievementProblem(RiverPollution())))
                points = misc.new_points(factory, solution, weights=weights)

                method_e = ENAUTILUS(PreGeneratedProblem(points=points),
                                     PointSearch)
                method_e.zh_prev = solution

            else:
                method_e = ENAUTILUS(RiverPollution(), SciPyDE)

            # method_e.zh = solution
            method_e.current_iter = nautilus_v1.current_iter
            method_e.user_iters = nautilus_v1.user_iters

            print("E-NAUTILUS\nselected iteration point: %s:" %
                  ",".join(map(str, solution)))

            while method_e and method_e.current_iter > 0:
                if solution is None:
                    solution = method_e.problem.nadir

                method_e.problem.nadir = nadir
                method_e.problem.ideal = ideal
                cmd = tui.iter_enautilus(method_e,
                                         initial_iterpoint=solution,
                                         initial_bound=method_e.fh_lo)
                if cmd:
                    print(method_e.current_iter)
                    current_iter = method_e.current_iter
                    break
    if tui.HAS_INPUT:
        input("Press ENTER to exit")
Esempio n. 6
0
    ci = method.current_iter
    if ci > 0:
        try:
            from prompt_toolkit import prompt
            weights = prompt(u'Weights (10 or 20): ',
                             default=u"20",
                             validator=tui.NumberValidator())
        except:
            weights = "20"

        factory = IterationPointFactory(
            SciPyDE(AchievementProblem(NaurulaWeistroffer())))
        points = misc.new_points(factory, solution, WEIGHTS[weights])

        method = ENAUTILUS(PreGeneratedProblem(points=points), PointSearch)
        method.current_iter = ci
        method.zh_prev = solution
        print("E-NAUTILUS\nselected iteration point: %s:" %
              ",".join(map(str, method.zh_prev)))

    while method.current_iter > 0:
        if solution is None:
            solution = method.problem.nadir
            # Generate new points
        # print solution

        method.problem.nadir = nadir
        method.problem.ideal = ideal
        tui.iter_enautilus(method)
        solution = method.zh_prev