Skip to content
This repository was archived by the owner on Jul 16, 2024. It is now read-only.
This repository was archived by the owner on Jul 16, 2024. It is now read-only.

How to initialize problem with lower_bound and upper_bound  #190

@panlei7

Description

@panlei7

I hope to initialize class MyProblem with bounds in arguments, not assign values directly in init(self, dim) like examples. The codes below is wrong, and the error messages is at the end.

from PyGMO.problem import base

class MyProblem(base):
    """Defined problem needed by PyGMO

    MyProblem(forward, lower_bound, upper_bound)

    forward: a instance of class Forward.(Forward is a class about the fitness function)
    lower_bound, upper_bound: bounds of the problem
    """

    def __init__(self, forward, lower_bound, upper_bound):
        self.forward = forward
        dim = forward.nx_ig * forward.ny_ig
        super(MyProblem, self).__init__(dim)
        self.set_bounds(lower_bound, upper_bound)

    def _objfun_impl(self, x):
        f = self.foward.get_obj(x)
        return (f, )

    def human_readable_extra(self):
        return "\n\t Problem dimension: " + str(self.__dim)
Traceback (most recent call last):
  File "/usr/local/bin/ttinv", line 9, in <module>
    load_entry_point('islandopt', 'console_scripts', 'ttinv')()
  File "/Users/lei/Work/pagmo_fmm/traveltime/command_line.py", line 43, in main
    isl = island(algo, prob, num_individual)
  File "/usr/local/lib/python3.5/site-packages/PyGMO/core/__init__.py", line 242, in island
    return _generic_island_ctor(None, *args, **kwargs)
  File "/usr/local/lib/python3.5/site-packages/PyGMO/core/__init__.py", line 132, in _generic_island_ctor
    return py_island(*args, **kwargs)
  File "/usr/local/lib/python3.5/site-packages/PyGMO/core/__init__.py", line 119, in _generic_island_ctor
    super(type(self), self).__init__(*ctor_args)
  File "/usr/local/lib/python3.5/site-packages/PyGMO/core/__init__.py", line 48, in __init__
    _core._base_island.__init__(self, *args)
  File "/usr/local/lib/python3.5/site-packages/PyGMO/problem/_base.py", line 36, in __get_deepcopy__
    return deepcopy(self)
  File "/usr/local/Cellar/python3/3.5.2_3/Frameworks/Python.framework/Versions/3.5/lib/python3.5/copy.py", line 182, in deepcopy
    y = _reconstruct(x, rv, 1, memo)
  File "/usr/local/Cellar/python3/3.5.2_3/Frameworks/Python.framework/Versions/3.5/lib/python3.5/copy.py", line 292, in _reconstruct
    y = callable(*args)
TypeError: __init__() missing 3 required positional arguments: 'forward', 'lower_bound', and 'upper_bound'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions