Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Real Variable Type - Precision addition #399

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions pymoo/core/variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ def get(self, **kwargs):

class BoundedVariable(Variable):

def __init__(self, value=None, bounds=(None, None), strict=None, **kwargs) -> None:
def __init__(self, value=None, bounds=(None, None), strict=None, precision = 6, **kwargs) -> None:
super().__init__(value=value, **kwargs)
self.bounds = bounds
self.precision = precision

if strict is None:
strict = bounds
Expand All @@ -49,7 +50,9 @@ class Real(BoundedVariable):

def _sample(self, n):
low, high = self.bounds
return np.random.uniform(low=low, high=high, size=n)
self.step = 10**(-self.precision)
n_steps = int(np.round((high - low) / self.step))
return np.round(low + np.random.randint(n_steps+1, size = n) * self.step, self.precision)


class Integer(BoundedVariable):
Expand Down