動態規劃--加工順序問題

來源:互聯網
上載者:User
import java.util.ArrayList;import java.util.Arrays;import java.util.Collections;import java.util.Comparator;import java.util.List;class Job implements Comparable<Job>{int t1;int t2;int id;public Job(int id,int t1,int t2){this.id = id;this.t1 = t1;this.t2 = t2;}public int compareTo(Job o) { // t1 非減排序if(this.t1<o.t1)return -1;elsereturn 1;}}class Com implements Comparator<Job>{public int compare(Job o1, Job o2) {if(o1.t2<o2.t2)return 1;elsereturn -1;}}public class MachiningOrder {public static void main(String args[]){Job jobs [] = {new Job(1,3,7),new Job(2,8,2),new Job(3,10,6),new Job(4,12,18),new Job(5,6,3),new Job(6,9,10),new Job(7,15,4)};List<Job> j = Arrays.asList(jobs);getSequence(j);}public static void getSequence(List<Job> jobs){List<Job> N1 = new ArrayList<Job>();List<Job> N2 = new ArrayList<Job>();for(int i=0;i<jobs.size();i++){if(jobs.get(i).t1<jobs.get(i).t2)N1.add(jobs.get(i));elseN2.add(jobs.get(i));}Collections.sort(N1);Collections.sort(N2,new Com());System.out.println("加工順序");for(int i=0;i<N1.size();i++)System.out.print(N1.get(i).id);for(int i=0;i<N2.size();i++)System.out.print(N2.get(i).id);}}/* *加工順序問題 *有兩個機器在流水線作業,產品經過第一個機器加工過後然後再放入第二個機器加工,求 *所有物品加工完後的總時間最小 *思路: *1.M1[i]表示在第一個機器上經過所用的時間 *  M2[i]表示在第二個機器上加工的時間 *2. 令N1中表示 N1={i|M1[i]<M2[i]} N2={i|M1[i]>M2[i]} *3. 將N1中的工件按非減排序,將N2中的按非增排序 *4.將N1N2就是要求的序列 * */

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.