-
Notifications
You must be signed in to change notification settings - Fork 0
/
function.cpp
148 lines (143 loc) · 3.96 KB
/
function.cpp
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#include "function.h"
void rules()
{
cout << "This is formatted in form of dept timetable." << endl;
cout << "The input was take from a file (input.txt)" << endl;
cout << "Additional contraints followed are: " << endl;
cout << "1. one subject can have only 1 class in a day. " << endl;
cout << "2. tutorials can have 2 slots one : 1st and two : 6th if required" << endl;
cout << "3. Lab takes up 3 slots (3 hours as same as institute)" << endl;
cout << "4. Lectures can take 7th to 12th slots" << endl;
cout << "i have taken input to demontrate that time table cannot be built " << endl;
cout << "properly because you cannot get a proper time table obeying the above CONSTRAINTS." << endl;
cout << "you can change minor field from 1 0 3 to 1 0 2 and you will get a proper timetable" << endl;
cout << "**MAXIMIZE TERMINAL TO GET A BETTER LOOK AT THE TIMETABLE." << endl;
cout << "\n\n";
}
int *parse(string inp)
{
int *time = new int[3];
stringstream ss(inp);
ss >> time[0] >> time[1] >> time[2];
return time;
}
int *getInput(dept &d)
{
int *tip, *np;
np = new int[6];
const string inp_file = "test_input1.txt";
ifstream fin("input/" + inp_file);
int n;
fin >> n;
string inp = "";
while (n--)
{
while (inp == "")
getline(fin, inp);
d.setMaxClass(parse(inp));
tip = d.getMaxClass();
inp = "";
np[0] = tip[2];
while (inp == "")
getline(fin, inp);
d.setClassDur(parse(inp));
int gap;
fin >> gap;
d.setBreak(gap);
np[5] = gap;
inp = "";
while (inp == "")
getline(fin, inp);
d.setName(inp);
string CourseCode = inp.substr(0, 2);
for (int i = 0; i < 4; i++)
{
inp = "";
while (inp == "")
getline(fin, inp);
int m;
fin >> m;
np[1 + i] = m;
while (m--)
{
inp = "";
while (inp == "")
getline(fin, inp);
stringstream ss(inp);
bool tut, lab;
int lec;
string profName;
ss >> tut >> lab >> lec;
while (ss >> inp)
{
profName += inp + " ";
}
prof pr = prof(profName, CourseCode + to_string(100 + i * 10 + m));
course c_temp = course(lec, tut, lab, pr);
d.insertCourse(i, c_temp);
}
}
}
fin.close();
return np;
}
timetable maketimetable(scalar<duo<int, string>> &z, int *p, int Break)
{
int n = z.size();
timetable tt(p[0] + 6, p[0], p[5]);
int n_l = z[n - 1].p[0];
int g[5];
for (int i = 0; i < 5; i++)
g[i] = n_l / 5;
for (int i = 0; i < n_l % 5; i++)
g[4 - i]++;
for (int i = 0; i < Break; i++)
{
for (int j = 0; j < 5; j++)
{
tt.setString("BREAK", j, 4 + i);
}
}
for (int i = 0; i < 5; i++)
{
int j = 0, k = 0;
while (j < 5 && k < n - 1)
{
if (z[k].p[0] > 0)
{
tt.setString(z[k].t, i, j + 6);
z[k].p[0]--;
j++;
}
k++;
}
}
for (int i = 0; i < n - 1; i++)
{
if (z[i].p[0])
{
cout << "**" << z[i].t << " cannot be accomodated in time table .(We are following one subject per day)" << endl;
}
}
int j = 0;
for (int i = 0; i < n - 1; i++)
{
if (z[i].p[2])
{
tt.setString(z[i].t + "L", j, 1);
tt.setString(z[i].t + "L", j, 2);
tt.setString(z[i].t + "L", j, 3);
j++;
}
}
j = 0;
for (int i = 0; i < n - 1; i++)
{
if (z[i].p[1])
{
tt.setString(z[i].t + "T", j, 0);
j++;
}
}
return tt;
}