-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfirst.cpp
More file actions
64 lines (52 loc) · 2.51 KB
/
first.cpp
File metadata and controls
64 lines (52 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/* randomly generating samples.
* we assume all course take same hours.
* and we can find some relationship between real hours and indexs of container
*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <iterator>
//#include <random>
#include <map>
#include <vector>
using namespace std;
// the parameter should be pass value by address
int first(map<int, map<int,int> >& classTable, vector<vector<int> >& schedule, vector<vector<int> >& schedule2, vector<int> course_inf, int row_max, int col_max){
int cost = 0;//The number of class clash
int i = 0; //The number of current iteration
int T = 4;//depends on how many courses we have
srand((unsigned int)time(NULL));
while(i<T){
cout<<"****** Round "<<i+1<<" ******"<<endl;
int crn_course = i;
int index_teacher = course_inf[crn_course];// each crn_course have their own teacher numbers
int row_tem = rand() % row_max;//time
int col_tem = rand() % col_max;//location
//debug check the random number
cout<<"randomly generated two numbers represent time & location for the course."<<endl;
cout<<"random number for time: "<<row_tem<<endl;
cout<<"random number for location: "<<col_tem<<endl;
cout<<"The teacher index is: "<<course_inf[i];
map<int,int> time_loc;
time_loc.insert(pair<int, int>(row_tem, col_tem));
classTable[crn_course] = time_loc;
schedule[row_tem][col_tem]++ ; // at this time, the room gonna hold the course
schedule2[row_tem][index_teacher]++; // at this time, the teacher gonna teach the course
//debug check the clash number
//time & location
cout<<" "<<endl;
cout<<"print out how many course on this time and location:"<<endl;
cout<<"in the schedule1 of time&location: "<<"There is "<<schedule[row_tem][col_tem]<<" course."<<endl;
//time & teacher
cout<<" "<<endl;
cout<<"print out how many course on this time for a teacher: "<<endl;
cout<<"in the schedule2 of time&teacher: "<<"The teacher has "<<schedule2[row_tem][index_teacher]<<" course at this time period."<<endl;
if(schedule[row_tem][col_tem]>1) cost++;
cout<<"the cost after check the clash of time and location: "<<cost<<endl;
if(schedule2[row_tem][index_teacher]>1) cost++;
cout<<"the cost after check the clash of time and teacher: "<<cost<<endl;
cout<<" "<<endl;
i++;
}
return cost;
}