def feature_extractor2_numpy(sample): resource, work_packages, total_time = sample work_packages = [[ p.getX(), p.getY(), p.getUrgency(), p.getWorkingTime(), p.getUrgency() / p.getWorkingTime(), p.getId() ] for p in work_packages] gnn_feature = np.zeros((define.package_num, define.package_num, 3)) mask = np.zeros((define.package_num, define.package_num, 1)) node_feature = np.zeros((define.package_num, 3)) for p_i in work_packages: i = p_i[5] node_feature[i, 0] = p_i[2] node_feature[i, 1] = p_i[3] node_feature[i, 2] = total_time for p_j in work_packages: j = p_j[5] gnn_feature[i, j, 4] = define.dis(p_i[0], p_j[0], p_i[1], p_j[1]) / define.speed gnn_feature[i, j, 5] = define.dis(resource[0], p_i[0], resource[1], p_i[1]) / define.speed + p_i[3] gnn_feature[i, j, 6] = define.dis(resource[0], p_j[0], resource[1], p_j[1]) / define.speed + p_j[3] mask[i, j] = 1 # for i in range(7): # print(np.max(gnn_feature[:,:,i])) # input() return np.expand_dims(gnn_feature, axis=0), np.expand_dims( mask, axis=0), np.expand_dims(node_feature, axis=0)
def feature_extractor_base(sample, device): resource, work_packages, total_time = sample work_packages = [[ p.getX(), p.getY(), p.getUrgency(), p.getWorkingTime(), p.getUrgency() / p.getWorkingTime(), p.getId() ] for p in work_packages] work_packages.sort(key=lambda x: x[5]) gnn_feature = np.zeros((define.package_num, define.package_num, 5)) resource_dis = np.zeros(define.package_num) for p_i in work_packages: i = p_i[5] gnn_feature[i, :, 0] = p_i[2] gnn_feature[:, i, 1] = p_i[2] gnn_feature[i, :, 2] = p_i[3] gnn_feature[:, i, 3] = p_i[3] resource_dis[i] = define.dis(p_i[0], resource[1], p_i[1], resource[1]) for p_j in work_packages: j = p_j[5] gnn_feature[i, j, 4] = define.dis(p_i[0], p_j[0], p_i[1], p_j[1]) return torch.from_numpy(gnn_feature).to(device), torch.from_numpy( resource_dis).to(device)
def feature_extractor(sample): resource, work_packages, total_time = sample work_packages = [[ p.getX(), p.getY(), p.getUrgency(), p.getWorkingTime(), p.getUrgency() / p.getWorkingTime() ] for p in work_packages] work_packages.sort(key=lambda x: x[4]) work_packages.reverse() gnn_feature = np.zeros((define.package_num, define.package_num, 8)) mask = np.zeros((define.package_num, define.package_num, 1)) for i, p_i in enumerate(work_packages): for j, p_j in enumerate(work_packages): gnn_feature[i, j, 0] = p_i[2] gnn_feature[i, j, 1] = p_j[2] gnn_feature[i, j, 2] = p_i[3] gnn_feature[i, j, 3] = p_j[3] gnn_feature[i, j, 4] = define.dis(p_i[0], p_j[0], p_i[1], p_j[1]) / define.speed gnn_feature[i, j, 5] = define.dis(resource[0], p_i[0], resource[1], p_i[1]) / define.speed gnn_feature[i, j, 6] = define.dis(resource[0], p_j[0], resource[1], p_j[1]) / define.speed gnn_feature[i, j, 7] = total_time mask[i, j] = 1 # for i in range(7): # print(np.max(gnn_feature[:,:,i])) # input() return np.expand_dims(gnn_feature, axis=0), np.expand_dims(mask, axis=0)
def extract_feat(resource, work_packages): work_packages = [[ p.getX(), p.getY(), p.getUrgency(), p.getWorkingTime(), p.getUrgency(), p.getId() ] for p in work_packages] rx, ry, rid = resource.getPosition() gnn_feature = np.zeros((define.get_value('package_num') + 1, define.get_value('package_num') + 1, 4)) for p_i in work_packages: i = p_i[5] for p_j in work_packages: j = p_j[5] gnn_feature[i, j, 0] = p_i[2] gnn_feature[i, j, 1] = p_j[2] gnn_feature[ i, j, 2] = define.dis(p_i[0], p_j[0], p_i[1], p_j[1]) / define.get_value('speed') + p_j[3] gnn_feature[i, j, 3] = 1 for p in work_packages: i = p[5] gnn_feature[-1, i, 2] = define.dis( p[0], rx, p[1], ry) / define.get_value('speed') + p[3] gnn_feature[i, -1, 2] = define.dis(p[0], rx, p[1], ry) / define.get_value('speed') return torch.from_numpy(gnn_feature).unsqueeze(0).float()
def feature_extractor2(sample): resource, work_packages, total_time, end_axis = sample work_packages = [[ p.getX(), p.getY(), p.getUrgency(), p.getWorkingTime(), p.getUrgency(), p.getId() ] for p in work_packages] gnn_feature = np.zeros( (define.get_value('package_num'), define.get_value('package_num'), 8)) mask = np.zeros( (define.get_value('package_num'), define.get_value('package_num'), 1)) for p_i in work_packages: i = p_i[5] for p_j in work_packages: j = p_j[5] gnn_feature[i, j, 0] = p_i[2] gnn_feature[i, j, 1] = p_j[2] # gnn_feature[i, j, 2] = p_i[3] # gnn_feature[i, j, 3] = p_j[3] gnn_feature[i, j, 2] = define.dis(end_axis[0], p_i[0], end_axis[1], p_i[1]) / define.get_value('speed') gnn_feature[i, j, 3] = define.dis(end_axis[0], p_j[0], end_axis[1], p_j[1]) / define.get_value('speed') gnn_feature[ i, j, 4] = define.dis(p_i[0], p_j[0], p_i[1], p_j[1]) / define.get_value('speed') + p_j[3] gnn_feature[ i, j, 5] = define.dis(resource[0], p_i[0], resource[1], p_i[1]) / define.get_value('speed') + p_i[3] gnn_feature[ i, j, 6] = define.dis(resource[0], p_j[0], resource[1], p_j[1]) / define.get_value('speed') + p_j[3] gnn_feature[i, j, 7] = total_time mask[i, j] = 1 # for i in range(7): # print(np.max(gnn_feature[:,:,i])) # input() return np.expand_dims(gnn_feature, axis=0), np.expand_dims(mask, axis=0)
def feature_func(args): gnn_feature, mask, i, p_i, total_time, work_packages, resource = args for j, p_j in enumerate(work_packages): gnn_feature[i, j, 0] = p_i[2] gnn_feature[i, j, 1] = p_j[2] gnn_feature[i, j, 2] = p_i[3] / max(total_time, 1e-3) gnn_feature[i, j, 3] = p_j[3] / max(total_time, 1e-3) gnn_feature[i, j, 4] = define.dis(p_i[0], p_j[0], p_i[1], p_j[1]) / define.speed / max( total_time, 1e-3) gnn_feature[i, j, 5] = define.dis(resource[0], p_i[0], resource[1], p_i[1]) / define.speed / max( total_time, 1e-3) gnn_feature[i, j, 6] = define.dis(resource[0], p_j[0], resource[1], p_j[1]) / define.speed / max( total_time, 1e-3) for k in range(2, 7): if gnn_feature[i, j, k] > 1: tmp = gnn_feature[i, j, k] - 1 gnn_feature[i, j, k] = 2 - np.exp(-tmp) mask[i, j] = 1
def getReturnTime(self, p): end_x, end_y = self.__resource.getInitialPos() p_x, p_y = p.getPosition() t = define.dis(end_x, p_x, end_y, p_y) / self.speed return t