def testCPlusResult(): fu = pd.read_csv( "/Users/sean/Documents/Projects/Packing-Algorithm/data/c_test.csv") _len = fu.shape[0] for i in range(_len): PltFunc.addPolygon(json.loads(fu["polygon"][i])) PltFunc.showPlt()
def showLPResult(): fu = pd.read_csv( "/Users/sean/Documents/Projects/Packing-Algorithm/record/lp_result.csv" ) _len = fu.shape[0] for i in range(_len): PltFunc.addPolygon(json.loads(fu["polygon"][i])) PltFunc.showPlt()
def showAll(self): # for i in range(0,2): for i in range(0, len(self.polygons)): PltFunc.addPolygon(self.polygons[i]) length = max(self.width, self.contain_length) # PltFunc.addLine([[self.width,0],[self.width,self.contain_height]],color="blue") PltFunc.showPlt(width=max(length, self.width), height=max(length, self.width), minus=100)
def showPolys(self): for poly in self.polys: PltFunc.addPolygon(poly) PltFunc.addPolygonColor([[0, 0], [self.cur_length, 0], [self.cur_length, self.width], [0, self.width]]) PltFunc.showPlt(width=1000, height=1000)
def getPredictionRelative(self): model = load_model("/Users/sean/Documents/Projects/Packing-Algorithm/model/lstm_num_5_layer_128_56_2_epochs_70.h5") pre_train = pd.read_csv("/Users/sean/Documents/Projects/Data/pre_train.csv") # 读取形状 _input = pd.read_csv("/Users/sean/Documents/Projects/Data/input_seq.csv") # 读取输入 _output = pd.read_csv("/Users/sean/Documents/Projects/Data/output_relative_position.csv") # 读取输入 # index=random.randint(4000,5000) index=4500 polys=json.loads(pre_train["polys"][index]) # 形状 X = np.array([json.loads(_input["x_256"][index])]) # 输入 predicted_Y = model.predict(X, verbose=0)[0]*1500 print(predicted_Y) Y=np.array(json.loads(_output["y"][index]))*1500 print(Y) old_centroid=[0,0] for i,poly in enumerate(polys): # 获得初始的中心和预测的位置 centroid_origin=GeoFunc.getPt(Polygon(poly).centroid) centroid_predicted=[Y[i][0]+old_centroid[0],Y[i][1]+old_centroid[1]] # 获得新的形状并更新 new_poly=GeoFunc.getSlide(poly,centroid_predicted[0]-centroid_origin[0],centroid_predicted[1]-centroid_origin[1]) old_centroid=GeoFunc.getPt(Polygon(new_poly).centroid) PltFunc.addPolygon(poly) PltFunc.addPolygonColor(new_poly) PltFunc.showPlt()
def showPolys(self, polys): for i in range(0, len(polys) - 1): PltFunc.addPolygon(polys[i]) PltFunc.addPolygonColor(polys[len(polys) - 1]) length = max(self.width, self.contain_length) PltFunc.showPlt(width=max(length, self.width), height=max(length, self.width), minus=200)
def getPredictionAbsolute(self): model = load_model("/Users/sean/Documents/Projects/Packing-Algorithm/model/absolute_lstm_num_8_layer_128_56_2_epochs_200.h5") file= pd.read_csv("/Users/sean/Documents/Projects/Data/8_lstm_test.csv") # 读取输入 index=random.randint(3700,4700) index=3000 polys=json.loads(file["polys"][index]) # 形状 X = np.array([json.loads(file["x_256"][index])]) # 输入 predicted_Y = model.predict(X, verbose=0)[0]*4000 for i,poly in enumerate(polys): centroid_origin=GeoFunc.getPt(Polygon(poly).centroid) PltFunc.addPolygon(poly) new_poly=GeoFunc.getSlide(poly,predicted_Y[i][0]-centroid_origin[0],predicted_Y[i][1]-centroid_origin[1]) PltFunc.addPolygonColor(new_poly) PltFunc.showPlt()
def showResult(self): '''显示排样结果''' for poly in self.cur_polys: PltFunc.addPolygon(poly) PltFunc.showPlt(width=2000, height=2000)