24282 1 yıl önce
ebeveyn
işleme
cb91357c04

+ 10 - 10
sd-framework/src/main/java/com/sd/framework/util/packing/GA.java

@@ -1,6 +1,5 @@
 package com.sd.framework.util.packing;
 
-import com.sd.framework.util.packing.entity.Instance;
 import com.sd.framework.util.packing.entity.Solution;
 import com.sd.framework.util.packing.model.Genome;
 import com.sd.framework.util.packing.model.Item;
@@ -62,26 +61,27 @@ public class GA {
     /**
      * 遗传算法的构造函数
      *
-     * @param instance 实例对象
+     * @param length 布长
+     * @param width  布宽
+     * @param items  装箱明细
      */
-    public GA(Instance instance) {
-        this.length = instance.getLength();
-        this.width = instance.getWidth();
-        this.items = Item.copy(instance.getItemList().toArray(new Item[0]));
-    }
-
-    public GA(double length, double width, Item[] items) {
+    private GA(double length, double width, Item[] items) {
         this.length = length;
         this.width = width;
         this.items = items;
     }
 
+    public static Solution solve(double length, double width, Item[] items) {
+        GA ga = new GA(length, width, items);
+        return ga.solve();
+    }
+
     /**
      * 遗传算法主函数
      *
      * @return 最佳装载结果对象Solution
      */
-    public Solution solve() {
+    private Solution solve() {
         initVar();
         while (t < maxGen) {
             popSize = population.size();