New file |
| | |
| | | package com.whyc.dto.dischargePlan; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Random; |
| | | import java.util.stream.Collectors; |
| | | |
| | | public class DisPlanDto { |
| | | //自动生成放电计划 |
| | | public static List createPlan(List<StationNode> l0, List<StationNode> l1) { |
| | | List<StationNode> l2 = new ArrayList<>(); |
| | | List list = new ArrayList(); |
| | | if (l0 != null && l0.size() >= 0) { |
| | | StationNode s0 = l0.get(0); |
| | | int groupId0 = s0.getGroupId(); |
| | | list.add(s0); |
| | | for (int j = 0; j < l1.size(); j++) { |
| | | StationNode s1 = l1.get(j); |
| | | int groupId1 = s1.getGroupId(); |
| | | if (groupId1 != groupId0) { |
| | | list.add(s1); |
| | | } |
| | | if (j + 1 < l1.size()) { |
| | | //包左不包右 |
| | | l2 = l1.subList(j + 1, l1.size()); |
| | | } |
| | | if (list.size() < 3) { |
| | | StationNode s2 = ChooseS2(groupId0, groupId1, l2); |
| | | l1.remove(s2); |
| | | } |
| | | l1.remove(s1); |
| | | break; |
| | | } |
| | | l0.remove(s0); |
| | | } |
| | | return list; |
| | | } |
| | | |
| | | //寻找s2 |
| | | public static StationNode ChooseS2(int g0, int g1, List<StationNode> l2) { |
| | | if (l2 != null && l2.size() >= 0) { |
| | | for (int i = 0; i < l2.size(); i++) { |
| | | StationNode s2 = l2.get(i); |
| | | int g2 = s2.getGroupId(); |
| | | if (g2 != g0 && g2 != g0) { |
| | | return s2; |
| | | } |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | /*StationNode s1 = new StationNode(0, 1, "1001"); |
| | | StationNode s2 = new StationNode(1, 2, "1002"); |
| | | StationNode s3 = new StationNode(0, 2, "1003"); |
| | | StationNode s4 = new StationNode(1, 3, "1004"); |
| | | StationNode s5 = new StationNode(0, 1, "1005"); |
| | | StationNode s6 = new StationNode(1, 4, "1006"); |
| | | StationNode s7 = new StationNode(1, 4, "1007"); |
| | | StationNode s8 = new StationNode(0, 1, "1008"); |
| | | StationNode s9 = new StationNode(1, 2, "1009"); |
| | | StationNode s10 = new StationNode(0, 2, "10010"); |
| | | StationNode s11 = new StationNode(1, 3, "1011"); |
| | | StationNode s12 = new StationNode(0, 1, "1012"); |
| | | StationNode s13 = new StationNode(1, 4, "1013"); |
| | | StationNode s14 = new StationNode(1, 4, "1014"); |
| | | StationNode s15 = new StationNode(0, 1, "1015"); |
| | | StationNode s16 = new StationNode(1, 2, "1016"); |
| | | StationNode s17 = new StationNode(0, 2, "1017"); |
| | | StationNode s18 = new StationNode(1, 3, "1018"); |
| | | StationNode s19 = new StationNode(0, 1, "1019"); |
| | | StationNode s20 = new StationNode(1, 4, "1020"); |
| | | StationNode s21 = new StationNode(1, 4, "1021"); |
| | | StationNode s22 = new StationNode(0, 1, "1022"); |
| | | StationNode s23 = new StationNode(1, 2, "1023"); |
| | | StationNode s24 = new StationNode(0, 2, "1024"); |
| | | StationNode s25 = new StationNode(1, 3, "1025"); |
| | | StationNode s26 = new StationNode(0, 1, "1026"); |
| | | StationNode s27 = new StationNode(1, 4, "1027"); |
| | | StationNode s28 = new StationNode(1, 4, "1028");*/ |
| | | List<StationNode> list = new ArrayList<>(); |
| | | for (int i = 1; i <= 30; i++) { |
| | | StationNode s = new StationNode(); |
| | | s.setStationId("1000" + i); |
| | | Random random = new Random(); |
| | | int nodetype = random.nextInt(2); |
| | | s.setNodeType(nodetype); |
| | | int groupId = random.nextInt(5); |
| | | s.setGroupId(groupId); |
| | | list.add(s); |
| | | } |
| | | System.out.println(list.size()); |
| | | for (StationNode sn : list) { |
| | | System.out.println(sn.getNodeType() + " " + sn.getGroupId() + " " + sn.getStationId()); |
| | | } |
| | | /*System.out.println("++++++++++"); |
| | | List<StationNode> l = list.subList(2, 4); |
| | | for (StationNode snl : l) { |
| | | System.out.println(snl.getNodeType() + " " + snl.getGroupId() + " " + snl.getStationId()); |
| | | } |
| | | System.out.println("********************"); |
| | | for (StationNode sn : list) { |
| | | System.out.println(sn.getNodeType() + " " + sn.getGroupId() + " " + sn.getStationId()); |
| | | }*/ |
| | | Map<Integer, List<StationNode>> map = list.stream().collect(Collectors.groupingBy(StationNode::getNodeType)); |
| | | List<StationNode> list0 = map.get(0); |
| | | List<StationNode> list1 = map.get(1); |
| | | /*for (Integer node : map.keySet()) { |
| | | System.out.println(node + " " + map.get(node).toString()); |
| | | }*/ |
| | | //createPlan(list0, list1); |
| | | } |
| | | } |