$title teacher assignment problem
*some teachers are will to take overtime sessions

SETS I teachers /1, 2, 3, 4, 5, 6, 7, 8, 9, 10/
     J schools /1, 2, 3, 4, 5, 6, 7, 8, 9, 10/
     MW(J) Schools with classes on Mon and Wed /1, 2, 3, 4, 5, 6, 7, 8/
     TT(J) Schools with classes on Tue and Thr /9, 10/
     K sessions /am, pm/;


SCALAR
     Overtime 	The max classes that an overtime teacher is willing to teach /3/
     Regular	The max classes that a regular teacher is willing to teach /2/;

PARAMETER Y(I)  indicates whether teacher i is willing to teach overtime classes
/1	1
2	0
3	1
4	0
5	0
6	1
7	1
8	0
9	1
10	0/;

TABLE S(I,K,J) the combined score of the teachers' and schools' preference

        1       2       3       4       5       6       7       8       9       10
1.am    4       10      18      4       10      18      100     72      49      90
2.am    7       36      28      12      21      40      90      42      64      3
3.am    21      54      50      18      80      30      40      56      4       8
4.am    70      80      6       16      8       28      23      10      12      2
5.am    16      50      24      20      35      60      54      2       10      54
6.am    35      6       90      24      24      45      10      3       90      16
7.am    64      27      54      15      4       28      16      12      10      70
8.am    6       2       12      16      81      16      15      50      6       35
9.am    12      70      21      50      48      3       2       60      24      54
10.am   9       18      3       28      5       60      7       48      27      80

1.pm    4       10      18      4       10      18      100     72      49      90
2.pm    7       36      28      12      21      40      90      42      64      3
3.pm    21      54      50      18      80      30      40      56      4       8
4.pm    70      80      6       16      8       28      23      10      12      2
5.pm    16      50      24      20      35      60      54      2       10      54
6.pm    35      6       90      24      24      45      10      3       90      16
7.pm    64      27      54      15      4       28      16      12      10      70
8.pm    6       2       12      16      81      16      15      50      6       35
9.pm    12      70      21      50      48      3       2       60      24      54
10.pm   9       18      3       28      5       60      7       48      27      80

VARIABLES
X(I,K,J) the assignment of teacher i to school j where X is either 0 or 1
Z	the total score over the 10 schools;

POSITIVE VARIABLE X;

EQUATIONS

	SCORE define the total score which is the objective function
	SCHOOLAM(K,J) restriction that only one teacher is assigned to one am session
        SCHOOLPM(K,J) restriction that only one teacher is assigned to one pm session
	MAXCLASS(I) restriction that each teacher's maximum classes willing to teach
	TamMW(I,K) restriction that only one MW am session is assigned to one teacher
	TpmMW(I,K) restriction that only one MW pm session is assigned to one teacher
	TamTT(I,K) restriction that only one TT am session is assigned to one teacher 
	TpmTT(I,K) restriction that only one TT am session is assigned to one teacher
	DIFFSCH(I,J) restriction that each teachers are assigned to two different school;

SCORE.. Z =E= SUM(I,(SUM(K,(SUM(J,S(I,K,J)*X(I,K,J))))));
MAXCLASS(I).. SUM((K,J), X(I,K,J)) =L= ((Y(I)*Overtime)+((1-Y(I))*Regular));
SCHOOLAM("am",J).. SUM(I, X(I,"am",J)) =E= 1;
SCHOOLPM("pm",J).. SUM(I, X(I,"pm",J)) =E= 1;
TamMW(I,"am").. SUM(MW, X(I,"am",MW)) =L= 1;
TpmMW(I,"pm").. SUM(MW, X(I,"pm",MW)) =L= 1;
TamTT(I,"am").. SUM(TT, X(I,"am",TT)) =L= 1;
TpmTT(I,"pm").. SUM(TT, X(I,"pm",TT)) =L= 1;
DIFFSCH(I,J)..  X(I,"pm",J)-(1- X(I,"am",J)) =L= 0;

MODEL ASSIGN/ALL/;
SOLVE ASSIGN USING LP MAXIMIZING Z;