| | |
| | | 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; |
| | |
| | | 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()); |
| | |
| | | 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; |
| | | |