aboutsummaryrefslogtreecommitdiff
path: root/src/ats/plugin_ats_mlp.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2015-02-10 23:24:01 +0000
committerChristian Grothoff <christian@grothoff.org>2015-02-10 23:24:01 +0000
commit1c323bd4cbb388a9e7515a1f733a3062bf093aee (patch)
tree7cc525d79149d44840b9f7a0040aaf3e69ecd665 /src/ats/plugin_ats_mlp.c
parentaedaaed687db1ff20b447378f01ad7306921450c (diff)
downloadgnunet-1c323bd4cbb388a9e7515a1f733a3062bf093aee.tar.gz
gnunet-1c323bd4cbb388a9e7515a1f733a3062bf093aee.zip
fixing #3657 (replace ATS_Information with struct), but WIHTOUT fixing ATS testcases yet
Diffstat (limited to 'src/ats/plugin_ats_mlp.c')
-rw-r--r--src/ats/plugin_ats_mlp.c230
1 files changed, 93 insertions, 137 deletions
diff --git a/src/ats/plugin_ats_mlp.c b/src/ats/plugin_ats_mlp.c
index b97261d46..7d402044f 100644
--- a/src/ats/plugin_ats_mlp.c
+++ b/src/ats/plugin_ats_mlp.c
@@ -62,6 +62,29 @@ enum MLP_Output_Format
62}; 62};
63 63
64 64
65enum QualityMetrics
66{
67 RQ_QUALITY_METRIC_DELAY = 0,
68 RQ_QUALITY_METRIC_DISTANCE = 1,
69 RQ_QUALITY_METRIC_COUNT = 2
70};
71
72
73static const char *
74print_quality_type (enum QualityMetrics qm)
75{
76 switch (qm){
77 case RQ_QUALITY_METRIC_DELAY:
78 return "delay";
79 case RQ_QUALITY_METRIC_DISTANCE:
80 return "distance";
81 default:
82 GNUNET_break (0);
83 return NULL;
84 }
85}
86
87
65struct MLP_Solution 88struct MLP_Solution
66{ 89{
67 int lp_res; 90 int lp_res;
@@ -125,7 +148,7 @@ struct MLP_Problem
125 /* Row index constraint 9: relativity*/ 148 /* Row index constraint 9: relativity*/
126 unsigned int r_c9; 149 unsigned int r_c9;
127 /* Row indices quality metrics */ 150 /* Row indices quality metrics */
128 int r_q[GNUNET_ATS_QualityPropertiesCount]; 151 int r_q[RQ_QUALITY_METRIC_COUNT];
129 /* Row indices ATS network quotas */ 152 /* Row indices ATS network quotas */
130 int r_quota[GNUNET_ATS_NetworkTypeCount]; 153 int r_quota[GNUNET_ATS_NetworkTypeCount];
131 154
@@ -136,7 +159,7 @@ struct MLP_Problem
136 /* Column index Proportionality (R) column */ 159 /* Column index Proportionality (R) column */
137 int c_r; 160 int c_r;
138 /* Column index quality metrics */ 161 /* Column index quality metrics */
139 int c_q[GNUNET_ATS_QualityPropertiesCount]; 162 int c_q[RQ_QUALITY_METRIC_COUNT];
140 163
141 /* Problem matrix */ 164 /* Problem matrix */
142 /* Current index */ 165 /* Current index */
@@ -161,23 +184,17 @@ struct MLP_Variables
161 /* LP MIP Gap */ 184 /* LP MIP Gap */
162 double lp_mip_gap; 185 double lp_mip_gap;
163 186
164 /* ATS Quality metrics 187 /* Number of quality metrics @deprecated, use RQ_QUALITY_METRIC_COUNT */
165 *
166 * Array with GNUNET_ATS_QualityPropertiesCount elements
167 * contains mapping to GNUNET_ATS_Property*/
168 int q[GNUNET_ATS_QualityPropertiesCount];
169
170 /* Number of quality metrics */
171 int m_q; 188 int m_q;
172 189
173 /* Number of quality metrics */ 190 /* Number of quality metrics */
174 int m_rc; 191 int m_rc;
175 192
176 /* Quality metric coefficients*/ 193 /* Quality metric coefficients*/
177 double co_Q[GNUNET_ATS_QualityPropertiesCount]; 194 double co_Q[RQ_QUALITY_METRIC_COUNT];
178 195
179 /* Ressource costs coefficients*/ 196 /* Ressource costs coefficients*/
180 double co_RC[GNUNET_ATS_QualityPropertiesCount]; 197 double co_RC[RQ_QUALITY_METRIC_COUNT];
181 198
182 /* Diversity coefficient */ 199 /* Diversity coefficient */
183 double co_D; 200 double co_D;
@@ -207,7 +224,7 @@ struct MLP_Variables
207 * array with GNUNET_ATS_QualityPropertiesCount elements 224 * array with GNUNET_ATS_QualityPropertiesCount elements
208 * contains mapping to GNUNET_ATS_Property 225 * contains mapping to GNUNET_ATS_Property
209 * */ 226 * */
210 int rc[GNUNET_ATS_QualityPropertiesCount]; 227 int rc[RQ_QUALITY_METRIC_COUNT];
211 228
212}; 229};
213 230
@@ -584,7 +601,7 @@ mlp_delete_problem (struct GAS_MLP_Handle *mlp)
584 mlp->p.r_c4 = MLP_UNDEFINED; 601 mlp->p.r_c4 = MLP_UNDEFINED;
585 mlp->p.r_c6 = MLP_UNDEFINED; 602 mlp->p.r_c6 = MLP_UNDEFINED;
586 mlp->p.r_c9 = MLP_UNDEFINED; 603 mlp->p.r_c9 = MLP_UNDEFINED;
587 for (c = 0; c < mlp->pv.m_q ; c ++) 604 for (c = 0; c < RQ_QUALITY_METRIC_COUNT ; c ++)
588 mlp->p.r_q[c] = MLP_UNDEFINED; 605 mlp->p.r_q[c] = MLP_UNDEFINED;
589 for (c = 0; c < GNUNET_ATS_NetworkTypeCount; c ++) 606 for (c = 0; c < GNUNET_ATS_NetworkTypeCount; c ++)
590 mlp->p.r_quota[c] = MLP_UNDEFINED; 607 mlp->p.r_quota[c] = MLP_UNDEFINED;
@@ -679,30 +696,6 @@ mlp_solve_to_string (int retcode)
679 } 696 }
680} 697}
681 698
682/**
683 * Extract an ATS performance info from an address
684 *
685 * @param address the address
686 * @param type the type to extract in HBO
687 * @return the value in HBO or GNUNET_ATS_VALUE_UNDEFINED in HBO if value does not exist
688 */
689static uint32_t
690get_performance_info (struct ATS_Address *address, uint32_t type)
691{
692 int c1;
693 GNUNET_assert (NULL != address);
694
695 if ((NULL == address->atsi) || (0 == address->atsi_count))
696 return GNUNET_ATS_VALUE_UNDEFINED;
697
698 for (c1 = 0; c1 < address->atsi_count; c1++)
699 {
700 if (ntohl (address->atsi[c1].type) == type)
701 return ntohl (address->atsi[c1].value);
702 }
703 return GNUNET_ATS_VALUE_UNDEFINED;
704}
705
706 699
707struct CountContext 700struct CountContext
708{ 701{
@@ -960,7 +953,6 @@ mlp_create_problem_add_address_information (void *cls,
960 struct ATS_Peer *peer; 953 struct ATS_Peer *peer;
961 struct MLP_information *mlpi; 954 struct MLP_information *mlpi;
962 char *name; 955 char *name;
963 double prop;
964 double cur_bigm; 956 double cur_bigm;
965 uint32_t addr_net; 957 uint32_t addr_net;
966 uint32_t addr_net_index; 958 uint32_t addr_net_index;
@@ -979,7 +971,7 @@ mlp_create_problem_add_address_information (void *cls,
979 return GNUNET_OK; 971 return GNUNET_OK;
980 } 972 }
981 973
982 addr_net = get_performance_info (address, GNUNET_ATS_NETWORK_TYPE); 974 addr_net = address->properties.scope;
983 for (addr_net_index = 0; addr_net_index < GNUNET_ATS_NetworkTypeCount; addr_net_index++) 975 for (addr_net_index = 0; addr_net_index < GNUNET_ATS_NetworkTypeCount; addr_net_index++)
984 { 976 {
985 if (mlp->pv.quota_index[addr_net_index] == addr_net) 977 if (mlp->pv.quota_index[addr_net_index] == addr_net)
@@ -1110,22 +1102,16 @@ mlp_create_problem_add_address_information (void *cls,
1110 /* For all quality metrics, set quality of this address */ 1102 /* For all quality metrics, set quality of this address */
1111 if (GNUNET_YES == mlp->opt_dbg_optimize_quality) 1103 if (GNUNET_YES == mlp->opt_dbg_optimize_quality)
1112 { 1104 {
1113 for (c = 0; c < mlp->pv.m_q; c++) 1105 mlp_create_problem_set_value (p,
1114 { 1106 p->r_q[RQ_QUALITY_METRIC_DELAY],
1115 prop = address->atsin[c].norm; 1107 mlpi->c_b,
1116 if ((prop < 1.0) && (prop > 2.0)) 1108 address->norm_delay.norm,
1117 { 1109 __LINE__);
1118 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1110 mlp_create_problem_set_value (p,
1119 "PROP == %.3f \t ", 1111 p->r_q[RQ_QUALITY_METRIC_DISTANCE],
1120 prop); 1112 mlpi->c_b,
1121 GNUNET_break (0); 1113 address->norm_distance.norm,
1122 } 1114 __LINE__);
1123 mlp_create_problem_set_value (p,
1124 p->r_q[c],
1125 mlpi->c_b,
1126 prop,
1127 __LINE__);
1128 }
1129 } 1115 }
1130 } 1116 }
1131 1117
@@ -1183,11 +1169,14 @@ mlp_create_problem_add_invariant_rows (struct GAS_MLP_Handle *mlp, struct MLP_Pr
1183 { 1169 {
1184 for (c = 0; c < mlp->pv.m_q; c++) 1170 for (c = 0; c < mlp->pv.m_q; c++)
1185 { 1171 {
1186 GNUNET_asprintf (&name, "c7_q%i_%s", c, 1172 GNUNET_asprintf (&name,
1187 GNUNET_ATS_print_property_type (mlp->pv.q[c])); 1173 "c7_q%i_%s", c,
1174 print_quality_type (c));
1188 p->r_q[c] = mlp_create_problem_create_constraint (p, name, GLP_FX, 0.0, 0.0); 1175 p->r_q[c] = mlp_create_problem_create_constraint (p, name, GLP_FX, 0.0, 0.0);
1189 GNUNET_free (name); 1176 GNUNET_free (name);
1190 mlp_create_problem_set_value (p, p->r_q[c], p->c_q[c], -1, __LINE__); 1177 mlp_create_problem_set_value (p,
1178 p->r_q[c],
1179 p->c_q[c], -1, __LINE__);
1191 } 1180 }
1192 } 1181 }
1193 } 1182 }
@@ -1222,7 +1211,7 @@ mlp_create_problem_add_invariant_columns (struct GAS_MLP_Handle *mlp, struct MLP
1222 { 1211 {
1223 for (c = 0; c < mlp->pv.m_q; c++) 1212 for (c = 0; c < mlp->pv.m_q; c++)
1224 { 1213 {
1225 GNUNET_asprintf (&name, "q_%u", mlp->pv.q[c]); 1214 GNUNET_asprintf (&name, "q_%u", c);
1226 p->c_q[c] = mlp_create_problem_create_column (p, name, GLP_CV, GLP_LO, 0.0, 0.0, mlp->pv.co_Q[c]); 1215 p->c_q[c] = mlp_create_problem_create_column (p, name, GLP_CV, GLP_LO, 0.0, 0.0, mlp->pv.co_Q[c]);
1227 GNUNET_free (name); 1216 GNUNET_free (name);
1228 } 1217 }
@@ -1866,13 +1855,10 @@ GAS_mlp_address_add (void *solver,
1866{ 1855{
1867 struct GAS_MLP_Handle *mlp = solver; 1856 struct GAS_MLP_Handle *mlp = solver;
1868 1857
1869 GNUNET_assert (NULL != solver);
1870 GNUNET_assert (NULL != address);
1871
1872 if (GNUNET_ATS_NetworkTypeCount <= network) 1858 if (GNUNET_ATS_NetworkTypeCount <= network)
1873 { 1859 {
1874 GNUNET_break (0); 1860 GNUNET_break (0);
1875 return; 1861 return;
1876 } 1862 }
1877 1863
1878 if (NULL == address->solver_information) 1864 if (NULL == address->solver_information)
@@ -1911,36 +1897,23 @@ GAS_mlp_address_add (void *solver,
1911 * 1897 *
1912 * @param solver solver handle 1898 * @param solver solver handle
1913 * @param address the address 1899 * @param address the address
1914 * @param type the ATSI type in HBO
1915 * @param abs_value the absolute value of the property
1916 * @param rel_value the normalized value
1917 */ 1900 */
1918static void 1901static void
1919GAS_mlp_address_property_changed (void *solver, 1902GAS_mlp_address_property_changed (void *solver,
1920 struct ATS_Address *address, 1903 struct ATS_Address *address)
1921 enum GNUNET_ATS_Property type,
1922 uint32_t abs_value,
1923 double rel_value)
1924{ 1904{
1925 struct MLP_information *mlpi = address->solver_information; 1905 struct MLP_information *mlpi = address->solver_information;
1926 struct GAS_MLP_Handle *mlp = solver; 1906 struct GAS_MLP_Handle *mlp = solver;
1927 int c1;
1928 int type_index;
1929
1930 GNUNET_assert (NULL != solver);
1931 GNUNET_assert (NULL != address);
1932 1907
1933 if (NULL == mlpi) 1908 if (NULL == mlpi)
1934 { 1909 {
1935 LOG (GNUNET_ERROR_TYPE_INFO, 1910 LOG (GNUNET_ERROR_TYPE_INFO,
1936 _("Updating address property `%s' for peer `%s' %p not added before\n"), 1911 _("Updating address property for peer `%s' %p not added before\n"),
1937 GNUNET_ATS_print_property_type (type), 1912 GNUNET_i2s (&address->peer),
1938 GNUNET_i2s(&address->peer), 1913 address);
1939 address); 1914 GNUNET_break (0);
1940 GNUNET_break (0); 1915 return;
1941 return;
1942 } 1916 }
1943
1944 if (NULL == 1917 if (NULL ==
1945 GNUNET_CONTAINER_multipeermap_get (mlp->requested_peers, 1918 GNUNET_CONTAINER_multipeermap_get (mlp->requested_peers,
1946 &address->peer)) 1919 &address->peer))
@@ -1948,34 +1921,26 @@ GAS_mlp_address_property_changed (void *solver,
1948 /* Peer is not requested, so no need to update problem */ 1921 /* Peer is not requested, so no need to update problem */
1949 return; 1922 return;
1950 } 1923 }
1951 LOG (GNUNET_ERROR_TYPE_INFO, "Updating property `%s' address for peer `%s' to abs %llu rel %.3f\n", 1924 LOG (GNUNET_ERROR_TYPE_DEBUG,
1952 GNUNET_ATS_print_property_type (type), 1925 "Updating properties for peer `%s'\n",
1953 GNUNET_i2s(&address->peer), 1926 GNUNET_i2s(&address->peer));
1954 abs_value,
1955 rel_value);
1956 1927
1957 if (GNUNET_YES == mlp->opt_dbg_feasibility_only) 1928 if (GNUNET_YES == mlp->opt_dbg_feasibility_only)
1958 return; 1929 return;
1959 1930
1960 /* Find row index */
1961 type_index = -1;
1962 for (c1 = 0; c1 < mlp->pv.m_q; c1++)
1963 {
1964 if (type == mlp->pv.q[c1])
1965 {
1966 type_index = c1;
1967 break;
1968 }
1969 }
1970 if (-1 == type_index)
1971 {
1972 GNUNET_break (0);
1973 return; /* quality index not found */
1974 }
1975
1976 /* Update c7) [r_q[index]][c_b] = f_q * q_averaged[type_index] */ 1931 /* Update c7) [r_q[index]][c_b] = f_q * q_averaged[type_index] */
1977 if (GNUNET_YES == mlp_create_problem_update_value (&mlp->p, 1932 if ( (GNUNET_YES ==
1978 mlp->p.r_q[type_index], mlpi->c_b, rel_value, __LINE__)) 1933 mlp_create_problem_update_value (&mlp->p,
1934 mlp->p.r_q[RQ_QUALITY_METRIC_DELAY],
1935 mlpi->c_b,
1936 address->norm_delay.norm,
1937 __LINE__)) ||
1938 (GNUNET_YES ==
1939 mlp_create_problem_update_value (&mlp->p,
1940 mlp->p.r_q[RQ_QUALITY_METRIC_DISTANCE],
1941 mlpi->c_b,
1942 address->norm_distance.norm,
1943 __LINE__)) )
1979 { 1944 {
1980 mlp->stat_mlp_prob_updated = GNUNET_YES; 1945 mlp->stat_mlp_prob_updated = GNUNET_YES;
1981 if (GNUNET_YES == mlp->opt_mlp_auto_solve) 1946 if (GNUNET_YES == mlp->opt_mlp_auto_solve)
@@ -2037,17 +2002,14 @@ get_peer_pref_value (struct GAS_MLP_Handle *mlp,
2037 2002
2038 preferences = mlp->env->get_preferences (mlp->env->cls, peer); 2003 preferences = mlp->env->get_preferences (mlp->env->cls, peer);
2039 res = 0.0; 2004 res = 0.0;
2040 for (c = 0; c < GNUNET_ATS_PreferenceCount; c++) 2005 for (c = 0; c < GNUNET_ATS_PREFERENCE_END; c++)
2041 { 2006 {
2042 if (c != GNUNET_ATS_PREFERENCE_END) 2007 /* fprintf (stderr, "VALUE[%u] %s %.3f \n",
2043 { 2008 * c, GNUNET_i2s (&cur->addr->peer), t[c]); */
2044 /* fprintf (stderr, "VALUE[%u] %s %.3f \n", 2009 res += preferences[c];
2045 * c, GNUNET_i2s (&cur->addr->peer), t[c]); */
2046 res += preferences[c];
2047 }
2048 } 2010 }
2049 2011
2050 res /= (GNUNET_ATS_PreferenceCount -1); 2012 res /= GNUNET_ATS_PREFERENCE_END;
2051 res += 1.0; 2013 res += 1.0;
2052 2014
2053 LOG (GNUNET_ERROR_TYPE_DEBUG, 2015 LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -2646,34 +2608,28 @@ libgnunet_plugin_ats_mlp_init (void *cls)
2646 } 2608 }
2647 2609
2648 /* Get quality metric coefficients from configuration */ 2610 /* Get quality metric coefficients from configuration */
2649 int i_delay = MLP_NaN; 2611 for (c = 0; c < RQ_QUALITY_METRIC_COUNT; c++)
2650 int i_distance = MLP_NaN;
2651 int q[GNUNET_ATS_QualityPropertiesCount] = GNUNET_ATS_QualityProperties;
2652 for (c = 0; c < GNUNET_ATS_QualityPropertiesCount; c++)
2653 { 2612 {
2654 /* initialize quality coefficients with default value 1.0 */ 2613 /* initialize quality coefficients with default value 1.0 */
2655 mlp->pv.co_Q[c] = MLP_DEFAULT_QUALITY; 2614 mlp->pv.co_Q[c] = MLP_DEFAULT_QUALITY;
2656
2657 mlp->pv.q[c] = q[c];
2658 if (q[c] == GNUNET_ATS_QUALITY_NET_DELAY)
2659 i_delay = c;
2660 if (q[c] == GNUNET_ATS_QUALITY_NET_DISTANCE)
2661 i_distance = c;
2662 } 2615 }
2663 2616
2664 if ( (i_delay != MLP_NaN) && 2617
2665 (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (env->cfg, "ats", 2618 if (GNUNET_OK ==
2666 "MLP_COEFFICIENT_QUALITY_DELAY", &tmp)) ) 2619 GNUNET_CONFIGURATION_get_value_size (env->cfg, "ats",
2667 mlp->pv.co_Q[i_delay] = (double) tmp / 100; 2620 "MLP_COEFFICIENT_QUALITY_DELAY",
2621 &tmp))
2622 mlp->pv.co_Q[RQ_QUALITY_METRIC_DELAY] = (double) tmp / 100;
2668 else 2623 else
2669 mlp->pv.co_Q[i_delay] = MLP_DEFAULT_QUALITY; 2624 mlp->pv.co_Q[RQ_QUALITY_METRIC_DELAY] = MLP_DEFAULT_QUALITY;
2670 2625
2671 if ( (i_distance != MLP_NaN) && 2626 if (GNUNET_OK ==
2672 (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (env->cfg, "ats", 2627 GNUNET_CONFIGURATION_get_value_size (env->cfg, "ats",
2673 "MLP_COEFFICIENT_QUALITY_DISTANCE", &tmp)) ) 2628 "MLP_COEFFICIENT_QUALITY_DISTANCE",
2674 mlp->pv.co_Q[i_distance] = (double) tmp / 100; 2629 &tmp))
2630 mlp->pv.co_Q[RQ_QUALITY_METRIC_DISTANCE] = (double) tmp / 100;
2675 else 2631 else
2676 mlp->pv.co_Q[i_distance] = MLP_DEFAULT_QUALITY; 2632 mlp->pv.co_Q[RQ_QUALITY_METRIC_DISTANCE] = MLP_DEFAULT_QUALITY;
2677 2633
2678 /* Get minimum bandwidth per used address from configuration */ 2634 /* Get minimum bandwidth per used address from configuration */
2679 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (env->cfg, "ats", 2635 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (env->cfg, "ats",
@@ -2759,7 +2715,7 @@ libgnunet_plugin_ats_mlp_init (void *cls)
2759 /* Setting MLP Input variables */ 2715 /* Setting MLP Input variables */
2760 mlp->pv.b_min = b_min; 2716 mlp->pv.b_min = b_min;
2761 mlp->pv.n_min = n_min; 2717 mlp->pv.n_min = n_min;
2762 mlp->pv.m_q = GNUNET_ATS_QualityPropertiesCount; 2718 mlp->pv.m_q = RQ_QUALITY_METRIC_COUNT;
2763 mlp->stat_mlp_prob_changed = GNUNET_NO; 2719 mlp->stat_mlp_prob_changed = GNUNET_NO;
2764 mlp->stat_mlp_prob_updated = GNUNET_NO; 2720 mlp->stat_mlp_prob_updated = GNUNET_NO;
2765 mlp->opt_mlp_auto_solve = GNUNET_YES; 2721 mlp->opt_mlp_auto_solve = GNUNET_YES;