forked from zachtaylor1/SWProj
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudentAssignment.cs
More file actions
286 lines (257 loc) · 13 KB
/
StudentAssignment.cs
File metadata and controls
286 lines (257 loc) · 13 KB
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SWProjv1
{
class StudentAssignment
{
public static String dunnName { get; set; } = "DUNN";
public static String mackayName { get; set; } = "Mackay";
public static int numOfDoubles { get; set; } = 120;//MacKay rooms
private static int numUsedDoubles = 0;
public static int numOfSingles { get; set; } = 60;//Dunn rooms
private static int numUsedSingles = 0;
public static double reqCoefficient { get; set; } //how easy it is to qualify as a potential roommate, 0 is super easy, -1 will be always
public void dunnRoomEmptied()
{
numUsedSingles--;
}
public void mackayRoomEptied()
{
numUsedDoubles--;
}
private static bool macKayFull()
{
if (numUsedDoubles < numOfDoubles)
return false;
else
return true;
}
private static bool dunnFull()
{
if (numUsedSingles < numOfSingles)
return false;
else
return true;
}
private static bool roommateRequestMatch(ResApplicationForm a0, ResApplicationForm a1)
{
if (a0.studentID.Equals(a1.roommateID) && a0.roommateID.Equals(a1.studentID) &&
a0.gender.Equals(a1.gender) && a0.preferBuilding.Equals(a1.preferBuilding) &&
!a0.roommateID.Equals("") & !a1.roommateID.Equals(""))
return true;
else
return false;
}
private static bool substanceRequire(ResApplicationForm a0, ResApplicationForm a1)
{
if ((!a0.smokes || a1.liveWithSmoke) && (!a0.drinks || a1.liveWithDrink) && (!a0.marijuana || a1.liveWithMarijuana))
return true;
else
return false;
}
private static double areCompatible(ResApplicationForm a0, ResApplicationForm a1)
{
double howGood = 0;
if (a0.schoolYear.Equals(a1.schoolYear))
howGood += 2;
if (a0.country.Equals(a1.country))
howGood += 2;
if (a0.socialLevel.Equals(a1.socialLevel))
howGood += 2;
if (a0.volumeLevel.Equals(a1.volumeLevel))
howGood += 2;
if (a0.bedtime.Equals(a1.bedtime))
howGood += 1;
if (a0.wakeUp.Equals(a1.wakeUp))
howGood += 1;
if (a0.overnightVisitors.Equals(a1.overnightVisitors))
howGood += 1;
if (a0.cleanliness.Equals(a1.cleanliness))
howGood += 1;
if (a0.studiesInRoom.Equals(a1.studiesInRoom))
howGood += 1;
foreach (String h0 in a0.hobbies)
foreach (String h1 in a1.hobbies)
if (h0.Equals(h1))
howGood += 0.25;
foreach (String s0 in a0.sports)
foreach (String s1 in a1.sports)
if (s0.Equals(s1))
howGood += 0.25;
foreach (String m0 in a0.music)
foreach (String m1 in a1.music)
if (m0.Equals(m1))
howGood += 0.25;
return howGood;
}
private static List<ResApplicationForm> createAndAssignPools(List<ResApplicationForm> pool, int year) //returns a list of applications that have been accepted, and need to be removed
{
List<ResApplicationForm> accepted = new List<ResApplicationForm>();
foreach (ResApplicationForm a0 in pool) //create pools of potentials
{
if (!a0.confirmed && !macKayFull())
{
List<ResApplicationForm> potentials = new List<ResApplicationForm>();
List<Double> potentialCoefficients = new List<Double>();
double coefficient;
foreach (ResApplicationForm a1 in pool)
if (!a1.confirmed && !a0.applicationID.Equals(a1.applicationID) && !macKayFull())
if (substanceRequire(a0, a1) && substanceRequire(a1, a0)) //the two fulfill substance boolean
if ((coefficient = areCompatible(a0, a1)) > reqCoefficient) //the two fulfill coefficent requirement
{
potentials.Add(a1);
potentialCoefficients.Add(coefficient);
}
if (potentials.Count() == 0) //has no potential roommates, may be reconsidered after adding Dunn overflow
{
}
else
{
int highestIndex = 0;
for (int i = 1; i < potentials.Count; i++)
{
if (potentialCoefficients[i] > potentialCoefficients[highestIndex])
highestIndex = i;
}
a0.confirmed = true;
ResApplicationForm a1 = potentials[highestIndex];
a1.confirmed = true;
accepted.Add(a0);
accepted.Add(a1);
numUsedDoubles++;
//pair the two, assign to MacKay
String roomID0 = Server.getEmptyRoomID(mackayName, year.ToString());
String roomNum0 = Server.getRoomNum(roomID0, year.ToString());
String roomID1 = Server.getAdjoiningID(roomID0, roomNum0);
Server.assignRoom(a0.studentID, roomID0);
Server.assignRoom(a1.studentID, roomID1);
}
}
}
foreach (ResApplicationForm a0 in accepted) //cleaning the pool
pool.Remove(a0);
return accepted;
}
public static String assign(List<ResApplicationForm> applications, int year)
{
foreach (ResApplicationForm a0 in applications) //matches roommate requests, assigns and removes
if (!a0.confirmed && !macKayFull())
foreach (ResApplicationForm a1 in applications)
if (!a1.confirmed && !a0.confirmed && !a0.applicationID.Equals(a1.applicationID))
if (a0.roommateRequest && a1.roommateRequest)
if (roommateRequestMatch(a0, a1))
{
a0.confirmed = true;
a1.confirmed = true;
numUsedDoubles++;
//pair the two, assign to MacKay
String roomID0 = Server.getEmptyRoomID(mackayName, year.ToString());
String roomNum0 = Server.getRoomNum(roomID0, year.ToString());
String roomID1 = Server.getAdjoiningID(roomID0, roomNum0);
Server.assignRoom(a0.studentID, roomID0);
Server.assignRoom(a1.studentID, roomID1);
}
List<ResApplicationForm> malePool = new List<ResApplicationForm>(); //gender divided pools
List<ResApplicationForm> femalePool = new List<ResApplicationForm>();
List<ResApplicationForm> otherPool = new List<ResApplicationForm>();
foreach (ResApplicationForm a0 in applications)
if (a0.preferBuilding.Equals(mackayName) && !a0.confirmed)
{
if (a0.gender.Equals("male"))
malePool.Add(a0);
else if (a0.gender.Equals("female"))
femalePool.Add(a0);
else
otherPool.Add(a0);
}
List<ResApplicationForm> fulfilled = new List<ResApplicationForm>();
fulfilled.AddRange(createAndAssignPools(malePool, year)); //matching MacKay roommates
fulfilled.AddRange(createAndAssignPools(femalePool, year));
fulfilled.AddRange(createAndAssignPools(otherPool, year));
foreach (ResApplicationForm a0 in fulfilled)
applications.Remove(a0); //remove fulfilled MacKay applications from List
List<ResApplicationForm> dunnPool = new List<ResApplicationForm>();
List<ResApplicationForm> dunnFulfilled = new List<ResApplicationForm>();
foreach (ResApplicationForm a0 in applications)
if (!a0.confirmed && a0.preferBuilding.Equals(dunnName))
dunnPool.Add(a0);
foreach (ResApplicationForm a0 in dunnPool) //assigning Dunn applicants
if (!dunnFull())
{
a0.confirmed = true;
dunnFulfilled.Add(a0);
numUsedSingles++;
//assign to Dunn
String roomID0 = Server.getEmptyRoomID(dunnName, year.ToString());
String roomNum0 = Server.getRoomNum(roomID0, year.ToString());
Server.assignRoom(a0.studentID, roomID0);
}
foreach (ResApplicationForm a0 in dunnFulfilled) //remove fulfilled Dunn applications from List
{
dunnPool.Remove(a0);
applications.Remove(a0);
}
if (dunnFull() && !macKayFull()) //move Dunn overflow and rerun gendered pools for roommates
{
foreach (ResApplicationForm a0 in dunnPool)
if (!a0.confirmed)
{
if (a0.gender.Equals("male"))
malePool.Add(a0);
else if (a0.gender.Equals("female"))
femalePool.Add(a0);
else
otherPool.Add(a0);
}
List<ResApplicationForm> newFulfilled = new List<ResApplicationForm>();
newFulfilled.AddRange(createAndAssignPools(malePool, year)); //matching MacKay roommates
newFulfilled.AddRange(createAndAssignPools(femalePool, year));
newFulfilled.AddRange(createAndAssignPools(otherPool, year));
foreach (ResApplicationForm a0 in newFulfilled)
applications.Remove(a0); //remove newFulfilled MacKay applications from List
//Console.WriteLine("The Dunn has been filled, and the MacKay might also have been filled.");
}
else if (!dunnFull() && macKayFull()) //move MacKay unmatchables and overflow to Dunn, as many as there is room
{
foreach (ResApplicationForm a0 in applications)
if (!dunnFull())
{
a0.confirmed = true;
numUsedSingles++;
//assign to Dunn
String roomID0 = Server.getEmptyRoomID(dunnName, year.ToString());
String roomNum0 = Server.getRoomNum(roomID0, year.ToString());
Server.assignRoom(a0.studentID, roomID0);
}
applications.Clear();
//Console.WriteLine("The MacKay has been filled, and the Dunn might also have been filled.");
}
else if (dunnFull() && macKayFull()) //do nothing
{
applications.Clear();
//Console.WriteLine("Both the Dunn and the MacKay have been filled. There may be some students who were not accepted.");
}
else //move MacKay unmatchables to Dunn, as many as there is room
{
foreach (ResApplicationForm a0 in applications)
if (!dunnFull())
{
a0.confirmed = true;
numUsedSingles++;
//assign to Dunn
String roomID0 = Server.getEmptyRoomID(dunnName, year.ToString());
String roomNum0 = Server.getRoomNum(roomID0, year.ToString());
Server.assignRoom(a0.studentID, roomID0);
//Console.WriteLine("Cleanup to Dunn: " + a0.studentID);
}
applications.Clear();
//Console.WriteLine("All or most applicants have been placed in their desired residences.");
}
//Console.Read();
return "Successful.";
}
}
}