| |

VerySource

 Forgot password?
 Register
Search
View: 734|Reply: 5

Solve the problem, or you will never get up, begging!

[Copy link]

2

Threads

13

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-1-7 16:20:01
| Show all posts |Read mode
I am currently working on a middle school schedule system. My approach is this, using the random schedule method:
The main line of class scheduling is: the main line of teachers:
Put all the teachers in the current grade into an array, and then randomly select the data in the class schedule according to the class taught by the teacher and the number of courses taught by the teacher. If there is a conflict, reselect randomly. If it conflicts again and again, stop random, choose the class that has conflicts first, and from the random to the end, if there is a conflict, use the while statement to reschedule the class. If no conflict exists, use the lesson plan!
The problems I encountered were:
1: Generate the class schedules of all classes into a data table, that is, the schedule matrix, if according to the above and the select statement, continuously and randomly select the eligible class hours from the matrix and arrange for the teacher
The problem is: if the number of class hours in all subjects is the same as the number of class hours in the class's curriculum, that is, the program will not run until half, that is, the class schedule cannot always be completely arranged, which is basically the same for each table. There are three to five blanks in the curriculum, which means that there are about five lessons.
However, if the class schedule is increased by one each day, that is, the schedule is greater than the duration of all subjects, then the schedule can be easily arranged. Although there are still conflicts, it is not a big deal.
The fatal question is, why are the curriculum hours the same as that of all subjects, that is, exactly the same, absolutely not wrong, why can't it be fully realized by checking and inserting data?
The above random selection method is to select the appropriate class hours from the Matrix table, and then insert the data into the CourseScheduling table and delete the corresponding data in the Matrix table
There are 1140 test data in the previous table, but there are about 60 data left in the table each time it is executed (there are 30 classes in each class, that is, there are about 2 classes in each class that cannot be scheduled)
Of course, if a conflict is encountered, it will be executed 20 times in a row. If there is a conflict, this data will be selected as the class time.
The above analysis is theoretically okay. Why is there such a problem? Why can't two lessons be scheduled per table
The program did not prompt any errors, but the browser's progress bar stopped moving when it was halfway. I saw that the CPU was 100% utilization, and I could see that the program was executing every time, but why Can't execute successfully?
Here is my code, let's take a look!
for (int i = 0; i <LessCourseNumTeaID.Count; i ++) // ID numbers of all teachers
{
ArrayList MyClassNum = GetCurrentTeaAllClassName (LessCourseNumTeaID [i] .ToString (). Trim ()); // Get all classes taught by the teacher in the current grade
for (int j = 0; j <MyClassNum.Count; j ++) // All classes in the current grade taught by this teacher
{
string MySqlStr = "select ID from Matrix where grade =" + "'" + GradeNameComBox.SelectedValue.ToString (). Trim () + "'" + "and class name =" + "'" + MyClassNum [j]. ToString (). Trim () + "'";
int HaveCourseNum = GetCurrentSubjectCourseNum (GetCurrentTeaSubject (LessCourseNumTeaID [i] .ToString (). Trim ())); // Get the number of class hours per week for this course for the teacher in the current grade
bool MyBL = true;
int ConfictNum = 0;
int CursorCouseNum = 0;
while (MyBL) // execute the loop until a satisfactory class time is found,
{
string MySqlStr1 = GetGoodCourseNum (MySqlStr); // Pass MySqlStr to obtain all ID numbers that meet the conditions, and then randomly select an ID number to send over
MyReader = MyClass.MySqlDataReader (MySqlStr1, MyKey, MyValue, MySqlDbType, MyFieldLength);
while (MyReader.Read ())
{
if (CheckConflictSecond (LessCourseNumTeaID [i] .ToString (). Trim (), MyReader ["day name"]. ToString (). Trim (), MyReader ["day value"]. ToString (). Trim (), MyClassNum [j] .ToString (). Trim ()))
{
ConfictNum = ConfictNum + 1;
if (ConfictNum == 20)
{
ConflictInfor = ConflictInfor + GetTeaName (LessCourseNumTeaID [i] .ToString (). Trim ()) + "," + GetCurrentTeaSubject (LessCourseNumTeaID [i] .ToString (). Trim ()) + "," + MyReader ["Day Name" ] .ToString (). Trim () + ", section" + MyReader ["day value"]. ToString (). Trim () + ", conflict! <br>";
InsertIntoCourseScheduling (MyClassNum [j] .ToString (). Trim (), MyReader ["day name"]. ToString (). Trim (), MyReader ["day value"]. ToString (). Trim (), LessCourseNumTeaID [i ] .ToString (). Trim (), GetTeaName (LessCourseNumTeaID [i] .ToString (). Trim ()), GetCurrentTeaSubject (LessCourseNumTeaID [i] .ToString (). Trim ()), GradeNameComBox.SelectedValue.ToString (). Trim ());
DeleteMartixData (MyReader ["ID"]. ToString (). Trim ()); // Delete the matrix data corresponding to the current grade
CursorCouseNum = CursorCouseNum + 1;
}
}
else
{
InsertIntoCourseScheduling (MyClassNum [j] .ToString (). Trim (), MyReader ["day name"]. ToString (). Trim (), MyReader ["day value"]. ToString (). Trim (), LessCourseNumTeaID [i ] .ToString (). Trim (), GetTeaName (LessCourseNumTeaID [i] .ToString (). Trim ()), GetCurrentTeaSubject (LessCourseNumTeaID [i] .ToString (). Trim ()), GradeNameComBox.SelectedValue.ToString (). Trim ());
DeleteMartixData (MyReader ["ID"]. ToString (). Trim ()); // Delete the matrix data corresponding to the current grade
CursorCouseNum = CursorCouseNum + 1;
}
}
MyReader.Close ();
MyClass.CloseDataBaseCon ();
if (CursorCouseNum == HaveCourseNum)
{
MyBL = false;
}
}
}
}
Reply

Use magic Report

0

Threads

15

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-1-9 10:45:02
| Show all posts
Too long to understand. . .
Reply

Use magic Report

0

Threads

43

Posts

29.00

Credits

Newbie

Rank: 1

Credits
29.00

 China

Post time: 2020-1-9 16:27:02
| Show all posts
Too long to read. . .
Reply

Use magic Report

2

Threads

13

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

 Author| Post time: 2020-1-10 00:36:01
| Show all posts
help?
Reply

Use magic Report

0

Threads

64

Posts

35.00

Credits

Newbie

Rank: 1

Credits
35.00

 China

Post time: 2020-1-10 13:45:01
| Show all posts
The innermost layer, if it can be predicted that the results are repeated, the search should be ended immediately. In other words, search should not be performed on a tree, but on a graph.
Reply

Use magic Report

2

Threads

13

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

 Author| Post time: 2020-1-10 17:45:01
| Show all posts
Searching on a graph, how to understand?
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list