Introduction of several algorithms of class scheduling at present

Source: Internet
Author: User
Tags bitwise

Research on the algorithm of general university scheduling----2. Introduction of several algorithms for scheduling classes at present

2 The introduction of several algorithms for class scheduling at present

2. 1. Automatic Course scheduling algorithm

1. Description of the problem

The simplified description of the automatic scheduling problem we are discussing is as follows:

The courses to be arranged are {C1, C2,., Cn}, the total number of courses is N, and the weekly schedule of each course (2 consecutive hours per session) is {N1, N2,., Nn}, 5 days a week for each teaching day, Monday ~ Friday, and a maximum of 4 teaching sessions per teaching day, 1 ~ 2, 3 ~ 4, 5 ~ 6 and 7 ~ 8 (hereinafter referred to as 1th, 2, 3, 4 time periods). In this hypothesis, it is apparent that the total number of teaching periods per week is 5x4 = 20, and the following constraints exist:

N≤20, (1)

N = 6n, I =1, ni≤20. (2)

The problem of automatic scheduling is to design appropriate data structures and algorithms to determine the time period in which each course should be held in {C1, C2,. Cn}, and to ensure that any time period is occupied by only one course.

2. Main data structure

For each course, assign a 2-byte "time period assignment word" (unsigned integer): {T1, T2,., Tn}. Any of these time-period assigned words (assuming TI) have the following format:

Ti's data Type C language format is defined as: unsigned int.  The highest level of Ti is whether the course is currently a valid sign, 0 is valid, 1 means invalid (such as class suspension, etc.); others are called course allocation bits, each of which occupies 3 consecutive digits (bit), indicating a teaching day (Monday ~ Friday) The value of the time period for which the course is scheduled, 0 for the day, 1 to 4 Represents the corresponding time period that is scheduled (an invalid value of more than 4).

In this design, the valid time period allocation words should be less than 32 768 (hex 8000), and the time period allocation words greater than or equal to 32 768 correspond to courses that are currently invalid (even if the course assignment is set up), so it is easy to suspend/start classes.

3. Algorithm for scheduling classes

Under the above hypothesis, the goal of the automatic scheduling algorithm is to determine {C1, C2,., Cn} corresponding to {T1, T2,., Tn}.

In terms of the possibility of arrangement, there is a total of!/(20-N)! The Seed row method (the meaning of N is shown in (2)). If there are 4 courses, 2 times a week for each course, then n = 8, the 8 lessons may be arranged in 20!/(20-8)! = 5 079 110 400, or more than 5 billion species. If you choose a scheme without principle, it will take a huge amount of time. Therefore, the premise of the course is that there must be a definite principle of course scheduling. We use the rotation allocation method as a scheduling principle: starting from the 1th period of Monday, after each course is arranged in the order listed in {C1, C2,., Cn} (1 times per course), and then continue to the subsequent time period in that order until all courses are run in accordance with {N1, N2,., N The value given in n}. In the algorithm description will be used {c[1], c[2],., c[n]} = {C1, C2,., Cn}, to {N1, N2,., Nn}

and {T1, T2,., Tn} also use the same notation.

Algorithm 1 Course algorithm

Enter {C1, C2,., Cn}, {N1, N2,., Nn}.

Output {T1, T2,., Tn}.

① initialization:

Weekday Value week = 1

Time period Value segment = 1

{T [1], T [2],., t [n]} each time period is assigned word zeroing

② a new round of scanning courses:

Flag = 0 To continue processing flags

For the course index value C-index = 1, 2,., n do the following:

If N[c-index] > 0, do the following:

Write the value of segment to T[c-index] (week-1) 3 3~week 3 3-1 bit N[c-index] value minus 1

If N[c-index] > 0, place flag = 1

If week = 5 and segment = 4

Then: Place flag = 1 and turn ③

Otherwise: if segment = 4

Then: Place segment = 1 and week increase by 1

Otherwise: segment increased by 1

The detection has been fully scheduled:

If flag = 1

Then: Turn ②

Otherwise: Turn ③

③ Detection is successful:

If flag = 1

Then: too many classes

Otherwise: successful course scheduling

④ algorithm End

Obviously, the time complexity of this algorithm is O (n) (n is the total number of classes per week, see (2)), while the storage time period allocation word used space of 2 n bytes (n is the number of courses).

4. Conflict Detection Algorithms

Sometimes after the automatic course completion, it is necessary to manually adjust the schedule of certain courses, such as the first course in the human intervention to change the number of weeks to week, the time period of segment position, according to the above data structure to do the following operations:

