|
@@ -1,87 +1,89 @@
|
|
|
-package test;
|
|
|
-
|
|
|
-import test.entity.OccupyPerX;
|
|
|
-import test.entity.Point;
|
|
|
-import test.entity.WholeIndexOccupy;
|
|
|
+package index.alg;
|
|
|
+
|
|
|
+import index.adjust.Adjust;
|
|
|
+import index.adjust.PointXYCorRevise;
|
|
|
+import index.alg.analyse.CalHpTimeDistance;
|
|
|
+import index.entity.OccupyPerX;
|
|
|
+import index.entity.Point;
|
|
|
+import index.entity.WholeIndexOccupy;
|
|
|
+import index.file.OperateFile;
|
|
|
+import index.fit.Fit;
|
|
|
+import index.plot.Plot;
|
|
|
+import org.apache.commons.math3.analysis.function.Gaussian;
|
|
|
|
|
|
import java.io.FileNotFoundException;
|
|
|
-import java.lang.reflect.Array;
|
|
|
import java.sql.SQLException;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
public class Cal {
|
|
|
-
|
|
|
ArrayList<OccupyPerX> occupyPerXArrayList = new ArrayList<>();//占用情况
|
|
|
-
|
|
|
Integer numOfGaps = 100;
|
|
|
+ Fit fit = new Fit();
|
|
|
|
|
|
- public ArrayList<Point> calShape() throws SQLException, FileNotFoundException {
|
|
|
-
|
|
|
+ public ArrayList<Point> calShape(Integer workDirection) throws SQLException, FileNotFoundException {
|
|
|
GetPoints getPoints = new GetPoints();
|
|
|
- getPoints.getPoints();
|
|
|
-
|
|
|
+ getPoints.getPoints(workDirection);
|
|
|
ArrayList<Point> realShapePoints = getPoints.realShapePoints;//实际形状的平面坐标
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
// GetPoints getPoints = new GetPoints();//所有待计算点
|
|
|
ArrayList<Point> allPoints = getPoints.allPoints;//所有待计算点,铲车作业平面坐标
|
|
|
+
|
|
|
+ ///
|
|
|
+ ArrayList<ArrayList<Date>> dateForAna = getPoints.dateForAna;
|
|
|
+ CalHpTimeDistance calHpTimeDistance = new CalHpTimeDistance(dateForAna);
|
|
|
+ calHpTimeDistance.buildDistribution(10);
|
|
|
+ ///
|
|
|
+ System.out.println("未过滤前点数量 : " + allPoints.size() );
|
|
|
Split split = new Split();
|
|
|
split.cal(realShapePoints);
|
|
|
-
|
|
|
ArrayList<Double> xIndexCorList = split.xIndexCorList;//格点横坐标List
|
|
|
ArrayList<Double> yIndexCorList = split.yIndexCorList;//格点纵坐标List
|
|
|
WholeIndexOccupy wholeIndexOccupy = split.wholeIndexOccupy;//初始垛位的占用情况
|
|
|
// ArrayList<Point> occupyShapeList = wholeIndexOccupy.getOccupyPointsArrayList();//坐标形式的初始形状
|
|
|
-
|
|
|
System.out.println(occupyPerXArrayList);
|
|
|
-
|
|
|
// wholeIndexOccupy.printOccupy();
|
|
|
-
|
|
|
Double xGap = split.xGap;//横向上采用的间隔
|
|
|
Double yGap = split.yGap;//纵向上采用的间隔
|
|
|
-
|
|
|
Double minX = xIndexCorList.get(0);
|
|
|
Double maxX = xIndexCorList.get(xIndexCorList.size() - 1);
|
|
|
Double minY = yIndexCorList.get(0);
|
|
|
Double maxY = yIndexCorList.get(yIndexCorList.size() - 1);
|
|
|
-
|
|
|
wholeIndexOccupy.printOccupy(minX,minY,xGap,yGap);
|
|
|
ArrayList<Point> occupyShapeList = wholeIndexOccupy.getOccupyPointsArrayList();//坐标形式的初始形状
|
|
|
-
|
|
|
-
|
|
|
ArrayList<Point> pointAfterExclude = new ArrayList<>();//过滤后的所有点的坐标
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
OperateFile operateFile = new OperateFile();
|
|
|
- operateFile.printPoint("Y:\\allpoints.txt",allPoints);
|
|
|
-
|
|
|
-
|
|
|
+ //所有的作业轨迹点,只是点,不用连成直线
|
|
|
+// operateFile.printPoint("Y:\\allpoints.txt",allPoints);
|
|
|
+ operateFile.printPoint("/Users/haoqianpan/file/programfile/meanshift/out/allpoints.txt",allPoints);
|
|
|
+ operateFile.printPoint("/Users/haoqianpan/file/programfile/meanshift/out/initialcor.txt",occupyShapeList);
|
|
|
//对待计算点,进行过滤,过滤掉在网格以外的,这部分后面单独写个过滤类
|
|
|
for(int i = 0 ; i < allPoints.size();i++){
|
|
|
-
|
|
|
Point point = allPoints.get(i);
|
|
|
Double corX = point.getColX();
|
|
|
Double corY = point.getColY();
|
|
|
-
|
|
|
if ( (corX < maxX) && (corX > minX) && (corY < maxY) && (corY > minY)){
|
|
|
-
|
|
|
pointAfterExclude.add(point);
|
|
|
-
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
-
|
|
|
- operateFile.printPoint("Y:\\pointsexclude.txt",pointAfterExclude);
|
|
|
-
|
|
|
+ System.out.println("过滤后点数量:" + pointAfterExclude.size());
|
|
|
+ //对所有的轨迹点经过排除后剩下来的点
|
|
|
+// operateFile.printPoint("Y:\\pointsexclude.txt",pointAfterExclude);
|
|
|
+ operateFile.printPoint("/Users/haoqianpan/file/programfile/meanshift/out/pointsexclude.txt",pointAfterExclude);
|
|
|
|
|
|
|
|
|
|
|
|
//占用的网格为1,不占用的网格0
|
|
|
ArrayList<ArrayList<Integer>> occupyList = changeWholeIndexOccupyToList(wholeIndexOccupy);
|
|
|
+// for (int i = 0; i < occupyList.size();i++){
|
|
|
+//
|
|
|
+// System.out.println("ceshi");
|
|
|
+// System.out.println(occupyList.get(i));
|
|
|
+//
|
|
|
+//
|
|
|
+// }
|
|
|
+// System.out.println(occupyList);
|
|
|
|
|
|
|
|
|
// System.out.println("print all points---------------" );
|
|
@@ -95,175 +97,182 @@ public class Cal {
|
|
|
|
|
|
// System.out.println( x + " " + y);
|
|
|
|
|
|
-
|
|
|
Integer xIndex = split.identifyXIndex(x);
|
|
|
Integer yIndex = split.identifyYIndex(y);
|
|
|
|
|
|
+ //检查占用,如果占用了就把1设置成0,
|
|
|
if (yIndex < numOfGaps && yIndex >=0){
|
|
|
-
|
|
|
ArrayList<Integer> arrayList = occupyList.get(xIndex);
|
|
|
arrayList.set(yIndex,0);
|
|
|
occupyList.set(xIndex,arrayList);
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
// System.out.println("print all points end -----------");
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
for (int i = 0 ; i < occupyList.size();i++){
|
|
|
-
|
|
|
ArrayList<Integer> arrayList = occupyList.get(i);
|
|
|
|
|
|
StringBuffer sb = new StringBuffer();
|
|
|
+ StringBuffer sb1 = new StringBuffer();
|
|
|
for (int jj = 0 ; jj < arrayList.size();jj++){
|
|
|
-
|
|
|
-
|
|
|
if (arrayList.get(jj).toString().equals("0")){
|
|
|
+// System.out.println("该列有空格");
|
|
|
sb.append(" ");
|
|
|
+ sb1.append("+");
|
|
|
}
|
|
|
else {
|
|
|
sb.append(arrayList.get(jj).toString());
|
|
|
+ sb1.append(arrayList.get(jj).toString());
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
String arrayListString = sb.toString();
|
|
|
-
|
|
|
- System.out.println("print string----------" + arrayListString);
|
|
|
+ String arrayListString1 = sb1.toString();
|
|
|
+ System.out.println("print string----------" + arrayListString1);
|
|
|
String[] arrays = arrayListString.split("\\s+");
|
|
|
-//
|
|
|
-// for (int k = 0;k < arrays.length;k++){
|
|
|
-//
|
|
|
-// System.out.println(arrays[k]);
|
|
|
-//
|
|
|
-// }
|
|
|
-
|
|
|
String maxString ="";
|
|
|
-
|
|
|
-
|
|
|
//这里需要再想想
|
|
|
for (int j = 0 ; j < arrays.length;j++){
|
|
|
-
|
|
|
String temp = arrays[j];
|
|
|
if (temp.length() > maxString.length()){
|
|
|
-
|
|
|
maxString = temp;
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
-
|
|
|
Integer indexBegin = arrayListString.indexOf(maxString) - 1;
|
|
|
Integer indexEnd = indexBegin + maxString.length();
|
|
|
-
|
|
|
OccupyPerX occupyPerX = new OccupyPerX();
|
|
|
occupyPerX.setMinYIndex(indexBegin);
|
|
|
occupyPerX.setMaxYIndex(indexEnd);
|
|
|
occupyPerXArrayList.add(occupyPerX);
|
|
|
-
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
ArrayList<Point> shape = new ArrayList<>();
|
|
|
for (int i = 0 ; i < occupyPerXArrayList.size();i++){
|
|
|
-
|
|
|
-// OccupyPerX occupyPerX = occupyPerXArrayList.get(i);
|
|
|
-// Double xCor = minX + i * xGap + 0.5 * xGap;
|
|
|
-// Integer yIndex = occupyPerX.maxYIndex;
|
|
|
-// Double yCor = minY + yIndex * yGap + 0.5 * yGap;
|
|
|
-// Point point = new Point();
|
|
|
-// point.setColX(xCor);
|
|
|
-// point.setColY(yCor);
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
OccupyPerX occupyPerX = occupyPerXArrayList.get(i);
|
|
|
- Double xCor1 = minX + i * xGap;
|
|
|
- Double xCor2 = minX + i * xGap + xGap;
|
|
|
+ Double xCor = minX + i * xGap + 0.5 * xGap;
|
|
|
Integer yIndex = occupyPerX.maxYIndex;
|
|
|
Double yCor = minY + yIndex * yGap + 0.5 * yGap;
|
|
|
-
|
|
|
- Point point1 = new Point();
|
|
|
- point1.setColX(xCor1);
|
|
|
- point1.setColY(yCor);
|
|
|
-
|
|
|
- Point point2 = new Point();
|
|
|
- point2.setColX(xCor2);
|
|
|
- point2.setColY(yCor);
|
|
|
-
|
|
|
-
|
|
|
- shape.add(point1);
|
|
|
- shape.add(point2);
|
|
|
- }
|
|
|
-
|
|
|
- for (int i = (occupyPerXArrayList.size() -1) ; i >=0;i--){
|
|
|
-
|
|
|
+ Point point = new Point();
|
|
|
+ point.setColX(xCor);
|
|
|
+ point.setColY(yCor);
|
|
|
+ shape.add(point);
|
|
|
// OccupyPerX occupyPerX = occupyPerXArrayList.get(i);
|
|
|
-// Double xCor = minX + i * xGap + 0.5 * xGap;
|
|
|
-// Integer yIndex = occupyPerX.minYIndex;
|
|
|
+// Double xCor1 = minX + i * xGap;
|
|
|
+// Double xCor2 = minX + i * xGap + xGap;
|
|
|
+// Integer yIndex = occupyPerX.maxYIndex;
|
|
|
// Double yCor = minY + yIndex * yGap + 0.5 * yGap;
|
|
|
-// Point point = new Point();
|
|
|
-// point.setColX(xCor);
|
|
|
-// point.setColY(yCor);
|
|
|
-//
|
|
|
-// shape.add(point);
|
|
|
+// Point point1 = new Point();
|
|
|
+// point1.setColX(xCor1);
|
|
|
+// point1.setColY(yCor);
|
|
|
+// Point point2 = new Point();
|
|
|
+// point2.setColX(xCor2);
|
|
|
+// point2.setColY(yCor);
|
|
|
+// shape.add(point1);
|
|
|
+// shape.add(point2);
|
|
|
+ }
|
|
|
|
|
|
+ for (int i = (occupyPerXArrayList.size() -1) ; i >=0;i--){
|
|
|
OccupyPerX occupyPerX = occupyPerXArrayList.get(i);
|
|
|
- Double xCor1 = minX + i * xGap;
|
|
|
- Double xCor2 = minX + i * xGap + xGap;
|
|
|
+ Double xCor = minX + i * xGap + 0.5 * xGap;
|
|
|
Integer yIndex = occupyPerX.minYIndex;
|
|
|
Double yCor = minY + yIndex * yGap + 0.5 * yGap;
|
|
|
+ Point point = new Point();
|
|
|
+ point.setColX(xCor);
|
|
|
+ point.setColY(yCor);
|
|
|
+ shape.add(point);
|
|
|
+// OccupyPerX occupyPerX = occupyPerXArrayList.get(i);
|
|
|
+// Double xCor1 = minX + i * xGap;
|
|
|
+// Double xCor2 = minX + i * xGap + xGap;
|
|
|
+// Integer yIndex = occupyPerX.minYIndex;
|
|
|
+// Double yCor = minY + yIndex * yGap + 0.5 * yGap;
|
|
|
+// Point point1 = new Point();
|
|
|
+// point1.setColX(xCor1);
|
|
|
+// point1.setColY(yCor);
|
|
|
+// Point point2 = new Point();
|
|
|
+// point2.setColX(xCor2);
|
|
|
+// point2.setColY(yCor);
|
|
|
+// shape.add(point2);
|
|
|
+// shape.add(point1);
|
|
|
+ }
|
|
|
|
|
|
- Point point1 = new Point();
|
|
|
- point1.setColX(xCor1);
|
|
|
- point1.setColY(yCor);
|
|
|
+ //对算法结果做一些调整
|
|
|
|
|
|
- Point point2 = new Point();
|
|
|
- point2.setColX(xCor2);
|
|
|
- point2.setColY(yCor);
|
|
|
|
|
|
- shape.add(point2);
|
|
|
- shape.add(point1);
|
|
|
+ ArrayList<Point> shapeFill = fit.allCircleFitDefault(shape);
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ //填充空值
|
|
|
+ Adjust adjust = new Adjust();
|
|
|
+// ArrayList<Point> shapeFill = fit.allCircleFitDefault(afterAdjustPointsList);
|
|
|
+// shape = fit.excludePoints(shape);
|
|
|
shape.add(shape.get(0));
|
|
|
- System.out.println(shape.size() + ")))))))))))))))000");
|
|
|
-
|
|
|
-
|
|
|
+ ArrayList<Point> afterAdjustPointsList = adjust.fillArrayListPlus(occupyShapeList,shape,5);
|
|
|
// System.out.println(shape.size());
|
|
|
// for (int i = 0 ; i < shape.size() ; i++){
|
|
|
-
|
|
|
// System.out.println(shape.get(i).getColX() + " " + shape.get(i).getColY() );
|
|
|
// System.out.println(shape.get(i).getColY());
|
|
|
-
|
|
|
// }
|
|
|
|
|
|
- operateFile.printPoint("Y:\\changed.txt",shape);
|
|
|
+ //计算后垛位形状,已经网格化处理
|
|
|
+// operateFile.printPoint("Y:\\changed.txt",shape);
|
|
|
+// Special special = new Special();
|
|
|
+ operateFile.printPoint("/Users/haoqianpan/file/programfile/meanshift/out/changed.txt",shape);
|
|
|
+// operateFile.printPoint("/Users/haoqianpan/file/programfile/meanshift/out/changedFill.txt",shapeFill);
|
|
|
+ //拟合
|
|
|
+ operateFile.printPoint("/Users/haoqianpan/file/programfile/meanshift/out/changedFill.txt",shapeFill);
|
|
|
+ //对计算结果进行修正,
|
|
|
+// operateFile.printPoint("Y:\\adjustchanged.txt",afterAdjustPointsList);
|
|
|
+ operateFile.printPoint("/Users/haoqianpan/file/programfile/meanshift/out/adjustchanged.txt",afterAdjustPointsList);
|
|
|
+
|
|
|
+ ///打印,临时用的,主要是为了调整坐标
|
|
|
+ PointXYCorRevise pointXYCorRevise = new PointXYCorRevise();
|
|
|
+ //测试
|
|
|
+ for (int i = 0 ; i <realShapePoints.size();i++){
|
|
|
+
|
|
|
+ Point point = realShapePoints.get(i);
|
|
|
+ System.out.println(point.getColX() + " " + point.getColY());
|
|
|
|
|
|
- ArrayList<Point> afterAdjustPointsList = adjustShape(occupyShapeList,shape,5);
|
|
|
+ }
|
|
|
|
|
|
- operateFile.printPoint("Y:\\adjustchanged.txt",afterAdjustPointsList);
|
|
|
- return shape;
|
|
|
+ realShapePoints = pointXYCorRevise.revise(realShapePoints);
|
|
|
+ afterAdjustPointsList = pointXYCorRevise.revise(afterAdjustPointsList);
|
|
|
+ pointAfterExclude = pointXYCorRevise.revise(pointAfterExclude);
|
|
|
|
|
|
+ for (int i = 0 ; i < realShapePoints.size();i++){
|
|
|
|
|
|
+ Point point = realShapePoints.get(i);
|
|
|
+ System.out.println(point.getColX() + " " + point.getColY());
|
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
+ operateFile.printPoint("/Users/haoqianpan/file/programfile/meanshift/out/revise/initial.txt",realShapePoints);
|
|
|
+ operateFile.printPoint("/Users/haoqianpan/file/programfile/meanshift/out/revise/adjustchanged.txt",afterAdjustPointsList);
|
|
|
+ operateFile.printPoint("/Users/haoqianpan/file/programfile/meanshift/out/revise/pointsexclude.txt",pointAfterExclude);
|
|
|
|
|
|
|
|
|
+// Plot plot = new Plot();
|
|
|
+// Map mapInitialShape = new HashMap();
|
|
|
+// Map mapAdjustChanged = new HashMap();
|
|
|
+// Map mapPointExclude = new HashMap();
|
|
|
+//
|
|
|
+// mapInitialShape.put("FILE_NAME","initial.txt");
|
|
|
+// mapInitialShape.put("POINTS_LIST",realShapePoints);
|
|
|
+//
|
|
|
+// mapAdjustChanged.put("FILE_NAME","adjustchanged.txt");
|
|
|
+// mapAdjustChanged.put("POINTS_LIST",afterAdjustPointsList);
|
|
|
+//
|
|
|
+// mapPointExclude.put("FILE_NAME","pointsexclude.txt");
|
|
|
+// mapPointExclude.put("POINTS_LIST",pointAfterExclude);
|
|
|
+//
|
|
|
+// ArrayList<Map> mapArrayList = new ArrayList<>();
|
|
|
+// mapArrayList.add(mapInitialShape);
|
|
|
+// mapArrayList.add(mapAdjustChanged);
|
|
|
+// mapArrayList.add(mapPointExclude);
|
|
|
+//
|
|
|
+// plot.revisePlot("/Users/haoqianpan/file/programfile/meanshift/out/revise/",mapArrayList);
|
|
|
|
|
|
|
|
|
|
|
|
+ return shape;
|
|
|
|
|
|
|
|
|
|
|
@@ -323,9 +332,9 @@ public class Cal {
|
|
|
|
|
|
public ArrayList<Point> adjustShape(ArrayList<Point> initialShapeList,ArrayList<Point> changedShapeList,Integer adjustSize){
|
|
|
|
|
|
-
|
|
|
- Integer size = initialShapeList.size() - 1;
|
|
|
-
|
|
|
+// Integer size = initialShapeList.size() - 1;
|
|
|
+ Integer size = initialShapeList.size();
|
|
|
+//
|
|
|
System.out.println(size + "size");
|
|
|
|
|
|
ArrayList<Point> afterAdjustPointsList = new ArrayList<>();
|
|
@@ -340,13 +349,38 @@ public class Cal {
|
|
|
Integer indexEnd = indexBegin + adjustSize;
|
|
|
|
|
|
Double avgDec = 0.0;
|
|
|
+ //
|
|
|
+ ArrayList<Point> pointArrayList = new ArrayList<>();//存放差值,借用arraylist<point>
|
|
|
+
|
|
|
for (int j = indexBegin;j < indexEnd; j++){
|
|
|
Point iniPoint = initialShapeList.get(j);
|
|
|
Point chaPoint = changedShapeList.get(j);
|
|
|
+ Point pointDis = new Point();
|
|
|
+ pointDis.setColY(chaPoint.getColY() - iniPoint.getColY());
|
|
|
+ pointDis.setColX(chaPoint.getColX());
|
|
|
+ pointArrayList.add(pointDis);
|
|
|
avgDec = avgDec + chaPoint.getColY() - iniPoint.getColY();
|
|
|
+ System.out.println("差值" + (chaPoint.getColY() - iniPoint.getColY()));
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+// double[] param = fit.gaussFit(pointArrayList);
|
|
|
+ //求高斯分布值
|
|
|
+// Gaussian gaussian = new Gaussian(param[0],param[1],param[2]);
|
|
|
+// ArrayList<Double> dPoint = new ArrayList<>();
|
|
|
+// for (int ii = 0 ; ii < pointArrayList.size();ii++){
|
|
|
+//
|
|
|
+// Point point = pointArrayList.get(ii);
|
|
|
+// Double x = point.getColX();
|
|
|
+// Double y = gaussian.value(x);
|
|
|
+// dPoint.add(y);
|
|
|
+//
|
|
|
+// }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
avgDec = avgDec / adjustSize;
|
|
|
- System.out.println(avgDec + " avgdec");
|
|
|
+// System.out.println(avgDec + " avgdec");
|
|
|
|
|
|
for (int j = indexBegin ; j < indexEnd;j++){
|
|
|
|
|
@@ -355,13 +389,16 @@ public class Cal {
|
|
|
Point adjustPoint = new Point();
|
|
|
adjustPoint.setColX(intPoint.getColX());
|
|
|
adjustPoint.setColY(intPoint.getColY() + avgDec);
|
|
|
+// adjustPoint.setColY(intPoint.getColY() + gaussian.value(intPoint.getColX()));
|
|
|
+// System.out.println(new Date());
|
|
|
|
|
|
afterAdjustPointsList.add(adjustPoint);
|
|
|
}
|
|
|
//后面扩充不整除的情况
|
|
|
}
|
|
|
|
|
|
- afterAdjustPointsList.add(afterAdjustPointsList.get(0));
|
|
|
+
|
|
|
+// afterAdjustPointsList.add(afterAdjustPointsList.get(0));
|
|
|
|
|
|
|
|
|
|
|
@@ -370,4 +407,6 @@ public class Cal {
|
|
|
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
}
|