复现一篇分布式装配混合零空闲置换流水车间调度问题的代码

  • 摘要
  • 说明
  • 代码
    • 测试类
    • 算法主体
    • 启发式H11
    • 计算Cmax
    • 读取测试集文件
  • 结果
    • 测试集
  • 参考文献

摘要

In this paper, we study the distributed assembly mixed no-idle permutation flowshop scheduling problem (DAMNIPFSP) with total tardiness objective. We first formulate the problem. Second, based on the characteristics of the DAMNIPFSP, an improved Iterated Greedy algorithm, named RIG (Referenced Iterated Greedy), with two novel destruction methods, four new reconstruction methods and six new local search methods is presented. Among them, two of the reconstruction methods and four of the local search methods are based on a reference, which proves key to performance. Finally, RIG is compared with the related algorithms through experiments. The results show that the new RIG algorithm is a new state-of-the-art procedure for the DAMNIPFSP with the total tardiness criterion.

说明

这篇文章使用的模型比较新,是分布式带装配混合零空闲置换流水车间调度模型。主要考虑到现实中并非所有机器都有零空闲约束的问题。本博客实现了其算法,模型并未使用其模型,而是使用了分布式装配置换流水车间调度模型,评价指标使用了Cmax,并未使用原文中的总延迟指标。感兴趣的请自行实现其代码。本人并不精通Java,出于研究需要,使用了Java作为编程语言,感兴趣的可使用C或C++,可进一步提高算法效率。另外,由于各种因素,本博客仅供参考,请大家批判阅读、使用,算法实现过程中难免会有疏漏和谬误,欢迎各位批评指正并与我进行交流,这将有助于改善我的工作。测试集可能不完全相同,有需要的请私信。

代码

测试集请在该网站自行下载:调度测试集

测试类

