static int[,] GenerateAdjMatrix(StudentsByLecture studentsByLecture) { int n = studentsByLecture.Keys.Count; int[,] matrix = new int[n, n]; var lectures = studentsByLecture.Keys.ToList(); for (int i = 0; i < lectures.Count - 1; i++) { var lectureAName = lectures[i]; var lectureAStudents = studentsByLecture[lectureAName]; for (int j = i + 1; j < lectures.Count; j++) { var lectureBName = lectures[j]; var lectureBStudents = studentsByLecture[lectureBName]; if (Program.HasCommonMember(lectureAStudents, lectureBStudents)) { matrix[i, j] = 1; matrix[j, i] = 1; } } } return(matrix); }
public void Calculate(string dataPath, string indexFile) { DATA_PATH = dataPath; INDEX_FILE = indexFile; studentsByLecture = GetStudents(); adjMatrix = GenerateAdjMatrix(studentsByLecture); (var colorCount, var lectureColors) = ColorGraph(adjMatrix); calculatedColorCount = colorCount; calculatedLectureColors = lectureColors; }
static StudentsByLecture GetStudents() { var lectures = Program.ReadFile("Lectures"); var studentsByLecture = new StudentsByLecture(); foreach (var lecture in lectures) { studentsByLecture[lecture] = Program.ReadFile(lecture); } return(studentsByLecture); }
StudentsByLecture GetStudents() { lectures = ReadFile(INDEX_FILE).ToArray(); var studentsByLecture = new StudentsByLecture(); foreach (var lecture in lectures) { studentsByLecture[lecture] = ReadFile(lecture); } return(studentsByLecture); }