Example #1
0
        public static void Main(string[] args)
        {
            var dfs = new DFS();

            dfs.TestDFS();
            // var bfs = new BFS();
            // bfs.TestBFS();

            // var fibo = new Fibonacci();
            // fibo.TestFibonacci();

            // var floodFill = new FloodFill();
            // floodFill.TestFloodFillDFS();
            // floodFill.TestGraphTraversalBlockedSpacesAnd4MovesDFS();
            // floodFill.TestShortestPathTraversal();

            var greedy = new GreedyAlgo();

            // greedy.ComputeMaxTasksCompleted();
            greedy.ComputeMaxPrioritizedTasksCompleted();

            // DicesSumModel diceSumModel = new DicesSumModel();
            // diceSumModel.TestProbabilityDiceSum();

            // DateTimeModel dateTimeModel = new DateTimeModel();
            // dateTimeModel.TestMultipleDateTimeDiff();

            // Build webhost
            // BuildWebHost(args).Run();
        }
Example #2
0
        public void basic_greedy_algorithm()
        {
            GreedyAlgo algo    = new GreedyAlgo();
            var        results = algo.Start("ABCABBA", "CBABAC");

            Vertex[] expected = new Vertex[] {
                new Vertex(2, 'A', 0, 2),
                new Vertex(2, 'B', 1, 3),
                new Vertex(2, 'B', 1, 1),
                new Vertex(2, 'C', 2, 0),
                new Vertex(3, 'C', 2, 5),
                new Vertex(3, 'A', 3, 4),
                new Vertex(3, 'A', 3, 2),
                new Vertex(3, 'B', 4, 3),
                new Vertex(3, 'B', 4, 1),
                new Vertex(4, 'A', 6, 4),
                new Vertex(4, 'A', 6, 2)
            };

            for (int x = 0; x < 11; x++)
            {
                Assert.AreEqual(expected[x].D, results[x].D, $"D failed at x={x}");
                Assert.AreEqual(expected[x].C, results[x].C, $"C failed at x={x}");
                Assert.AreEqual(expected[x].X, results[x].X, $"X failed at x={x}");
                Assert.AreEqual(expected[x].Y, results[x].Y, $"Y failed at x={x}");
            }
        }
        public ActionResult Create([Bind(Include = "id,version_number,program_code,program_title,course_code,course_title,course_hours,section_number,have_final_exam,final_exam_note,room_request,exam_length,weekday,time,room,teacher_name,proctor,is_deleted,created_by,created_on,modified_by,modified_on")] exam_timetable exam_timetable)
        {
            if (ModelState.IsValid)
            {
                GreedyAlgo algo  = new GreedyAlgo();
                ExamTables table = algo.arrangeExam();
                int?       versionNo;
                if (!(db.exam_timetable.Count() > 0))
                {
                    versionNo = 0;
                }
                else
                {
                    versionNo = db.exam_timetable.OrderByDescending(e => e.id).First().version_number;
                    versionNo++;
                }

                foreach (var item in table.solution)
                {
                    foreach (var singleSession in item.sessionIds)
                    {
                        var section = singleSession.sessionId;
                        exam_timetable.version_number  = versionNo;
                        exam_timetable.program_code    = db.programs.Find(db.sections.Find(section).program_id).program_code;
                        exam_timetable.program_title   = db.programs.Find(db.sections.Find(section).program_id).title;
                        exam_timetable.course_code     = db.courses.Find(item.courseId).code;
                        exam_timetable.course_title    = db.courses.Find(item.courseId).title;
                        exam_timetable.course_hours    = db.courses.Find(item.courseId).hours;
                        exam_timetable.section_number  = db.sections.Find(section).section_number;
                        exam_timetable.have_final_exam = db.course_exam.Where(ce => ce.course_id == item.courseId).First().have_final_exam;
                        exam_timetable.final_exam_note = db.course_exam.Where(ce => ce.course_id == item.courseId).First().final_exam_note;
                        exam_timetable.room_request    = db.room_type.Find(item.roomType).type;
                        var sectionEntity = db.sections.Find(section);
                        if (sectionEntity != null && db.faculties.Find(sectionEntity.faculty_id) != null) // the function to get teacher name is not right here
                        {
                            exam_timetable.teacher_name = db.faculties.Find(sectionEntity.faculty_id).first_name + " " +
                                                          db.faculties.Find(sectionEntity.faculty_id).last_name;
                        }
                        else
                        {
                            exam_timetable.teacher_name = "";
                        }

                        if (item.protorId > 0)
                        {
                            exam_timetable.exam_length = db.course_exam.Where(ce => ce.course_id == item.courseId).First().exam_length.ToString();
                            exam_timetable.weekday     = getWeekday(item.weekDay);
                            exam_timetable.time        = getTime(item.startHour, item.endHour, Convert.ToDouble(exam_timetable.exam_length));
                            exam_timetable.room        = db.rooms.Find(item.roomId).name;
                            exam_timetable.proctor     = db.faculties.Find(item.protorId).first_name + " " +
                                                         db.faculties.Find(item.protorId).last_name;
                        }
                        else
                        {
                            exam_timetable.exam_length = "0";
                            exam_timetable.weekday     = "N/A";
                            exam_timetable.time        = "";
                            exam_timetable.room        = "";
                            exam_timetable.proctor     = "";
                        }

                        exam_timetable.is_deleted = false;
                        exam_timetable.created_on = DateTime.Now;
                        db.exam_timetable.Add(exam_timetable);
                        db.SaveChanges();
                    }
                }

                return(RedirectToAction("Index"));
            }

            return(View(exam_timetable));
        }