package practice.comparison;import Instances.DataProcessing;
import practice.dapfsp.Heuristic1;import java.util.ArrayList;
import java.util.List;/*** @Date: 2022/3/30 9:22* @Author: * @File: TestRIG.class* @Software: IDEA* @Email: 1532116227@qq.com*/
public class TestRIG
{public static void main(String[] args){//小规模========================================================================================================int count = 1;int jobs[] = {8, 12, 16, 20, 24};int machines[] = {2, 3, 4, 5};int factories[] = {2, 3, 4};int products[] = {2, 3, 4};int instnces[] = {1, 2, 3, 4, 5};int[][] p = new int[0][];ReadTxt readTxt = new ReadTxt();List<Integer> pi = new ArrayList<>();//工件序列RIG2 rig2 = new RIG2();List<Integer> apt = new ArrayList<>();int[] assignSet;for (int n = 0; n < jobs.length; n++)//job.length - 1{for (int m = 0; m < machines.length; m++)//mechine.length - 1{for (int k = 0; k < factories.length; k++)//num.length - 1{for (int i = 0; i < products.length; i++){for (int j = 0; j < instnces.length; j++){p = readTxt.getProcessingTimes("D:\\Instances\\DAPFSPSmall\\ProcessingTime\\I" + "_"+ jobs[n] + "_" + machines[m] + " _" + factories[k] + "_" + products[i] + "_" + instnces[j] + ".txt", jobs[n], machines[m]);apt = readTxt.getAssemblyTimes("D:\\Instances\\DAPFSPSmall\\AssemblyTime\\I" + "_"+ jobs[n] + "_" + machines[m] + " _" + factories[k] + "_" + products[i] + "_" + instnces[j] + ".txt", products[i]);assignSet = new int[jobs[n]];assignSet = readTxt.getAssignSet("D:\\Instances\\DAPFSPSmall\\AssignSet\\I" + "_"+ jobs[n] + "_" + machines[m] + " _" + factories[k] + "_" + products[i] + "_" + instnces[j] + ".txt", jobs[n], products[i]);System.out.println(count++);pi = rig2.algorithm(p, apt, factories[k], products[i], assignSet);System.out.println(pi);System.out.println("============================================");}}}}}//==============================================================================================================
//        int[][] p = {{4, 6, 2}, {3, 4, 2}, {5, 2, 3}, {5, 4, 2}, {4, 2, 2}, {3, 3, 3},
//                {4, 3, 2}, {3, 5, 2}, {6, 2, 3}, {3, 5, 2}, {4, 4, 2}, {4, 3, 3}};//加工时间矩阵
//        int[] assignSet = {1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4};//==============================================================================================================
//        int[][] p = {{1, 3}, {5, 8}, {7, 5}, {9, 7}, {9, 3}, {3, 4}, {8, 1}, {4, 3}, {2, 5}};
//        int[] assignSet = {2, 2, 1, 1, 3, 1, 3, 2, 2};//==============================================================================================================
//        int[][] p = {{3, 4}, {1, 3}, {5, 8}, {7, 5}, {8, 1}, {4, 3}, {9, 7}, {9, 3}, {2, 5}};
//        int[] assignSet = {1, 2, 2, 1, 3, 2, 1, 3, 2};
//        int numOfProduct = 4;//产品数
//        List<Integer> lambda = new ArrayList<>();//产品序列
//        RIG rig = new RIG();
//        apt = List.of(6, 19, 12);//集合中的元素个数已确定,不能再改变时才能使用
//        pi = rig.algorithm(p, pi, apt, lambda, F, t, assignSet);//==============================================================================================================
//        int F = 2;//工厂数
//        int t = 4;//产品数
//        List<Integer> pi = new ArrayList<>();//工件序列
//        RIG2 rig2 = new RIG2();
//        List<Integer> apt;
//        apt = List.of(6, 8, 5, 8);//装配时间
//        pi = rig2.algorithm(p, apt, F, t, assignSet);
//        System.out.println(pi);}
}

算法主体

package practice.comparison;import practice.calculateCMAX.CalculateCmaxPFSP;
import practice.dapfsp.Heuristic1;import java.util.*;/*** @Date: 2022/4/6 20:36* @Author: * @File: RIG2.class* @Software: IDEA* @Email: 1532116227@qq.com*/
public class RIG2
{Random random = new Random();public List<Integer> algorithm(int[][] p, List<Integer> apt, int F, int t, int[] assignSet){double beta = 0.05;List<Integer> piT;Heuristic1 h1 = new Heuristic1();List<Integer> pi_product;pi_product = Heuristic1.ruleOfSPT(apt);//产品的装配序列List<Integer> pi_product0 = listCopy(pi_product);List<Integer>[] sequence = new List[t];List<Integer>[] solution1 = new List[t];List<Integer>[] best_solution = new List[t];List<Integer> pi_product1;for (int i = 0; i < t; i++){sequence[i] = new ArrayList<>();best_solution[i] = new ArrayList<>();solution1[i] = new ArrayList<>();}for (int i = 0; i < assignSet.length; i++){sequence[assignSet[i] - 1].add(i + 1);}//==============================================================================================================//Obtain the initial solution by H11/H12
//        piT = h1.algorithm(p, t, apt, sequence, pi_product);sequence = h1.algorithm(p, t, apt, sequence, pi_product);
//        System.out.println(piT);
//        List<Integer>[][] assignment;//解码:将一个解解码为一个调度
//        assignment = new List[1][F];
//        assignment[0] = Heuristic1.assignByNR1(p, piT, F);//NR1
//        assignment[0] = Heuristic1.ecfRule(p, piT, F);//NR2
//        for (int i = 0; i < F; i++)
//        {//            solution.addAll(assignment[0][i]);
//        }
//        best_solution.addAll(solution);for (int i = 0; i < t; i++){best_solution[i].addAll(sequence[i]);}pi_product1 = listCopy(pi_product);//==============================================================================================================int LSType = 0;switch (LSType){case 0:pi_product = insertProductLS(sequence, p, pi_product, t, F, apt);
//                System.out.println(pi_product);sequence = insertJobLS(sequence, p, pi_product, t, F, apt);break;case 1:pi_product = insertProductRfLS(sequence, pi_product1, p, pi_product, t, F, apt);
//                System.out.println(pi_product);sequence = insertJobRfLS(sequence, best_solution, p, pi_product, t, F, apt);break;case 2:pi_product = swapProductRfLS(sequence, pi_product1, p, pi_product, t, F, apt);sequence = swapJobRfLS(sequence, best_solution, p, pi_product, t, F, apt);break;}pi_product1 = listCopy(pi_product);for (int i = 0; i < t; i++){best_solution[i] = listCopy(sequence[i]);solution1[i] = listCopy(sequence[i]);
//            best_solution[i].clear();
//            best_solution[i].addAll(sequence[i]);
//            solution1[i].addAll(sequence[i]);}int dp = 3;int dj = 5;int Gen = 100, gen = 0;int ConType = 1;List<Integer> lambdap = new ArrayList<>();List<Integer> lambda = new ArrayList<>();List<Integer> lambdaj = new ArrayList<>();List<List<Integer>> lists = new ArrayList<>();while (gen < Gen){lists = destructionProduct(dp, pi_product);lambda = lists.get(0);lambdap = lists.get(1);switch (ConType){case 0:pi_product = reconstructionProduct(lambda, lambdap, sequence, apt, p, F);break;case 1:pi_product = reconstructionProductRF(lambda, lambdap, sequence, pi_product1, apt, p, F, t);break;}lambdaj = destructionJob(dj, pi_product, solution1);switch (ConType){case 0:solution1 = reconstructionJob(lambdaj, pi_product, solution1, sequence, apt, p, F);break;case 1:solution1 = reconstructionJobRF(lambdaj, pi_product, solution1, sequence, best_solution, apt, p, F, t);break;}switch (LSType){case 0:pi_product = insertProductLS(solution1, p, pi_product, t, F, apt);solution1 = insertJobLS(solution1, p, pi_product, t, F, apt);break;case 1:
//                    pi_product = insertProductRfLS(sequence, pi_product1, p, pi_product, t, F, apt);
//                    sequence = insertJobRfLS(sequence, best_solution, p, pi_product, t, F, apt);pi_product = insertProductRfLS(solution1, pi_product1, p, pi_product, t, F, apt);solution1 = insertJobRfLS(solution1, best_solution, p, pi_product, t, F, apt);break;case 2:
//                    pi_product = swapProductRfLS(sequence, pi_product1, p, pi_product, t, F, apt);
//                    sequence = swapJobRfLS(sequence, best_solution, p, pi_product, t, F, apt);pi_product = swapProductRfLS(solution1, pi_product1, p, pi_product, t, F, apt);solution1 = swapJobRfLS(solution1, best_solution, p, pi_product, t, F, apt);break;}int r;int cmax1;int cmax2;int cmax3;List<Integer>[] schedule = new List[F];List<Integer> list1 = new ArrayList<>();List<Integer> list2 = new ArrayList<>();List<Integer> list3 = new ArrayList<>();for (int i = 0; i < t; i++){list1.addAll(solution1[pi_product.get(i) - 1]);list2.addAll(sequence[pi_product0.get(i) - 1]);list3.addAll(best_solution[pi_product1.get(i) - 1]);}//==============================================================================================================
//            schedule = Heuristic1.assignByNR1(p, list1, F);//NR1schedule = Heuristic1.ecfRule(p, list1, F);cmax1 = calAssembleCmax(schedule, p, F, pi_product, sequence, apt);//==============================================================================================================
//            schedule = Heuristic1.assignByNR1(p, list2, F);//NR1schedule = Heuristic1.ecfRule(p, list2, F);cmax2 = calAssembleCmax(schedule, p, F, pi_product0, sequence, apt);//==============================================================================================================
//            schedule = Heuristic1.assignByNR1(p, list3, F);//NR1schedule = Heuristic1.ecfRule(p, list3, F);cmax3 = calAssembleCmax(schedule, p, F, pi_product1, sequence, apt);//==============================================================================================================double RPD, TempFactor;if (cmax1 < cmax2){//                sequence = solution1;sequence = list1DimArrayCopy(solution1);pi_product0.clear();pi_product0.addAll(pi_product);if (cmax1 < cmax3){best_solution = list1DimArrayCopy(solution1);pi_product1.clear();pi_product1.addAll(pi_product);}}else if (beta > 0){RPD = (cmax1 - cmax2) / cmax2 * 100;TempFactor = beta * (sumOfPij(p)) / 10 * p.length * p[0].length;r = random.nextInt();if (r < Math.exp(-RPD / TempFactor)){sequence = list1DimArrayCopy(solution1);pi_product0.clear();pi_product0.addAll(pi_product);}}gen += 1;}List<Integer> list = new ArrayList<>();for (int i = 0; i < best_solution.length; i++){list.addAll(best_solution[pi_product1.get(i) - 1]);}int Cmax;List<Integer>[] schedule = new List[F];
//        schedule = Heuristic1.assignByNR1(p, list, F);//NR1schedule = Heuristic1.ecfRule(p, list, F);Cmax = calAssembleCmax(schedule, p, F, pi_product1, sequence, apt);System.out.println("Cmax = " + Cmax);return list;}private List<Integer>[] reconstructionJobRF(List<Integer> lambdaj, List<Integer> pi_product, List<Integer>[] solution1, List<Integer>[] sequence, List<Integer>[] best_solution, List<Integer> apt, int[][] p, int F, int t){int cmaxTemp = 0;int cmax = 0;int index = 0;int r;int removed;List<Integer> list = new ArrayList<>();List<Integer>[] schedule = new List[F];for (int i = 0; i < t; i++){for (int h = 0; h < best_solution[i].size(); h++){if (lambdaj.contains(best_solution[i].get(h))){removed = lambdaj.remove(lambdaj.indexOf(best_solution[i].get(h)));}else{continue;}if (sequence[i].contains(removed)){cmax = Integer.MAX_VALUE;for (int k = 0; k < solution1[i].size() + 1; k++){solution1[i].add(k, removed);list.clear();for (int j = 0; j < solution1.length; j++){list.addAll(solution1[pi_product.get(j) - 1]);}
//                        schedule = Heuristic1.assignByNR1(p, list, F);//NR1schedule = Heuristic1.ecfRule(p, list, F);cmaxTemp = calAssembleCmax2(schedule, solution1, p, F, pi_product, sequence, apt);solution1[i].remove(k);if (cmaxTemp < cmax){cmax = cmaxTemp;index = k;}}solution1[i].add(index, removed);
//                    break;}}}return solution1;}private List<Integer> reconstructionProductRF(List<Integer> lambda, List<Integer> lambdap, List<Integer>[] sequence, List<Integer> pi_product1, List<Integer> apt, int[][] p, int F, int t){int r;int removed;int cmax;
//        List<Integer> copyLambdap = new ArrayList<>();
//        copyLambdap = listCopy(lambdap);List<Integer>[] schedule = new List[F];List<Integer> list1 = new ArrayList<>();int cmaxTemp = 0;int index = 0;for (int l = 0; l < t; l++){cmax = Integer.MAX_VALUE;if (lambdap.contains(pi_product1.get(l))){removed = lambdap.remove(lambdap.indexOf(pi_product1.get(l)));for (int k = 0; k < lambda.size() + 1; k++){list1.clear();lambda.add(k, removed);for (int i = 0; i < lambda.size(); i++){list1.addAll(sequence[lambda.get(i) - 1]);}
//                schedule = Heuristic1.assignByNR1(p, list1, F);//NR1schedule = Heuristic1.ecfRule(p, list1, F);
//                if (schedule == null)
//                {//                    System.out.println();
//                }cmaxTemp = calAssembleCmax(schedule, p, F, lambda, sequence, apt);lambda.remove(k);if (cmaxTemp < cmax){cmax = cmaxTemp;index = k;}}lambda.add(index, removed);}}return lambda;}private List<Integer>[] swapJobRfLS(List<Integer>[] sequence, List<Integer>[] best_solution, int[][] p, List<Integer> pi_product, int t, int F, List<Integer> apt){List<Integer>[] schedule = new List[F];List<Integer> list1 = new ArrayList<>();List<Integer> list2 = new ArrayList<>();List<Integer> list3 = new ArrayList<>();List<Integer>[] solution1 = new List[sequence.length];List<Integer>[] solution2 = new List[sequence.length];int Cnt = 0;int CntJob, h;int remove;int cmaxTemp = 0;int cmax = 0;cmax = Integer.MAX_VALUE;while (Cnt < t){solution1 = list1DimArrayCopy(sequence);CntJob = 0;h = 0;while (CntJob < sequence[Cnt].size()){int bestIndex = 0;solution2 = list1DimArrayCopy(solution1);
//                remove = solution2[Cnt].remove(h);
//                remove = solution2[Cnt].remove(best_solution[Cnt].indexOf(best_solution[Cnt].get(h)));for (int k = 0; k < solution2[Cnt].size(); k++){if (k != h){list1.clear();Collections.swap(solution2[Cnt], k, best_solution[Cnt].indexOf(best_solution[Cnt].get(h)));for (int l = 0; l < t; l++){list1.addAll(solution2[pi_product.get(l) - 1]);}
//                        schedule = Heuristic1.assignByNR1(p, list1, F);//NR1schedule = Heuristic1.ecfRule(p, list1, F);cmaxTemp = calAssembleCmax(schedule, p, F, pi_product, sequence, apt);if (cmaxTemp < cmax){cmax = cmaxTemp;bestIndex = k;}Collections.swap(solution2[Cnt], k, best_solution[Cnt].indexOf(best_solution[Cnt].get(h)));}}Collections.swap(solution2[Cnt], bestIndex, best_solution[Cnt].indexOf(best_solution[Cnt].get(h)));list2.clear();for (int i = 0; i < solution1.length; i++){list2.addAll(solution1[pi_product.get(i) - 1]);}
//                if (cmax < calAssembleCmax(Heuristic1.assignByNR1(p, list2, F), p, F, pi_product, sequence, apt))if (cmax < calAssembleCmax(Heuristic1.ecfRule(p, list2, F), p, F, pi_product, sequence, apt)){solution1[Cnt].clear();solution1[Cnt].addAll(solution2[Cnt]);CntJob = 0;}else{CntJob += 1;}h = h % solution1[Cnt].size();}list2.clear();list3.clear();for (int i = 0; i < t; i++){list3.addAll(sequence[pi_product.get(i) - 1]);list2.addAll(solution1[pi_product.get(i) - 1]);}
//            if (calAssembleCmax(Heuristic1.assignByNR1(p, list2, F), p, F, pi_product, sequence, apt) < calAssembleCmax(Heuristic1.assignByNR1(p, list3, F), p, F, pi_product, sequence, apt))if (calAssembleCmax(Heuristic1.ecfRule(p, list2, F), p, F, pi_product, sequence, apt) < calAssembleCmax(Heuristic1.ecfRule(p, list3, F), p, F, pi_product, sequence, apt)){sequence = solution1;Cnt = 0;}else{Cnt += 1;}}return sequence;}private List<Integer> swapProductRfLS(List<Integer>[] sequence, List<Integer> pi_product1, int[][] p, List<Integer> pi_product, int t, int F, List<Integer> apt){List<Integer>[] solution = new List[sequence.length];solution = list1DimArrayCopy(sequence);List<Integer> copyOfPiProduct = new ArrayList<>();
//        copyOfPiProduct = listCopy(pi_product);int cnt = 0;int j = 0;int removed;List<Integer> list = new ArrayList<>();
//        int temp = 0;
//        List<Integer> temp_solution = new ArrayList<>();
//        Map<List<Integer>, Integer> map = new HashMap<>();List<Integer>[] schedule = new List[F];int bestIndex = 0;int cmaxTemp = 0;List<Integer> list1 = new ArrayList<>();int cmax = 0;cmax = Integer.MAX_VALUE;while (cnt < t){copyOfPiProduct = listCopy(pi_product);for (int k = 0; k < copyOfPiProduct.size(); k++){if (k != j){list.clear();list1.clear();Collections.swap(copyOfPiProduct, k, copyOfPiProduct.indexOf(pi_product1.get(j)));for (int i = 0; i < pi_product.size(); i++){list.addAll(solution[copyOfPiProduct.get(i) - 1]);list1.addAll(sequence[pi_product.get(i) - 1]);}schedule = Heuristic1.ecfRule(p, list, F);//NR1cmaxTemp = calAssembleCmax(schedule, p, F, copyOfPiProduct, sequence, apt);Collections.swap(copyOfPiProduct, k, pi_product.indexOf(pi_product1.get(j)));if (cmaxTemp < cmax){cmax = cmaxTemp;bestIndex = k;}}}Collections.swap(copyOfPiProduct, bestIndex, copyOfPiProduct.indexOf(pi_product1.get(j)));if (cmax < calAssembleCmax(Heuristic1.ecfRule(p, list1, F), p, F, pi_product, sequence, apt)){pi_product.clear();pi_product.addAll(copyOfPiProduct);cnt = 0;}else{cnt += 1;}j = (j + 1) % t;}return pi_product;}private List<Integer>[] insertJobRfLS(List<Integer>[] sequence, List<Integer>[] best_solution, int[][] p, List<Integer> pi_product, int t, int F, List<Integer> apt){List<Integer>[] schedule = new List[F];List<Integer> list1 = new ArrayList<>();List<Integer> list2 = new ArrayList<>();List<Integer> list3 = new ArrayList<>();List<Integer>[] solution1 = new List[sequence.length];List<Integer>[] solution2 = new List[sequence.length];int Cnt = 0;int CntJob, h;int remove;int cmaxTemp = 0;int cmax = 0;cmax = Integer.MAX_VALUE;while (Cnt < t){solution1 = list1DimArrayCopy(sequence);CntJob = 0;h = 0;while (CntJob < sequence[Cnt].size()){int bestIndex = 0;solution2 = list1DimArrayCopy(solution1);
//                remove = solution2[Cnt].remove(h);remove = solution2[Cnt].remove(best_solution[Cnt].indexOf(best_solution[Cnt].get(h)));for (int k = 0; k < solution2[Cnt].size() + 1; k++){if (k != h){list1.clear();solution2[Cnt].add(k, remove);for (int l = 0; l < t; l++){list1.addAll(solution2[pi_product.get(l) - 1]);}
//                        schedule = Heuristic1.assignByNR1(p, list1, F);//NR1schedule = Heuristic1.ecfRule(p, list1, F);cmaxTemp = calAssembleCmax(schedule, p, F, pi_product, sequence, apt);if (cmaxTemp < cmax){cmax = cmaxTemp;bestIndex = k;}solution2[Cnt].remove(k);}}solution2[Cnt].add(bestIndex, remove);
//                System.out.println(bestIndex);
//                System.out.println(Cnt);list2.clear();for (int i = 0; i < solution1.length; i++){list2.addAll(solution1[pi_product.get(i) - 1]);}
//                if (cmax < calAssembleCmax(Heuristic1.assignByNR1(p, list2, F), p, F, pi_product, sequence, apt))if (cmax < calAssembleCmax(Heuristic1.ecfRule(p, list2, F), p, F, pi_product, sequence, apt)){solution1[Cnt].clear();solution1[Cnt].addAll(solution2[Cnt]);CntJob = 0;}else{CntJob += 1;}h = h % solution1[Cnt].size();}list2.clear();list3.clear();for (int i = 0; i < t; i++){list3.addAll(sequence[pi_product.get(i) - 1]);list2.addAll(solution1[pi_product.get(i) - 1]);}
//            if (calAssembleCmax(Heuristic1.assignByNR1(p, list2, F), p, F, pi_product, sequence, apt) < calAssembleCmax(Heuristic1.assignByNR1(p, list3, F), p, F, pi_product, sequence, apt))if (calAssembleCmax(Heuristic1.ecfRule(p, list2, F), p, F, pi_product, sequence, apt) < calAssembleCmax(Heuristic1.ecfRule(p, list3, F), p, F, pi_product, sequence, apt)){sequence = solution1;Cnt = 0;}else{Cnt += 1;}}return sequence;}private List<Integer> insertProductRfLS(List<Integer>[] sequence, List<Integer> pi_product1, int[][] p, List<Integer> pi_product, int t, int F, List<Integer> apt){List<Integer>[] solution = new List[sequence.length];solution = list1DimArrayCopy(sequence);List<Integer> copyOfPiProduct = new ArrayList<>();
//        copyOfPiProduct = listCopy(pi_product);int cnt = 0;int j = 0;int removed;List<Integer> list = new ArrayList<>();
//        int temp = 0;
//        List<Integer> temp_solution = new ArrayList<>();
//        Map<List<Integer>, Integer> map = new HashMap<>();List<Integer>[] schedule = new List[F];int bestIndex = 0;int cmaxTemp = 0;List<Integer> list1 = new ArrayList<>();int cmax = 0;cmax = Integer.MAX_VALUE;while (cnt < t){copyOfPiProduct = listCopy(pi_product);removed = copyOfPiProduct.remove(copyOfPiProduct.indexOf(pi_product1.get(j)));for (int k = 0; k < copyOfPiProduct.size() + 1; k++){if (k != j){list.clear();list1.clear();copyOfPiProduct.add(k, removed);for (int i = 0; i < pi_product.size(); i++){list.addAll(solution[copyOfPiProduct.get(i) - 1]);list1.addAll(sequence[pi_product.get(i) - 1]);}
//                    schedule = Heuristic1.assignByNR1(p, list, F);//NR1schedule = Heuristic1.ecfRule(p, list, F);cmaxTemp = calAssembleCmax(schedule, p, F, copyOfPiProduct, sequence, apt);copyOfPiProduct.remove(k);if (cmaxTemp < cmax){cmax = cmaxTemp;bestIndex = k;}}}copyOfPiProduct.add(bestIndex, removed);//            if (cmax < calAssembleCmax(Heuristic1.assignByNR1(p, list1, F), p, F, pi_product, sequence, apt))if (cmax < calAssembleCmax(Heuristic1.ecfRule(p, list1, F), p, F, pi_product, sequence, apt)){pi_product.clear();pi_product.addAll(copyOfPiProduct);cnt = 0;}else{cnt += 1;}j = (j + 1) % t;}return pi_product;}private int sumOfPij(int[][] p){int s = 0;for (int i = 0; i < p.length; i++){for (int j = 0; j < p[0].length; j++){s += p[i][j];}}return s;}private List<Integer>[] reconstructionJob(List<Integer> lambdaj, List<Integer> pi_product, List<Integer>[] solution1, List<Integer>[] sequence, List<Integer> apt, int[][] p, int F){int cmaxTemp = 0;int cmax = 0;int index = 0;int r;int removed;List<Integer> list = new ArrayList<>();List<Integer>[] schedule = new List[F];while (lambdaj.size() > 0){r = random.nextInt(lambdaj.size());removed = lambdaj.remove(r);for (int i = 0; i < sequence.length; i++){if (sequence[i].contains(removed)){cmax = Integer.MAX_VALUE;for (int k = 0; k < solution1[i].size() + 1; k++){solution1[i].add(k, removed);list.clear();for (int j = 0; j < solution1.length; j++){list.addAll(solution1[pi_product.get(j) - 1]);}
//                        schedule = Heuristic1.assignByNR1(p, list, F);//NR1schedule = Heuristic1.ecfRule(p, list, F);cmaxTemp = calAssembleCmax2(schedule, solution1, p, F, pi_product, sequence, apt);solution1[i].remove(k);if (cmaxTemp < cmax){cmax = cmaxTemp;index = k;}}solution1[i].add(index, removed);break;}}}return solution1;}private List<Integer> destructionJob(int dj, List<Integer> pi_product, List<Integer>[] solution1){int r1;int r2;int count = 0;List<List<Integer>> list = new ArrayList<>();
//        List<Integer> list1 = new ArrayList<>();
//        for (int i = 0; i < pi_product.size(); i++)
//        {//            list1.addAll(solution1[pi_product.get(i) - 1]);
//        }List<Integer> lambdaj = new ArrayList<>();
//        List<Integer> lambda = new ArrayList<>();
//        for (int i = 0; i < dj; i++)while (count < dj){r1 = random.nextInt(pi_product.size());if (solution1[r1].size() > 0){r2 = random.nextInt(solution1[r1].size());lambdaj.add(solution1[r1].remove(r2));count++;}//其中一个被取完,且未取够5个}list.add(lambdaj);
//        list.add(solution1);return lambdaj;}private List<Integer> reconstructionProduct(List<Integer> lambda, List<Integer> lambdap, List<Integer>[] sequence, List<Integer> apt, int[][] p, int F){int r;int removed;int cmax;
//        List<Integer> copyLambdap = new ArrayList<>();
//        copyLambdap = listCopy(lambdap);List<Integer>[] schedule = new List[F];List<Integer> list1 = new ArrayList<>();int cmaxTemp = 0;int index = 0;while (lambdap.size() > 0){cmax = Integer.MAX_VALUE;r = random.nextInt(lambdap.size());removed = lambdap.remove(r);for (int k = 0; k < lambda.size() + 1; k++){list1.clear();lambda.add(k, removed);for (int i = 0; i < lambda.size(); i++){list1.addAll(sequence[lambda.get(i) - 1]);}
//                schedule = Heuristic1.assignByNR1(p, list1, F);//NR1schedule = Heuristic1.ecfRule(p, list1, F);
//                if (schedule == null)
//                {//                    System.out.println();
//                }cmaxTemp = calAssembleCmax(schedule, p, F, lambda, sequence, apt);lambda.remove(k);if (cmaxTemp < cmax){cmax = cmaxTemp;index = k;}}lambda.add(index, removed);}return lambda;}private List<List<Integer>> destructionProduct(int dp, List<Integer> pi_product){int r;List<List<Integer>> list = new ArrayList<>();List<Integer> copyPiProduct = new ArrayList<>();copyPiProduct = listCopy(pi_product);List<Integer> lambdaP = new ArrayList<>();List<Integer> lambda = new ArrayList<>();while (lambdaP.size() < dp){if (copyPiProduct.size() <= 0){break;}else{r = random.nextInt(copyPiProduct.size());lambdaP.add(copyPiProduct.remove(r));}}list.add(copyPiProduct);list.add(lambdaP);return list;}private List<Integer>[] insertJobLS(List<Integer>[] sequence, int[][] p, List<Integer> pi_product, int t, int F, List<Integer> apt){//        int[] n_lambda = new int[t];
//        for (int i = 0; i < t; i++)
//        {//            n_lambda[i] = list.get(i).size();
//        }List<Integer>[] schedule = new List[F];List<Integer> list1 = new ArrayList<>();List<Integer> list2 = new ArrayList<>();List<Integer> list3 = new ArrayList<>();List<Integer>[] solution1 = new List[sequence.length];List<Integer>[] solution2 = new List[sequence.length];int Cnt = 0;int CntJob, h;int remove;int cmaxTemp = 0;int cmax = 0;cmax = Integer.MAX_VALUE;while (Cnt < t){solution1 = list1DimArrayCopy(sequence);CntJob = 0;h = 0;while (CntJob < sequence[Cnt].size()){int bestIndex = 0;solution2 = list1DimArrayCopy(solution1);remove = solution2[Cnt].remove(h);for (int k = 0; k < solution2[Cnt].size() + 1; k++){if (k != h){list1.clear();solution2[Cnt].add(k, remove);for (int l = 0; l < t; l++){list1.addAll(solution2[pi_product.get(l) - 1]);}
//                        schedule = Heuristic1.assignByNR1(p, list1, F);//NR1schedule = Heuristic1.ecfRule(p, list1, F);cmaxTemp = calAssembleCmax(schedule, p, F, pi_product, sequence, apt);if (cmaxTemp < cmax){cmax = cmaxTemp;bestIndex = k;}solution2[Cnt].remove(k);}}solution2[Cnt].add(bestIndex, remove);
//                System.out.println(bestIndex);
//                System.out.println(Cnt);list2.clear();for (int i = 0; i < solution1.length; i++){list2.addAll(solution1[pi_product.get(i) - 1]);}
//                if (cmax < calAssembleCmax(Heuristic1.assignByNR1(p, list2, F), p, F, pi_product, sequence, apt))if (cmax < calAssembleCmax(Heuristic1.ecfRule(p, list2, F), p, F, pi_product, sequence, apt)){solution1[Cnt].clear();solution1[Cnt].addAll(solution2[Cnt]);CntJob = 0;}else{CntJob += 1;}h = h % solution1[Cnt].size();}list2.clear();list3.clear();for (int i = 0; i < t; i++){list3.addAll(sequence[pi_product.get(i) - 1]);list2.addAll(solution1[pi_product.get(i) - 1]);}
//            if (calAssembleCmax(Heuristic1.assignByNR1(p, list2, F), p, F, pi_product, sequence, apt) < calAssembleCmax(Heuristic1.assignByNR1(p, list3, F), p, F, pi_product, sequence, apt))if (calAssembleCmax(Heuristic1.ecfRule(p, list2, F), p, F, pi_product, sequence, apt) < calAssembleCmax(Heuristic1.ecfRule(p, list3, F), p, F, pi_product, sequence, apt)){sequence = solution1;Cnt = 0;}else{Cnt += 1;}}return sequence;}private List<Integer> insertProductLS(List<Integer>[] sequence, int[][] p, List<Integer> pi_product, int t, int F, List<Integer> apt){List<Integer>[] solution = new List[sequence.length];solution = list1DimArrayCopy(sequence);List<Integer> copyOfPiProduct = new ArrayList<>();
//        copyOfPiProduct = listCopy(pi_product);int cnt = 0;int j = 0;int removed;List<Integer> list = new ArrayList<>();
//        int temp = 0;
//        List<Integer> temp_solution = new ArrayList<>();
//        Map<List<Integer>, Integer> map = new HashMap<>();List<Integer>[] schedule = new List[F];int bestIndex = 0;int cmaxTemp = 0;List<Integer> list1 = new ArrayList<>();int cmax = 0;cmax = Integer.MAX_VALUE;while (cnt < t){copyOfPiProduct = listCopy(pi_product);removed = copyOfPiProduct.remove(j);for (int k = 0; k < copyOfPiProduct.size() + 1; k++){if (k != j){list.clear();list1.clear();copyOfPiProduct.add(k, removed);for (int i = 0; i < pi_product.size(); i++){list.addAll(solution[copyOfPiProduct.get(i) - 1]);list1.addAll(sequence[pi_product.get(i) - 1]);}
//                    schedule = Heuristic1.assignByNR1(p, list, F);//NR1schedule = Heuristic1.ecfRule(p, list, F);cmaxTemp = calAssembleCmax(schedule, p, F, copyOfPiProduct, sequence, apt);copyOfPiProduct.remove(k);if (cmaxTemp < cmax){cmax = cmaxTemp;bestIndex = k;}}}copyOfPiProduct.add(bestIndex, removed);//            if (cmax < calAssembleCmax(Heuristic1.assignByNR1(p, list1, F), p, F, pi_product, sequence, apt))if (cmax < calAssembleCmax(Heuristic1.ecfRule(p, list1, F), p, F, pi_product, sequence, apt)){pi_product.clear();pi_product.addAll(copyOfPiProduct);cnt = 0;}else{cnt += 1;}j = (j + 1) % t;}return pi_product;}private int calAssembleCmax2(List<Integer>[] schedule, List<Integer>[] solution1, int[][] p, int F, List<Integer> pi_product, List<Integer>[] sequence, List<Integer> apt){//分配工厂int[][] newp;int Cmax = 0;
//        List<Integer>[][] assignment = new List[1][F];
//        assignment[0] = Heuristic1.ecfRule(p, piT, F);//NR2
//        assignment[0] = Heuristic1.assignByNR1(p, piT, F);//NR1CalculateCmaxPFSP ccp = new CalculateCmaxPFSP();List<Integer>[] lists = new List[F];for (int j = 0; j < F; j++){newp = getNewp(p, schedule[j]);lists[j] = ccp.forwardMethod3(newp);}Map<Integer, Integer> map = new HashMap<>();for (int i = 0; i < schedule.length; i++){for (int j = 0; j < schedule[i].size(); j++){map.put(schedule[i].get(j), lists[i].get(j));}}//计算装配完成时间int[] Cmax_Assemble = new int[pi_product.size()];int temp;for (int i = 0; i < pi_product.size(); i++)
//        for (int i = 0; i < assignment.length; i++){temp = Integer.MIN_VALUE;for (int j = 0; j < solution1[pi_product.get(i) - 1].size(); j++){temp = Math.max(temp, map.get(solution1[pi_product.get(i) - 1].get(j)));}Cmax_Assemble[i] = temp;}
//        Cmax = Cmax_Assemble[pi_product.get(0) - 1] + apt.get(pi_product.get(0) - 1);Cmax = Cmax_Assemble[0] + apt.get(pi_product.get(0) - 1);for (int i = 1; i < Cmax_Assemble.length; i++){//            if (Cmax > Cmax_Assemble[pi_product.get(i) - 1])if (Cmax > Cmax_Assemble[i]){Cmax += apt.get(pi_product.get(i) - 1);}else{Cmax = Cmax_Assemble[i] + apt.get(pi_product.get(i) - 1);}}
//        System.out.println("Cmax = " + Cmax);return Cmax;}public int calAssembleCmax(List<Integer>[] schedule, int[][] p, int F, List<Integer> pi_product, List<Integer>[] sequence, List<Integer> apt){//分配工厂int[][] newp;int Cmax = 0;
//        List<Integer>[][] assignment = new List[1][F];
//        assignment[0] = Heuristic1.ecfRule(p, piT, F);//NR2
//        assignment[0] = Heuristic1.assignByNR1(p, piT, F);//NR1CalculateCmaxPFSP ccp = new CalculateCmaxPFSP();List<Integer>[] lists = new List[F];for (int j = 0; j < F; j++){if (schedule[j].size() == 0){break;}else{newp = getNewp(p, schedule[j]);}
//            if (newp.length == 0 || newp[0].length == 0)
//            {//                System.out.println();
//            }lists[j] = ccp.forwardMethod3(newp);}Map<Integer, Integer> map = new HashMap<>();for (int i = 0; i < schedule.length; i++){for (int j = 0; j < schedule[i].size(); j++){map.put(schedule[i].get(j), lists[i].get(j));}}//计算装配完成时间int[] Cmax_Assemble = new int[pi_product.size()];int temp;for (int i = 0; i < pi_product.size(); i++)
//        for (int i = 0; i < assignment.length; i++){temp = Integer.MIN_VALUE;for (int j = 0; j < sequence[pi_product.get(i) - 1].size(); j++){temp = Math.max(temp, map.get(sequence[pi_product.get(i) - 1].get(j)));}Cmax_Assemble[i] = temp;}
//        Cmax = Cmax_Assemble[pi_product.get(0) - 1] + apt.get(pi_product.get(0) - 1);Cmax = Cmax_Assemble[0] + apt.get(pi_product.get(0) - 1);for (int i = 1; i < Cmax_Assemble.length; i++){//            if (Cmax > Cmax_Assemble[pi_product.get(i) - 1])if (Cmax > Cmax_Assemble[i]){Cmax += apt.get(pi_product.get(i) - 1);}else{Cmax = Cmax_Assemble[i] + apt.get(pi_product.get(i) - 1);}}
//        System.out.println("Cmax = " + Cmax);return Cmax;}private List<Integer>[] list1DimArrayCopy(List<Integer>[] solution)//一维List类型数组的拷贝{List<Integer>[] lists = new List[solution.length];for (int i = 0; i < solution.length; i++){lists[i] = new ArrayList<>();lists[i].addAll(solution[i]);}return lists;}private List<Integer> listCopy(List<Integer> list){List<Integer> copy = new ArrayList<>();copy.addAll(list);return copy;}private int[][] getNewp(int[][] p, List<Integer> pi){int[][] newp = new int[pi.size()][];for (int i = 0; i < pi.size(); i++){newp[i] = p[pi.get(i) - 1];}return newp;}private List<Integer>[][] list2DimArrayCopy(List<Integer>[][] solution)//二维List类型数组的拷贝{List<Integer>[][] lists = new List[solution.length][solution[0].length];for (int i = 0; i < solution.length; i++){for (int j = 0; j < solution[0].length; j++){lists[i][j] = new ArrayList<>();lists[i][j].addAll(solution[i][j]);}}return lists;}
}

启发式H11

package practice.dapfsp;import practice.calculateCMAX.CalculateCmaxPFSP;import java.util.*;/*** @Date: 2022/3/30 20:58* @Author: * @File: Heuristic1.class* @Software: IDEA* @Email: 1532116227@qq.com*/
public class Heuristic1
{public List<Integer>[] algorithm(int[][] p, int t, List<Integer> apt, List<Integer>[] sequence, List<Integer> pi_product){//        List<Integer> pi_product;List<Integer> piT = new ArrayList<>();
//        pi_product = ruleOfSPT(apt);List<Integer>[] parSeq = new List[t];for (int i = 0; i < t; i++){parSeq[i] = new ArrayList<>();}for (int i = 0; i < t; i++){//            parSeq[i] = heuristicFL(p, sequence[pi_product.get(i) - 1]);parSeq[i] = heuristicFL(p, sequence[i]);}
//        for (int i = 0; i < t; i++)
//        {//            piT.addAll(parSeq[i]);
//        }return parSeq;}private List<Integer> heuristicFL(int[][] p, List<Integer> sequence){int[] TPj;int[][] newp;List<Integer> R = new ArrayList<>();List<Integer> S = new ArrayList<>();List<Integer> copySeq = listCopy(sequence);
//        R = listCopy(copySeq);CalculateCmaxPFSP ccp = new CalculateCmaxPFSP();newp = getNewp(p, sequence);TPj = getTP(newp);Map<Integer, Integer> map = new HashMap<>();for (int i = 0; i < sequence.size(); i++){map.put(copySeq.get(i), TPj[i]);}List<Map.Entry<Integer, Integer>> lst = new ArrayList<>(map.entrySet());Collections.sort(lst, (o1, o2) -> o1.getValue() - o2.getValue());for (Map.Entry<Integer, Integer> entry : lst){R.add(entry.getKey());}int[][] p1 = {p[R.get(0) - 1], p[R.get(1) - 1]};int[][] p2 = {p[R.get(1) - 1], p[R.get(0) - 1]};if (ccp.forwardMethod(p1) < ccp.forwardMethod(p2)){S.add(R.get(0));S.add(R.get(1));}else{S.add(R.get(1));S.add(R.get(0));}for (int i = 2; i < R.size(); i++){S = insertAndEvaluation(p, S, R.get(i));}//两两交换位置List<Integer> copyS = new ArrayList<>();copyS = listCopy(S);int[][] newp1;int[][] newp2;newp2 = getNewp(p, S);Map<List<Integer>, Integer> map1 = new HashMap<>();for (int i = 0; i < copyS.size() - 1; i++){for (int j = i + 1; j < copyS.size(); j++){Collections.swap(copyS, i, j);newp1 = getNewp(p, copyS);map1.put(listCopy(copyS), ccp.forwardMethod(newp1));Collections.swap(copyS, i, j);}}List<Map.Entry<List<Integer>, Integer>> lst1 = new ArrayList<>(map1.entrySet());Collections.sort(lst1, (o1, o2) -> o1.getValue().compareTo(o2.getValue()));//升序for (Map.Entry<List<Integer>, Integer> entry : lst1){if (entry.getValue() < ccp.forwardMethod(newp2)){copyS.clear();copyS.addAll(entry.getKey());}break;}return copyS;}private static List<Integer> insertAndEvaluation(int[][] p, List<Integer> pi, int index){int[] cmax = new int[pi.size() + 1];int[][] pp = new int[pi.size() + 1][];
//        List<Integer> list = new ArrayList<>();//插入得到所有的组合for (int i = 0; i <= pi.size(); i++){pi.add(i, index);for (int j = 0; j < pi.size(); j++){pp[j] = p[pi.get(j) - 1];}
//            ForwardCalculation fc = new ForwardCalculation();//前向计算
//            List<int[][]> listIE = fc.forwardMethod(pp);//前向计算
//            cmax[i] = getCmax(listIE);CalculateCmaxPFSP ccp = new CalculateCmaxPFSP();cmax[i] = ccp.forwardMethod(pp);pi.remove(i);}int elementIndex = minElementIndex(cmax);if (p.length == pi.size() + 1){System.out.println("Cmax = " + cmax[elementIndex]);}pi.add(elementIndex, index);return pi;}private static int minElementIndex(int[] array){int min = array[0];int index = 0;for (int i = 1; i < array.length; i++){if (array[i] < min){min = array[i];index = i;}}return index;}private List<Integer> listCopy(List<Integer> list){List<Integer> copy = new ArrayList<>();copy.addAll(list);return copy;}private static int[][] getNewp(int[][] p, List<Integer> pi){int[][] newp = new int[pi.size()][];for (int i = 0; i < pi.size(); i++){newp[i] = p[pi.get(i) - 1];}return newp;}private static int[] getTP(int[][] p){int[] TP = new int[p.length];for (int i = 0; i < p.length; i++){for (int j = 0; j < p[0].length; j++){TP[i] = TP[i] + p[i][j];}}return TP;}public static List<Integer> ruleOfSPT(List<Integer> apt){Map<Integer, Integer> map = new HashMap<>();List<Integer> pi = new ArrayList<>();for (int i = 0; i < apt.size(); i++){map.put(i + 1, apt.get(i));}List<Map.Entry<Integer, Integer>> lst = new ArrayList<>(map.entrySet());Collections.sort(lst, (o1, o2) -> o1.getValue().compareTo(o2.getValue()));//升序
//        Collections.sort(list, (o1, o2) -> o2.getValue().compareTo(o1.getValue()));//降序for (Map.Entry<Integer, Integer> entry : lst){pi.add(entry.getKey());}return pi;}public static List<Integer>[] assignByNR1(int[][] p, List<Integer> pi, int F)//NR1{CalculateCmaxPFSP ccp = new CalculateCmaxPFSP();int[][] newp;int Cmax;int Cmax_temp;int Factory_Index = 0;List<Integer>[] Lambda = new List[F];//List类型的数组for (int i = 0; i < F; i++){Lambda[i] = new ArrayList<>();}for (int k = 0; k < F; k++){if (k > pi.size() - 1){break;}else{Lambda[k].add(pi.get(k));}}for (int k = F; k < pi.size(); k++){Cmax = Integer.MAX_VALUE;for (int i = 0; i < F; i++){newp = getNewp(p, Lambda[i]);Cmax_temp = ccp.forwardMethod(newp);if (Cmax_temp < Cmax){Cmax = Cmax_temp;Factory_Index = i;}}Lambda[Factory_Index].add(pi.get(k));}return Lambda;}public static List<Integer>[] ecfRule(int[][] p, List<Integer> pi, int F)//NR2{//        int[][] p = {{1, 4}, {86, 21}, {28, 67}, {32, 17}};CalculateCmaxPFSP ccp = new CalculateCmaxPFSP();
//        List<Integer> pi = List.of(1, 2, 3, 4);
//        int F = 2;int[][] newp;int Cmax;int Cmax_temp;int Factory_Index = 0;List<Integer>[] Lambda = new List[F];//List类型的数组for (int i = 0; i < F; i++){Lambda[i] = new ArrayList<>();}for (int k = 0; k < F; k++){if (k > pi.size() - 1){break;}else{Lambda[k].add(pi.get(k));}}for (int k = F; k < p.length; k++){if (k > pi.size() - 1){break;}else{Cmax = Integer.MAX_VALUE;for (int i = 0; i < F; i++){Lambda[i].add(pi.get(k));newp = getNewp(p, Lambda[i]);Cmax_temp = ccp.forwardMethod(newp);if (Cmax_temp < Cmax){Cmax = Cmax_temp;Factory_Index = i;}Lambda[i].remove(pi.get(k));}Lambda[Factory_Index].add(pi.get(k));}}
//        for (int i = 0; i < F; i++)
//        {//            System.out.println(Lambda[i]);
//        }return Lambda;}
}

计算Cmax

package practice.calculateCMAX;import org.junit.Test;import java.util.ArrayList;
import java.util.List;public class CalculateCmaxPFSP
{//    @Testpublic int forwardMethod(int[][] p){//        List<int[][]> list = new ArrayList<>();int[][] s = new int[p.length][p[0].length];int[][] c = new int[p.length][p[0].length + 1];c[0][0] = 0;for (int i = 0; i < p[0].length; i++){s[0][i] = c[0][i];c[0][i + 1] = s[0][i] + p[0][i];}for (int j = 1; j < p.length; j++){c[j][0] = c[j - 1][1];for (int i = 0; i < p[0].length; i++){s[j][i] = Math.max(c[j][i], c[j - 1][i + 1]);c[j][i + 1] = s[j][i] + p[j][i];}}
//        list.add(s);
//        list.add(c);
//        return list;return c[c.length - 1][c[0].length - 1];}//    @Testpublic List<int[][]> forwardMethod2(int[][] p){List<int[][]> list = new ArrayList<>();int[][] s = new int[p.length][p[0].length];int[][] c = new int[p.length][p[0].length + 1];c[0][0] = 0;for (int i = 0; i < p[0].length; i++){s[0][i] = c[0][i];c[0][i + 1] = s[0][i] + p[0][i];}for (int j = 1; j < p.length; j++){c[j][0] = c[j - 1][1];for (int i = 0; i < p[0].length; i++){s[j][i] = Math.max(c[j][i], c[j - 1][i + 1]);c[j][i + 1] = s[j][i] + p[j][i];}}list.add(s);list.add(c);return list;//        return c[c.length - 1][c[0].length - 1];}public List<Integer> forwardMethod3(int[][] p)//带装配{List<Integer> list = new ArrayList<>();int[][] s = new int[p.length][p[0].length];int[][] c = new int[p.length][p[0].length + 1];c[0][0] = 0;for (int i = 0; i < p[0].length; i++){s[0][i] = c[0][i];c[0][i + 1] = s[0][i] + p[0][i];}for (int j = 1; j < p.length; j++){c[j][0] = c[j - 1][1];for (int i = 0; i < p[0].length; i++){s[j][i] = Math.max(c[j][i], c[j - 1][i + 1]);c[j][i + 1] = s[j][i] + p[j][i];}}for (int i = 0; i < p.length; i++){list.add(c[i][c[0].length - 1]);}
//        list.add(s);
//        list.add(c);return list;//        return c[c.length - 1][c[0].length - 1];}//    @Testpublic int reverseMethod(int[][] p){List<int[][]> list = new ArrayList<>();int[][] ss = new int[p.length][p[0].length + 1];int[][] cc = new int[p.length][p[0].length];ss[p.length - 1][p[0].length] = 0;for (int i = p[0].length; i > 0; i--){cc[p.length - 1][i - 1] = ss[p.length - 1][i];ss[p.length - 1][i - 1] = cc[p.length - 1][i - 1] + p[p.length - 1][i - 1];}for (int j = p.length; j > 1; j--){ss[j - 2][p[0].length] = ss[j - 1][p[0].length - 1];for (int i = p[0].length; i > 0; i--){cc[j - 2][i - 1] = Math.max(ss[j - 2][i], ss[j - 1][i - 1]);ss[j - 2][i - 1] = cc[j - 2][i - 1] + p[j - 2][i - 1];}}
//        list.add(ss);
//        list.add(cc);
//        return list;return ss[0][0];}//    @Testpublic List<int[][]> reverseMethod2(int[][] p){List<int[][]> list = new ArrayList<>();int[][] ss = new int[p.length][p[0].length + 1];int[][] cc = new int[p.length][p[0].length];ss[p.length - 1][p[0].length] = 0;for (int i = p[0].length; i > 0; i--){cc[p.length - 1][i - 1] = ss[p.length - 1][i];ss[p.length - 1][i - 1] = cc[p.length - 1][i - 1] + p[p.length - 1][i - 1];}for (int j = p.length; j > 1; j--){ss[j - 2][p[0].length] = ss[j - 1][p[0].length - 1];for (int i = p[0].length; i > 0; i--){cc[j - 2][i - 1] = Math.max(ss[j - 2][i], ss[j - 1][i - 1]);ss[j - 2][i - 1] = cc[j - 2][i - 1] + p[j - 2][i - 1];}}list.add(ss);list.add(cc);return list;
//        return ss[0][0];}
}

读取测试集文件

package practice.comparison;import java.io.*;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;/*** @Date: 2022/4/8 16:24* @Author: * @File: ReadTxt.class* @Software: IDEA* @Email: 1532116227@qq.com*/
public class ReadTxt
{public int[][] getProcessingTimes(String filePath, int n, int m){File f = new File(filePath);if (!f.exists()){System.out.println("找不到文件");return null;}int[][] p = new int[n][m];int[] a = null;String[] values;try{BufferedReader br = new BufferedReader(new FileReader(f));Scanner sc = new Scanner(br);for (int i = 0; i < n; i++){values = sc.nextLine().split(",");for (int j = 0; j < m; j++){p[i][j] = Integer.parseInt(values[j]);}}br.close();}catch (FileNotFoundException e){e.printStackTrace();}catch (IOException e){e.printStackTrace();}return p;}public List<Integer> getAssemblyTimes(String filePath, int l){List<Integer> apt = new ArrayList<>();File f = new File(filePath);if (!f.exists()){System.out.println("找不到文件");return null;}int[] pp = new int[l];try{BufferedReader br = new BufferedReader(new FileReader(f));Scanner sc = new Scanner(br);for (int i = 0; i < l; i++){String[] values = sc.nextLine().split(",");pp[i] = Integer.parseInt(values[1]);}br.close();}catch (IOException e){e.printStackTrace();}for (int i = 0; i < l; i++){apt.add(pp[i]);}return apt;}public int[] getAssignSet(String filePath, int n, int l){File f = new File(filePath);if (!f.exists()){System.out.println("找不到文件");return null;}int[] as = new int[n];try{BufferedReader br = new BufferedReader(new FileReader(f));Scanner sc = new Scanner(br);for (int i = 0; i < n; i++){String[] values = sc.nextLine().split(",");as[i] = Integer.parseInt(values[1]);}br.close();}catch (IOException e){e.printStackTrace();}return as;}
}

结果

测试集

参考文献

Y. Z. Li, Q. K. Pan, R. Ruiz, and H. Y. Sang, “A referenced iterated greedy algorithm for the distributed assembly mixed no-idle permutation flowshop scheduling problem with the total tardiness criterion,” Knowledge-Based Systems, vol. 239, Mar. 2022, doi: 10.1016/j.knosys.2021.108036.

复现一篇分布式装配混合零空闲置换流水车间调度问题的代码相关推荐

