tasks_generator 1.8 → 1.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b19015067da3f39d1bea51e7c22c8abb170d3f05
4
- data.tar.gz: d7e478ed7d608617c9da8401d01d5b1b040dd35e
3
+ metadata.gz: a550ffc5a43041543931cb26d2cdec5eabddb128
4
+ data.tar.gz: d6b25723ace5bbbb41c2ceced196e99668bec6e3
5
5
  SHA512:
6
- metadata.gz: 342f431e0cd418333f175c73f926ecef620dcb469de54c9d450dc91a6ae4d239c3660fc4663c3e529ead1296aa5dc67238e0fa4ad86b7d3e6486a9774b0a3261
7
- data.tar.gz: 78a2e722c793c490e469b5dc79906ee2e27e2a4d576e0064516870bade3cf4c185fcbfc4f347cb239d179dd68322e6ad5c7a0ae4495422490655ad86612b389b
6
+ metadata.gz: ce0369a8f050ea1a3f18477b3f7d50e710f7538a995d29059eb969d761c05e0ab83ccf50fe5942d65f5f59e19b37d0fa73a9527cf306c4ecfb2324468abfc688
7
+ data.tar.gz: 640e9e50dd935964e0031f1cca35dfd8e86d80c34db0ecb48c64e0a19f2b94770bbfad9b83ef5a52a98e43e0fc0bd8e54a79654207bf7b2486dc7f4de1b84b20
@@ -5,7 +5,7 @@
5
5
 
6
6
  namespace ailab {
7
7
 
8
- void generator_t::mark_second_levels(std::vector<question_t> &questions, std::vector<topic_t> const &topics) noexcept {
8
+ void generator_t::mark_questions(std::vector<question_t> &questions, std::vector<topic_t> const &topics) noexcept {
9
9
  std::unordered_map<size_t, size_t> topic_id_to_index;
10
10
  std::unordered_map<size_t, size_t> topic_index_to_parent_index;
11
11
  for (size_t i = 0; i < topics.size(); ++i)
@@ -28,6 +28,14 @@ void generator_t::mark_second_levels(std::vector<question_t> &questions, std::ve
28
28
  q.set_second_level_topic_id(topics[topic_index].get_topic_id());
29
29
  }
30
30
  }
31
+ for (question_t &q : questions) {
32
+ size_t topic_id = q.get_topic_id();
33
+ if (topic_id_to_index.find(topic_id) != topic_id_to_index.end()) {
34
+ size_t topic_index = topic_id_to_index[topic_id];
35
+ size_t parent_topic_id = topics[topic_index].get_parent_id();
36
+ q.set_parent_topic_id(parent_topic_id);
37
+ }
38
+ }
31
39
  }
32
40
 
33
41
  }
@@ -119,28 +119,28 @@ class generator_t {
119
119
  return true;
120
120
  }
121
121
 
122
- void mark_second_levels(std::vector<question_t> &questions, std::vector<topic_t> const &topics) noexcept;
122
+ void mark_questions(std::vector<question_t> &questions, std::vector<topic_t> const &topics) noexcept;
123
123
 
124
124
  public:
125
125
  generator_t(config_t const &cnf, std::vector<topic_t> const &topics_, std::vector<question_t> const &questions_) noexcept :
126
126
  config(cnf),
127
127
  topics(topics_),
128
128
  questions(questions_) {
129
- mark_second_levels(questions, topics);
129
+ mark_questions(questions, topics);
130
130
  }
131
131
 
132
132
  generator_t(config_t &&cnf, std::vector<topic_t> &&topics_, std::vector<question_t> &&questions_) noexcept :
133
133
  config(cnf),
134
134
  topics(topics_),
135
135
  questions(questions_) {
136
- mark_second_levels(questions, topics);
136
+ mark_questions(questions, topics);
137
137
  }
138
138
 
139
139
  generator_t(generator_t const &other) noexcept :
140
140
  config(other.config),
141
141
  topics(other.topics),
142
142
  questions(other.questions) {
143
- mark_second_levels(questions, topics);
143
+ mark_questions(questions, topics);
144
144
  }
