-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquestion_1.mos
99 lines (81 loc) · 3.13 KB
/
question_1.mos
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
!@encoding CP1252
model FalconDieCasting
uses "mmxprs"; !gain access to the Xpress-Optimizer solver
declarations
NUMMACHINES = 5
NUMPARTS = 5
NUMWEEKS = 2
MACHINERANGE = 1..NUMMACHINES !j
PARTRANGE = 1..NUMPARTS !i
u: real !maximum regular time per week
v: real !maximum overtime per week
b: array(PARTRANGE) of real !demand for each part
s: array(PARTRANGE, MACHINERANGE) of real !setup time for producing each part on each machine
y: array(PARTRANGE) of real !percentage yield of useable parts for each part
r: array(PARTRANGE, MACHINERANGE) of real !production rate of each part on each machine, needs to be initialised and then * by yield
M: array(PARTRANGE, MACHINERANGE) of real !big M, max amount P could be
!DECISION VARIABLES
P: array(PARTRANGE,MACHINERANGE) of mpvar !amount produced of each part on each machine
X: array(PARTRANGE, MACHINERANGE) of mpvar !binary, machine used to make part
O: array(MACHINERANGE) of mpvar !Overtime for each machine
!OBJECTIVE FUNCTION
OvertimeSumOF: linctr !Question 1: Sum of all overtime hours
!CONSTRAINTS
TimeCS: array(MACHINERANGE) of linctr
DemandCS: array(PARTRANGE) of linctr
MCS: array(PARTRANGE, MACHINERANGE) of linctr
OCS: array(MACHINERANGE) of linctr
end-declarations
!initialise all constants/variables
u := 120.0 !maximum regular time per week
v := 48.0 !maximum overtime per week
b :: [ 3500, 3000, 4000, 4000, 2800] !demand for each part
s :: [ 8, 10, 999, 999, 999,!setup time for producing each part on each machine
999, 8, 10, 8, 999,
999, 999, 999, 12, 999,
8, 999, 999, 999, 8,
999, 999, 24, 999, 20]
r :: [ 40.0, 35.0, 0.0, 0.0, 0.0, !production rate initial values
0.0, 25.0, 30.0, 35.0, 0.0,
0.0, 0.0, 0.0, 50.0, 0.0,
60.0, 0.0, 0.0, 0.0, 60.0,
0.0, 0.0, 45.0, 0.0, 50.0]
y :: [0.6, 0.55, 0.75, 0.65, 0.6]
!initial calculations, set to binary or integer
forall(j1 in 1..NUMMACHINES) do
forall(i1 in 1..NUMPARTS) do
P(i1,j1) is_integer !make P, amount produced an integer vlaue
X(i1,j1) is_binary !make X, whether or not started
r(i1,j1) := r(i1,j1)*y(i1) !calculate r, taking into account yield of each machines
M(i1,j1) := r(i1,j1)*(u + v - s(i1,j1))
end-do
end-do
!OBJECTIVE FUNCTION QUESTION 1
OvertimeSumOF := sum(j2 in 1..NUMMACHINES) O(j2)
!TIME CONSTRAINTS
forall(j3 in 1..NUMMACHINES) do
!timetaken(j3) := sum(i3 in 1..NUMPARTS) (P(i3,j3)/r(i3,j3) + X(i3,j3)*s(i3,j3))
TimeCS(j3) := sum(i3 in PARTRANGE | r(i3,j3)>0) (P(i3,j3)/r(i3,j3) + X(i3,j3)*s(i3,j3)) <= u + O(j3)
end-do
!DEMAND CONSTRAINTS
forall(i4 in 1..NUMPARTS) do
DemandCS(i4) := (sum(j4 in 1..NUMMACHINES) P(i4,j4)) >= b(i4) !demand CS for 2nd week
end-do
!BIG M CONSTRAINTS
forall(i5 in PARTRANGE) do
forall(j5 in MACHINERANGE) do
MCS(i5,j5) := P(i5,j5) <= M(i5,j5)*X(i5,j5)
end-do
end-do
!MAX OVERTIME CONSTRAINT
forall(j6 in MACHINERANGE) do
OCS(j6) := O(j6) <= v
end-do
minimise(OvertimeSumOF) !Question1
writeln("Question 1 Objective is Overtime Sum =", getact(OvertimeSumOF))
write("Overtime hours: ")
forall (i in 1..NUMMACHINES) do
write(getsol(O(i)))
write(", ")
end-do
end-model