Multi dimensional array in pymoo #454
circlewithedges
started this conversation in
Show and tell
Replies: 1 comment 1 reply
-
Your variables always need to be 1-dimensional (this is the case for many optimization frameworks by the way). You can flatten the array during optimization and then reshape it when evaluating. I have. provided an example for this a while ago for a 2-dimensional matrix (in theory this works for any dimension) |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
As I am new to coding and also to these type of optimization. I was trying to define a function using 2 dimension array. Can I do this using pymoo and what necessary changes i have to make in order to use multidimensional array. Reason for using multi dimensional array is that i have to solve large Optimization problem which consist Variables up to 4 indices (e.g. X_i_j_k_l) and i, j ,k, l can run up to any no. , is there any other way to implement this other than multi dimensional array. These i j k l can run up to different no.(e.g. i-(1,5), j- (1-3), k-(1-8), l - (1-14))
I have tried to write a code in 2d array but error is coming.
import numpy as np
from pymoo.core.problem import ElementwiseProblem
class MyProblem(ElementwiseProblem):
problem = MyProblem()
from pymoo.algorithms.moo.nsga2 import NSGA2
from pymoo.operators.crossover.sbx import SBX
from pymoo.operators.mutation.pm import PM
from pymoo.operators.sampling.rnd import FloatRandomSampling
algorithm = NSGA2(
pop_size=40,
n_offsprings=10,
sampling=FloatRandomSampling(),
crossover=SBX(prob=0.9, eta=15),
mutation=PM(eta=20),
eliminate_duplicates=True
)
from pymoo.termination import get_termination
termination = get_termination("n_gen", 40)
from pymoo.optimize import minimize
res = minimize(problem,
algorithm,
termination,
seed=1,
save_history=True,
verbose=True)
X = res.X
F = res.F
Beta Was this translation helpful? Give feedback.
All reactions