Browse Source

三个组件的所有排列情况

duh 6 years ago
parent
commit
d651bb02af

+ 10 - 1
src/main/java/model/Room.java

@@ -3,6 +3,8 @@ package model;
 import config.subConfig.RoomConfig;
 
 import java.awt.*;
+import java.util.ArrayList;
+import java.util.List;
 
 /**
  * @author duh
@@ -37,7 +39,14 @@ public class Room extends ModuleInAxis {
         g2d.drawRect(x, y-width, length, width);
         g2d.dispose();
     }
-
+    public List<Integer> getRoomLengthLeft(){
+        List<Integer> roomLength = new ArrayList<>();
+        roomLength.add(bottomLeft);
+        roomLength.add(rightLeft);
+        roomLength.add(topLeft);
+        roomLength.add(leftLeft);
+        return roomLength;
+    }
     public int getLength() {
         return length;
     }

+ 117 - 10
src/main/java/utils/CalcYizhiArrayUtils.java

@@ -1,5 +1,8 @@
 package utils;
 
+import model.Room;
+import model.template.Template;
+
 import java.util.ArrayList;
 import java.util.List;
 
@@ -14,6 +17,10 @@ public class CalcYizhiArrayUtils {
     private List<Integer> twoAlignAllShortLength;
     private List<Integer> twoAlignAllLongLength;
 
+    /**
+     * 只有一个需要两边靠墙的模块
+     * @return
+     */
     public List<List<Integer>> calcYizhiWithOnlyOneTwoAlign(){
         List<List<Integer>> list = new ArrayList<>();
         int totalOneLenth = 0;
@@ -28,22 +35,22 @@ public class CalcYizhiArrayUtils {
         if(leftForTwo>=twoLongLength &&twoLongLength>twoShortLength ){
             System.out.println("可以一字排,长短边皆可,方案如下:");
             //TWO at left
-            List<List<Integer>> twoAtLeftShort = addTwoAlignLeft(210);
+            List<List<Integer>> twoAtLeftShort = addTwoAlignLeft(944);
             list.addAll(twoAtLeftShort);
-            List<List<Integer>> twoAtLeftLong = addTwoAlignLeft(211);
+            List<List<Integer>> twoAtLeftLong = addTwoAlignLeft(943);
             list.addAll(twoAtLeftLong);
             //TWO at rightt
-            List<List<Integer>> twoAtRightShort = addTwoAlignRight(220);
+            List<List<Integer>> twoAtRightShort = addTwoAlignRight(933);
             list.addAll(twoAtRightShort);
-            List<List<Integer>> twoAtRightLong = addTwoAlignRight(221);
+            List<List<Integer>> twoAtRightLong = addTwoAlignRight(932);
             list.addAll(twoAtRightLong);
         }else if(leftForTwo>=twoShortLength){
             System.out.println("可以一字排,只有短边,方案如下:");
             //TWO at left
-            List<List<Integer>> twoAtLeftShort = addTwoAlignLeft(210);
+            List<List<Integer>> twoAtLeftShort = addTwoAlignLeft(943);
             list.addAll(twoAtLeftShort);
             //TWO at rightt
-            List<List<Integer>> twoAtRightShort = addTwoAlignRight(220);
+            List<List<Integer>> twoAtRightShort = addTwoAlignRight(933);
             list.addAll(twoAtRightShort);
         }else {
             System.out.println("totalOneLenth is longer than 3nd wall");
@@ -53,20 +60,34 @@ public class CalcYizhiArrayUtils {
 
     private List<List<Integer>> addTwoAlignRight(int numberCode) {
         List<List<Integer>> twoAtRight = new ArrayList<>();
-        List<List<Integer>> oneArray2 = getAllArrayList(oneAlignAllLength.size());
-        twoAtRight.addAll(oneArray2);
+        List<List<Integer>> oneArray = getAllArrayList(oneAlignAllLength.size());
+        List<List<Integer>> topArray = getTopArrayForOneArray(oneArray);
+        twoAtRight.addAll(topArray);
         for (List<Integer> twoAtLeftItem : twoAtRight){
             twoAtLeftItem.add(numberCode);
         }
         return twoAtRight;
     }
 
+    private List<List<Integer>> getTopArrayForOneArray(List<List<Integer>> oneArray) {
+        List<List<Integer>> topArray = new ArrayList<>();
+        oneArray.forEach(x->{
+            List<Integer> topItem = new ArrayList<>();
+            for(int i = 1;i<=x.size();i++){
+                topItem.add(300+x.get(i-1)*10+i);
+            }
+            topArray.add(topItem);
+        });
+        return topArray;
+    }
+
     private List<List<Integer>> addTwoAlignLeft(int numberCode) {
         List<List<Integer>> twoAtLeft = new ArrayList<>();
         List<List<Integer>> oneArray = getAllArrayList(oneAlignAllLength.size());
-        twoAtLeft.addAll(oneArray);
+        List<List<Integer>> topArray = getTopArrayForOneArray(oneArray);
+        twoAtLeft.addAll(topArray);
         for (List<Integer> twoAtLeftItem : twoAtLeft){
-            twoAtLeftItem.add(0,numberCode);
+            twoAtLeftItem.add(numberCode);
         }
         return twoAtLeft;
     }
@@ -144,4 +165,90 @@ public class CalcYizhiArrayUtils {
     public void setTwoAlignAllLongLength(List<Integer> twoAlignAllLongLength) {
         this.twoAlignAllLongLength = twoAlignAllLongLength;
     }
+//    public List<List<Integer>> calcArray(){
+//        List<List<Integer>>
+//    }
+    public void calcYizhiWithOnlyOneTwoAlign(Room room, List<Template> templates){
+        List<Integer> oneAlignLengthList = new ArrayList<>();
+        int twoLong = 0;
+        int twoShort = 0;
+        for(Template template:templates){
+            List<Integer> alignWall = template.getAlignWall();
+            if(alignWall.size() == 1){
+                int alignWallIndex = alignWall.get(0);
+                switch (alignWallIndex%2){
+                    case 0:
+                        oneAlignLengthList.add(template.getLength());
+                        break;
+                    case 1:
+                        oneAlignLengthList.add(template.getWidth());
+                        break;
+                }
+            }else {
+                int length = template.getLength();
+                int width = template.getWidth();
+                if(length>width){
+                    twoLong = length;
+                    twoShort = width;
+                }else {
+                    twoLong = width;
+                    twoShort = length;
+                }
+            }
+        }
+        calcYizhiWithOnlyOneTwoAlign(room.getRoomLengthLeft(),oneAlignLengthList,twoLong,twoShort);
+    }
+
+    private void calcYizhiWithOnlyOneTwoAlign(List<Integer> roomLengthLeft, List<Integer> oneAlignLengthList, int twoLong, int twoShort) {
+        getTwoAlignArray();
+    }
+
+    private List<Integer> getTwoAlignArray() {
+        List<Integer> twoBaiFangArray = new ArrayList<>();
+        int begin = 900;
+        //9-2边靠墙组件 2-角落 1-边
+        twoBaiFangArray.add(begin+21);
+        twoBaiFangArray.add(begin+22);
+        twoBaiFangArray.add(begin+32);
+        twoBaiFangArray.add(begin+33);
+        twoBaiFangArray.add(begin+43);
+        twoBaiFangArray.add(begin+44);
+        return twoBaiFangArray;
+    }
+
+    /**
+     * 2个组件放4边
+     */
+    public List<List<Integer>> get2Template4BianArray(){
+        List<List<Integer>> lists = new ArrayList<>();
+        List<List<Integer>> oneLists = new ArrayList<>();
+        for (int i=1;i<5;i++){
+            for (int j=1;j<5;j++){
+                List<Integer> arrayList = new ArrayList<>();
+                if(i!=j){
+                    arrayList.add(i*10+1);
+                    arrayList.add(j*10+2);
+                    oneLists.add(arrayList);
+                }else {
+                    arrayList.add(i*100+10+1);
+                    arrayList.add(j*100+20+2);
+                    oneLists.add(arrayList);
+                    List<Integer> arrayList2 = new ArrayList<>();
+                    arrayList2.add(i*100+10+2);
+                    arrayList2.add(j*100+20+1);
+                    oneLists.add(arrayList2);
+                }
+            }
+        }
+        oneLists.forEach(x->{
+            List<Integer> twoAlignWallBaifang = getTwoAlignArray();
+            for(Integer integer : twoAlignWallBaifang){
+                List<Integer> list = new ArrayList<>();
+                list.addAll(x);
+                list.add(integer);
+                lists.add(list);
+            }
+        });
+        return lists;
+    }
 }

+ 8 - 0
src/test/java/utils/CalcYizhiArrayUtilsTest.java

@@ -47,7 +47,15 @@ public class CalcYizhiArrayUtilsTest {
 
     @Test
     public void calcYizhiWithOnlyOneTwoAlign() {
+        System.out.println("yizhi begin");
         List<List<Integer>> list = calcYizhiArrayUtils.calcYizhiWithOnlyOneTwoAlign();
         list.forEach(x -> System.out.println(x));
+        System.out.println("yizhi end");
+    }
+    @Test
+    public void get2Template4BianArray() {
+        List<List<Integer>> list = calcYizhiArrayUtils.get2Template4BianArray();
+        list.forEach(x -> System.out.println(x));
+        System.out.println(list.size());
     }
 }