-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
431 lines (409 loc) · 18.1 KB
/
Copy pathProgram.cs
File metadata and controls
431 lines (409 loc) · 18.1 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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
using System;
using System.Collections.Generic;
using System.Collections;
namespace ProjektstudiumZuordnung
{
class Program
{
public static List<Initiator> initiatorList = new List<Initiator>();
public static List<Project> projectList = new List<Project>();
public static List<Student> studentList = new List<Student>();
public static List<Student> leftStudentList = new List<Student>();
private static int unAssignetStudents { get; set; }
static void Main(string[] args)
{
Console.WriteLine("Begin Initiation");
GetData();
Console.WriteLine("Loaded Data");
AddingInitiatorsToProjects();
Console.WriteLine("Added Initiaros");
Console.WriteLine("Start Adding Student to Projects");
AddingStudentsToProjects();
Console.WriteLine("Added Students to Projects");
Console.WriteLine("Allocate remaining Students");
RemainingAllocation();
Console.WriteLine("Allocated remaining Students");
Console.WriteLine("Output groups");
ResultOfAlgorithm();
}
static void GetData()
{
InitStudents();
InitInitiators();
InitProjects();
foreach (Student s in studentList)
{
s.SetOriginalFavourites();
}
}
static void InitStudents()
{
// studentList.Add(new Student(new List<Favourite>() { new Favourite(1, Job.KONZEPTION), new Favourite(0, Job.PROJEKTMANAGEMENT), new Favourite(2, Job.KONZEPTION) }, DegreeCourse.OMB, 9, false, -1));
// studentList.Add(new Student(new List<Favourite>() { new Favourite(2, Job.KONZEPTION), new Favourite(2, Job.ORGANISATION), new Favourite(0, Job.KONZEPTION) }, DegreeCourse.MKB, 7, false, -1));
// studentList.Add(new Student(new List<Favourite>() { new Favourite(1, Job.ORGANISATION), new Favourite(1, Job.KONZEPTION), new Favourite(1, Job.PROJEKTMANAGEMENT) }, DegreeCourse.MIB, 10, false, -1));
// studentList.Add(new Student(new List<Favourite>() { new Favourite(2, Job.KONZEPTION), new Favourite(0, Job.ORGANISATION), new Favourite(0, Job.PROJEKTMANAGEMENT) }, DegreeCourse.MKB, 11, false, -1));
// studentList.Add(new Student(new List<Favourite>() { new Favourite(2, Job.PROJEKTMANAGEMENT), new Favourite(1, Job.PROJEKTMANAGEMENT), new Favourite(0, Job.KONZEPTION) }, DegreeCourse.MIB, 6, false, -1));
// studentList.Add(new Student(new List<Favourite>() { new Favourite(0, Job.PROJEKTMANAGEMENT), new Favourite(0, Job.ORGANISATION), new Favourite(1, Job.ORGANISATION) }, DegreeCourse.OMB, 3, false, -1));
// studentList.Add(new Student(new List<Favourite>() { new Favourite(2, Job.KONZEPTION), new Favourite(0, Job.KONZEPTION), new Favourite(1, Job.PROJEKTMANAGEMENT) }, DegreeCourse.MIB, 2, false, -1));
// studentList.Add(new Student(new List<Favourite>() { new Favourite(0, Job.ORGANISATION), new Favourite(0, Job.PRODUKTION), new Favourite(2, Job.PROJEKTMANAGEMENT) }, DegreeCourse.OMB, 5, false, -1));
// studentList.Add(new Student(new List<Favourite>() { new Favourite(0, Job.KONZEPTION), new Favourite(1, Job.ORGANISATION), new Favourite(0, Job.PRODUKTION) }, DegreeCourse.MKB, 8, false, -1));
// studentList.Add(new Student(new List<Favourite>() { new Favourite(0, Job.ORGANISATION), new Favourite(1, Job.ORGANISATION), new Favourite(2, Job.PRODUKTION) }, DegreeCourse.OMB, 0, false, -1));
// studentList.Add(new Student(new List<Favourite>() { new Favourite(1, Job.PROJEKTMANAGEMENT), new Favourite(2, Job.KONZEPTION), new Favourite(0, Job.PRODUKTION) }, DegreeCourse.MKB, 4, false, -1));
}
static void InitInitiators()
{
// initiatorList.Add(new Initiator(DegreeCourse.MIB, 1, 1));
}
static void InitProjects()
{
// projectList.Add(new Project(4, new List<Job>() { Job.PROJEKTMANAGEMENT, Job.ORGANISATION, Job.PRODUKTION, Job.KONZEPTION }, new List<Student>(), 0, new Distribute[3] { new Distribute(DegreeCourse.MIB, 1), new Distribute(DegreeCourse.OMB, 1), new Distribute(DegreeCourse.MKB, 1) }, new List<Initiator>()));
// projectList.Add(new Project(3, new List<Job>() { Job.PROJEKTMANAGEMENT, Job.ORGANISATION, Job.KONZEPTION }, new List<Student>(), 1, new Distribute[3] { new Distribute(DegreeCourse.MIB, 1), new Distribute(DegreeCourse.OMB, 1), new Distribute(DegreeCourse.MKB, 1) }, new List<Initiator>()));
// projectList.Add(new Project(4, new List<Job>() { Job.PROJEKTMANAGEMENT, Job.ORGANISATION, Job.PRODUKTION, Job.KONZEPTION }, new List<Student>(), 2, new Distribute[3] { new Distribute(DegreeCourse.MIB, 1), new Distribute(DegreeCourse.OMB, 1), new Distribute(DegreeCourse.MKB, 1) }, new List<Initiator>()));
}
static void AddingInitiatorsToProjects()
{
foreach (Initiator init in initiatorList)
{
int groupeID = init.groupeID;
Project project = projectList[groupeID];
project.SetInitatorToStudentList(init);
}
foreach (Project project in projectList)
{
int length = project.students.Count;
if (length > 2)
{
Console.WriteLine("ERROR!!! to(o) many Initiators!");
}
else
{
Console.WriteLine("Assignment was successfull");
}
}
}
static void AddingStudentsToProjects()
{
unAssignetStudents = studentList.Count;
while (unAssignetStudents > 0)
{
int _student;
for (_student = 0; _student < studentList.Count; _student++)
{
int activeFavourite = 0;
Student student = studentList[_student];
if (student.matched == false)
{
Console.WriteLine("Student: " + studentList[_student].iD + " " + "is on turn");
Favourite favourite;
if (student.favouriteList.Count > 0)
{
favourite = student.favouriteList[activeFavourite];
Project project = GetProject(favourite.projectID);
if (project.IsSpaceLeftInProject() == true)
{
if (project.IsJobFree(favourite.job))
{
if (project.DegreeCourseDistributeCheck(student))
{
project.SetStudentToStudentList(student);
unAssignetStudents--;
}
else
{
student.RemoveFavourite(activeFavourite);
}
}
else
{
StudentVsStudent(favourite, project, student);
}
}
else
{
StudentVsStudent(favourite, project, student);
}
}
else
{
SwitchStudentInUnAssigntList(student);
unAssignetStudents--;
Console.WriteLine("switch");
}
}
Console.WriteLine("### Zyklus durch ###");
}
}
}
static void SwitchStudentInUnAssigntList(Student student)
{
bool b = false;
foreach (Student added in leftStudentList)
{
if (added.iD == student.iD)
{
b = true;
}
}
if (b == false)
{
leftStudentList.Add(student);
}
}
static Project GetProject(int id)
{
foreach (Project p in projectList)
{
if (p.projectID == id)
{
return p;
}
}
return null;
}
static void StudentVsStudent(Favourite currentStudentFavourite, Project relatedProject, Student student)
{
Student oldStudent = relatedProject.GetOldStudent(currentStudentFavourite);
switch (StudentVsStudentCaseFinder(currentStudentFavourite, relatedProject, student, oldStudent))
{
case 1:
Console.WriteLine("Identisch");
if (relatedProject.GetOldStudentStuGa(oldStudent).degreeCourse == student.degreeCourse)
{
Console.WriteLine("zahl " + CoinFlip());
if (CoinFlip() > 50)
{
Project _project = null;
foreach (Project p in projectList)
{
if (p.projectID == oldStudent.projectID)
{
_project = p;
}
}
_project.SetStudentToStudentList(student);
_project.Unmatch(oldStudent);
}
else
{
student.RemoveFavourite(0);
}
}
else
{
student.RemoveFavourite(0);
}
break;
case 2:
Console.WriteLine("Alt gewinnt ");
student.RemoveFavourite(0);
break;
case 3:
Console.WriteLine("neu gewinnt ");
if (relatedProject.DegreeCourseDistributeCheck(student))
{
relatedProject.SetStudentToStudentList(student);
unAssignetStudents--;
}
else
{
student.RemoveFavourite(0);
}
break;
default:
Console.WriteLine("----Null----");
break;
}
}
static int StudentVsStudentCaseFinder(Favourite currentStudentFavourite, Project relatedProject, Student student, Student oldStudent)
{
List<Favourite> oldStudentFavourites = oldStudent.originaleFavouriteList;
List<Favourite> currentStudentFavourites = student.originaleFavouriteList;
int i = 0;
foreach (Favourite favourite in oldStudentFavourites)
{
if (oldStudentFavourites[i].projectID == relatedProject.projectID && currentStudentFavourites[i].projectID == relatedProject.projectID)
{
Console.WriteLine("Identisch");
return 1;
}
if (oldStudentFavourites[i].projectID == relatedProject.projectID)
{
Console.WriteLine("Student OLD gewinnt! Kein switch!");
return 2;
}
if (currentStudentFavourites[i].projectID == relatedProject.projectID)
{
Console.WriteLine("Student NEW gewinnt! Switch!");
return 3;
}
i++;
}
return 4;
}
static int CoinFlip()
{
return new Random().Next(101);
}
static void RemainingAllocation()
{
if (leftStudentList.Count > 0)
{
ShuffleList();
int lS = leftStudentList.Count;
while (lS > 0)
{
for (int _leftStudent = 0; _leftStudent < leftStudentList.Count; _leftStudent++)
{
Student leftStudent = leftStudentList[_leftStudent];
if (leftStudent.matched == false)
{
foreach (Project project in projectList)
{
if (project.IsSpaceLeftInProject() == true)
{
Console.WriteLine(_leftStudent);
if (project.GetFreeJob(leftStudent))
{
project.SetStudentToStudentList(leftStudent);
lS--;
break;
}
else
{
project.SetStudentToStudentList(leftStudent);
lS--;
break;
}
}
}
}
}
}
}
}
static void ResultOfAlgorithm()
{
foreach (Project project in projectList)
{
Console.Write("Projekt " + project.projectID + ": (needs: " + project.capacity + " | has: " + project.students.Count + ") ");
if (project.capacity == project.students.Count)
{
Console.WriteLine("*** CHECK *** ");
}
else
{
Console.WriteLine("*** FAIL ***");
}
Console.Write("---- Needs Jobs: ");
foreach (Job job in project.jobs)
{
Console.Write(job + " ");
}
Console.WriteLine("");
Console.Write("---- Needs DegreeCourse: ");
foreach (Distribute degree in project.distribution)
{
Console.Write(degree.degreeCourse + "(" + degree.count + ") ");
}
Console.WriteLine("");
Console.Write("-- Initiatiors: ");
if (project.initiators.Count > 0)
{
foreach (Initiator initiator in project.initiators)
{
Console.Write(initiator.iD + " (" + initiator.degreeCourse + ")");
}
Console.WriteLine("");
}
else
{
Console.WriteLine("n/A ");
}
Console.Write("-- Students: ");
if (project.students.Count > 0)
{
foreach (Student student in project.students)
{
string job = "n/A";
if (student.GetFavouriteOfCurrentProject() != null)
{
job = student.GetFavouriteOfCurrentProject().job.ToString();
}
Console.Write(student.iD + " (" + student.degreeCourse + " " + job + ") ");
}
Console.WriteLine("");
}
else
{
Console.WriteLine("n/A ");
}
}
Console.Write("LeftStudents: ");
if (leftStudentList.Count > 0)
{
foreach (Student leftStudent in leftStudentList)
{
Console.Write(leftStudent.iD + " ");
}
Console.WriteLine("");
}
else
{
Console.WriteLine("n/A ");
}
HappioMeter();
}
static void ShuffleList()
{
for (int i = projectList.Count - 1; i > 0; i--)
{
Random random = new Random();
int j = random.Next(i + 1);
Project temp = projectList[i];
projectList[i] = projectList[j];
projectList[j] = temp;
}
}
static void HappioMeter()
{
List<double> Grade = new List<double>();
List<double> GradeProj = new List<double>();
double avg = 0;
double sum = 0;
double avgProj = 0;
double sumProj = 0;
Console.WriteLine("Durchschnittliche Zufriedenheit:");
foreach (Project project in projectList)
{
List<double> Grade1 = new List<double>();
double sum1 = 0;
double avg1 = 0;
foreach (Student student in project.students)
{
double marc = student.GetHappiness();
Grade.Add(marc);
Grade1.Add(marc);
}
foreach (double d in Grade1)
{
sum1 += d;
}
avg1 = sum1 / Grade1.Count;
GradeProj.Add(avg1);
Console.WriteLine("-- Prj. " + project.projectID + ": " + avg1);
}
foreach (double d in Grade)
{
sum += d;
}
avg = sum / Grade.Count;
foreach (double d in GradeProj)
{
sumProj += d;
}
avgProj = sumProj / GradeProj.Count;
Console.WriteLine("---- INSG Studenten.: " + avg);
Console.WriteLine("---- INSG Projekte.: " + avgProj);
}
}
}