示例#1
0
        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(
                filename=os.path.join(example_path, "AuxiliaryServices.csv")),
            PointSearch)
        method.current_iter = ci + 1
        method.zh_prev = method.zh = zh
        method.fh = fh
        method.fh_lo = fh_lo
        # method.fh_lo=list(method.bounds_factory.result(method.zh_prev))

        solution = tui.iter_nautilus(method)
    method.printCurrentIteration()
    try:
        from prompt_toolkit import prompt
        a = prompt(u'Press ENTER to exit')
    except:
        pass
示例#2
0
* River pollution problem

"""
from desdeo.method import NIMBUS, NAUTILUSv1
from desdeo.optimization import SciPyDE
from desdeo.preference import NIMBUSClassification
from desdeo.problem.toy import RiverPollution
from desdeo.utils import tui

if __name__ == "__main__":
    # Solve River Pollution problem using NAUTILUS
    # Using tui
    print("Solve with NAUTILUS method")
    natmeth = NAUTILUSv1(RiverPollution(), SciPyDE)
    NAUTILUS_solution = tui.iter_nautilus(natmeth)
    print("NAUTILUS solution")
    print(NAUTILUS_solution)
    # Output:
    # [-6.2927077117830965, -3.4038593790999485,
    #   -7.401394350956817, 1.6201876469013787]

    # Continue solving  River Pollution problem
    # From NAUTILUS solution

    nimmeth = NIMBUS(RiverPollution(), SciPyDE)
    nimmeth.init_iteration()
    print("Solving with NIMBUS method")
    class1 = NIMBUSClassification(nimmeth, [(">=", -5.5), (">=", -3.0),
                                            ("<=", -6.5), ("<=", -2.0)])
    iter1 = nimmeth.next_iteration(preference=class1)
示例#3
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")
示例#4
0
        [0.5, 0.1, 0.3, 0.1],
        [0.5, 0.3, 0.1, 0.1],
        [0.7, 0.1, 0.1, 0.1],
    ]
}

if __name__ == '__main__':

    from desdeo.utils import tui
    from desdeo.method import NAUTILUSv1
    from desdeo.optimization import SciPyDE

    # Solve River Pollution problem using NAUTILUS
    # Using tui
    method = NAUTILUSv1(RiverPollution(), SciPyDE)
    NAUTILUS_solution = tui.iter_nautilus(method)[0]
    print(method.problem.to_ui(NAUTILUS_solution))
    # Output:
    # [-6.2927077117830965, -3.4038593790999485,
    #   -7.401394350956817, 1.6201876469013787]

    # Continue solving  River Pollution problem
    # From NAUTILUS solution

    from desdeo.method import NIMBUS
    from desdeo.preference import NIMBUSClassification

    method = NIMBUS(RiverPollution(), SciPyDE)

    method.selected_solution = NAUTILUS_solution[0]