aboutsummaryrefslogtreecommitdiff
path: root/src/ats
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2012-01-19 17:29:18 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2012-01-19 17:29:18 +0000
commit3ffb89c725b34356c961bb827b5f83002d083191 (patch)
tree90fdd3573eb0dc86d78c833be84ff248e6dade81 /src/ats
parentac6004e54595513ceb3dd9e9eb75f728e2dc65fb (diff)
downloadgnunet-3ffb89c725b34356c961bb827b5f83002d083191.tar.gz
gnunet-3ffb89c725b34356c961bb827b5f83002d083191.zip
- latest changes
Diffstat (limited to 'src/ats')
-rw-r--r--src/ats/Makefile.am12
-rw-r--r--src/ats/gnunet-service-ats_addresses_mlp.c51
-rw-r--r--src/ats/gnunet-service-ats_addresses_mlp.h3
-rw-r--r--src/ats/perf_ats_mlp.c138
-rw-r--r--src/ats/test_ats_mlp.c4
5 files changed, 190 insertions, 18 deletions
diff --git a/src/ats/Makefile.am b/src/ats/Makefile.am
index 1f8a84a67..5b7e9a127 100644
--- a/src/ats/Makefile.am
+++ b/src/ats/Makefile.am
@@ -17,6 +17,7 @@ if HAVE_LIBGLPK
17 GN_LIBGLPK = -lglpk 17 GN_LIBGLPK = -lglpk
18 GN_MLP_SRC = gnunet-service-ats_addresses_mlp.c gnunet-service-ats_addresses_mlp.h 18 GN_MLP_SRC = gnunet-service-ats_addresses_mlp.c gnunet-service-ats_addresses_mlp.h
19 GN_MLP_TEST = test_ats_mlp 19 GN_MLP_TEST = test_ats_mlp
20 GN_MLP_PERF = perf_ats_mlp
20endif 21endif
21 22
22lib_LTLIBRARIES = libgnunetats.la 23lib_LTLIBRARIES = libgnunetats.la
@@ -52,7 +53,8 @@ gnunet_service_ats_LDADD = \
52 53
53check_PROGRAMS = \ 54check_PROGRAMS = \
54 test_ats_api_scheduling \ 55 test_ats_api_scheduling \
55 $(GN_MLP_TEST) 56 $(GN_MLP_TEST) \
57 $(GN_MLP_PERF)
56# test_ats_api_scheduling_get_type 58# test_ats_api_scheduling_get_type
57# test_ats_api_bandwidth_consumption 59# test_ats_api_bandwidth_consumption
58 60
@@ -68,6 +70,14 @@ test_ats_mlp_LDADD = \
68 $(GN_LIBGLPK) \ 70 $(GN_LIBGLPK) \
69 $(top_builddir)/src/util/libgnunetutil.la \ 71 $(top_builddir)/src/util/libgnunetutil.la \
70 $(top_builddir)/src/statistics/libgnunetstatistics.la 72 $(top_builddir)/src/statistics/libgnunetstatistics.la
73
74perf_ats_mlp_SOURCES = \
75 $(GN_MLP_SRC) \
76 perf_ats_mlp.c
77perf_ats_mlp_LDADD = \
78 $(GN_LIBGLPK) \
79 $(top_builddir)/src/util/libgnunetutil.la \
80 $(top_builddir)/src/statistics/libgnunetstatistics.la
71endif 81endif
72 82
73test_ats_api_scheduling_SOURCES = \ 83test_ats_api_scheduling_SOURCES = \
diff --git a/src/ats/gnunet-service-ats_addresses_mlp.c b/src/ats/gnunet-service-ats_addresses_mlp.c
index 17b4697d4..fa4d3a106 100644
--- a/src/ats/gnunet-service-ats_addresses_mlp.c
+++ b/src/ats/gnunet-service-ats_addresses_mlp.c
@@ -32,7 +32,7 @@
32#include "glpk.h" 32#include "glpk.h"
33 33
34#define WRITE_MLP GNUNET_NO 34#define WRITE_MLP GNUNET_NO
35#define DEBUG_ATS GNUNET_YES 35#define DEBUG_ATS GNUNET_NO
36#define VERBOSE_GLPK GNUNET_NO 36#define VERBOSE_GLPK GNUNET_NO
37 37
38/** 38/**
@@ -314,7 +314,7 @@ static void
314mlp_add_constraints_all_addresses (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_MultiHashMap * addresses) 314mlp_add_constraints_all_addresses (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_MultiHashMap * addresses)
315{ 315{
316 unsigned int n_addresses; 316 unsigned int n_addresses;
317 //int c; 317 int c;
318 char *name; 318 char *name;
319 319
320 /* Problem matrix*/ 320 /* Problem matrix*/
@@ -356,7 +356,7 @@ mlp_add_constraints_all_addresses (struct GAS_MLP_Handle *mlp, struct GNUNET_CON
356 * 356 *
357 * c 7) quality 357 * c 7) quality
358 * #rows: |quality properties| 358 * #rows: |quality properties|
359 * #indices:|quality properties| + |n_addresses| 359 * #indices: |n_addresses| + |quality properties|
360 * 360 *
361 * c 8) utilization 361 * c 8) utilization
362 * #rows: 1 362 * #rows: 1
@@ -367,7 +367,8 @@ mlp_add_constraints_all_addresses (struct GAS_MLP_Handle *mlp, struct GNUNET_CON
367 * #indices: |n_addresses| + |peers| 367 * #indices: |n_addresses| + |peers|
368 * */ 368 * */
369 369
370 int pi = ((7 * n_addresses) + (3 * n_addresses + mlp->m_q + 2)); 370 /* last +1 caused by glpk index starting with one */
371 int pi = ((7 * n_addresses) + (4 * n_addresses + mlp->m_q + mlp->c_p + 2) + 1);
371 mlp->cm_size = pi; 372 mlp->cm_size = pi;
372 mlp->ci = 1; 373 mlp->ci = 1;
373 374
@@ -453,7 +454,6 @@ mlp_add_constraints_all_addresses (struct GAS_MLP_Handle *mlp, struct GNUNET_CON
453 /* Set row bound == 1 */ 454 /* Set row bound == 1 */
454 glp_set_row_bnds (mlp->prob, peer->r_c2, GLP_FX, 1.0, 1.0); 455 glp_set_row_bnds (mlp->prob, peer->r_c2, GLP_FX, 1.0, 1.0);
455 456
456
457 /* Adding rows for c 9) */ 457 /* Adding rows for c 9) */
458 peer->r_c9 = glp_add_rows (mlp->prob, 1); 458 peer->r_c9 = glp_add_rows (mlp->prob, 1);
459 GNUNET_asprintf(&name, "c9_%s", GNUNET_i2s(&peer->id)); 459 GNUNET_asprintf(&name, "c9_%s", GNUNET_i2s(&peer->id));
@@ -492,23 +492,44 @@ mlp_add_constraints_all_addresses (struct GAS_MLP_Handle *mlp, struct GNUNET_CON
492 peer = peer->next; 492 peer = peer->next;
493 } 493 }
494 494
495 /* c 7) For all quality metrics */
495 496
496 /* For all quality metrics */
497/*
498 for (c = 0; c < mlp->m_q; c++) 497 for (c = 0; c < mlp->m_q; c++)
499 { 498 {
500 struct ATS_Peer *p = mlp->peer_head; 499 struct ATS_Peer *p = mlp->peer_head;
500 struct ATS_Address *addr = p->head;
501 struct MLP_information * mlpi;
502 double value = 1.0;
503
501 while (p != NULL) 504 while (p != NULL)
502 { 505 {
503 ia[mlp->ci] = row_index; 506 /* Adding rows for c 7) */
507 mlp->r_q[c] = glp_add_rows (mlp->prob, 1);
508 GNUNET_asprintf(&name, "c7_q%i_atsi_%i", c, mlp->q[c]);
509 glp_set_row_name (mlp->prob, mlp->r_q[c], name);
510 GNUNET_free (name);
511 /* Set row bound == 0 */
512 glp_set_row_bnds (mlp->prob, mlp->r_q[c], GLP_LO, 0.0, 0.0);
513
514 /* Set -q_m */
515 ia[mlp->ci] = mlp->r_q[c];
504 ja[mlp->ci] = mlp->c_q[c]; 516 ja[mlp->ci] = mlp->c_q[c];
505 ar[mlp->ci] = mlp->; 517 ar[mlp->ci] = -1;
506 mlp->ci++; 518 mlp->ci++;
507 519
520 while (addr != NULL)
521 {
522 mlpi = addr->mlp_information;
523 ia[mlp->ci] = mlp->r_q[c];
524 ja[mlp->ci] = mlpi->c_b;
525 ar[mlp->ci] = p->f * value;
526 mlp->ci++;
527
528 addr = addr->next;
529 }
508 p = p->next; 530 p = p->next;
509 } 531 }
510 } 532 }
511*/
512} 533}
513 534
514 535
@@ -575,12 +596,10 @@ static int
575mlp_create_problem (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_MultiHashMap * addresses) 596mlp_create_problem (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_MultiHashMap * addresses)
576{ 597{
577 int res = GNUNET_OK; 598 int res = GNUNET_OK;
578
579 int col; 599 int col;
580/*
581 int c; 600 int c;
582 char *name; 601 char *name;
583*/ 602
584 GNUNET_assert (mlp->prob == NULL); 603 GNUNET_assert (mlp->prob == NULL);
585 604
586 /* create the glpk problem */ 605 /* create the glpk problem */
@@ -625,7 +644,7 @@ mlp_create_problem (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_MultiHas
625 glp_set_obj_coef (mlp->prob, col, mlp->co_R); 644 glp_set_obj_coef (mlp->prob, col, mlp->co_R);
626 /* Column lower bound = 0.0 */ 645 /* Column lower bound = 0.0 */
627 glp_set_col_bnds (mlp->prob, col, GLP_LO, 0.0, 0.0); 646 glp_set_col_bnds (mlp->prob, col, GLP_LO, 0.0, 0.0);
628#if 0 647
629 /* Quality metric columns */ 648 /* Quality metric columns */
630 col = glp_add_cols(mlp->prob, mlp->m_q); 649 col = glp_add_cols(mlp->prob, mlp->m_q);
631 for (c = 0; c < mlp->m_q; c++) 650 for (c = 0; c < mlp->m_q; c++)
@@ -639,7 +658,7 @@ mlp_create_problem (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_MultiHas
639 /* Coefficient == Qm */ 658 /* Coefficient == Qm */
640 glp_set_obj_coef (mlp->prob, col + c, mlp->co_Q[c]); 659 glp_set_obj_coef (mlp->prob, col + c, mlp->co_Q[c]);
641 } 660 }
642#endif 661
643 /* Add columns for addresses */ 662 /* Add columns for addresses */
644 GNUNET_CONTAINER_multihashmap_iterate (addresses, create_columns_it, mlp); 663 GNUNET_CONTAINER_multihashmap_iterate (addresses, create_columns_it, mlp);
645 664
@@ -1130,6 +1149,8 @@ GAS_mlp_address_update (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_Mult
1130#if DEBUG_ATS 1149#if DEBUG_ATS
1131 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Updating existing address to peer `%s'\n", GNUNET_i2s (&address->peer)); 1150 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Updating existing address to peer `%s'\n", GNUNET_i2s (&address->peer));
1132#endif 1151#endif
1152 mlpi = address->mlp_information;
1153
1133 } 1154 }
1134 1155
1135 /* Recalculate */ 1156 /* Recalculate */
diff --git a/src/ats/gnunet-service-ats_addresses_mlp.h b/src/ats/gnunet-service-ats_addresses_mlp.h
index f5c243071..d4ae089b4 100644
--- a/src/ats/gnunet-service-ats_addresses_mlp.h
+++ b/src/ats/gnunet-service-ats_addresses_mlp.h
@@ -207,6 +207,9 @@ struct GAS_MLP_Handle
207 /* column index quality metrics */ 207 /* column index quality metrics */
208 int c_q[GNUNET_ATS_QualityPropertiesCount]; 208 int c_q[GNUNET_ATS_QualityPropertiesCount];
209 209
210 /* column index quality metrics */
211 int r_q[GNUNET_ATS_QualityPropertiesCount];
212
210 /* quality metric coefficients*/ 213 /* quality metric coefficients*/
211 double co_Q[GNUNET_ATS_QualityPropertiesCount]; 214 double co_Q[GNUNET_ATS_QualityPropertiesCount];
212 215
diff --git a/src/ats/perf_ats_mlp.c b/src/ats/perf_ats_mlp.c
new file mode 100644
index 000000000..79a362115
--- /dev/null
+++ b/src/ats/perf_ats_mlp.c
@@ -0,0 +1,138 @@
1/*
2 This file is part of GNUnet.
3 (C) 2010,2011 Christian Grothoff (and other contributing authors)
4
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20/**
21 * @file ats/test_ats_mlp.c
22 * @brief test for the MLP solver
23 * @author Christian Grothoff
24 * @author Matthias Wachs
25
26 */
27#include "platform.h"
28#include "gnunet_util_lib.h"
29#include "gnunet_statistics_service.h"
30#include "gnunet-service-ats_addresses_mlp.h"
31
32#define VERBOSE GNUNET_YES
33#define VERBOSE_ARM GNUNET_EXTRA_LOGGING
34
35#define MLP_MAX_EXEC_DURATION GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 3)
36#define MLP_MAX_ITERATIONS INT_MAX
37
38
39static int ret;
40
41struct GNUNET_STATISTICS_Handle * stats;
42
43struct GNUNET_CONTAINER_MultiHashMap * addresses;
44
45struct GAS_MLP_Handle *mlp;
46
47static void
48check (void *cls, char *const *args, const char *cfgfile,
49 const struct GNUNET_CONFIGURATION_Handle *cfg)
50{
51#if !HAVE_LIBGLPK
52 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "GLPK not installed!");
53 ret = 1;
54 return;
55#endif
56 struct ATS_Address addr[10];
57
58 stats = GNUNET_STATISTICS_create("ats", cfg);
59
60 addresses = GNUNET_CONTAINER_multihashmap_create (10);
61
62 GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_WEAK, &addr[0].peer.hashPubKey);
63 addr[0].mlp_information = NULL;
64 addr[0].next = NULL;
65 addr[0].prev = NULL;
66 addr[0].plugin = strdup ("dummy");
67
68 addr[1].peer = addr[0].peer;
69 addr[1].mlp_information = NULL;
70 addr[1].next = NULL;
71 addr[1].prev = NULL;
72 addr[1].plugin = strdup ("dummy2");
73
74 GNUNET_CONTAINER_multihashmap_put(addresses, &addr[0].peer.hashPubKey, &addr[0], GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
75
76 mlp = GAS_mlp_init (cfg, NULL, MLP_MAX_EXEC_DURATION, MLP_MAX_ITERATIONS);
77
78 /* Add a new address */
79#if 0
80 GAS_mlp_address_update (mlp, addresses, &addr[0]);
81
82 GNUNET_assert (mlp != NULL);
83 GNUNET_assert (mlp->addr_in_problem == 1);
84
85 /* Update an new address */
86 GAS_mlp_address_update (mlp, addresses, &addr[0]);
87 GNUNET_assert (mlp->addr_in_problem == 1);
88
89 /* Add a second address for same peer */
90 GNUNET_CONTAINER_multihashmap_put(addresses, &addr[0].peer.hashPubKey, &addr[1], GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
91 GAS_mlp_address_update (mlp, addresses, &addr[1]);
92 GNUNET_assert (mlp->addr_in_problem == 2);
93
94 /* Delete an address */
95 GNUNET_CONTAINER_multihashmap_remove (addresses, &addr[0].peer.hashPubKey, &addr[0]);
96 GAS_mlp_address_delete (mlp, addresses, &addr[0]);
97 GAS_mlp_address_delete (mlp, addresses, &addr[1]);
98#endif
99 GAS_mlp_done (mlp);
100
101 GNUNET_free (addr[0].plugin);
102 GNUNET_free (addr[1].plugin);
103 GNUNET_CONTAINER_multihashmap_destroy (addresses);
104 GNUNET_STATISTICS_destroy(stats, GNUNET_NO);
105
106 ret = 0;
107 return;
108}
109
110
111int
112main (int argc, char *argv[])
113{
114
115 static char *const argv2[] = { "test_ats_mlp",
116 "-c",
117 "test_ats_api.conf",
118#if VERBOSE
119 "-L", "DEBUG",
120#else
121 "-L", "WARNING",
122#endif
123 NULL
124 };
125
126 static struct GNUNET_GETOPT_CommandLineOption options[] = {
127 GNUNET_GETOPT_OPTION_END
128 };
129
130 GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2,
131 "test_ats_mlp", "nohelp", options,
132 &check, NULL);
133
134
135 return ret;
136}
137
138/* end of file test_ats_api_bandwidth_consumption.c */
diff --git a/src/ats/test_ats_mlp.c b/src/ats/test_ats_mlp.c
index 145e748b8..bf0c6a10a 100644
--- a/src/ats/test_ats_mlp.c
+++ b/src/ats/test_ats_mlp.c
@@ -65,7 +65,7 @@ check (void *cls, char *const *args, const char *cfgfile,
65 addr[0].prev = NULL; 65 addr[0].prev = NULL;
66 addr[0].plugin = strdup ("dummy"); 66 addr[0].plugin = strdup ("dummy");
67 67
68 addr[1].peer = addr[0].peer; 68 GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_WEAK, &addr[1].peer.hashPubKey);
69 addr[1].mlp_information = NULL; 69 addr[1].mlp_information = NULL;
70 addr[1].next = NULL; 70 addr[1].next = NULL;
71 addr[1].prev = NULL; 71 addr[1].prev = NULL;
@@ -86,7 +86,7 @@ check (void *cls, char *const *args, const char *cfgfile,
86 GNUNET_assert (mlp->addr_in_problem == 1); 86 GNUNET_assert (mlp->addr_in_problem == 1);
87 87
88 /* Add a second address for same peer */ 88 /* Add a second address for same peer */
89 GNUNET_CONTAINER_multihashmap_put(addresses, &addr[0].peer.hashPubKey, &addr[1], GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 89 GNUNET_CONTAINER_multihashmap_put(addresses, &addr[1].peer.hashPubKey, &addr[1], GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
90 GAS_mlp_address_update (mlp, addresses, &addr[1]); 90 GAS_mlp_address_update (mlp, addresses, &addr[1]);
91 GNUNET_assert (mlp->addr_in_problem == 2); 91 GNUNET_assert (mlp->addr_in_problem == 2);
92 92