t [i] = t [i] & (~ (7 << (week-1) * 3)) + (segment << (week-1)),

where &, ~, and n are bitwise-AND, bitwise-Reversed, and bitwise-Left-shift operators (hereinafter).

The question is how to determine if other courses have been scheduled for the same period of time. Set up a manually adjusted time period assignment

Word t[1], the problem is described as: Determine the time period assigned to the word T [1] with {t[2], T [3],., t [n]} an assignment word exists in the same course allocation bit on equal non-zero time period value, or {T [2], T [3],., t[ N]} If there is a time period allocation word that conflicts with T [1]. For simplicity, assume that the highest bit of all time-period allocation words is 0 in the following algorithm description.

Algorithm 2 Collision Detection algorithm

Enter T1 and {T2,., Tn}.

Outputs the time period assignment word in the T1 conflict with {T2,., Tn}.

① to C-index = 2, 3,., n do the following:

Initialize Mask Word mask = 7

For the week Value week = 1, 2, 3, 4, 5 do the following:

If t[1] & mask equals T[c-index] & mask, and they are not equal to 0

Then: t[1] conflict with T[c-index], turn ①

Mask left 3 bit (or multiply by 8)

② algorithm End

The time complexity of this algorithm is O (n) (n is the course gate number)

5. Algorithm Analysis

This algorithm takes the course as the center, makes the search match, takes the first matching value, and possesses the characteristics of less occupying space and faster operation. However, it does not select the best data, so the teaching resources (teachers, classrooms) can not be allocated reasonably, also can not meet some special requirements (such as some teachers like to class in the morning, some teachers tend to focus on the class, some courses arranged in the morning will be more appropriate, some courses can not be scheduled to the morning, etc.).

2. 2 Priority-based algorithm for scheduling classes

Mathematically speaking, the problem of course scheduling is a combination planning problem in the four dimensions of time, teacher, student and classroom, which is constrained by the teaching plan and various special requirements. The essence is to solve the conflict between the factors. In order to reduce the complexity of the algorithm in the course scheduling, we mainly adopt the piecemeal thought and the priority algorithm when designing the algorithm:

1. The pretreatment of course scheduling

1. Division of Equivalence classes

The task of having a common lecture object is divided into the same equivalence class, where there is only one conflict between each equivalence class, and there is no time conflict. Then follow the size, from large to small to deal with. The Division of equivalence classes can be divided by grade and then by line, as shown below:

Division of equivalence classes of subjects in lectures

Department of Management of the Department of Mechanical Engineering, Department of Automation.

Class 99 N 1 Subclass 1 Subclass 2 Subclass 3 Subclass 4.

Class 98 N 2 Subclass 5 Subclass 6 Subclass 7 Subclass 8.

Class 97 N 3 Subclass 9 Subclass 10 Subclass 11 Subclass 12.

Class 96 n 4 Subclass 13 Subclass 14 Subclass 15 Subclass 16.

This way, the grade is divided into four classes: 99 (n 1), 98 (n 2), 97 (n 3), 96 (n 4), and for each equivalence class N 1, n 2, n 3, and N 4 can be divided into sub-classes according to the faculties, and then each sub-class is scheduled to be processed separately, so that Can greatly reduce the complexity of the algorithm

2. Classroom classification

In order to use the classroom reasonably, we have adopted a classroom classification approach so as to avoid blindly seizing a large classroom phenomenon in the course of arranging courses with a small number of classes.

First, the classroom according to its type into a number of equivalence classes, as shown below, and then, according to the classroom capacity and then separately for each classroom equivalence class division: such as divided into 0~ 30 people, 30~ 60 people, 60~90, 90~ 120 people, 120~ 180 people, and several kinds of

Division of Classroom equivalence classes:

Classroom type equivalence class R classroom type equivalence class R

General Classroom R1 Listening Professor R5

Projection Classroom R2 Physics Laboratory R6

Multimedia Classroom R3 Chemistry Experiment Classroom R7

R4 Computer Experiment teaching R8 in cartography classroom

3. Time preprocessing

1) Construction Time Pattern Library

The time pattern is a time combination that is specified for various weekly hours hours according to the experience of the academic staff. For example, a course of weekly hours hours is 4, then its time combination can be: "11", "41"; Indicates that the course is two times a week, 12 in Monday and 12 in Thursday. In the meantime, these time patterns should be graded to achieve better results. As shown below

