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

about MixedVariableProblem,How to generate a matrix of specified shape #585

Open
AiIsBetter opened this issue Apr 10, 2024 · 1 comment
Assignees

Comments

@AiIsBetter
Copy link

class MixedVariableProblem(ElementwiseProblem):

def __init__(self, **kwargs):
    vars = {
        "b": Binary(),
        "x": Choice(options=["nothing", "multiply"]),
        "y": Integer(bounds=(0, 2)),
        "z": Real(bounds=(0, 5)),
    }
    super().__init__(vars=vars, n_obj=1, **kwargs)

def _evaluate(self, X, out, *args, **kwargs):
    b, x, z, y = X["b"], X["x"], X["z"], X["y"]

    f = z + y
    if b:
        f = 100 * f

    if x == "multiply":
        f = 10 * f

    out["F"] = f

I used the mixed-type variable setting method in the tutorial, but found that each variable can only generate one value each time it is evaluated, instead of specifying upper and lower limits to generate a matrix of corresponding dimensions like a normal Problem. If it is a normal Problem definition method, can each candidate solution be of binary type? Maybe I do not understand the specific method of generating candidate solutions. But according to my understanding, I need to use binary and floating-point variables in normal Problem。

@blankjul blankjul self-assigned this Apr 22, 2024
@blankjul
Copy link
Collaborator

If you have a SINGLE type you can define a vector. For mixed problems you always define one variable at a time.
You can define a problem with binary vectors as variables this way:
https://pymoo.org/customization/binary.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants