Flow Shop Scheduling

Flow Shop Scheduling Problem
Description:
N job {1,2, ........., n} in the pipeline processing to be completed by the two machines M1 and M2 thereof. Processing order of each job is processed first in M1, then processing on M2.
M1 and M2 of the time required for processing the job and i, respectively ai bi, 1≤i≤n. Problems assembly line height requirements determine the optimal processing sequence of the n operations such that the first job from the
start machining on the machine M1, the last job minimum time required to complete the processing on the machine M2.
Can assume any task once you start working, they not be interrupted until the task is completed, namely non-priority scheduling.
Input:
Input contains a number of use cases, the behavior of a first positive integer K (1 <= K <= 1000), is represented by the number of cases, the following use case of K, each with a first embodiment of the job number N (1 <= N <= 1000),
the next N lines of two non-negative integer, respectively, the processing time on the first machine and the second machine.
Output:
Each time an optimal use of the total used in scheduling use case one line of output, i.e. from the first machine to a second machine ends.
Sample input:
. 1
. 4
. 5. 6
12 is 2
. 4 14
. 8. 7
Sample Output:
33


Algorithm Description:

1 令 N1 = {i | and <bi}, N2 = {i | and> = bi}

2 n1 job sort by non-decreasing ai, n2 job sort bi nonincreasing

3 constitutes an optimal schedule to meet the law's Johnson

#include <iostream>
#include <algorithm>
using namespace std;
class JOB
{
public:
    int key,index;
    bool job;
};
bool cmp(JOB a,JOB b)
{
    return a.key<b.key;
}
int func(int n,int a[],int b[],int c[])
{
    int i,j,k;
    JOB *d =new JOB[n];
    for(i=0;i<n;i++)
    {
        if(a[i]<b[i])
        {
           
            d[i].job =true;
            d[i].key =a[i];
        }
        else
        {
            d[i].job=false;
            d[i].key=b[i];
        }
        d[i].index=i;
    }
    sort(d,n+d,cmp);
    j=0,k=n-1;
    for(i=0;i<n;i++)
    {
        if(d[i].job ==true)
            c[j++]=d[i].index;
        else 
            c[k--]=d[i].index;
    }
    j=a[c[0]];
    k=j+b[c[0]];
    for(i=1;i<n;i++)
    {
    j=j+a[c[i]];
    k= j<k ? k+b[c[i]] : j+b[c[i]] ;
    }
    delete d;
    return k;
}
int main()
{
    int i,n,m,a[100],b[100],c[100];
    cin>>n;
    while(n--)
    {
        cin>>m;
        for(i=0;i<m;i++)
        {
            cin>>a[i];
            cin>>b[i];
        }
        cout<<func(m,a,b,c)<<endl;
    }
    return 0;
}

operation result:

Reproduced in: https: //my.oschina.net/u/204616/blog/544994

Guess you like

Origin blog.csdn.net/weixin_33742618/article/details/91990127