Example of time pattern grading

Weekly hours priority Monday Tuesday Wednesday Thursday Friday

4 1 11 41

::

4 2 22 43

: :

Among them, from Monday to Friday with the number 1~ 5, the Class festival: 12, 34, 56, 78, late 12, late 34, respectively, by the number 1~ 6. For example, the number "42" represents the 34 section of Thursday

This time unit. Thus, for each weekly hours hour, all reasonable combinations of time can be stored in the Schema Library. For time processing, you can match the various patterns in the time pattern library.

2) Time Array

In order to show the class, teacher, classroom can schedule time, respectively, for them to establish a one-dimensional array l For example, an array of initial classes for a teacher can be (123456 123456 123456 123456 123456). There were five groups of data, representing five days of the week; And a set of data in total 6 characters "1, 2, 3, 4, 5, 6" represents the six time units of the day, respectively. When assigning time to a teacher, the corresponding character is set to 0L for example, an array of time classes for a teacher is (020456 103456 003456 120456 023456), which means that the teacher has 12 and 56 sections in Monday, 34 knots in Tuesday, and 12 knots in Wednesday. And 34, Thursday, 56, Friday, 12 sections have arranged courses, if you want to arrange the course, should be arranged in the non-0 time unit L for the class and the classroom can also do the same treatment, respectively, marking the time to schedule the course.

2. Class handling for each subclass

In the course of each subclass, we combine the idea of dividing, greedy and backtracking. L Firstly, according to the thought of dividing and ruling, divide the whole course into two stages: time allocation and classroom allocation. Then, according to the greedy algorithm idea, in time allocation, always in the unassigned time unit to choose the best class effect

Unit. When a deadlock occurs on a time allocation, the last record that conflicts occurs is searched up and then re-queued to resolve the conflict. The specific processing process is as follows:

1. Set the priority level

The classes in the sub-class calculate the priority L set the priority function to:

D  (g ) = J (g ) *C1 + T (g ) * C2 + P (g ) * C3 (1)

Among them, J (g ) represents the course level, the elective course level is set to 1, the required course level is set to 2; T (g ) indicate the weekly hours hours of the course; P (g ) indicate the number of participants in the course; C1,C2,

C3 is a parameter that can be adjusted. by formula (1) You can see that the higher the course level, the more weekly hours and the more participants, the higher the D(g ) value, the higher the priority; Conversely, the smaller the D (g ) value, the lower its priority. In this way, the course can be sorted according to the priority of the calculation, priority scheduling is high.

2. Querying available time units

The 1th step is to initialize an array of the maximum available time for a course, for (123456 123456 123456 123456 123456). The 2nd step is to find out all classes that take part in the course. The 3rd step is to query the time array of each class, get the class's scheduled time, and "with" the maximum time array of the course, so as to get the time unit that the course cannot arrange. The 4th step, the teacher time array and the relevant classroom time array, so that the final schedule of the course can be arranged by the class, teachers, classrooms can be scheduled hours

The intersection of the two.

3. Find the right time mode

After you find the time to schedule a lesson, you should match the appropriate time pattern in the time pattern library based on the weekly hours hours of the course. Upon completion of the above work, the class time and location of the course are determined. If a deadlock occurs in processing, you can search back up to the last record in conflict by backtracking, and then rearrange it to resolve deadlocks, and if you still cannot resolve the deadlock problem, you could output the course information to the list of conflicts.

3. Treatment of human intervention

It is necessary for the computer to automatically arrange the course, so that the universities can set up and adjust some parameters of the algorithm according to their specific requirements, and adjust the schedule of the computer. The human intervention process designed by this algorithm is:

The setting of parameters in equivalence class partitioning, the setting of classroom type, the setting of time pattern library, and the setting of parameters in priority function. Users can set these parameters and libraries according to their specific requirements. In addition, for computer-discharged curriculum, the user can also be adjusted through human-machine interaction, so as to obtain a user-satisfied curriculum.

4. Performance analysis

This algorithm divides classes and classrooms into equivalence classes and makes rational use of school resources. However, some special requirements can not be reflected in concrete.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
You can reprint the above text in any form, but must contain the following text
This article is writted By:liu zhen yuan
Copyed from:http://blog.csdn.net/kegao2741
If you had any problem about the artcile you'll feel free to contact me by mail "[Email protected]"



trackback:http://tb.blog.csdn.net/trackback.aspx?postid=651921

Introduction of several algorithms of class scheduling at present

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.