doum
13 小时以前 18ab70b5f19fce88ba91c08689f2f39bb9784ecf
server/visits/dmvisit_service/src/main/java/com/doumee/core/tsp/ClusterCustomKMeans.java
@@ -1,9 +1,7 @@
package com.doumee.core.tsp;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.*;
import com.doumee.core.utils.Constants;
import com.doumee.dao.admin.request.SketchCateModel;
@@ -78,6 +76,7 @@
                    cList.add(doublePointNew.getCustomer());
                    sketchCateModel.setTotalNum(Constants.formatBigdecimal(sketchCateModel.getTotalNum()).add(Constants.formatBigdecimal(doublePointNew.getCustomer().getTotalNum())));
                }
                sortPointByCenterPoint(cluster,cList);
                sketchCateModel.setCustomerList(cList);
                sketchCateModel.setStartPoint(cList.get(0));
                sketchCateModel.setTotalCustomer(cList.size());
@@ -86,6 +85,21 @@
            return list;
        }
    private void sortPointByCenterPoint(CentroidCluster<DoublePointNew> cluster, List<JkSketchCustomer> cList) {
        double clat = Constants.formatBigdecimal(cList.get(0).getLatitude()).doubleValue();
        double clong = Constants.formatBigdecimal(cList.get(0).getLongitude()).doubleValue();
        if(cluster!=null || cluster.getCenter() != null || cluster.getCenter().getPoint() != null && cluster.getCenter().getPoint().length>=2){
            clong = cluster.getCenter().getPoint()[1];
            clat = cluster.getCenter().getPoint()[0];
        }
        for(JkSketchCustomer c : cList){
            double latDiff = Constants.formatBigdecimal(c.getLatitude()).doubleValue() - clat;
            double lonDiff = Constants.formatBigdecimal(c.getLongitude()).doubleValue() - clong;
            c.setDistanceCenter(Math.sqrt(latDiff * latDiff + lonDiff * lonDiff)); // 欧氏距离
        }
        Collections.sort(cList, (p1, p2) -> Double.compare(p1.getDistanceCenter(), p2.getDistanceCenter()));
    }
    public  class  DoublePointNew extends  DoublePoint{
        private JkSketchCustomer customer;