Algorithm for creating a school timetable

后端 未结 16 1664
暖寄归人
暖寄归人 2020-12-04 04:57

I\'ve been wondering if there are known solutions for algorithm of creating a school timetable. Basically, it\'s about optimizing \"hour-dispersion\" (both in teachers and

16条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-04 05:28

    I don't know any one will agree with this code but i developed this code with the help of my own algorithm and is working for me in ruby.Hope it will help them who are searching for it in the following code the periodflag ,dayflag subjectflag and the teacherflag are the hash with the corresponding id and the flag value which is Boolean. Any issue contact me.......(-_-)

    periodflag.each do |k2,v2|

                if(TimetableDefinition.find(k2).period.to_i != 0)
                    subjectflag.each do |k3,v3|
                        if (v3 == 0)
                            if(getflag_period(periodflag,k2))
                                @teachers=EmployeesSubject.where(subject_name: @subjects.find(k3).name, division_id: division.id).pluck(:employee_id)
                                @teacherlists=Employee.find(@teachers)
                                teacherflag=Hash[teacher_flag(@teacherlists,teacherflag,flag).to_a.shuffle] 
                                teacherflag.each do |k4,v4|
                                    if(v4 == 0)
                                        if(getflag_subject(subjectflag,k3))
                                            subjectperiod=TimetableAssign.where("timetable_definition_id = ? AND subject_id = ?",k2,k3)
                                            if subjectperiod.blank?
                                                issubjectpresent=TimetableAssign.where("section_id = ? AND subject_id = ?",section.id,k3)
                                                if issubjectpresent.blank?
                                                    isteacherpresent=TimetableAssign.where("section_id = ? AND employee_id = ?",section.id,k4)
                                                    if isteacherpresent.blank?
                                                        @finaltt=TimetableAssign.new
                                                        @finaltt.timetable_struct_id=@timetable_struct.id
                                                        @finaltt.employee_id=k4
                                                        @finaltt.section_id=section.id
                                                        @finaltt.standard_id=standard.id
                                                        @finaltt.division_id=division.id
                                                        @finaltt.subject_id=k3
                                                        @finaltt.timetable_definition_id=k2
                                                        @finaltt.timetable_day_id=k1
                                                        set_school_id(@finaltt,current_user)
                                                        if(@finaltt.save)
    
                                                            setflag_sub(subjectflag,k3,1)
                                                            setflag_period(periodflag,k2,1)
                                                            setflag_teacher(teacherflag,k4,1)
                                                        end
                                                    end
                                                else
                                                    @subjectdetail=TimetableAssign.find_by_section_id_and_subject_id(@section.id,k3)
                                                    @finaltt=TimetableAssign.new
                                                    @finaltt.timetable_struct_id=@subjectdetail.timetable_struct_id
                                                    @finaltt.employee_id=@subjectdetail.employee_id
                                                    @finaltt.section_id=section.id
                                                    @finaltt.standard_id=standard.id
                                                    @finaltt.division_id=division.id
                                                    @finaltt.subject_id=@subjectdetail.subject_id
                                                    @finaltt.timetable_definition_id=k2
                                                    @finaltt.timetable_day_id=k1
                                                    set_school_id(@finaltt,current_user)
                                                    if(@finaltt.save)
    
                                                        setflag_sub(subjectflag,k3,1)
                                                        setflag_period(periodflag,k2,1)
                                                        setflag_teacher(teacherflag,k4,1)
                                                    end
                                                end
                                            end
                                        end
                                    end
                                end
                            end
                        end
                    end
                end
            end
    

提交回复
热议问题