作业调度方案C语言,2020-08-18 作业调度方案

本文介绍了一个车间调度问题的解决方法,通过使用特定的数据结构和算法,有效地实现了多个工件在多台机器上的合理分配和加工顺序,确保了生产线的高效运行。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#include

#include

#include

#include

#include

#include

#include

using namespace std;

long long qmi(int m, int k)

{

int res = 1, t = m;

while (k)

{

if (k&1) res = res * t;

t = t * t;

k >>= 1;

}

return res;

}

int read(){

int x = 0,f = 1;

char c = getchar();

while (c'9') {

if (c=='-') {

f = -1;

}

c = getchar();

}

while (c>='0'&&c<='9') {

x = x*10+c-'0';

c = getchar();

}

return x*f;

}

#define maxn 50

int n,m;

int ans = 0;

int worklist[maxn * maxn];//工作安排

int worknumber[maxn][maxn];//工作机器序号

int worktime[maxn][maxn];//加工时间

int cnt_now_work_step[maxn];//当前取到工件的工序牌号

int lasttime[maxn];//某个工件出现的最晚的时间(点)

bool timeline[maxn * maxn][maxn * maxn];//某一台机器在某一个时间(点)上是不是正在干活。

bool check_in_line(int begin_time_point, int end_time_length, int workid){//检查是否可以在生产线上

for (int time = begin_time_point; time <= end_time_length;time++)

if (timeline[workid][time])//若在产品线上

return false;

return true;

}

int main(){

cin >> m >> n;//m台机器加工n个工件

for (int i=1;i<=n*m;i++){

cin >> worklist[i];//工作安排

}

/*

其中前n行依次表示每个工件的每个工序所使用的机器号,

第1个数为第1个工序的机器号,

第2个数为第2个工序机器号,

等等。

*/

for (int i=1;i<=n;i++){

for (int j=1;j<=m;j++){

cin >> worknumber[i][j];

}

}

/*

后n行依次表示每个工件的每个工序的加工时间。

*/

for (int i=1;i<=n;i++){

for (int j=1;j<=m;j++){

cin >> worktime[i][j];

}

}

for (int i=1;i<=n*m;i++){//从1开始,一共有n*m个工作件

int nowitem = worklist[i];//当前工作的工作件

cnt_now_work_step[nowitem]++;//工序排号

int nownumber = worknumber[nowitem][cnt_now_work_step[nowitem]];//工作的机器序号

int costtime = worktime[nowitem][cnt_now_work_step[nowitem]];//花费的时间

for (int time = lasttime[nowitem]+1; ;time++)//扫描时间轴

if (check_in_line(time,time+costtime-1,nownumber)){//是否可以在线上

for (int marktime = time; marktime <= time+costtime-1 ;marktime++)//占据时间线

timeline[nownumber][marktime] = true;

lasttime[nowitem] = time + costtime - 1;//结尾时间

break;//打断时间扫描

}

}

for (int i=1;i<=n;i++)//机器数

ans = max(ans,lasttime[i]);//取最大的尾数

cout << ans << endl;

return 0;

}

/*

2 3

1 1 2 3 3 2

1 2

1 2

2 1

3 2

2 5

2 4

============

10

*/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值