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

wrapper() takes 1 positional argument but 2 were given #386

Open
cumttc opened this issue Oct 9, 2024 · 0 comments
Open

wrapper() takes 1 positional argument but 2 were given #386

cumttc opened this issue Oct 9, 2024 · 0 comments

Comments

@cumttc
Copy link

cumttc commented Oct 9, 2024

wrapper() 需要 1 个位置参数,但给出了 2 个
class dingwei(eaproblem): # 继承Problem父类

def __init__(self,**kwargs):
    name = 'MyProblem'  # 初始化name(函数名称,可以随意设置)
    M = 1  # 初始化M(目标维数)
    maxormins = [-1]  # 初始化maxormins(目标最小最大化标记列表,1:最小化该目标;-1:最大化该目标)
    Dim = 4 # 初始化Dim(决策变量维数)
    self.var_set = np.arange(0,1000,1)#初始化varSet(决策变量的取值范围)
    varTypes = [1,1,1,1]   # 初始化varTypes(决策变量的类型,元素为0表示对应的变量是连续的;1表示是离散的)
    lb = [100, 100, 100, 0]  # 决策变量下界
    ub = [900, 900, 900, 3]  # 决策变量上界
    lbin = [0, 0, 0, 1]  # 决策变量下边界(0表示不包含该变量的下边界,1表示包含)
    ubin = [0, 0, 0, 1]  # 决策变量上边界(0表示不包含该变量的上边界,1表示包含)
    self.s = kwargs.get('slowness', None)
    self.rcv = kwargs.get('rcv', None)
    self.t = kwargs.get('t', None)
    # 调用父类构造方法完成实例化
    eaproblem.__init__(self,name,M,maxormins,Dim,varTypes,lb,ub,lbin,ubin)
@eaproblem.single
def evalVars(self, Vars):  # 目标函数
    x,y,z,t0 = Vars[0],Vars[1],Vars[2],Vars[3]*0.02
    f = fun_d3(src = np.array([x,y,z]),slowness = self.s,rcv = self.rcv,t_obj = self.t,t0 = t0)
    print(f)
    return f

TypeError: wrapper() takes 1 positional argument but 2 were given
实际结果是,print(Vars)和print(f)并未被执行
我确保我的 fun_d3()返回值是一个浮点数,请问什么是导致它执行失败的?

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

1 participant