aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2013-02-25 10:02:21 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2013-02-25 10:02:21 +0000
commit2a72aaba9f1eab7bff73c67c531c43e8e8562c73 (patch)
treeb74776553726510da4ef15139f40e0e71897491b /src
parente96241b427a96832b5f145612dc1e1d5e4f5294f (diff)
downloadgnunet-2a72aaba9f1eab7bff73c67c531c43e8e8562c73.tar.gz
gnunet-2a72aaba9f1eab7bff73c67c531c43e8e8562c73.zip
changes
Diffstat (limited to 'src')
-rw-r--r--src/ats/gnunet-service-ats_addresses_mlp.c111
1 files changed, 62 insertions, 49 deletions
diff --git a/src/ats/gnunet-service-ats_addresses_mlp.c b/src/ats/gnunet-service-ats_addresses_mlp.c
index 4358c5cf4..d5ea73519 100644
--- a/src/ats/gnunet-service-ats_addresses_mlp.c
+++ b/src/ats/gnunet-service-ats_addresses_mlp.c
@@ -154,8 +154,16 @@ mlp_term_hook (void *info, const char *s)
154} 154}
155 155
156 156
157 static int 157/**
158 reset_peers (void *cls, const struct GNUNET_HashCode * key, void *value) 158 * Reset peers for next problem creation
159 *
160 * @param cls not used
161 * @param key the key
162 * @param value ATS_Peer
163 * @return GNUNET_OK
164 */
165static int
166reset_peers (void *cls, const struct GNUNET_HashCode * key, void *value)
159 { 167 {
160 struct ATS_Peer *peer = value; 168 struct ATS_Peer *peer = value;
161 peer->processed = GNUNET_NO; 169 peer->processed = GNUNET_NO;
@@ -373,29 +381,6 @@ mlp_lookup_ats (struct ATS_Address *addr, int ats_index)
373} 381}
374#endif 382#endif
375 383
376int GAS_mlp_solve_problem (void *solver, struct GAS_MLP_SolutionContext *ctx);
377
378
379static void
380mlp_scheduler (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
381{
382 struct GAS_MLP_Handle *mlp = cls;
383 struct GAS_MLP_SolutionContext ctx;
384
385 mlp->mlp_task = GNUNET_SCHEDULER_NO_TASK;
386
387 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
388 return;
389
390 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Scheduled problem solving\n");
391
392 if (mlp->num_addresses != 0)
393 GAS_mlp_solve_problem(mlp, &ctx);
394}
395
396
397
398
399static void 384static void
400update_quality (struct GAS_MLP_Handle *mlp, struct ATS_Address * address) 385update_quality (struct GAS_MLP_Handle *mlp, struct ATS_Address * address)
401{ 386{
@@ -805,10 +790,14 @@ static int mlp_create_problem_count_addresses (
805 790
806 791
807static void 792static void
808mlp_create_problem_set_value (struct MLP_Problem *p, int row, int col, double val) 793mlp_create_problem_set_value (struct MLP_Problem *p,
794 int row, int col, double val,
795 int line)
809{ 796{
810 if ((p->ci + 1) >= p->num_elements) 797 if ((p->ci) >= p->num_elements)
811 { 798 {
799 LOG (GNUNET_ERROR_TYPE_DEBUG, "[P]: line %u: Request for index %u bigger than array size of %u\n",
800 line, p->ci + 1, p->num_elements);
812 GNUNET_break (0); 801 GNUNET_break (0);
813 return; 802 return;
814 } 803 }
@@ -818,8 +807,8 @@ mlp_create_problem_set_value (struct MLP_Problem *p, int row, int col, double va
818 p->ja[p->ci] = col; 807 p->ja[p->ci] = col;
819 p->ar[p->ci] = val; 808 p->ar[p->ci] = val;
820#if DEBUG_MLP_PROBLEM_CREATION 809#if DEBUG_MLP_PROBLEM_CREATION
821 LOG (GNUNET_ERROR_TYPE_DEBUG, "[P]: Set value [%u,%u] == %.2f\n", 810 LOG (GNUNET_ERROR_TYPE_DEBUG, "[P]: line %u: Set value [%u,%u] in index %u == %.2f\n",
822 p->ia[p->ci], p->ja[p->ci], p->ar[p->ci]); 811 line, p->ia[p->ci], p->ja[p->ci], p->ci, p->ar[p->ci]);
823#endif 812#endif
824 p->ci++; 813 p->ci++;
825} 814}
@@ -892,6 +881,7 @@ mlp_create_problem_add_address_information (void *cls, const struct GNUNET_HashC
892 struct ATS_Peer *peer; 881 struct ATS_Peer *peer;
893 struct MLP_information *mlpi; 882 struct MLP_information *mlpi;
894 char *name; 883 char *name;
884 int c;
895 885
896 /* Check if we have to add this peer due to a pending request */ 886 /* Check if we have to add this peer due to a pending request */
897 if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains(mlp->peers, key)) 887 if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains(mlp->peers, key))
@@ -911,7 +901,7 @@ mlp_create_problem_add_address_information (void *cls, const struct GNUNET_HashC
911 peer->r_c9 = mlp_create_problem_create_constraint (p, name, GLP_LO, 0.0, 0.0); 901 peer->r_c9 = mlp_create_problem_create_constraint (p, name, GLP_LO, 0.0, 0.0);
912 GNUNET_free (name); 902 GNUNET_free (name);
913 /* c 9) set coefficient */ 903 /* c 9) set coefficient */
914 mlp_create_problem_set_value (p, peer->r_c9, p->c_r, -peer->f); 904 mlp_create_problem_set_value (p, peer->r_c9, p->c_r, -peer->f, __LINE__);
915 905
916 peer->processed = GNUNET_YES; 906 peer->processed = GNUNET_YES;
917 } 907 }
@@ -945,9 +935,9 @@ mlp_create_problem_add_address_information (void *cls, const struct GNUNET_HashC
945 GNUNET_free (name); 935 GNUNET_free (name);
946 936
947 /* c1) set b = 1 coefficient */ 937 /* c1) set b = 1 coefficient */
948 mlp_create_problem_set_value (p, mlpi->r_c1, mlpi->c_b, 1); 938 mlp_create_problem_set_value (p, mlpi->r_c1, mlpi->c_b, 1, __LINE__);
949 /* c1) set n = -M coefficient */ 939 /* c1) set n = -M coefficient */
950 mlp_create_problem_set_value (p, mlpi->r_c1, mlpi->c_n, -mlp->pv.BIG_M); 940 mlp_create_problem_set_value (p, mlpi->r_c1, mlpi->c_n, -mlp->pv.BIG_M, __LINE__);
951 941
952 /* Add constraint c 3) minimum bandwidth 942 /* Add constraint c 3) minimum bandwidth
953 * b_t + (-n_t * b_min) >= 0 943 * b_t + (-n_t * b_min) >= 0
@@ -957,36 +947,57 @@ mlp_create_problem_add_address_information (void *cls, const struct GNUNET_HashC
957 GNUNET_free (name); 947 GNUNET_free (name);
958 948
959 /* c3) set b = 1 coefficient */ 949 /* c3) set b = 1 coefficient */
960 mlp_create_problem_set_value (p, mlpi->r_c3, mlpi->c_b, 1); 950 mlp_create_problem_set_value (p, mlpi->r_c3, mlpi->c_b, 1, __LINE__);
961 /* c3) set n = -b_min coefficient */ 951 /* c3) set n = -b_min coefficient */
962 mlp_create_problem_set_value (p, mlpi->r_c3, mlpi->c_n, -mlp->pv.b_min); 952 mlp_create_problem_set_value (p, mlpi->r_c3, mlpi->c_n, -mlp->pv.b_min, __LINE__);
963 953
964 954
965 /* Set coefficient entries in invariant rows */ 955 /* Set coefficient entries in invariant rows */
966 /* c 4) minimum connections */ 956 /* c 4) minimum connections */
967 mlp_create_problem_set_value (p, p->r_c4, mlpi->c_n, 1); 957 mlp_create_problem_set_value (p, p->r_c4, mlpi->c_n, 1, __LINE__);
968 /* c 6) maximize diversity */ 958 /* c 6) maximize diversity */
969 mlp_create_problem_set_value (p, p->r_c6, mlpi->c_n, 1); 959 mlp_create_problem_set_value (p, p->r_c6, mlpi->c_n, 1, __LINE__);
970 /* c 2) 1 address peer peer */ 960 /* c 2) 1 address peer peer */
971 mlp_create_problem_set_value (p, peer->r_c2, mlpi->c_n, 1); 961 mlp_create_problem_set_value (p, peer->r_c2, mlpi->c_n, 1, __LINE__);
972 /* c 9) relativity */ 962 /* c 9) relativity */
973 mlp_create_problem_set_value (p, peer->r_c9, mlpi->c_b, 1); 963 mlp_create_problem_set_value (p, peer->r_c9, mlpi->c_b, 1, __LINE__);
974 /* c 8) utility */ 964 /* c 8) utility */
975 mlp_create_problem_set_value (p, p->r_c8, mlpi->c_b, 1); 965 mlp_create_problem_set_value (p, p->r_c8, mlpi->c_b, 1, __LINE__);
976 966
977 /* c 10) obey network specific quotas 967 /* c 10) obey network specific quotas
978 * (1)*b_1 + ... + (1)*b_m <= quota_n 968 * (1)*b_1 + ... + (1)*b_m <= quota_n
979 */ 969 */
980 int c;
981 for (c = 0; c < GNUNET_ATS_NetworkTypeCount; c++) 970 for (c = 0; c < GNUNET_ATS_NetworkTypeCount; c++)
982 { 971 {
983 if (mlp->pv.quota_index[c] == address->atsp_network_type) 972 if (mlp->pv.quota_index[c] == address->atsp_network_type)
984 { 973 {
985 mlp_create_problem_set_value (p, p->r_quota[c], mlpi->c_b, 1); 974 mlp_create_problem_set_value (p, p->r_quota[c], mlpi->c_b, 1, __LINE__);
986 break; 975 break;
987 } 976 }
988 } 977 }
989 978
979 /* c 7) Optimize quality */
980 /* For all quality metrics, set quality of this address */
981 for (c = 0; c < mlp->pv.m_q; c++)
982 {
983#if 0
984 mlpi = ta->solver_information;
985 value = mlpi->q_averaged[c];
986
987 mlpi->r_q[c] = p->r_q[c];
988
989 ia[p->ci] = p->r_q[c];
990 ja[p->ci] = mlpi->c_b;
991 ar[p->ci] = tp->f_q[c] * value;
992#if DEBUG_MLP_PROBLEM_CREATION
993 LOG (GNUNET_ERROR_TYPE_DEBUG, "[P]: Set value [%u,%u] == %.2f\n",
994 p->ia[p->ci], p->ja[p->ci], p->ar[p->ci]);
995#endif
996#endif
997 mlp_create_problem_set_value (p, p->r_q[c], mlpi->c_b, mlpi->q_averaged[c], __LINE__);
998 }
999
1000
990 return GNUNET_OK; 1001 return GNUNET_OK;
991} 1002}
992 1003
@@ -1007,7 +1018,7 @@ mlp_create_problem_add_invariant_rows (struct GAS_MLP_Handle *mlp, struct MLP_Pr
1007 /* Add row for c6) */ 1018 /* Add row for c6) */
1008 p->r_c6 = mlp_create_problem_create_constraint (p, "c6", GLP_FX, 0.0, 0.0); 1019 p->r_c6 = mlp_create_problem_create_constraint (p, "c6", GLP_FX, 0.0, 0.0);
1009 /* c6 )Setting -D */ 1020 /* c6 )Setting -D */
1010 mlp_create_problem_set_value (p, p->r_c6, p->c_d, -1); 1021 mlp_create_problem_set_value (p, p->r_c6, p->c_d, -1, __LINE__);
1011 1022
1012 /* Add rows for c 10) */ 1023 /* Add rows for c 10) */
1013 for (c = 0; c < GNUNET_ATS_NetworkTypeCount; c++) 1024 for (c = 0; c < GNUNET_ATS_NetworkTypeCount; c++)
@@ -1021,7 +1032,7 @@ mlp_create_problem_add_invariant_rows (struct GAS_MLP_Handle *mlp, struct MLP_Pr
1021 /* Adding rows for c 8) */ 1032 /* Adding rows for c 8) */
1022 p->r_c8 = mlp_create_problem_create_constraint (p, "c8", GLP_FX, 0.0, 0.0); 1033 p->r_c8 = mlp_create_problem_create_constraint (p, "c8", GLP_FX, 0.0, 0.0);
1023 /* -u */ 1034 /* -u */
1024 mlp_create_problem_set_value (p, p->r_c8, p->c_u, -1); 1035 mlp_create_problem_set_value (p, p->r_c8, p->c_u, -1, __LINE__);
1025 1036
1026 /* c 7) For all quality metrics */ 1037 /* c 7) For all quality metrics */
1027 for (c = 0; c < mlp->pv.m_q; c++) 1038 for (c = 0; c < mlp->pv.m_q; c++)
@@ -1029,7 +1040,7 @@ mlp_create_problem_add_invariant_rows (struct GAS_MLP_Handle *mlp, struct MLP_Pr
1029 GNUNET_asprintf(&name, "c7_q%i_%s", c, mlp_ats_to_string(mlp->pv.q[c])); 1040 GNUNET_asprintf(&name, "c7_q%i_%s", c, mlp_ats_to_string(mlp->pv.q[c]));
1030 p->r_q[c] = mlp_create_problem_create_constraint (p, name, GLP_FX, 0.0, 0.0); 1041 p->r_q[c] = mlp_create_problem_create_constraint (p, name, GLP_FX, 0.0, 0.0);
1031 GNUNET_free (name); 1042 GNUNET_free (name);
1032 mlp_create_problem_set_value (p, p->r_q[c], p->c_q[c], -1); 1043 mlp_create_problem_set_value (p, p->r_q[c], p->c_q[c], -1, __LINE__);
1033 } 1044 }
1034} 1045}
1035 1046
@@ -1086,12 +1097,14 @@ mlp_create_problem (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_MultiHas
1086 GNUNET_assert (NULL != p->prob); 1097 GNUNET_assert (NULL != p->prob);
1087 p->num_peers = GNUNET_CONTAINER_multihashmap_size (mlp->peers); 1098 p->num_peers = GNUNET_CONTAINER_multihashmap_size (mlp->peers);
1088 p->num_addresses = mlp_create_problem_count_addresses (mlp->peers, addresses); 1099 p->num_addresses = mlp_create_problem_count_addresses (mlp->peers, addresses);
1089 p->num_elements = ((7 * p->num_addresses) + (5 * p->num_addresses + mlp->pv.m_q + p->num_peers + 2) + 1); 1100
1090 LOG (GNUNET_ERROR_TYPE_DEBUG, "Rebuilding problem for %u peer(s) and %u addresse(s) == %u elements\n", 1101 /* Create problem matrix: 10 * #addresses + #q * #addresses + #q, + #peer + 2 + 1 */
1091 p->num_peers, p->num_addresses, p->num_elements); 1102 p->num_elements = (10 * p->num_addresses + mlp->pv.m_q * p->num_addresses + mlp->pv.m_q + p->num_peers + 2 + 1);
1103 LOG (GNUNET_ERROR_TYPE_DEBUG, "Rebuilding problem for %u peer(s) and %u addresse(s) and %u quality metrics == %u elements\n",
1104 p->num_peers, p->num_addresses, mlp->pv.m_q, p->num_elements);
1092 1105
1093 /* Set a problem name */ 1106 /* Set a problem name */
1094 glp_set_prob_name (p->prob, "GNUnet ats bandwidth distribution"); 1107 glp_set_prob_name (p->prob, "GNUnet ATS bandwidth distribution");
1095 /* Set optimization direction to maximize */ 1108 /* Set optimization direction to maximize */
1096 glp_set_obj_dir (p->prob, GLP_MAX); 1109 glp_set_obj_dir (p->prob, GLP_MAX);
1097 1110