Skip to content

[BUG] ImportError: cannot import name 'Literal' from 'typing' #766

@AmosJoseph

Description

@AmosJoseph

Checklist

  • I searched existing issues
  • I'm using the latest pymoo version

Bug Description

I run mixed variable problem, but error occurred.

Please see the code below:

Minimal Code to Reproduce

from pymoo.core.variable import Real, Integer
from pymoo.optimize import minimize
from pymoo.core.mixed import MixedVariableGA
import numpy as np
 
from pymoo.core.problem import ElementwiseProblem
 

class MultiObjectiveMixedVariableProblem(ElementwiseProblem):

    def __init__(self, **kwargs):
        vars = {
            "x1": Real(bounds=(3, 20)),
            "x2": Real(bounds=(20, 30)),
            "x3": Real(bounds=(0, 90)),
            "x4": Real(bounds=(0, 90)),
            "x5": Integer(bounds=(1, 3)),
        }
        super().__init__(vars=vars, n_obj=2, n_ieq_constr=0, **kwargs)

    def _evaluate(self, X, out, *args, **kwargs):
        x1, x2, x3, x4, x5  = X["x1"], X["x2"], X["x3"], X["x4"], X["x5"]

        f1 = -(0.157437 * (x1 ** 7) + 0.981186 * (x5 ** 6) * x2 - 0.220173 * (x4 ** 6) * x3 
        f2 = 0

        if x5 == 1:
            #f2 = 1600*100*lr*0.001*0.25*np.pi*(400+ 200/rt)*(200/rt)*0.000001
            f2 = x1*np.pi*(2+ 1/x2)*(1.59999/x2)   
        if x5 == 2:
            #f2 = 1640*100*lr*0.001*0.25*np.pi*(400+ 200/rt)*(200/rt)*0.000001
            f2 =  x1* np.pi*(2+ 1/x2)*(1.64/x2) 
        if x5 == 3:
            #f2 = 1700*100*lr*0.001*0.25*np.pi*(400+ 200/rt)*(200/rt)*0.000001   
            f2 = x1*np.pi*(2+ 1/x2)*(1.69999/x2)   
        
        #out["F"] = [f1, f2]
        out["F"] = f1, f2


from pymoo.visualization.scatter import Scatter
from pymoo.algorithms.moo.nsga2 import RankAndCrowdingSurvival
from pymoo.core.mixed import MixedVariableGA
from pymoo.optimize import minimize

problem = MultiObjectiveMixedVariableProblem()

algorithm = MixedVariableGA(pop_size=100, survival=RankAndCrowdingSurvival())
#algorithm = MixedVariableGA(pop_size=100, survival=RankAndCrowding())


res = minimize(problem,
               algorithm,
               ('n_gen', 200),
               seed=1,
               verbose=False)

Error Message

ImportError: cannot import name 'Literal' from 'typing' (D:\anaconda3\lib\typing.py)

PyMoo & Python Version

pymoo-0.6.1.2 python3.7.6

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions