You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
def __init__(self):
name = 'MyProblem' # 初始化name(函数名称,可以随意设置)
M = 1 # 初始化M(目标维数)
maxormins = [1] # 初始化maxormins(目标最小最大化标记列表,1:最小化该目标;-1:最大化该目标)
Dim = len(good_list) # 初始化Dim(决策变量维数)
varTypes = [1] * Dim # 初始化varTypes(决策变量的类型,元素为0表示对应的变量是连续的;1表示是离散的)
lb = [0] * Dim # 决策变量下界
ub = [Num_jz] * Dim # 决策变量上界
lbin = [0] * Dim # 决策变量下边界(0表示不包含该变量的下边界,1表示包含)
ubin = [0] * Dim # 决策变量上边界(0表示不包含该变量的上边界,1表示包含)
# 调用父类构造方法完成实例化
ea.Problem.__init__(self,
name,
M,
maxormins,
Dim,
varTypes,
lb,
ub,
lbin,
ubin)
def evalVars(self, pop): # 目标函数
x = pop.astype(int)
t = x.shape[0]
fx=[]
for i in range(0, t):
t1 = x[[i], :]
for j in t1:
f = 0
for k in range(xyz.shape[0]):
if np.array_equal(j, k):
f = f +((xyz[k][0]+xyz[k][0]//2)/vx+xyz[k][1]/vy+xyz[k][2]/vz)*L*good_list[j][2]
fx.append(f)
fx = np.array(fx).reshape(-1, 1)
ObjV = fx
return ObjV
调用main,会报错:Objv不合法
怎么解决呢
The text was updated successfully, but these errors were encountered:
-- coding: utf-8 --
import numpy as np
import geatpy as ea
A = 2 # x方向有A个货位
B = 2 # y方向有B个货架
C = 3 # z方向有C层
L = 10 # 货位的长、宽、高
vx = 1 # 叉车的x速度
vy = 0.5 # 叉车的y速度
vz = 2 # 叉车的z速度
Num_jz = ABC
good_list = [[1, [1, 1, 1], 0.05], [2, [1, 1, 2], 0.03], [3, [1, 1, 3], 0.06]]
生成 x, y, z 坐标的矩阵
x, y, z = np.meshgrid(np.arange(A), np.arange(B), np.arange(C), indexing='ij')
将三维矩阵转换为一维数组并编号
xyz = np.column_stack((x.reshape(-1), y.reshape(-1), z.reshape(-1)))
class MyProblem(ea.Problem): # 继承Problem父类
调用main,会报错:Objv不合法
怎么解决呢
The text was updated successfully, but these errors were encountered: