Batch job scheduling _ branch and bound

I.    Description of the problem

    Given a set of n operations j = {j1, j2, ..., jn}. Each job j [i] has two tasks are done on two machines. Each job must be dealt with by the machine 1, 2 is then processed by the machine. Job j [I] j need to machine processing time t [j] [i], where i = 1, 2, ..., n, j = 1, 2. Job scheduling for a determined set F. [J] [i] i is the job processing is completed on the machine the time j. All job completion processing of time on the machine 2 and f = sigma F [2] [i] is called the time of completion of the job and scheduling.

Batch job scheduling requirements for a given n operations, to develop the best job scheduling program, and the minimum time allowed to complete.

Second, the  feasibility analysis and problem-solving ideas selected algorithm strategy

   Resolve this issue with priority queue type branch and bound method. Since all permutations from n to find jobs in the minimum completion time and job scheduling, batch job scheduling problem so the solution space tree is a tree arrangement. For batch job scheduling problem can be demonstrated that there is an optimum scheduling jobs on the machine 1 and machine 2 in the same order to complete the job (job since each operation must be completed before operations performed on the machine 1 on the machine 2).

    If the job is not scheduled for, a job for which, whenever the job is finished processing on the machine 1 can start processing immediately 2 on the machine, the machine 1 has no free time to reach full working condition, this is not the case 2 schedule jobs on the machine referred to the sum of the operating time as S1, the same way the working time in the case where the operating state of the machine 2 over the sum referred to as S2, it certainly has:

    All the work machine 2 and completion time> = scheduled time and completion work machine + max {S1, S2} 2

Wherein when a job is not scheduled according to the machine 1, when the non-operating time scheduling in descending order, S1, and S2 and the local minimum and at the same time independent scheduling, whereby as the branch and bound algorithm bounding function.

Pseudocode describing the complexity analysis and

bbFlow(){

    Xu for each job in the time-ordered machines 1 and 2

    do{

        if (reaching a leaf node) {

            if (current job completion scheduled time on the machine 2 and <bestc) {

                Update bestc;

                Update optimal solution;

            }

        }else{

            For (int i = enode number of scheduled jobs;. I the total number of jobs <; i ++) {

                Obtain current next bb;

                If(bb < bestc){

                    Insert minimum heap node;

                }

            }

        }

        Remove a node expansion;

    }while(enode!=null&&enode.s<=n)

}

 

Third,  code implementation

package branch and bound algorithm; 

public  class Nodes the implements the Comparable {
     int S; // scheduled jobs 
    int SF2; // current time on the machine 2 is completed and 
    int BB; // current completion times and lower bounds 
    int [] F; // f finalize the [1] machine 1 time, f finalize the [2] time machine 2 
    int [] X; // current job scheduling 
    
    public nodes ( int n-) {
         // minimum stack node initialization 
        X = new new  int [ n-];
         for ( int I = 0; I <n-; I ++ ) 
            X [I] =i;
        s=0;
        f=new int[3];
        f[1]=0;
        f[2]=0;
        sf2=0;
        bb=0;
    }
    
    public Nodes(Nodes e,int[] ef,int ebb,int n){
        //最小堆新结点
        x=new int[n];
        for(int i=0;i<n;i++)
            x[i]=e.x[i];
        f=ef;
        sf2=e.sf2+f[2];
        bb=ebb;
        s=e.s+1;
    }
 
    @Override
    public int compareTo(Object o) {
        int xbb=((Nodes) o).bb;
        if(bb<xbb) return -1;
        if(bb==xbb) return 0;
        return 1;
    }
}

public class BBFlow {
    public int n;//作业数
    public intbestc; // minimum completion time and 
    public  int [] [] m; // time required to process the n operations array 
    public  int [] [] B; // time required to process the n operations to sort the array 
    public  int [ ] [] a; // correspondence relationship between an array of an array of m and b 
    public  int [] bestx; // optimal solution 
    public  Boolean [] [] Y; // working array 
    
