Machine Schedule (P1325)

第一次接触这样的题,


#include<iostream>
#include<algorithm>
#include<cstring>

using namespace std;

//freopen("C://i.txt","r",stdin);

#define N 301

int n,m,k;
bool map[N][N];
int vist[N];
int y[N];

bool SearchPath(int x)
{
	int i;
	for (i=0;i<m;i++) if (!vist[i])
	{ 
		if (map[x][i])
		{
			vist[i]=true;
			if (y[i]==-1||SearchPath(y[i]))
			{
				y[i]=x;
				return true;
			}
		}	
	}
	return false;
}

int MaxMatch()
{
	int i;
	int ans=0;
	memset(y,-1,sizeof(y));
	for (i=1;i<n;i++)
	{
		memset(vist,false,sizeof(vist));
		if (SearchPath(i))
		{
			ans++;
		}
	}
	return ans;
}

int main()
{
	freopen("C://i.txt","r",stdin);

	int i,j;
	while (cin>>n,n)
	{
		cin>>m>>k;
		memset(map,false,sizeof(map));
		while (k--)
		{
			int a,b,c;
			cin>>a>>b>>c;
			if (b&&c)
				map[b][c]=true;
		}
		cout<<MaxMatch()<<endl;
	}
}

Language:
Machine Schedule
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 9049 Accepted: 3856

Description

As we all know, machine scheduling is a very classical problem in computer science and has been studied for a very long history. Scheduling problems differ widely in the nature of the constraints that must be satisfied and the type of schedule desired. Here we consider a 2-machine scheduling problem.

There are two machines A and B. Machine A has n kinds of working modes, which is called mode_0, mode_1, ..., mode_n-1, likewise machine B has m kinds of working modes, mode_0, mode_1, ... , mode_m-1. At the beginning they are both work at mode_0.

For k jobs given, each of them can be processed in either one of the two machines in particular mode. For example, job 0 can either be processed in machine A at mode_3 or in machine B at mode_4, job 1 can either be processed in machine A at mode_2 or in machine B at mode_4, and so on. Thus, for job i, the constraint can be represent as a triple (i, x, y), which means it can be processed either in machine A at mode_x, or in machine B at mode_y.

Obviously, to accomplish all the jobs, we need to change the machine's working mode from time to time, but unfortunately, the machine's working mode can only be changed by restarting it manually. By changing the sequence of the jobs and assigning each job to a suitable machine, please write a program to minimize the times of restarting machines.

Input

The input file for this program consists of several configurations. The first line of one configuration contains three positive integers: n, m (n, m < 100) and k (k < 1000). The following k lines give the constrains of the k jobs, each line is a triple: i, x, y.

The input will be terminated by a line containing a single zero.

Output

The output should be one integer per line, which means the minimal times of restarting machine.

Sample Input

5 5 10
0 1 1
1 1 2
2 1 3
3 1 4
4 2 1
5 2 2
6 2 3
7 2 4
8 3 3
9 4 3
0

Sample Output

3

Source