145
145
 
146
146
  variants_t generate() {
@@ -5,7 +5,7 @@
5
5
  namespace ailab {
6
6
 
7
7
  class question_t {
8
- size_t question_id, topic_id, difficulty, second_level_topic_id;
8
+ size_t question_id, topic_id, difficulty, second_level_topic_id, parent_topic_id;
9
9
  std::string text;
10
10
 
11
11
  public:
@@ -14,6 +14,7 @@ class question_t {
14
14
  topic_id(topic_id),
15
15
  difficulty(difficulty),
16
16
  second_level_topic_id(0),
17
+ parent_topic_id(0),
17
18
  text(text) {
18
19
  }
19
20
 
@@ -25,6 +26,14 @@ class question_t {
25
26
  return second_level_topic_id;
26
27
  }
27
28
 
29
+ void set_parent_topic_id(size_t x) noexcept {
30
+ parent_topic_id = x;
31
+ }
32
+
33
+ size_t get_parent_topic_id() const noexcept {
34
+ return parent_topic_id;
35
+ }
36
+
28
37
  size_t get_question_id() const noexcept {
29
38
  return question_id;
30
39
  }
@@ -70,8 +70,8 @@ class variants_t {
70
70
  }
71
71
 
72
72
  double calculate_fitness_function() const noexcept {
73
- // if (!changed)
74
- // return fitness;
73
+ if (!changed)
74
+ return fitness;
75
75
  size_t questions_count = 0;
76
76
  for (auto const &v : questions)
77
77
  questions_count += v.size();
@@ -86,6 +86,18 @@ class variants_t {
86
86
  count += buffer[i] != buffer[i - 1];
87
87
  fitness = double(count) / questions_count;
88
88
  }
89
+ {
90
+ for (size_t i = 0; i < questions.size(); ++i) {
91
+ size_t buffer[questions[i].size()];
92
+ for (size_t j = 0; j < questions[i].size(); ++j)
93
+ buffer[j] = questions[i][j].get_parent_topic_id();
94
+ std::sort(buffer, buffer + questions[i].size());
95
+ size_t count = 1;
96
+ for (size_t j = 1; j < questions[i].size(); ++j)
97
+ count += buffer[j] != buffer[j - 1];
98
+ fitness += double(count) / questions[i].size();
99
+ }
100
+ }
89
101
  {
90
102
  for (size_t i = 0; i < questions.size(); ++i) {
91
103
  size_t buffer[questions[i].size()];
@@ -95,7 +107,7 @@ class variants_t {
95
107
  size_t count = 1;
96
108
  for (size_t j = 1; j < questions[i].size(); ++j)
97
109
  count += buffer[j] != buffer[j - 1];
98
- fitness += count * 10 / questions[i].size();
110
+ fitness += double(count) / questions[i].size();
99
111
  }
100
112
  }
101
113
  {
@@ -119,7 +131,7 @@ class variants_t {
119
131
  size_t count = 1;
120
132
  for (size_t j = 1; j < questions[i].size(); ++j)
121
133
  count += buffer[j] != buffer[j - 1];
122
- fitness += double(count) * 10.0 / questions[i].size();
134
+ fitness += double(count) / questions[i].size();
123
135
  }
124
136
  }
125
137
  {
@@ -171,7 +183,7 @@ class variants_t {
171
183
  fitness += x;
172
184
  }
173
185
  }
174
- // changed = false;
186
+ changed = false;
175
187
  return fitness;
176
188
  }
177
189
 
@@ -208,6 +220,7 @@ class variants_t {
208
220
  }
209
221
  }
210
222
  }
223
+ changed = true;
211
224
  }
212
225
 
213
226
  std::vector<std::vector<question_t>> const &get_questions() const noexcept {
@@ -1,3 +1,3 @@
1
1
  module TasksGenerator
2
- VERSION = "1.8"
2
+ VERSION = "1.9"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tasks_generator
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.8'
4
+ version: '1.9'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arslan Urtashev