    public BBFlow ( int n-, int [] [] m ) {
         the this .n = n-; 
        bestc = 10000 ;
         the this .m = m; 
        B = new new int[n][2];
        a=new int[n][2];
        bestx=new int[n];
        y=new boolean[n][2];
    }
    public void swap(int[][] b,int i,int j,int k,int t){
        int temp=b[i][j];
        b[i][j]=b[k][t];
        b[k][t]=temp;
    }
    public void swap(int [] X, int I, int J) {
         int TEMP = X [I]; 
        X [I] = X [J]; 
        X [J] = TEMP; 
    } 
    / ** 
     * n operations of the machine 1 and the desired 2 sort time 
     * / 
    public  void Sort () {
         int [] C = new new  int [n-];
         for ( int J = 0; J <2; J ++ ) {
             for ( int I = 0; I <n-; ++ I ) { 
                B [I] [J] = m [I] [J]; 
                C [I] = I; 
            }
            for(int i=0;i<n-1;i++){
                for(int k=n-1;k>i;k--){
                    if(b[k][j]<b[k-1][j]){
                        swap(b,k,j,k-1,j);
                        swap(c,k,k-1);
                    }
                }
            }
            for(int i=0;i<n;i++)
                a[c[i]][j]=i;
        }
    }
    /**
     * 计算完成时间和下界
     * @param enode
     * @param f
     * @return
     */
    public int bound(Nodes enode,int[] f){
        for(int k=0;k<n;k++){
            for(int j=0;j<2;j++){
                y[k][j]=false;
            }
        }
        for(int k=0;k<enode.s;k++){
            for(int j=0;j<2;j++){
                y[a[enode.x[k]][j]][j]=true;
            }
        }
        f[1]=enode.f[1]+m[enode.x[enode.s]][0];
        f[2]=((f[1]>enode.f[2])?f[1]:enode.f[2])+m[enode.x[enode.s]][1];
        int sf2=enode.sf2+f[2];
        int s1=0;
        int s2=0;
        int k1=n-enode.s;
        int k2=n-enode.s;
        int f3=f[2];
        //计算s1的值
        for(int j=0;j<n;j++){
            if(!y[j][0]){
                k1--;
                if(K1-enode.s-n-==. 1 ) 
                    F3 = (F [2]> F [. 1] + B [J] [0]) F [2]:? F [. 1] + B [J] [0 ]; 
                S1 + = F [. 1] + K1 * B [J] [0 ]; 
            } 
        } 
        // Calcd for s2 
        for ( int J = 0; J <n-; J ++ ) {
             IF ! (Y [J] [ . 1 ]) { 
                K2 - ; 
                S1 + B = [J] [. 1 ]; 
                S2 + F3 + K2 * B = [J] [. 1 ]; 
            } 
        } 
        // returns completion time and lower bounds 
        return   SF2 + ((S1> S2 ?) S1: S2); 
    } 
    / **
     * Priority Queue formula branch and bound algorithm batch job scheduling solution 
     * @param NN 
     * @return 
     * / 
    public  int bbFlow ( int NN) { 
        n = NN; 
        Sort (); // for n operations on the machine 1 and 2 The time required to sort 
        the LinkedList <nodes> = heap new new the LinkedList <nodes> (); 
        nodes eNode = new new nodes (n-);
         // search tree arrangement space 
        do {
             if (enode.s == n-) {
                 // leaf node 
                if (enode.sf2 < bestc) { 
                    bestc=enode.sf2;
                    for(int i=0;i<n;i++){
                        bestx[i]=enode.x[i];
                    }
                }
            }else{
                //产生当前扩展结点的儿子结点
                for(int i=enode.s;i<n;i++){
                    swap(enode.x,enode.s,i);
                    int[] f=new int[3];
                    int bb=bound(enode,f);
                    if(bb<bestc){
                        //Subtree optimal solution may contain
                         // node insertion minimum heap 
                        Nodes Node = new new Nodes (eNode, F, BB, n-); 
                        heap.add (Node); 
                        the Collections.sort (heap); 
                    } 
                    the swap (enode.x, enode.s, I); 
                } // complete junction extension 
            }
             // remove a node extension 
            eNode = heap.poll (); 
        } the while ! (eNode = null && enode.s <= n-);
         return bestc; 
    } 
 
    
    
    public  static  voidmain (String [] args) {
         int n-=. 3 ;
         int [] [] m = {{2,1}, {3,1}, {2,3}}; // m subscript from 0 
        BBFlow = F new new BBFlow (n-, m); 
        f.bbFlow (n-); 
        System.out.println ( "optimal batch job scheduling order:" );
         for ( int I = 0; I <n-; I ++ ) 
            the System .out.print ((f.bestx [I] + 1'd) + "" ); 
        System.out.println (); 
        System.out.println ( "minimum time required for the optimal schedule was:" + f.bestc ); 
    } 
} 

/ ************************* 
* run results 
* optimal batch job scheduling order: 
* 132
* Minimum required for optimal scheduling time: 18 
************************************************************ /

 

 

Guess you like

Origin www.cnblogs.com/LieYanAnYing/p/12038398.html