  1. 复现一篇分布式装配置换流水车间调度问题的代码——基于回溯搜索的超启发式算法

    复现一篇分布式装配置换流水车间调度问题的代码--基于回溯搜索的超启发式算法 摘要 算法框架 说明 代码 测试类 算法主体 Assignment Heuristics Individual Method ...

  2. 复现一篇分布式置换流水车间调度问题的代码——分布估计算法

    复现一篇分布式置换流水车间调度问题的代码--分布估计算法 摘要 说明 代码 测试类 算法主体 计算Cmax 读取测试集文件 结果 简单例子 测试集 参考文献 摘要 In this paper, an ...

  3. 【优化算法】遗传算法GA求解混合流水车间调度问题(附C++代码)

    [优化算法]遗传算法GA求解混合流水车间调度问题(附C++代码) 00 前言 各位读者大家好,好久没有介绍算法的推文了,感觉愧对了读者们热爱学习的心灵.于是,今天我们带来了一个神奇的优化算法--遗传算 ...

  4. 一种混合流水车间调度问题的建模思路

    混合流水车间调度问题(Hybrid Flow Shop Scheduling Problem,  HFSP)是一种典型的流水车间调度问题.它综合了经典流水车间和并行机两种调度的特点. 如下图所示,从开 ...

  5. 流水车间调度问题混合整数规划模型

