aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2013-02-27 15:04:17 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2013-02-27 15:04:17 +0000
commitc8dec9576290c75aae918564f27be6636c4f4e2f (patch)
tree35f3af3eee3245c580bd3f0142a8274c384b7a1a
parentd6353593a73706c2bdbaac7fbb111fca6bdab9a5 (diff)
downloadgnunet-c8dec9576290c75aae918564f27be6636c4f4e2f.tar.gz
gnunet-c8dec9576290c75aae918564f27be6636c4f4e2f.zip
quality update
-rw-r--r--src/ats/gnunet-service-ats_addresses_mlp.c128
1 files changed, 64 insertions, 64 deletions
diff --git a/src/ats/gnunet-service-ats_addresses_mlp.c b/src/ats/gnunet-service-ats_addresses_mlp.c
index b15eb61b3..64c1fde82 100644
--- a/src/ats/gnunet-service-ats_addresses_mlp.c
+++ b/src/ats/gnunet-service-ats_addresses_mlp.c
@@ -1016,7 +1016,7 @@ GAS_mlp_address_add (void *solver, struct GNUNET_CONTAINER_MultiHashMap * addres
1016 address->solver_information = GNUNET_malloc (sizeof (struct MLP_information)); 1016 address->solver_information = GNUNET_malloc (sizeof (struct MLP_information));
1017 mlpi = address->solver_information; 1017 mlpi = address->solver_information;
1018 for (c1 = 0; c1 < mlp->pv.m_q; c1++) 1018 for (c1 = 0; c1 < mlp->pv.m_q; c1++)
1019 for (c2 = 0; c2 < mlp->pv.m_q; c2++) 1019 for (c2 = 0; c2 < MLP_AVERAGING_QUEUE_LENGTH; c2++)
1020 mlpi->q[c1][c2] = NaN; 1020 mlpi->q[c1][c2] = NaN;
1021 } 1021 }
1022 else 1022 else
@@ -1042,8 +1042,10 @@ mlp_update_quality (struct GAS_MLP_Handle *mlp, struct ATS_Address * address,
1042 const struct GNUNET_ATS_Information *ats, uint32_t ats_count) 1042 const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
1043{ 1043{
1044 struct MLP_information *mlpi = address->solver_information; 1044 struct MLP_information *mlpi = address->solver_information;
1045 unsigned int c; 1045 unsigned int c_ats_entry;
1046 unsigned int c2; 1046 unsigned int c_queue_entries;
1047 unsigned int c_cmp;
1048 unsigned int c_queue_it;
1047 int type_index; 1049 int type_index;
1048 int avg_index; 1050 int avg_index;
1049 uint32_t type; 1051 uint32_t type;
@@ -1058,22 +1060,19 @@ mlp_update_quality (struct GAS_MLP_Handle *mlp, struct ATS_Address * address,
1058 GNUNET_assert (NULL != address->solver_information); 1060 GNUNET_assert (NULL != address->solver_information);
1059 GNUNET_assert (NULL != ats); 1061 GNUNET_assert (NULL != ats);
1060 1062
1061 for (c = 0; c < ats_count; c++) 1063 for (c_ats_entry = 0; c_ats_entry < ats_count; c_ats_entry++)
1062 { 1064 {
1063 type = ntohl (ats[c].type); 1065 type = ntohl (ats[c_ats_entry].type);
1064 value = ntohl (ats[c].value); 1066 value = ntohl (ats[c_ats_entry].value);
1065 type_index = -1; 1067 type_index = -1;
1066 avg_index = -1; 1068 avg_index = -1;
1067 1069
1068 /* Find index for this ATS type */ 1070 /* Find index for this ATS type */
1069 for (c2 = 0; c2 < mlp->pv.m_q; c2++) 1071 for (c_cmp = 0; c_cmp < mlp->pv.m_q; c_cmp++)
1070 { 1072 {
1071 LOG (GNUNET_ERROR_TYPE_DEBUG, "Comparing c==%u c2==%u %u and %u \n", 1073 if (type == mlp->pv.q[c_cmp])
1072 c, c2,
1073 type, mlp->pv.q[c2] );
1074 if (type == mlp->pv.q[c2])
1075 { 1074 {
1076 type_index = c2; 1075 type_index = c_cmp;
1077 break; 1076 break;
1078 } 1077 }
1079 } 1078 }
@@ -1105,28 +1104,29 @@ mlp_update_quality (struct GAS_MLP_Handle *mlp, struct ATS_Address * address,
1105 { 1104 {
1106 case GNUNET_ATS_QUALITY_NET_DISTANCE: 1105 case GNUNET_ATS_QUALITY_NET_DISTANCE:
1107 case GNUNET_ATS_QUALITY_NET_DELAY: 1106 case GNUNET_ATS_QUALITY_NET_DELAY:
1108 c2 = 0; 1107 c_queue_entries = 0;
1109 avg = 0; 1108 avg = 0;
1110 for (c = 0; c < MLP_AVERAGING_QUEUE_LENGTH; c++) 1109 for (c_queue_it = 0; c_queue_it < MLP_AVERAGING_QUEUE_LENGTH; c_queue_it++)
1111 { 1110 {
1112 if (mlpi->q[type_index][c] != NaN) 1111 if (mlpi->q[type_index][c_queue_it] != NaN)
1113 { 1112 {
1114 queue = mlpi->q[type_index] ; 1113 queue = mlpi->q[type_index] ;
1115 avg += queue[c]; 1114 avg += queue[c_queue_it];
1116 c2 ++; 1115 c_queue_entries ++;
1117 } 1116 }
1118 } 1117 }
1119 if ((c2 > 0) && (avg > 0)) 1118 if ((c_queue_entries > 0) && (avg > 0))
1120 /* avg = 1 / ((q[0] + ... + q[l]) /c3) => c3 / avg*/ 1119 /* avg = 1 / ((q[0] + ... + q[l]) /c3) => c3 / avg*/
1121 mlpi->q_averaged[type_index] = (double) c2 / avg; 1120 mlpi->q_averaged[type_index] = (double) c_queue_entries / avg;
1122 else 1121 else
1123 mlpi->q_averaged[type_index] = 0.0; 1122 mlpi->q_averaged[type_index] = 0.0;
1124 1123
1125 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%s': `%s' average sum: %f, average: %f, weight: %f\n", 1124 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%s': `%s' average sum of %u elements == %f, average == %f, weight == %f\n",
1126 GNUNET_i2s (&address->peer), 1125 GNUNET_i2s (&address->peer),
1127 mlp_ats_to_string(mlp->pv.q[type_index]), 1126 mlp_ats_to_string(mlp->pv.q[type_index]),
1127 c_queue_entries,
1128 avg, 1128 avg,
1129 avg / (double) c2, 1129 avg / (double) c_queue_entries,
1130 mlpi->q_averaged[type_index]); 1130 mlpi->q_averaged[type_index]);
1131 break; 1131 break;
1132 default: 1132 default:
@@ -1148,8 +1148,8 @@ mlp_update_quality (struct GAS_MLP_Handle *mlp, struct ATS_Address * address,
1148 //struct GNUNET_ATS_Information *ats = address->ats; 1148 //struct GNUNET_ATS_Information *ats = address->ats;
1149 GNUNET_assert (mlpi != NULL); 1149 GNUNET_assert (mlpi != NULL);
1150 1150
1151 int c; 1151 int c_ats_entry;
1152 for (c = 0; c < GNUNET_ATS_QualityPropertiesCount; c++) 1152 for (c_ats_entry = 0; c_ats_entry < GNUNET_ATS_QualityPropertiesCount; c_ats_entry++)
1153 { 1153 {
1154 1154
1155 /* FIXME int index = mlp_lookup_ats(address, mlp->q[c]); */ 1155 /* FIXME int index = mlp_lookup_ats(address, mlp->q[c]); */
@@ -1163,8 +1163,8 @@ mlp_update_quality (struct GAS_MLP_Handle *mlp, struct ATS_Address * address,
1163 mlp_ats_to_string(mlp->q[c]), 1163 mlp_ats_to_string(mlp->q[c]),
1164 (double) ats[index].value); 1164 (double) ats[index].value);
1165 1165
1166 int i = mlpi->q_avg_i[c];*/ 1166 int i = mlpi->q_avg_i[c_ats_entry];*/
1167 double * qp = mlpi->q[c]; 1167 double * qp = mlpi->q[c_ats_entry];
1168 /* FIXME 1168 /* FIXME
1169 qp[i] = (double) ats[index].value; 1169 qp[i] = (double) ats[index].value;
1170 */ 1170 */
@@ -1174,77 +1174,77 @@ mlp_update_quality (struct GAS_MLP_Handle *mlp, struct ATS_Address * address,
1174 { 1174 {
1175 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%s': `%s' queue[%u]: %f\n", 1175 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%s': `%s' queue[%u]: %f\n",
1176 GNUNET_i2s (&address->peer), 1176 GNUNET_i2s (&address->peer),
1177 mlp_ats_to_string(mlp->q[c]), 1177 mlp_ats_to_string(mlp->q[c_ats_entry]),
1178 t, 1178 t,
1179 qp[t]); 1179 qp[t]);
1180 } 1180 }
1181 1181
1182 if (mlpi->q_avg_i[c] + 1 < (MLP_AVERAGING_QUEUE_LENGTH)) 1182 if (mlpi->q_avg_i[c_ats_entry] + 1 < (MLP_AVERAGING_QUEUE_LENGTH))
1183 mlpi->q_avg_i[c] ++; 1183 mlpi->q_avg_i[c_ats_entry] ++;
1184 else 1184 else
1185 mlpi->q_avg_i[c] = 0; 1185 mlpi->q_avg_i[c_ats_entry] = 0;
1186 1186
1187 1187
1188 int c2; 1188 int c_queue_entries;
1189 int c3; 1189 int c_queue_it;
1190 double avg = 0.0; 1190 double avg = 0.0;
1191 switch (mlp->q[c]) 1191 switch (mlp->q[c_ats_entry])
1192 { 1192 {
1193 case GNUNET_ATS_QUALITY_NET_DELAY: 1193 case GNUNET_ATS_QUALITY_NET_DELAY:
1194 c3 = 0; 1194 c_queue_it = 0;
1195 for (c2 = 0; c2 < MLP_AVERAGING_QUEUE_LENGTH; c2++) 1195 for (c_queue_entries = 0; c_queue_entries < MLP_AVERAGING_QUEUE_LENGTH; c_queue_entries++)
1196 { 1196 {
1197 if (mlpi->q[c][c2] != -1) 1197 if (mlpi->q[c][c_queue_entries] != -1)
1198 { 1198 {
1199 double * t2 = mlpi->q[c] ; 1199 double * t2 = mlpi->q[c_ats_entry] ;
1200 avg += t2[c2]; 1200 avg += t2[c_queue_entries];
1201 c3 ++; 1201 c_queue_it ++;
1202 } 1202 }
1203 } 1203 }
1204 if ((c3 > 0) && (avg > 0)) 1204 if ((c_queue_it > 0) && (avg > 0))
1205 /* avg = 1 / ((q[0] + ... + q[l]) /c3) => c3 / avg*/ 1205 /* avg = 1 / ((q[0] + ... + q[l]) /c3) => c3 / avg*/
1206 mlpi->q_averaged[c] = (double) c3 / avg; 1206 mlpi->q_averaged[c_ats_entry] = (double) c_queue_it / avg;
1207 else 1207 else
1208 mlpi->q_averaged[c] = 0.0; 1208 mlpi->q_averaged[c_ats_entry] = 0.0;
1209 1209
1210 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%s': `%s' average sum: %f, average: %f, weight: %f\n", 1210 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%s': `%s' average sum: %f, average: %f, weight: %f\n",
1211 GNUNET_i2s (&address->peer), 1211 GNUNET_i2s (&address->peer),
1212 mlp_ats_to_string(mlp->q[c]), 1212 mlp_ats_to_string(mlp->q[c_ats_entry]),
1213 avg, 1213 avg,
1214 avg / (double) c3, 1214 avg / (double) c_queue_it,
1215 mlpi->q_averaged[c]); 1215 mlpi->q_averaged[c_ats_entry]);
1216 1216
1217 break; 1217 break;
1218 case GNUNET_ATS_QUALITY_NET_DISTANCE: 1218 case GNUNET_ATS_QUALITY_NET_DISTANCE:
1219 c3 = 0; 1219 c_queue_it = 0;
1220 for (c2 = 0; c2 < MLP_AVERAGING_QUEUE_LENGTH; c2++) 1220 for (c_queue_entries = 0; c_queue_entries < MLP_AVERAGING_QUEUE_LENGTH; queue_entries++)
1221 { 1221 {
1222 if (mlpi->q[c][c2] != -1) 1222 if (mlpi->q[c_ats_entry][c_queue_entries] != -1)
1223 { 1223 {
1224 double * t2 = mlpi->q[c] ; 1224 double * t2 = mlpi->q[c_ats_entry] ;
1225 avg += t2[c2]; 1225 avg += t2[c_queue_entries];
1226 c3 ++; 1226 c_queue_it ++;
1227 } 1227 }
1228 } 1228 }
1229 if ((c3 > 0) && (avg > 0)) 1229 if ((c_queue_it > 0) && (avg > 0))
1230 /* avg = 1 / ((q[0] + ... + q[l]) /c3) => c3 / avg*/ 1230 /* avg = 1 / ((q[0] + ... + q[l]) /c3) => c3 / avg*/
1231 mlpi->q_averaged[c] = (double) c3 / avg; 1231 mlpi->q_averaged[c_ats_entry] = (double) c_queue_it / avg;
1232 else 1232 else
1233 mlpi->q_averaged[c] = 0.0; 1233 mlpi->q_averaged[c_ats_entry] = 0.0;
1234 1234
1235 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%s': `%s' average sum: %f, average: %f, weight: %f\n", 1235 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%s': `%s' average sum: %f, average: %f, weight: %f\n",
1236 GNUNET_i2s (&address->peer), 1236 GNUNET_i2s (&address->peer),
1237 mlp_ats_to_string(mlp->q[c]), 1237 mlp_ats_to_string(mlp->q[c_ats_entry]),
1238 avg, 1238 avg,
1239 avg / (double) c3, 1239 avg / (double) c_queue_it,
1240 mlpi->q_averaged[c]); 1240 mlpi->q_averaged[c_ats_entry]);
1241 1241
1242 break; 1242 break;
1243 default: 1243 default:
1244 break; 1244 break;
1245 } 1245 }
1246 1246
1247 if ((mlpi->c_b != 0) && (mlpi->r_q[c] != 0)) 1247 if ((mlpi->c_b != 0) && (mlpi->r_q[c_ats_entry] != 0))
1248 { 1248 {
1249 1249
1250 /* Get current number of columns */ 1250 /* Get current number of columns */
@@ -1254,7 +1254,7 @@ mlp_update_quality (struct GAS_MLP_Handle *mlp, struct ATS_Address * address,
1254 double *val = GNUNET_malloc (cols * sizeof (double) + 1); 1254 double *val = GNUNET_malloc (cols * sizeof (double) + 1);
1255 1255
1256 /* Get the matrix row of quality */ 1256 /* Get the matrix row of quality */
1257 int length = glp_get_mat_row(mlp->prob, mlp->r_q[c], ind, val); 1257 int length = glp_get_mat_row(mlp->prob, mlp->r_q[c_ats_entry], ind, val);
1258 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "cols %i, length %i c_b %i\n", cols, length, mlpi->c_b); 1258 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "cols %i, length %i c_b %i\n", cols, length, mlpi->c_b);
1259 int c4; 1259 int c4;
1260 /* Get the index if matrix row of quality */ 1260 /* Get the index if matrix row of quality */
@@ -1264,11 +1264,11 @@ mlp_update_quality (struct GAS_MLP_Handle *mlp, struct ATS_Address * address,
1264 { 1264 {
1265 /* Update the value */ 1265 /* Update the value */
1266 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Updating quality `%s' column `%s' row `%s' : %f -> %f\n", 1266 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Updating quality `%s' column `%s' row `%s' : %f -> %f\n",
1267 mlp_ats_to_string(mlp->q[c]), 1267 mlp_ats_to_string(mlp->q[c_ats_entry]),
1268 glp_get_col_name (mlp->prob, ind[c4]), 1268 glp_get_col_name (mlp->prob, ind[c4]),
1269 glp_get_row_name (mlp->prob, mlp->r_q[c]), 1269 glp_get_row_name (mlp->prob, mlp->r_q[c_ats_entry]),
1270 val[c4], 1270 val[c4],
1271 mlpi->q_averaged[c]); 1271 mlpi->q_averaged[c_ats_entry]);
1272 val[c4] = mlpi->q_averaged[c]; 1272 val[c4] = mlpi->q_averaged[c];
1273 found = GNUNET_YES; 1273 found = GNUNET_YES;
1274 break; 1274 break;
@@ -1279,9 +1279,9 @@ mlp_update_quality (struct GAS_MLP_Handle *mlp, struct ATS_Address * address,
1279 { 1279 {
1280 1280
1281 ind[length+1] = mlpi->c_b; 1281 ind[length+1] = mlpi->c_b;
1282 val[length+1] = mlpi->q_averaged[c]; 1282 val[length+1] = mlpi->q_averaged[c_ats_entry];
1283 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%i ind[%i] val[%i]: %i %f\n", length+1, length+1, length+1, mlpi->c_b, mlpi->q_averaged[c]); 1283 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%i ind[%i] val[%i]: %i %f\n", length+1, length+1, length+1, mlpi->c_b, mlpi->q_averaged[c_ats_entry]);
1284 glp_set_mat_row (mlp->prob, mlpi->r_q[c], length+1, ind, val); 1284 glp_set_mat_row (mlp->prob, mlpi->r_q[c_ats_entry], length+1, ind, val);
1285 } 1285 }
1286 else 1286 else
1287 { 1287 {