-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
201 lines (183 loc) · 8.04 KB
/
Program.cs
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
using System;
using System.IO;
namespace Google_Hashcode2022
{
public class Program
{
static void Main(string[] args)
{
bool firstLine = true;
int n_projects = 0;
int n_contributors = 0;
List<Contributor> contributors = new List<Contributor>();
List<Project> projects = new List<Project>();
fileParser(firstLine, n_contributors, n_projects, contributors, projects);
List<Project> endedProjects = scoreSystem(projects, contributors);
fileWrite(endedProjects);
}
///Build Models and start prioritizing Data
private static void fileParser(bool firstLine, int n_contributors, int n_projects, List<Contributor> contributors, List<Project> projects)
{
int tmp_c = n_contributors;
int tmp_p = n_projects;
Contributor c = new Contributor("");
Project p = new Project("");
int n_skill_req = 0;
int n_skills = 0;
foreach (var line in File.ReadLines("./InputFiles/c_collaboration.in.txt"))
{
if (firstLine)
{
firstLine = false;
n_contributors = int.Parse(line.Split(" ")[0]);
n_projects = int.Parse(line.Split(" ")[1]);
}
else if (n_contributors > 0 || n_skills > 0)
{
//Contributors
if (n_skills == 0) //first line contributor
{
c = new Contributor(line.Split(" ")[0]);
n_skills = int.Parse(line.Split(" ")[1]);
--n_contributors;
}
else // insert skill in c contributor
{
int lv = Int32.Parse(line.Split(" ")[1]);
c.lista_skill.Add(new Skill(line.Split(" ")[0], lv));
--n_skills;
}
if (n_skills == 0)
{
contributors.Add(c);
}
}
//Projects
else if (n_projects > 0 || n_skill_req > 0)
{
if (n_skill_req == 0)
{ // new project
string name = line.Split(" ")[0];
int duration = Int32.Parse(line.Split(" ")[1]);
int score = Int32.Parse(line.Split(" ")[2]);
int day = Int32.Parse(line.Split(" ")[3]);
n_skill_req = Int32.Parse(line.Split(" ")[4]);
p = new Project(name, score, day, n_skill_req, duration);
--n_projects;
}
else
{ // add skill to project
int lv = Int32.Parse(line.Split(" ")[1]);
p.skill_list_required.Add(new Skill(line.Split(" ")[0], lv));
--n_skill_req;
}
if (n_skill_req == 0)
{
projects.Add(p);
}
}
else
{ //end
Console.WriteLine("----------------- ERROR IN READING INPUT FILE ----------------------");
}
}
}
private static List<Project> scoreSystem(List<Project> inputProjects, List<Contributor> inputContributors)
{
//passo i parsati
List<Project> projects = inputProjects;
List<Contributor> contributors = inputContributors;
List<List<Project>> calendar = new List<List<Project>>();
List<Project> assingedProjects = new List<Project>();
List<Project> endProjects = new List<Project>();
List<Contributor> freeContributors = new List<Contributor>();
freeContributors = contributors;
projects.Sort();
//maxScadenza = punteggio del progetto + bestbefore del progetto. Ossia
//i giorni disponibili tali per cui quel progetto ci darà punti.
int maxScadenza = projects.Last().day_to_terminate + projects.Last().score;
int score = 0;
for (int day = 0; day < maxScadenza; day++)
{
//aggiornare e controllare se un progetto è finito
foreach (Project project in projects)
{
if (assingedProjects.Contains(project))
{
project.duration--;
if (project.duration == 0)
{
endProjects.Add(project);
assingedProjects.Remove(project);
int delay = day - project.day_to_terminate;
if (delay < 0) delay = 0;
score += project.score - delay;
//migliorare le skills
foreach (Contributor contributor in project.list_contributor)
{
freeContributors.Add(contributor);
}
}
}
}
//assegnare i progetti
foreach (Project project in projects)
{
List<Skill> soddisfatte = new List<Skill>();
if (!assingedProjects.Contains(project) && !endProjects.Contains(project))
{
foreach (Skill reqSkill in project.skill_list_required)
{
Contributor tmp = null;
bool found = false;
foreach (Contributor contributor in freeContributors)
{
if (found) break;
foreach (Skill contSkill in contributor.lista_skill)
{
if (contSkill.name == reqSkill.name && contSkill.level >= reqSkill.level)
{
tmp = contributor;
project.number_contributor--;
project.list_contributor.Add(contributor);
soddisfatte.Add(reqSkill);
found = true;
break;
}
}
}
if (tmp != null)
freeContributors.Remove(tmp);
}
if (project.number_contributor == 0)
{
assingedProjects.Add(project);
}
calendar.Add(assingedProjects);
}
}
}
return endProjects;
}
private static void fileWrite(List<Project> completedProjects)
{
string path = "./OutputFiles/results.txt";
string text = completedProjects.Count + "\n"; //PRIMA RIGA E' NUMERO PROGETTI
foreach (Project item in completedProjects)
{
text += item.name + "\n"; //add project name
foreach (Contributor person in item.list_contributor)
{ //importante, lista di contributor in ordine già!
text += person.name + " "; //add people
}
text += "\n";
}
File.WriteAllText(path, text);
}
/* private static List<Project> scoreSystem_rapporto (List<Contributor> lista_c, List<Project> lista_p) {
List<Project> res = new List<Project>();
for (int i =0; i )
return res;
}*/
}
}