1. 符号说明: 集合 L LOT集合 M Machine集合 O Step集合 T 时间集合 参数 l Lot l,l∈L l_AM AM lot l,l_AM∈L m_o 第o道工序的Machine m,m_o∈M m_Last 最后一道工序的Machine m,m_Last∈M o_l Lot l 的工序,o_l∈O o_Last Lot l 的最后一道工序,o_Last∈O t 时间 t,t∈T 〖QTY〗_l Lot l 的wafer qty,l∈L 〖WPH〗_Om 第o道工序的Machine m的WPH,m∈M,o∈O K_lom Lot l 的第o道工序是否可以在machine m上加工,可以加工则为1,反之则为0,l∈L,m∈M,o∈O C_m Machine m 的Capability/Uptime,m∈M t_lo Lot l 在第o step的buffer time + transfer time,l∈L,o∈O p_lo Lot l 在第o step的process time,l∈L,o∈O r_l Lot l 的release time,l∈L d_(m_Last ) 最后一道工序machine m 的daily monitor的inhibit due time,m_Last∈M 〖RQT〗_l LOT l release时身上剩余的Qtime,l∈L w_l LOT l release时身上是否有Qtime,l∈L 〖QT〗_(loo^· ) Lot l 在第o step到第o· step的Q time,l∈L,o∈O,o^·∈O 〖qt〗_(loo^· ) Lot l 在第o step到第o· step是否有Q time,有Q time则为1,反之为0,l∈L,o∈O,o^·∈O 〖ts_SD_PM〗_m Machine m 在t时间开始SD_PM,m∈M,t∈T 〖te_SD_PM〗_m Machine m 在t时间结束SD_PM,m∈M,t∈T r_m Machine m 的release time,m∈M N 一个正无穷大的数 中间变量 Cmax 所有lot的完工时间 〖UT〗_(Last m) 最后一道工序的machine m的UT,m∈M QTmax 所有over Q time的lot数量 CTmax 所有lot的cycle time 〖MOVEmax〗_(Last m) 每个机台的move,m∈M e_lo Lot l 在第o step的end time,l∈L,o∈O,〖e_lo=s〗_lo+p_lo 〖CT〗_l Lot l 的cycle time,l∈L b_lm 0-1变量,Lot l 是否在机台PM前加工,若在PM前完成则为1,若在PM后开始则为0,l∈L,m∈M 决策变量 x_lom 0-1变量,Lot l 的第o道工序是否在machine m上加工,l∈L,o∈O,m∈M s_lo Lot l 在第o step的start time,l∈L,o∈O v_lo 0-1变量,Lot l 是否在第o道工序over Qtime,l∈L,o∈O 2. 目标函数: ①所有lot的完工时间;②-机台UT;③-机台move;④over Q time lot数量;⑤lot的cycle time min⁡(Cmax,〖−UT〗_(Last m),QTmax,−MOVEmax,CTmax) 3. 约束条件: 约束1:lot的每道工序只能在一个机台上加工; ∑8_(o∈O,m∈M)▒〖x_lom×K_lom=1〗,∀l∈L (1) 约束2:lot在每个工序机台上的加工时间; p_lo=〖QTY〗_l∕〖WPH〗_Om ,∀l∈L,o∈O,m∈M(2) 约束3:每道工序对应机台的capability限制; ∑8_(l∈L)▒〖x_lom×〖QTY〗_l∕〖WPH〗_Om ≤C_m 〗,∀o∈O,m∈M(3) 约束4:LOT 到站后才能上机台; r_(l ) 〖<s〗_l1,∀l∈L (4) 约束5:机台可用后lot才能上机台; r_m<s_l1,∀l∈L,m∈M(5) 约束6:lot在上一站机台加工完才能进入下一站的机台; s_lo+p_lo+t_l(o+1) ≤s_l(o+1) ,∀l∈L,o∈O(6) 约束7&8:机台SD_PM时无lot加工; 〖s_lo+p_lo≤ts_SD_PM〗_m+N×(1−b_lm )+N×(1−x_lom ),∀l∈L,o∈O,m∈M(7) s_lo≥〖te_SD_PM〗_m−N×b_lm−N×x_lom,∀l∈L,o∈O,m∈M(8) 约束9:lot刚rlease上机台时不over Qtime; s_l1−r_(l )≤〖RQT〗_l×w_l,∀l∈L(9) 约束10:lot只有在Q time loop中才可能会over Qtime; v_lo≤〖qt〗_loq,∀l∈L,o∈O,q∈O,o<q(10) 约束11:lot上机台时不over Qtime; s_l(o+1)(s_lo+p_lo )≤〖QT〗_lo(o+1) ×〖qt〗_lo(o+1) ,∀l∈L,o∈O(11) 约束12&13:Lot 是否在第o道工序 over Q time,若over记1,反之记0; 〖QT〗_lo(o+1) −s_l(o+1) +s_lo+p_lo≤N×(〖1−v〗_lo ),∀l∈L,o∈O(12) 〖QT〗_lo(o+1) −s_l(o+1) +s_lo+p_lo≥−N〖×v〗_lo,∀l∈L,o∈O(13) 约束14:AM lot至少在机台卡Mon前2小时上机台 ∑8_(l∈l_AM)▒∑8_(o∈o_Last)▒〖〖〖x_lom×s〗_lo≤d〗_(m_Last )−2〗,∀m∈M,m_Last∈M(14) 约束15:Lot的cycle time; 〖CT〗_l=∑8_(o∈o_Last)(s_lo+p_lo−r_(l ) ) ,∀l∈L(15) 约束16:所有lot的总加工时间; Cmax=∑8_(l∈L)▒∑8_(o∈o_Last)(s_lo+p_lo ) (16) 约束17:所有lot over Qtime的个数; QTmax=∑8_(l∈L)▒〖QT〗_(l(O,o^·)) ,∀o∈O,o^·∈O(17) 约束18:所有lot的cycle time; CTmax=∑8_(l∈L)▒〖CT〗_l (18) 约束19:最后一道工序机台的UT; 〖UT〗_(Last m)=∑8_(l∈L)▒∑8_(o∈o_Last)▒〖x_lom×p_lo 〗 〖/C〗_(Last m),∀m∈M(19) 约束20:最后一道工序机台的move; 〖MOVEmax〗_(Last m)=∑8_(l∈L)▒∑8_(o∈o_Last)▒〖x_lom×〖QTY〗_l 〗,∀m∈M(20) 将上述MIP模型输出python调用ortools求解器的求解代码,并输入20个lot/10个machine/5个工艺步骤的简单数据,运行出结果,将结果输出一个可视化的甘特图;
最新发布
03-12
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值