pymoo icon indicating copy to clipboard operation
pymoo copied to clipboard

about MixedVariableProblem,How to generate a matrix of specified shape

Open AiIsBetter opened this issue 1 year ago • 1 comments

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。

AiIsBetter avatar Apr 10 '24 08:04 AiIsBetter

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

blankjul avatar Apr 22 '24 02:04 blankjul