    流水车间调度问题(FSP)描述为:有n个独立的工件按照相同的工艺路线在m台机器伤加工,每个工件需要经过m道工序,这些工序分别要求不同的机器,并且各工序的加工过程不能中断. 以最大完工时间为目标的流水车 ...

  6. 利用CVX和gurobi这个求解器复现一篇混合整数线性规划问题时遇到的问题

    利用CVX和gurobi这个求解器复现一篇混合整数线性规划问题时遇到的问题 1.当出现从cvx 转换为double 时出现错误: ![](https://img-blog.csdnimg.cn/202 ...

  7. 学习笔记:The Log(我所读过的最好的一篇分布式技术文章

     学习笔记:The Log(我所读过的最好的一篇分布式技术文章)         前言 这是一篇学习笔记. 学习的材料来自Jay Kreps的一篇讲Log的博文. 原文很长,但是我坚持看完了,收获 ...

  8. 6个月为50篇AI论文写摘要,网友:这有啥,我曾被要求1.5小时内复现一篇论文...

    点击上方"视学算法",选择加"星标"或"置顶" 重磅干货,第一时间送达 来源丨机器之心 编辑丨极市平台 导读 快速阅读论文是研究人员不可或缺 ...

  9. 导师:寒假复现几篇顶会论文?答:3天1篇!

    3天复现1篇顶会论文!?这怎么做的到? 自己读论文总会遇到很多问题: 不知道从哪里找论文.不知道如何甄别论文质量? 找到论文之后,找不到论文源代码? 好不容易找到代码,却配置不好环境,更别说复现论文了 ...

最新文章

  1. 【Ethereum】以太坊ERC20 Token标准完整说明
  2. 探测电磁波就能揪出恶意软件,网友:搁这给电脑把脉呢?
  3. 洛谷P3694 邦邦的大合唱
  4. java 配置信息_[Java教程]java 配置信息类 Properties 的简单使用
  5. 设计模式之“适配器模式”
  6. C/C++添加设置任务计划
  7. 揭秘阿里云 RTS SDK 是如何实现直播降低延迟和卡顿
  8. [转载] Java字符串分割方法
  9. 测试开发面试技巧_面试技巧将给您带来信心并帮助您获得开发工作
  10. Docker入门者手册
  11. can总线一帧多少字节多少位_一条CAN报文到底有多少位?-汽车电子-与非网
  12. PHP删除字符串最后一个字符的几种方法总结
  13. SpringBoot整合Quartz
  14. 【bat】一个脚本文件,关闭IE,重置IE,配置IE,设置IE的ActionX等选项.并自动管理员身份运行
  15. linux安装java运行环境_如何安装java运行环境
  16. 游戏模型制作的注意事项——模型规范
  17. 如何用一台普通相机拍照红蓝立体3D图片
  18. android头条的状态栏_今日头条如何设置电脑版 今日头条苹果手机任务栏在哪
  19. canvas制作圆角矩形(包括填充矩形的功能)
  20. 操作系统的内核到底是什么?

热门文章

  1. 转载+手敲《一位26岁哈佛硕士生的26条成长感悟》
  2. JS:数组Array的使用方法及获取数组的长度length
  3. python3学习笔记之八——爬取百度音乐盒临时列表中的音乐
  4. Three.js入门 (参考胖达老师)| 大帅老猿threejs特训
  5. js 16进制字符串转字符串
  6. UML对基于B/S模式的图书管理系统的分析与设计
  7. 用一顿简餐来解释JavaScript中的状态
  8. android usb设置在哪,手机usb调试在哪,小编教你安卓手机怎么打开USB调试
  9. 湖南大学头歌实训小测
  10. 文档还在手动保存?自动保存帮你轻松办公(适用于word,wps)