Closed corsair20141 closed 11 months ago
@corsair20141 try to increase n_gen
in termination from 100 to 1000, you will get 4 solutions.(they are very close)
Why am I only getting 1 in the first place though? Is there really only 1 non-dominated solution? Typically, with homogeneous variable NSGA-2, you get a pareto front that is the size of your population (50)
Hello @corsair20141, optimization problem involves a lot of domain knowledge. I am not physicist and don't understand your beam problem deeply, so I can't make sure only one non-dominated solution for your problem. The final solution:
[{'BeamHeight': 10, 'FlangeWidth': 10.0, 'WebThickness': 1.0000000000000002, 'FlangeThickness': 1.0, 'Material': 'al_7075'}
{'BeamHeight': 10, 'FlangeWidth': 10.0, 'WebThickness': 1.0, 'FlangeThickness': 1.0, 'Material': 'al_7075'}]
If you doubt it, re-check the constraints and objective functions.
Typically, with homogeneous variable NSGA-2, you get a pareto front that is the size of your population (50)
You're right. if the the size of non-dominated solutions is larger than 50, pymoo only returns 50.
Here is a new problem that has shown up. It seems that the "Choice" method does not work properly on strings; when I have the Choice options as "Material": Choice(options=["al_7075","ss_303"])
sometimes the "choice" becomes "al_707"
which is a partial of one of the string options but not an actual option. This causes errors and may be related to why I am only getting a single survivor in the pareto set, not sure. But this bug is also present in the mixed-variable GA sample code in the documentation (provided below):
from pymoo.core.problem import ElementwiseProblem
from pymoo.core.variable import Real, Integer, Choice, Binary
from pymoo.core.mixed import MixedVariableGA
from pymoo.visualization.scatter import Scatter
from pymoo.algorithms.moo.nsga2 import RankAndCrowdingSurvival
from pymoo.optimize import minimize
from pymoo.core.population import Population
import pandas as pd
class MultiObjectiveMixedVariableProblem(ElementwiseProblem):
def __init__(self, **kwargs):
vars = {
"b": Binary(),
"x": Choice(options=["nothing", "multiply"]),
"y": Integer(bounds=(-2, 2)),
"z": Real(bounds=(-5, 5)),
}
super().__init__(vars=vars, n_obj=2, n_ieq_constr=0, **kwargs)
def _evaluate(self, X, out, *args, **kwargs):
b, x, z, y = X["b"], X["x"], X["z"], X["y"]
f1 = z ** 2 + y ** 2
f2 = (z+2) ** 2 + (y-1) ** 2
if b:
f2 = 100 * f2
print(f"\n{x}")
if x == "multiply":
f2 = 10 * f2
print("Multiplying f2!!!")
out["F"] = [f1, f2]
problem = MultiObjectiveMixedVariableProblem()
algorithm = MixedVariableGA(pop_size=20, survival=RankAndCrowdingSurvival())
res = minimize(problem,
algorithm,
('n_gen', 50),
seed=1,
save_history=True,
verbose=True)
plot = Scatter()
plot.add(problem.pareto_front(), plot_type="line", color="black", alpha=0.7)
plot.add(res.F, facecolor="none", edgecolor="red")
plot.show()
Output showing "Choice":
multipl
multipl
nothing
multipl
multipl
nothing
...
Notice that "multipl" is not "multiply" and therefore the logic inside the example problem does not work.
if x == "multiply":
f2 = 10 * f2
print("Multiplying f2!!!")
There is a bug with the "Choice" variable type.
Hello @corsair20141, Here is the result of your demo code:
And the stdout:
multiply
Multiplying f2!!!
multiply
Multiplying f2!!!
multiply
Multiplying f2!!!
multiply
Multiplying f2!!!
multiply
Multiplying f2!!!
multiply
Multiplying f2!!!
nothing
multiply
Multiplying f2!!!
multiply
...
nothing
multipl
50 | 1000 | 1.8830697321 | 4.9642532090
And pymoo version:
import pymoo
print(pymoo.__version__)
> 0.6.0.1
That is not what happens on my machine. I am also Pymoo Version 0.6.0.1
I get truncated "multipl" and therefore it does NOT trigger the conditional multiplication logic inside the function definition
...
nothing
nothing
multipl
multipl
multipl
multipl
nothing
multipl
nothing
multipl
50 | 1000 | 1.8830697321 | 4.9642532090
print(pymoo.__version__)
0.6.0.1
It appears to truncate the choices at the length of the first choice string. Output if choices are ["noth","mulitply"]:
noth
noth
mult
noth
mult
mult
noth
mult
can you quickly check if it works with the newest version of the main
branch?
What numpy version are you using? Does updating it resolve the issue?
The latest version of Pymoo (0.6.1) fixed the issue, thank you;.
When using the
MixedVariableGA
algorithm, no pareto front is created. Additionally, if you dores.X
andres.F
there is only one output (i.e. the pareto set is not being saved, there should be a population of 50).Code is below. From what I can tell it is similar setup to the MixedVariableGA sample problem. Removing constraints does not fix the issue.