aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--po/POTFILES.in84
-rw-r--r--src/ats/Makefile.am2
-rw-r--r--src/ats/plugin_ats_mlp.c463
-rw-r--r--src/ats/plugin_ats_mlp.h634
-rw-r--r--src/ats/plugin_ats_ril.c727
-rw-r--r--src/ats/plugin_ats_ril.h191
6 files changed, 857 insertions, 1244 deletions
diff --git a/po/POTFILES.in b/po/POTFILES.in
index b1378da55..176b6d8c5 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -3,11 +3,19 @@ src/arm/arm_monitor_api.c
3src/arm/gnunet-arm.c 3src/arm/gnunet-arm.c
4src/arm/gnunet-service-arm.c 4src/arm/gnunet-service-arm.c
5src/arm/mockup-service.c 5src/arm/mockup-service.c
6src/ats-tests/ats-testing-experiment.c
7src/ats-tests/ats-testing-log.c
8src/ats-tests/ats-testing-preferences.c
9src/ats-tests/ats-testing-traffic.c
10src/ats-tests/ats-testing.c
11src/ats-tests/gnunet-ats-sim.c
12src/ats-tests/gnunet-solver-eval.c
13src/ats-tool/gnunet-ats.c
6src/ats/ats_api_performance.c 14src/ats/ats_api_performance.c
7src/ats/ats_api_scheduling.c 15src/ats/ats_api_scheduling.c
8src/ats/gnunet-ats-solver-eval.c 16src/ats/gnunet-ats-solver-eval.c
9src/ats/gnunet-service-ats_addresses.c
10src/ats/gnunet-service-ats.c 17src/ats/gnunet-service-ats.c
18src/ats/gnunet-service-ats_addresses.c
11src/ats/gnunet-service-ats_normalization.c 19src/ats/gnunet-service-ats_normalization.c
12src/ats/gnunet-service-ats_performance.c 20src/ats/gnunet-service-ats_performance.c
13src/ats/gnunet-service-ats_reservations.c 21src/ats/gnunet-service-ats_reservations.c
@@ -15,14 +23,6 @@ src/ats/gnunet-service-ats_scheduling.c
15src/ats/plugin_ats_mlp.c 23src/ats/plugin_ats_mlp.c
16src/ats/plugin_ats_proportional.c 24src/ats/plugin_ats_proportional.c
17src/ats/plugin_ats_ril.c 25src/ats/plugin_ats_ril.c
18src/ats-tests/ats-testing.c
19src/ats-tests/ats-testing-experiment.c
20src/ats-tests/ats-testing-log.c
21src/ats-tests/ats-testing-preferences.c
22src/ats-tests/ats-testing-traffic.c
23src/ats-tests/gnunet-ats-sim.c
24src/ats-tests/gnunet-solver-eval.c
25src/ats-tool/gnunet-ats.c
26src/block/block.c 26src/block/block.c
27src/block/plugin_block_template.c 27src/block/plugin_block_template.c
28src/block/plugin_block_test.c 28src/block/plugin_block_test.c
@@ -31,8 +31,8 @@ src/cadet/cadet_common.c
31src/cadet/cadet_path.c 31src/cadet/cadet_path.c
32src/cadet/cadet_test_lib.c 32src/cadet/cadet_test_lib.c
33src/cadet/cadet_tunnel_tree.c 33src/cadet/cadet_tunnel_tree.c
34src/cadet/gnunet-cadet.c
35src/cadet/gnunet-cadet-profiler.c 34src/cadet/gnunet-cadet-profiler.c
35src/cadet/gnunet-cadet.c
36src/cadet/gnunet-service-cadet.c 36src/cadet/gnunet-service-cadet.c
37src/cadet/gnunet-service-cadet_channel.c 37src/cadet/gnunet-service-cadet_channel.c
38src/cadet/gnunet-service-cadet_connection.c 38src/cadet/gnunet-service-cadet_connection.c
@@ -46,12 +46,12 @@ src/consensus/gnunet-consensus-profiler.c
46src/consensus/gnunet-service-consensus.c 46src/consensus/gnunet-service-consensus.c
47src/conversation/conversation_api.c 47src/conversation/conversation_api.c
48src/conversation/conversation_api_call.c 48src/conversation/conversation_api_call.c
49src/conversation/gnunet-conversation.c
50src/conversation/gnunet-conversation-test.c 49src/conversation/gnunet-conversation-test.c
51src/conversation/gnunet-helper-audio-playback.c 50src/conversation/gnunet-conversation.c
52src/conversation/gnunet-helper-audio-playback-gst.c 51src/conversation/gnunet-helper-audio-playback-gst.c
53src/conversation/gnunet-helper-audio-record.c 52src/conversation/gnunet-helper-audio-playback.c
54src/conversation/gnunet-helper-audio-record-gst.c 53src/conversation/gnunet-helper-audio-record-gst.c
54src/conversation/gnunet-helper-audio-record.c
55src/conversation/gnunet-service-conversation.c 55src/conversation/gnunet-service-conversation.c
56src/conversation/microphone.c 56src/conversation/microphone.c
57src/conversation/plugin_gnsrecord_conversation.c 57src/conversation/plugin_gnsrecord_conversation.c
@@ -112,8 +112,8 @@ src/dv/gnunet-service-dv.c
112src/dv/plugin_transport_dv.c 112src/dv/plugin_transport_dv.c
113src/env/env.c 113src/env/env.c
114src/exit/gnunet-daemon-exit.c 114src/exit/gnunet-daemon-exit.c
115src/exit/gnunet-helper-exit.c
116src/exit/gnunet-helper-exit-windows.c 115src/exit/gnunet-helper-exit-windows.c
116src/exit/gnunet-helper-exit.c
117src/experimentation/gnunet-daemon-experimentation.c 117src/experimentation/gnunet-daemon-experimentation.c
118src/experimentation/gnunet-daemon-experimentation_capabilities.c 118src/experimentation/gnunet-daemon-experimentation_capabilities.c
119src/experimentation/gnunet-daemon-experimentation_experiments.c 119src/experimentation/gnunet-daemon-experimentation_experiments.c
@@ -144,8 +144,8 @@ src/fs/gnunet-auto-share.c
144src/fs/gnunet-daemon-fsprofiler.c 144src/fs/gnunet-daemon-fsprofiler.c
145src/fs/gnunet-directory.c 145src/fs/gnunet-directory.c
146src/fs/gnunet-download.c 146src/fs/gnunet-download.c
147src/fs/gnunet-fs.c
148src/fs/gnunet-fs-profiler.c 147src/fs/gnunet-fs-profiler.c
148src/fs/gnunet-fs.c
149src/fs/gnunet-helper-fs-publish.c 149src/fs/gnunet-helper-fs-publish.c
150src/fs/gnunet-publish.c 150src/fs/gnunet-publish.c
151src/fs/gnunet-search.c 151src/fs/gnunet-search.c
@@ -164,10 +164,10 @@ src/fs/plugin_block_fs.c
164src/gns/gns_api.c 164src/gns/gns_api.c
165src/gns/gnunet-bcd.c 165src/gns/gnunet-bcd.c
166src/gns/gnunet-dns2gns.c 166src/gns/gnunet-dns2gns.c
167src/gns/gnunet-gns.c
168src/gns/gnunet-gns-helper-service-w32.c 167src/gns/gnunet-gns-helper-service-w32.c
169src/gns/gnunet-gns-import.c 168src/gns/gnunet-gns-import.c
170src/gns/gnunet-gns-proxy.c 169src/gns/gnunet-gns-proxy.c
170src/gns/gnunet-gns.c
171src/gns/gnunet-service-gns.c 171src/gns/gnunet-service-gns.c
172src/gns/gnunet-service-gns_interceptor.c 172src/gns/gnunet-service-gns_interceptor.c
173src/gns/gnunet-service-gns_resolver.c 173src/gns/gnunet-service-gns_resolver.c
@@ -176,15 +176,15 @@ src/gns/nss/nss_gns.c
176src/gns/nss/nss_gns_query.c 176src/gns/nss/nss_gns_query.c
177src/gns/plugin_block_gns.c 177src/gns/plugin_block_gns.c
178src/gns/plugin_gnsrecord_gns.c 178src/gns/plugin_gnsrecord_gns.c
179src/gns/w32nsp-install.c
180src/gns/w32nsp-resolve.c
181src/gns/w32nsp-uninstall.c
182src/gns/w32nsp.c
179src/gnsrecord/gnsrecord.c 183src/gnsrecord/gnsrecord.c
180src/gnsrecord/gnsrecord_crypto.c 184src/gnsrecord/gnsrecord_crypto.c
181src/gnsrecord/gnsrecord_misc.c 185src/gnsrecord/gnsrecord_misc.c
182src/gnsrecord/gnsrecord_serialization.c 186src/gnsrecord/gnsrecord_serialization.c
183src/gnsrecord/plugin_gnsrecord_dns.c 187src/gnsrecord/plugin_gnsrecord_dns.c
184src/gns/w32nsp.c
185src/gns/w32nsp-install.c
186src/gns/w32nsp-resolve.c
187src/gns/w32nsp-uninstall.c
188src/hello/address.c 188src/hello/address.c
189src/hello/gnunet-hello.c 189src/hello/gnunet-hello.c
190src/hello/hello.c 190src/hello/hello.c
@@ -204,31 +204,31 @@ src/namecache/gnunet-service-namecache.c
204src/namecache/namecache_api.c 204src/namecache/namecache_api.c
205src/namecache/plugin_namecache_postgres.c 205src/namecache/plugin_namecache_postgres.c
206src/namecache/plugin_namecache_sqlite.c 206src/namecache/plugin_namecache_sqlite.c
207src/namestore/gnunet-namestore.c
208src/namestore/gnunet-namestore-fcfsd.c 207src/namestore/gnunet-namestore-fcfsd.c
208src/namestore/gnunet-namestore.c
209src/namestore/gnunet-service-namestore.c 209src/namestore/gnunet-service-namestore.c
210src/namestore/namestore_api.c 210src/namestore/namestore_api.c
211src/namestore/namestore_api_monitor.c 211src/namestore/namestore_api_monitor.c
212src/namestore/plugin_namestore_postgres.c 212src/namestore/plugin_namestore_postgres.c
213src/namestore/plugin_namestore_sqlite.c 213src/namestore/plugin_namestore_sqlite.c
214src/nat/gnunet-helper-nat-client.c
215src/nat/gnunet-helper-nat-client-windows.c 214src/nat/gnunet-helper-nat-client-windows.c
216src/nat/gnunet-helper-nat-server.c 215src/nat/gnunet-helper-nat-client.c
217src/nat/gnunet-helper-nat-server-windows.c 216src/nat/gnunet-helper-nat-server-windows.c
217src/nat/gnunet-helper-nat-server.c
218src/nat/gnunet-nat-server.c 218src/nat/gnunet-nat-server.c
219src/nat/nat_auto.c
220src/nat/nat.c 219src/nat/nat.c
220src/nat/nat_auto.c
221src/nat/nat_mini.c 221src/nat/nat_mini.c
222src/nat/nat_test.c 222src/nat/nat_test.c
223src/nse/gnunet-nse.c
224src/nse/gnunet-nse-profiler.c 223src/nse/gnunet-nse-profiler.c
224src/nse/gnunet-nse.c
225src/nse/gnunet-service-nse.c 225src/nse/gnunet-service-nse.c
226src/nse/nse_api.c 226src/nse/nse_api.c
227src/peerinfo-tool/gnunet-peerinfo.c
228src/peerinfo-tool/gnunet-peerinfo_plugins.c
227src/peerinfo/gnunet-service-peerinfo.c 229src/peerinfo/gnunet-service-peerinfo.c
228src/peerinfo/peerinfo_api.c 230src/peerinfo/peerinfo_api.c
229src/peerinfo/peerinfo_api_notify.c 231src/peerinfo/peerinfo_api_notify.c
230src/peerinfo-tool/gnunet-peerinfo.c
231src/peerinfo-tool/gnunet-peerinfo_plugins.c
232src/peerstore/gnunet-peerstore.c 232src/peerstore/gnunet-peerstore.c
233src/peerstore/gnunet-service-peerstore.c 233src/peerstore/gnunet-service-peerstore.c
234src/peerstore/peerstore_api.c 234src/peerstore/peerstore_api.c
@@ -288,30 +288,30 @@ src/testbed/gnunet-daemon-latency-logger.c
288src/testbed/gnunet-daemon-testbed-blacklist.c 288src/testbed/gnunet-daemon-testbed-blacklist.c
289src/testbed/gnunet-daemon-testbed-underlay.c 289src/testbed/gnunet-daemon-testbed-underlay.c
290src/testbed/gnunet-helper-testbed.c 290src/testbed/gnunet-helper-testbed.c
291src/testbed/gnunet_mpi_test.c
292src/testbed/gnunet-service-test-barriers.c 291src/testbed/gnunet-service-test-barriers.c
293src/testbed/gnunet-service-testbed_barriers.c 292src/testbed/gnunet-service-testbed-logger.c
294src/testbed/gnunet-service-testbed.c 293src/testbed/gnunet-service-testbed.c
294src/testbed/gnunet-service-testbed_barriers.c
295src/testbed/gnunet-service-testbed_cache.c 295src/testbed/gnunet-service-testbed_cache.c
296src/testbed/gnunet-service-testbed_connectionpool.c 296src/testbed/gnunet-service-testbed_connectionpool.c
297src/testbed/gnunet-service-testbed_cpustatus.c 297src/testbed/gnunet-service-testbed_cpustatus.c
298src/testbed/gnunet-service-testbed_links.c 298src/testbed/gnunet-service-testbed_links.c
299src/testbed/gnunet-service-testbed-logger.c
300src/testbed/gnunet-service-testbed_meminfo.c 299src/testbed/gnunet-service-testbed_meminfo.c
301src/testbed/gnunet-service-testbed_oc.c 300src/testbed/gnunet-service-testbed_oc.c
302src/testbed/gnunet-service-testbed_peers.c 301src/testbed/gnunet-service-testbed_peers.c
303src/testbed/gnunet_testbed_mpi_spawn.c
304src/testbed/gnunet-testbed-profiler.c 302src/testbed/gnunet-testbed-profiler.c
305src/testbed/testbed_api_barriers.c 303src/testbed/gnunet_mpi_test.c
304src/testbed/gnunet_testbed_mpi_spawn.c
306src/testbed/testbed_api.c 305src/testbed/testbed_api.c
306src/testbed/testbed_api_barriers.c
307src/testbed/testbed_api_hosts.c 307src/testbed/testbed_api_hosts.c
308src/testbed/testbed_api_operations.c 308src/testbed/testbed_api_operations.c
309src/testbed/testbed_api_peers.c 309src/testbed/testbed_api_peers.c
310src/testbed/testbed_api_sd.c 310src/testbed/testbed_api_sd.c
311src/testbed/testbed_api_services.c 311src/testbed/testbed_api_services.c
312src/testbed/testbed_api_statistics.c 312src/testbed/testbed_api_statistics.c
313src/testbed/testbed_api_testbed.c
314src/testbed/testbed_api_test.c 313src/testbed/testbed_api_test.c
314src/testbed/testbed_api_testbed.c
315src/testbed/testbed_api_topology.c 315src/testbed/testbed_api_topology.c
316src/testbed/testbed_api_underlay.c 316src/testbed/testbed_api_underlay.c
317src/testbed/testbed_logger_api.c 317src/testbed/testbed_logger_api.c
@@ -321,20 +321,20 @@ src/testing/testing.c
321src/topology/friends.c 321src/topology/friends.c
322src/topology/gnunet-daemon-topology.c 322src/topology/gnunet-daemon-topology.c
323src/transport/gnunet-helper-transport-bluetooth.c 323src/transport/gnunet-helper-transport-bluetooth.c
324src/transport/gnunet-helper-transport-wlan.c
325src/transport/gnunet-helper-transport-wlan-dummy.c 324src/transport/gnunet-helper-transport-wlan-dummy.c
326src/transport/gnunet-service-transport_blacklist.c 325src/transport/gnunet-helper-transport-wlan.c
327src/transport/gnunet-service-transport.c 326src/transport/gnunet-service-transport.c
327src/transport/gnunet-service-transport_blacklist.c
328src/transport/gnunet-service-transport_clients.c 328src/transport/gnunet-service-transport_clients.c
329src/transport/gnunet-service-transport_hello.c 329src/transport/gnunet-service-transport_hello.c
330src/transport/gnunet-service-transport_manipulation.c 330src/transport/gnunet-service-transport_manipulation.c
331src/transport/gnunet-service-transport_neighbours.c 331src/transport/gnunet-service-transport_neighbours.c
332src/transport/gnunet-service-transport_plugins.c 332src/transport/gnunet-service-transport_plugins.c
333src/transport/gnunet-service-transport_validation.c 333src/transport/gnunet-service-transport_validation.c
334src/transport/gnunet-transport.c
335src/transport/gnunet-transport-certificate-creation.c 334src/transport/gnunet-transport-certificate-creation.c
336src/transport/gnunet-transport-wlan-receiver.c 335src/transport/gnunet-transport-wlan-receiver.c
337src/transport/gnunet-transport-wlan-sender.c 336src/transport/gnunet-transport-wlan-sender.c
337src/transport/gnunet-transport.c
338src/transport/plugin_transport_bluetooth.c 338src/transport/plugin_transport_bluetooth.c
339src/transport/plugin_transport_http_client.c 339src/transport/plugin_transport_http_client.c
340src/transport/plugin_transport_http_common.c 340src/transport/plugin_transport_http_common.c
@@ -342,15 +342,15 @@ src/transport/plugin_transport_http_server.c
342src/transport/plugin_transport_smtp.c 342src/transport/plugin_transport_smtp.c
343src/transport/plugin_transport_tcp.c 343src/transport/plugin_transport_tcp.c
344src/transport/plugin_transport_template.c 344src/transport/plugin_transport_template.c
345src/transport/plugin_transport_udp_broadcasting.c
346src/transport/plugin_transport_udp.c 345src/transport/plugin_transport_udp.c
346src/transport/plugin_transport_udp_broadcasting.c
347src/transport/plugin_transport_unix.c 347src/transport/plugin_transport_unix.c
348src/transport/plugin_transport_wlan.c 348src/transport/plugin_transport_wlan.c
349src/transport/transport-testing.c
350src/transport/transport_api.c
349src/transport/transport_api_address_to_string.c 351src/transport/transport_api_address_to_string.c
350src/transport/transport_api_blacklist.c 352src/transport/transport_api_blacklist.c
351src/transport/transport_api.c
352src/transport/transport_api_monitoring.c 353src/transport/transport_api_monitoring.c
353src/transport/transport-testing.c
354src/tun/regex.c 354src/tun/regex.c
355src/tun/tun.c 355src/tun/tun.c
356src/util/bandwidth.c 356src/util/bandwidth.c
@@ -365,8 +365,8 @@ src/util/connection.c
365src/util/container_bloomfilter.c 365src/util/container_bloomfilter.c
366src/util/container_heap.c 366src/util/container_heap.c
367src/util/container_meta_data.c 367src/util/container_meta_data.c
368src/util/container_multihashmap32.c
369src/util/container_multihashmap.c 368src/util/container_multihashmap.c
369src/util/container_multihashmap32.c
370src/util/container_multipeermap.c 370src/util/container_multipeermap.c
371src/util/container_slist.c 371src/util/container_slist.c
372src/util/crypto_crc.c 372src/util/crypto_crc.c
@@ -381,8 +381,8 @@ src/util/crypto_symmetric.c
381src/util/disk.c 381src/util/disk.c
382src/util/getopt.c 382src/util/getopt.c
383src/util/getopt_helpers.c 383src/util/getopt_helpers.c
384src/util/gnunet-config.c
385src/util/gnunet-config-diff.c 384src/util/gnunet-config-diff.c
385src/util/gnunet-config.c
386src/util/gnunet-ecc.c 386src/util/gnunet-ecc.c
387src/util/gnunet-helper-w32-console.c 387src/util/gnunet-helper-w32-console.c
388src/util/gnunet-resolver.c 388src/util/gnunet-resolver.c
@@ -413,8 +413,8 @@ src/util/time.c
413src/util/w32cat.c 413src/util/w32cat.c
414src/util/win.c 414src/util/win.c
415src/util/winproc.c 415src/util/winproc.c
416src/vpn/gnunet-helper-vpn.c
417src/vpn/gnunet-helper-vpn-windows.c 416src/vpn/gnunet-helper-vpn-windows.c
417src/vpn/gnunet-helper-vpn.c
418src/vpn/gnunet-service-vpn.c 418src/vpn/gnunet-service-vpn.c
419src/vpn/gnunet-vpn.c 419src/vpn/gnunet-vpn.c
420src/vpn/vpn_api.c 420src/vpn/vpn_api.c
diff --git a/src/ats/Makefile.am b/src/ats/Makefile.am
index cd79d619b..533cddec7 100644
--- a/src/ats/Makefile.am
+++ b/src/ats/Makefile.am
@@ -518,8 +518,6 @@ test_ats_solver_preferences_ril_LDADD = \
518 518
519EXTRA_DIST = \ 519EXTRA_DIST = \
520 ats.h \ 520 ats.h \
521 plugin_ats_mlp.h \
522 plugin_ats_ril.h \
523 test_ats_api.conf \ 521 test_ats_api.conf \
524 test_ats_mlp.conf \ 522 test_ats_mlp.conf \
525 test_ats_solver_default.conf \ 523 test_ats_solver_default.conf \
diff --git a/src/ats/plugin_ats_mlp.c b/src/ats/plugin_ats_mlp.c
index 436a58b0e..98244c9ae 100644
--- a/src/ats/plugin_ats_mlp.c
+++ b/src/ats/plugin_ats_mlp.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 (C) 2011 Christian Grothoff (and other contributing authors) 3 (C) 2011-2014 Christian Grothoff (and other contributing authors)
4 4
5 GNUnet is free software; you can redistribute it and/or modify 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 6 it under the terms of the GNU General Public License as published
@@ -26,6 +26,398 @@
26 */ 26 */
27 27
28#include "plugin_ats_mlp.h" 28#include "plugin_ats_mlp.h"
29#include "platform.h"
30#include "gnunet_util_lib.h"
31#include "gnunet_ats_service.h"
32#include "gnunet_ats_plugin.h"
33#include "gnunet-service-ats_addresses.h"
34#include "gnunet_statistics_service.h"
35#include <float.h>
36#include <glpk.h>
37
38
39#define BIG_M_VALUE (UINT32_MAX) /10
40#define BIG_M_STRING "unlimited"
41
42#define MLP_AVERAGING_QUEUE_LENGTH 3
43
44#define MLP_MAX_EXEC_DURATION GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10)
45#define MLP_MAX_ITERATIONS 4096
46
47#define DEFAULT_D 1.0
48#define DEFAULT_R 1.0
49#define DEFAULT_U 1.0
50#define DEFAULT_QUALITY 1.0
51#define DEFAULT_MIN_CONNECTIONS 4
52#define DEFAULT_PEER_PREFERENCE 1.0
53
54#define MLP_NaN -1
55#define MLP_UNDEFINED 0
56#define GLP_YES 1.0
57#define GLP_NO 0.0
58
59enum MLP_Output_Format
60{
61 MLP_MPS,
62 MLP_CPLEX,
63 MLP_GLPK
64};
65
66
67struct MLP_Solution
68{
69 int lp_res;
70 int lp_presolv;
71 int mip_res;
72 int mip_presolv;
73
74 double lp_objective_value;
75 double mlp_objective_value;
76 double mlp_gap;
77 double lp_mlp_gap;
78
79 int p_elements;
80 int p_cols;
81 int p_rows;
82
83 int n_peers;
84 int n_addresses;
85
86};
87
88struct ATS_Peer
89{
90 struct GNUNET_PeerIdentity id;
91
92 /* Was this peer already added to the current problem? */
93 int processed;
94
95 /* constraint 2: 1 address per peer*/
96 unsigned int r_c2;
97
98 /* constraint 9: relativity */
99 unsigned int r_c9;
100
101 /* Legacy preference value */
102 double f;
103};
104
105struct MLP_Problem
106{
107 /**
108 * GLPK (MLP) problem object
109 */
110 glp_prob *prob;
111
112 /* Number of addresses in problem */
113 unsigned int num_addresses;
114 /* Number of peers in problem */
115 unsigned int num_peers;
116 /* Number of elements in problem matrix */
117 unsigned int num_elements;
118
119 /* Row index constraint 2: */
120 unsigned int r_c2;
121 /* Row index constraint 4: minimum connections */
122 unsigned int r_c4;
123 /* Row index constraint 6: maximize diversity */
124 unsigned int r_c6;
125 /* Row index constraint 8: utilization*/
126 unsigned int r_c8;
127 /* Row index constraint 9: relativity*/
128 unsigned int r_c9;
129 /* Row indices quality metrics */
130 int r_q[GNUNET_ATS_QualityPropertiesCount];
131 /* Row indices ATS network quotas */
132 int r_quota[GNUNET_ATS_NetworkTypeCount];
133
134 /* Column index Diversity (D) column */
135 int c_d;
136 /* Column index Utilization (U) column */
137 int c_u;
138 /* Column index Proportionality (R) column */
139 int c_r;
140 /* Column index quality metrics */
141 int c_q[GNUNET_ATS_QualityPropertiesCount];
142
143 /* Problem matrix */
144 /* Current index */
145 unsigned int ci;
146 /* Row index array */
147 int *ia;
148 /* Column index array */
149 int *ja;
150 /* Column index value */
151 double *ar;
152
153};
154
155struct MLP_Variables
156{
157 /* Big M value for bandwidth capping */
158 double BIG_M;
159
160 /* MIP Gap */
161 double mip_gap;
162
163 /* LP MIP Gap */
164 double lp_mip_gap;
165
166 /* ATS Quality metrics
167 *
168 * Array with GNUNET_ATS_QualityPropertiesCount elements
169 * contains mapping to GNUNET_ATS_Property*/
170 int q[GNUNET_ATS_QualityPropertiesCount];
171
172 /* Number of quality metrics */
173 int m_q;
174
175 /* Number of quality metrics */
176 int m_rc;
177
178 /* Quality metric coefficients*/
179 double co_Q[GNUNET_ATS_QualityPropertiesCount];
180
181 /* Ressource costs coefficients*/
182 double co_RC[GNUNET_ATS_QualityPropertiesCount];
183
184 /* Diversity coefficient */
185 double co_D;
186
187 /* Utility coefficient */
188 double co_U;
189
190 /* Relativity coefficient */
191 double co_R;
192
193 /* Minimum bandwidth assigned to an address */
194 unsigned int b_min;
195
196 /* Minimum number of addresses with bandwidth assigned */
197 unsigned int n_min;
198
199 /* Quotas */
200 /* Array mapping array index to ATS network */
201 int quota_index[GNUNET_ATS_NetworkTypeCount];
202 /* Outbound quotas */
203 unsigned long long quota_out[GNUNET_ATS_NetworkTypeCount];
204 /* Inbound quotas */
205
206 unsigned long long quota_in[GNUNET_ATS_NetworkTypeCount];
207
208 /* ATS ressource costs
209 * array with GNUNET_ATS_QualityPropertiesCount elements
210 * contains mapping to GNUNET_ATS_Property
211 * */
212 int rc[GNUNET_ATS_QualityPropertiesCount];
213
214};
215
216/**
217 * MLP Handle
218 */
219struct GAS_MLP_Handle
220{
221 struct GNUNET_ATS_PluginEnvironment *env;
222
223 /**
224 * Statistics handle
225 */
226 struct GNUNET_STATISTICS_Handle *stats;
227
228 /**
229 * Address hashmap for lookups
230 */
231 const struct GNUNET_CONTAINER_MultiPeerMap *addresses;
232
233 /**
234 * Addresses' bandwidth changed callback
235 */
236 GAS_bandwidth_changed_cb bw_changed_cb;
237
238 /**
239 * Addresses' bandwidth changed callback closure
240 */
241 void *bw_changed_cb_cls;
242
243 /**
244 * ATS function to get preferences
245 */
246 GAS_get_preferences get_preferences;
247
248 /**
249 * Closure for ATS function to get preferences
250 */
251 void *get_preferences_cls;
252
253 /**
254 * ATS function to get properties
255 */
256 GAS_get_properties get_properties;
257
258 /**
259 * Closure for ATS function to get properties
260 */
261 void *get_properties_cls;
262
263 /**
264 * Exclude peer from next result propagation
265 */
266 const struct GNUNET_PeerIdentity *exclude_peer;
267
268 /**
269 * Encapsulation for the MLP problem
270 */
271 struct MLP_Problem p;
272
273 /**
274 * Encapsulation for the MLP problem variables
275 */
276 struct MLP_Variables pv;
277
278 /**
279 * Encapsulation for the MLP solution
280 */
281 struct MLP_Solution ps;
282
283 /**
284 * Bulk lock
285 */
286
287 int stat_bulk_lock;
288
289 /**
290 * Number of changes while solver was locked
291 */
292 int stat_bulk_requests;
293
294 /**
295 * GLPK LP control parameter
296 */
297 glp_smcp control_param_lp;
298
299 /**
300 * GLPK LP control parameter
301 */
302 glp_iocp control_param_mlp;
303
304 /**
305 * Peers with pending address requests
306 */
307 struct GNUNET_CONTAINER_MultiPeerMap *requested_peers;
308
309 /**
310 * Was the problem updated since last solution
311 */
312 int stat_mlp_prob_updated;
313
314 /**
315 * Has the problem size changed since last solution
316 */
317 int stat_mlp_prob_changed;
318
319 /**
320 * Solve the problem automatically when updates occur?
321 * Default: GNUNET_YES
322 * Can be disabled for test and measurements
323 */
324 int opt_mlp_auto_solve;
325
326 /**
327 * Write all MILP problems to a MPS file
328 */
329 int opt_dump_problem_all;
330
331 /**
332 * Write all MILP problem solutions to a file
333 */
334 int opt_dump_solution_all;
335
336 /**
337 * Write MILP problems to a MPS file when solver fails
338 */
339 int opt_dump_problem_on_fail;
340
341 /**
342 * Write MILP problem solutions to a file when solver fails
343 */
344 int opt_dump_solution_on_fail;
345
346 /**
347 * solve feasibility only
348 */
349 int opt_dbg_feasibility_only;
350
351 /**
352 * solve autoscale the problem
353 */
354 int opt_dbg_autoscale_problem;
355
356 /**
357 * use the intopt presolver instead of simplex
358 */
359 int opt_dbg_intopt_presolver;
360
361 /**
362 * Print GLPK output
363 */
364 int opt_dbg_glpk_verbose;
365
366 /**
367 * solve autoscale the problem
368 */
369 int opt_dbg_optimize_relativity;
370
371 /**
372 * solve autoscale the problem
373 */
374 int opt_dbg_optimize_diversity;
375
376 /**
377 * solve autoscale the problem
378 */
379 int opt_dbg_optimize_quality;
380
381 /**
382 * solve autoscale the problem
383 */
384 int opt_dbg_optimize_utility;
385
386
387 /**
388 * Output format
389 */
390 enum MLP_Output_Format opt_log_format;
391};
392
393/**
394 * Address specific MLP information
395 */
396struct MLP_information
397{
398
399 /* Bandwidth assigned */
400 struct GNUNET_BANDWIDTH_Value32NBO b_out;
401 struct GNUNET_BANDWIDTH_Value32NBO b_in;
402
403 /* Address selected */
404 int n;
405
406 /* bandwidth column index */
407 signed int c_b;
408
409 /* address usage column */
410 signed int c_n;
411
412 /* row indexes */
413
414 /* constraint 1: bandwidth capping */
415 unsigned int r_c1;
416
417 /* constraint 3: minimum bandwidth */
418 unsigned int r_c3;
419};
420
29 421
30 422
31/** 423/**
@@ -148,6 +540,7 @@ static int
148mlp_term_hook (void *info, const char *s) 540mlp_term_hook (void *info, const char *s)
149{ 541{
150 struct GAS_MLP_Handle *mlp = info; 542 struct GAS_MLP_Handle *mlp = info;
543
151 if (mlp->opt_dbg_glpk_verbose) 544 if (mlp->opt_dbg_glpk_verbose)
152 LOG (GNUNET_ERROR_TYPE_ERROR, "%s", s); 545 LOG (GNUNET_ERROR_TYPE_ERROR, "%s", s);
153 return 1; 546 return 1;
@@ -237,7 +630,7 @@ mlp_delete_problem (struct GAS_MLP_Handle *mlp)
237 * @param ats_index the ATS index 630 * @param ats_index the ATS index
238 * @return string with result 631 * @return string with result
239 */ 632 */
240const char * 633static const char *
241mlp_ats_to_string (int ats_index) 634mlp_ats_to_string (int ats_index)
242{ 635{
243 switch (ats_index) { 636 switch (ats_index) {
@@ -274,7 +667,7 @@ mlp_ats_to_string (int ats_index)
274 * @param retcode return code 667 * @param retcode return code
275 * @return string with result 668 * @return string with result
276 */ 669 */
277const char * 670static const char *
278mlp_status_to_string (int retcode) 671mlp_status_to_string (int retcode)
279{ 672{
280 switch (retcode) { 673 switch (retcode) {
@@ -296,12 +689,13 @@ mlp_status_to_string (int retcode)
296 } 689 }
297} 690}
298 691
692
299/** 693/**
300 * Translate glpk solver error codes to text 694 * Translate glpk solver error codes to text
301 * @param retcode return code 695 * @param retcode return code
302 * @return string with result 696 * @return string with result
303 */ 697 */
304const char * 698static const char *
305mlp_solve_to_string (int retcode) 699mlp_solve_to_string (int retcode)
306{ 700{
307 switch (retcode) { 701 switch (retcode) {
@@ -798,6 +1192,7 @@ mlp_create_problem_add_address_information (void *cls,
798 return GNUNET_OK; 1192 return GNUNET_OK;
799} 1193}
800 1194
1195
801/** 1196/**
802 * Create the invariant columns c4, c6, c10, c8, c7 1197 * Create the invariant columns c4, c6, c10, c8, c7
803 */ 1198 */
@@ -899,7 +1294,7 @@ mlp_create_problem_add_invariant_columns (struct GAS_MLP_Handle *mlp, struct MLP
899 * Create the MLP problem 1294 * Create the MLP problem
900 * 1295 *
901 * @param mlp the MLP handle 1296 * @param mlp the MLP handle
902 * @return GNUNET_OK or GNUNET_SYSERR 1297 * @return #GNUNET_OK or #GNUNET_SYSERR
903 */ 1298 */
904static int 1299static int
905mlp_create_problem (struct GAS_MLP_Handle *mlp) 1300mlp_create_problem (struct GAS_MLP_Handle *mlp)
@@ -972,11 +1367,12 @@ mlp_create_problem (struct GAS_MLP_Handle *mlp)
972 return res; 1367 return res;
973} 1368}
974 1369
1370
975/** 1371/**
976 * Solves the LP problem 1372 * Solves the LP problem
977 * 1373 *
978 * @param mlp the MLP Handle 1374 * @param mlp the MLP Handle
979 * @return GNUNET_OK if could be solved, GNUNET_SYSERR on failure 1375 * @return #GNUNET_OK if could be solved, #GNUNET_SYSERR on failure
980 */ 1376 */
981static int 1377static int
982mlp_solve_lp_problem (struct GAS_MLP_Handle *mlp) 1378mlp_solve_lp_problem (struct GAS_MLP_Handle *mlp)
@@ -1018,7 +1414,7 @@ mlp_solve_lp_problem (struct GAS_MLP_Handle *mlp)
1018 * @param value the address 1414 * @param value the address
1019 * @return #GNUNET_OK to continue 1415 * @return #GNUNET_OK to continue
1020 */ 1416 */
1021int 1417static int
1022mlp_propagate_results (void *cls, 1418mlp_propagate_results (void *cls,
1023 const struct GNUNET_PeerIdentity *key, 1419 const struct GNUNET_PeerIdentity *key,
1024 void *value) 1420 void *value)
@@ -1133,16 +1529,20 @@ mlp_propagate_results (void *cls,
1133 return GNUNET_OK; 1529 return GNUNET_OK;
1134} 1530}
1135 1531
1136static void notify (struct GAS_MLP_Handle *mlp, 1532
1137 enum GAS_Solver_Operation op, 1533static void
1138 enum GAS_Solver_Status stat, 1534notify (struct GAS_MLP_Handle *mlp,
1139 enum GAS_Solver_Additional_Information add) 1535 enum GAS_Solver_Operation op,
1536 enum GAS_Solver_Status stat,
1537 enum GAS_Solver_Additional_Information add)
1140{ 1538{
1141 if (NULL != mlp->env->info_cb) 1539 if (NULL != mlp->env->info_cb)
1142 mlp->env->info_cb (mlp->env->info_cb_cls, op, stat, add); 1540 mlp->env->info_cb (mlp->env->info_cb_cls, op, stat, add);
1143} 1541}
1144 1542
1145static void mlp_branch_and_cut_cb (glp_tree *tree, void *info) 1543
1544static void
1545mlp_branch_and_cut_cb (glp_tree *tree, void *info)
1146{ 1546{
1147 struct GAS_MLP_Handle *mlp = info; 1547 struct GAS_MLP_Handle *mlp = info;
1148 double mlp_obj = 0; 1548 double mlp_obj = 0;
@@ -1206,9 +1606,9 @@ static void mlp_branch_and_cut_cb (glp_tree *tree, void *info)
1206 * Solves the MLP problem 1606 * Solves the MLP problem
1207 * 1607 *
1208 * @param solver the MLP Handle 1608 * @param solver the MLP Handle
1209 * @return GNUNET_OK if could be solved, GNUNET_SYSERR on failure 1609 * @return #GNUNET_OK if could be solved, #GNUNET_SYSERR on failure
1210 */ 1610 */
1211int 1611static int
1212GAS_mlp_solve_problem (void *solver) 1612GAS_mlp_solve_problem (void *solver)
1213{ 1613{
1214 struct GAS_MLP_Handle *mlp = solver; 1614 struct GAS_MLP_Handle *mlp = solver;
@@ -1516,7 +1916,7 @@ GAS_mlp_solve_problem (void *solver)
1516 * @param address the address to add 1916 * @param address the address to add
1517 * @param network network type of this address 1917 * @param network network type of this address
1518 */ 1918 */
1519void 1919static void
1520GAS_mlp_address_add (void *solver, 1920GAS_mlp_address_add (void *solver,
1521 struct ATS_Address *address, 1921 struct ATS_Address *address,
1522 uint32_t network) 1922 uint32_t network)
@@ -1567,7 +1967,7 @@ GAS_mlp_address_add (void *solver,
1567 * @param abs_value the absolute value of the property 1967 * @param abs_value the absolute value of the property
1568 * @param rel_value the normalized value 1968 * @param rel_value the normalized value
1569 */ 1969 */
1570void 1970static void
1571GAS_mlp_address_property_changed (void *solver, 1971GAS_mlp_address_property_changed (void *solver,
1572 struct ATS_Address *address, 1972 struct ATS_Address *address,
1573 uint32_t type, 1973 uint32_t type,
@@ -1647,7 +2047,7 @@ GAS_mlp_address_property_changed (void *solver,
1647 * @param cur_session the current session 2047 * @param cur_session the current session
1648 * @param new_session the new session 2048 * @param new_session the new session
1649 */ 2049 */
1650void 2050static void
1651GAS_mlp_address_session_changed (void *solver, 2051GAS_mlp_address_session_changed (void *solver,
1652 struct ATS_Address *address, 2052 struct ATS_Address *address,
1653 uint32_t cur_session, 2053 uint32_t cur_session,
@@ -1667,7 +2067,7 @@ GAS_mlp_address_session_changed (void *solver,
1667 * @param address the address 2067 * @param address the address
1668 * @param in_use usage state 2068 * @param in_use usage state
1669 */ 2069 */
1670void 2070static void
1671GAS_mlp_address_inuse_changed (void *solver, 2071GAS_mlp_address_inuse_changed (void *solver,
1672 struct ATS_Address *address, 2072 struct ATS_Address *address,
1673 int in_use) 2073 int in_use)
@@ -1687,7 +2087,7 @@ GAS_mlp_address_inuse_changed (void *solver,
1687 * @param current_network the current network 2087 * @param current_network the current network
1688 * @param new_network the new network 2088 * @param new_network the new network
1689 */ 2089 */
1690void 2090static void
1691GAS_mlp_address_change_network (void *solver, 2091GAS_mlp_address_change_network (void *solver,
1692 struct ATS_Address *address, 2092 struct ATS_Address *address,
1693 uint32_t current_network, 2093 uint32_t current_network,
@@ -1790,10 +2190,10 @@ GAS_mlp_address_change_network (void *solver,
1790 * @param address the address to delete 2190 * @param address the address to delete
1791 * @param session_only delete only session not whole address 2191 * @param session_only delete only session not whole address
1792 */ 2192 */
1793void 2193static void
1794GAS_mlp_address_delete (void *solver, 2194GAS_mlp_address_delete (void *solver,
1795 struct ATS_Address *address, 2195 struct ATS_Address *address,
1796 int session_only) 2196 int session_only)
1797{ 2197{
1798 struct ATS_Peer *p; 2198 struct ATS_Peer *p;
1799 struct GAS_MLP_Handle *mlp = solver; 2199 struct GAS_MLP_Handle *mlp = solver;
@@ -1925,7 +2325,7 @@ get_peer_pref_value (struct GAS_MLP_Handle *mlp, const struct GNUNET_PeerIdentit
1925 * @param peer the peer 2325 * @param peer the peer
1926 * @return suggested address 2326 * @return suggested address
1927 */ 2327 */
1928const struct ATS_Address * 2328static const struct ATS_Address *
1929GAS_mlp_get_preferred_address (void *solver, 2329GAS_mlp_get_preferred_address (void *solver,
1930 const struct GNUNET_PeerIdentity *peer) 2330 const struct GNUNET_PeerIdentity *peer)
1931{ 2331{
@@ -1978,7 +2378,7 @@ GAS_mlp_get_preferred_address (void *solver,
1978 * 2378 *
1979 * @param solver the solver 2379 * @param solver the solver
1980 */ 2380 */
1981void 2381static void
1982GAS_mlp_bulk_start (void *solver) 2382GAS_mlp_bulk_start (void *solver)
1983{ 2383{
1984 LOG (GNUNET_ERROR_TYPE_DEBUG, "Locking solver for bulk operation ...\n"); 2384 LOG (GNUNET_ERROR_TYPE_DEBUG, "Locking solver for bulk operation ...\n");
@@ -1989,7 +2389,8 @@ GAS_mlp_bulk_start (void *solver)
1989 s->stat_bulk_lock ++; 2389 s->stat_bulk_lock ++;
1990} 2390}
1991 2391
1992void 2392
2393static void
1993GAS_mlp_bulk_stop (void *solver) 2394GAS_mlp_bulk_stop (void *solver)
1994{ 2395{
1995 LOG (GNUNET_ERROR_TYPE_DEBUG, "Unlocking solver from bulk operation ...\n"); 2396 LOG (GNUNET_ERROR_TYPE_DEBUG, "Unlocking solver from bulk operation ...\n");
@@ -2019,7 +2420,7 @@ GAS_mlp_bulk_stop (void *solver)
2019 * @param solver the MLP handle 2420 * @param solver the MLP handle
2020 * @param peer the peer 2421 * @param peer the peer
2021 */ 2422 */
2022void 2423static void
2023GAS_mlp_stop_get_preferred_address (void *solver, 2424GAS_mlp_stop_get_preferred_address (void *solver,
2024 const struct GNUNET_PeerIdentity *peer) 2425 const struct GNUNET_PeerIdentity *peer)
2025{ 2426{
@@ -2050,7 +2451,7 @@ GAS_mlp_stop_get_preferred_address (void *solver,
2050 * @param kind the kind to change the preference 2451 * @param kind the kind to change the preference
2051 * @param pref_rel the relative score 2452 * @param pref_rel the relative score
2052 */ 2453 */
2053void 2454static void
2054GAS_mlp_address_change_preference (void *solver, 2455GAS_mlp_address_change_preference (void *solver,
2055 const struct GNUNET_PeerIdentity *peer, 2456 const struct GNUNET_PeerIdentity *peer,
2056 enum GNUNET_ATS_PreferenceKind kind, 2457 enum GNUNET_ATS_PreferenceKind kind,
@@ -2097,7 +2498,7 @@ GAS_mlp_address_change_preference (void *solver,
2097 * @param kind the kind to change the preference 2498 * @param kind the kind to change the preference
2098 * @param score the score 2499 * @param score the score
2099 */ 2500 */
2100void 2501static void
2101GAS_mlp_address_preference_feedback (void *solver, 2502GAS_mlp_address_preference_feedback (void *solver,
2102 void *application, 2503 void *application,
2103 const struct GNUNET_PeerIdentity *peer, 2504 const struct GNUNET_PeerIdentity *peer,
@@ -2139,7 +2540,8 @@ libgnunet_plugin_ats_mlp_done (void *cls)
2139 struct GAS_MLP_Handle *mlp = cls; 2540 struct GAS_MLP_Handle *mlp = cls;
2140 GNUNET_assert (mlp != NULL); 2541 GNUNET_assert (mlp != NULL);
2141 2542
2142 LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutting down mlp solver\n"); 2543 LOG (GNUNET_ERROR_TYPE_DEBUG,
2544 "Shutting down mlp solver\n");
2143 mlp_delete_problem (mlp); 2545 mlp_delete_problem (mlp);
2144 2546
2145 GNUNET_CONTAINER_multipeermap_iterate (mlp->requested_peers, 2547 GNUNET_CONTAINER_multipeermap_iterate (mlp->requested_peers,
@@ -2152,7 +2554,8 @@ libgnunet_plugin_ats_mlp_done (void *cls)
2152 glp_free_env(); 2554 glp_free_env();
2153 GNUNET_free (mlp); 2555 GNUNET_free (mlp);
2154 2556
2155 LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutdown down of mlp solver complete\n"); 2557 LOG (GNUNET_ERROR_TYPE_DEBUG,
2558 "Shutdown down of mlp solver complete\n");
2156 return NULL; 2559 return NULL;
2157} 2560}
2158 2561
diff --git a/src/ats/plugin_ats_mlp.h b/src/ats/plugin_ats_mlp.h
deleted file mode 100644
index 99ee74012..000000000
--- a/src/ats/plugin_ats_mlp.h
+++ /dev/null
@@ -1,634 +0,0 @@
1/*
2 (C) 2011 Christian Grothoff (and other contributing authors)
3
4 GNUnet is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published
6 by the Free Software Foundation; either version 3, or (at your
7 option) any later version.
8
9 GNUnet is distributed in the hope that it will be useful, but
10 WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with GNUnet; see the file COPYING. If not, write to the
16 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA.
18 */
19
20/**
21 * @file ats/plugin_ats_mlp.h
22 * @brief ats MLP problem solver
23 * @author Matthias Wachs
24 * @author Christian Grothoff
25 */
26#include "platform.h"
27#include "gnunet_util_lib.h"
28#include "gnunet_ats_service.h"
29#include "gnunet_ats_plugin.h"
30#include "gnunet-service-ats_addresses.h"
31#include "gnunet_statistics_service.h"
32#include <float.h>
33#if HAVE_LIBGLPK
34#include "glpk.h"
35#endif
36
37#ifndef GNUNET_SERVICE_ATS_ADDRESSES_MLP_H
38#define GNUNET_SERVICE_ATS_ADDRESSES_MLP_H
39
40#define BIG_M_VALUE (UINT32_MAX) /10
41#define BIG_M_STRING "unlimited"
42
43#define MLP_AVERAGING_QUEUE_LENGTH 3
44
45#define MLP_MAX_EXEC_DURATION GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10)
46#define MLP_MAX_ITERATIONS 4096
47
48#define DEFAULT_D 1.0
49#define DEFAULT_R 1.0
50#define DEFAULT_U 1.0
51#define DEFAULT_QUALITY 1.0
52#define DEFAULT_MIN_CONNECTIONS 4
53#define DEFAULT_PEER_PREFERENCE 1.0
54
55#define MLP_NaN -1
56#define MLP_UNDEFINED 0
57#define GLP_YES 1.0
58#define GLP_NO 0.0
59
60enum MLP_Output_Format
61{
62 MLP_MPS,
63 MLP_CPLEX,
64 MLP_GLPK
65};
66
67
68struct MLP_Solution
69{
70 int lp_res;
71 int lp_presolv;
72 int mip_res;
73 int mip_presolv;
74
75 double lp_objective_value;
76 double mlp_objective_value;
77 double mlp_gap;
78 double lp_mlp_gap;
79
80 int p_elements;
81 int p_cols;
82 int p_rows;
83
84 int n_peers;
85 int n_addresses;
86
87};
88
89struct ATS_Peer
90{
91 struct GNUNET_PeerIdentity id;
92
93 /* Was this peer already added to the current problem? */
94 int processed;
95
96 /* constraint 2: 1 address per peer*/
97 unsigned int r_c2;
98
99 /* constraint 9: relativity */
100 unsigned int r_c9;
101
102 /* Legacy preference value */
103 double f;
104};
105
106struct MLP_Problem
107{
108 /**
109 * GLPK (MLP) problem object
110 */
111#if HAVE_LIBGLPK
112 glp_prob *prob;
113#else
114 void *prob;
115#endif
116
117 /* Number of addresses in problem */
118 unsigned int num_addresses;
119 /* Number of peers in problem */
120 unsigned int num_peers;
121 /* Number of elements in problem matrix */
122 unsigned int num_elements;
123
124 /* Row index constraint 2: */
125 unsigned int r_c2;
126 /* Row index constraint 4: minimum connections */
127 unsigned int r_c4;
128 /* Row index constraint 6: maximize diversity */
129 unsigned int r_c6;
130 /* Row index constraint 8: utilization*/
131 unsigned int r_c8;
132 /* Row index constraint 9: relativity*/
133 unsigned int r_c9;
134 /* Row indices quality metrics */
135 int r_q[GNUNET_ATS_QualityPropertiesCount];
136 /* Row indices ATS network quotas */
137 int r_quota[GNUNET_ATS_NetworkTypeCount];
138
139 /* Column index Diversity (D) column */
140 int c_d;
141 /* Column index Utilization (U) column */
142 int c_u;
143 /* Column index Proportionality (R) column */
144 int c_r;
145 /* Column index quality metrics */
146 int c_q[GNUNET_ATS_QualityPropertiesCount];
147
148 /* Problem matrix */
149 /* Current index */
150 unsigned int ci;
151 /* Row index array */
152 int *ia;
153 /* Column index array */
154 int *ja;
155 /* Column index value */
156 double *ar;
157
158};
159
160struct MLP_Variables
161{
162 /* Big M value for bandwidth capping */
163 double BIG_M;
164
165 /* MIP Gap */
166 double mip_gap;
167
168 /* LP MIP Gap */
169 double lp_mip_gap;
170
171 /* ATS Quality metrics
172 *
173 * Array with GNUNET_ATS_QualityPropertiesCount elements
174 * contains mapping to GNUNET_ATS_Property*/
175 int q[GNUNET_ATS_QualityPropertiesCount];
176
177 /* Number of quality metrics */
178 int m_q;
179
180 /* Number of quality metrics */
181 int m_rc;
182
183 /* Quality metric coefficients*/
184 double co_Q[GNUNET_ATS_QualityPropertiesCount];
185
186 /* Ressource costs coefficients*/
187 double co_RC[GNUNET_ATS_QualityPropertiesCount];
188
189 /* Diversity coefficient */
190 double co_D;
191
192 /* Utility coefficient */
193 double co_U;
194
195 /* Relativity coefficient */
196 double co_R;
197
198 /* Minimum bandwidth assigned to an address */
199 unsigned int b_min;
200
201 /* Minimum number of addresses with bandwidth assigned */
202 unsigned int n_min;
203
204 /* Quotas */
205 /* Array mapping array index to ATS network */
206 int quota_index[GNUNET_ATS_NetworkTypeCount];
207 /* Outbound quotas */
208 unsigned long long quota_out[GNUNET_ATS_NetworkTypeCount];
209 /* Inbound quotas */
210
211 unsigned long long quota_in[GNUNET_ATS_NetworkTypeCount];
212
213 /* ATS ressource costs
214 * array with GNUNET_ATS_QualityPropertiesCount elements
215 * contains mapping to GNUNET_ATS_Property
216 * */
217 int rc[GNUNET_ATS_QualityPropertiesCount];
218
219};
220
221/**
222 * MLP Handle
223 */
224struct GAS_MLP_Handle
225{
226 struct GNUNET_ATS_PluginEnvironment *env;
227
228 /**
229 * Statistics handle
230 */
231 struct GNUNET_STATISTICS_Handle *stats;
232
233 /**
234 * Address hashmap for lookups
235 */
236 const struct GNUNET_CONTAINER_MultiPeerMap *addresses;
237
238 /**
239 * Addresses' bandwidth changed callback
240 */
241 GAS_bandwidth_changed_cb bw_changed_cb;
242
243 /**
244 * Addresses' bandwidth changed callback closure
245 */
246 void *bw_changed_cb_cls;
247
248 /**
249 * ATS function to get preferences
250 */
251 GAS_get_preferences get_preferences;
252
253 /**
254 * Closure for ATS function to get preferences
255 */
256 void *get_preferences_cls;
257
258 /**
259 * ATS function to get properties
260 */
261 GAS_get_properties get_properties;
262
263 /**
264 * Closure for ATS function to get properties
265 */
266 void *get_properties_cls;
267
268 /**
269 * Exclude peer from next result propagation
270 */
271 const struct GNUNET_PeerIdentity *exclude_peer;
272
273 /**
274 * Encapsulation for the MLP problem
275 */
276 struct MLP_Problem p;
277
278 /**
279 * Encapsulation for the MLP problem variables
280 */
281 struct MLP_Variables pv;
282
283 /**
284 * Encapsulation for the MLP solution
285 */
286 struct MLP_Solution ps;
287
288 /**
289 * Bulk lock
290 */
291
292 int stat_bulk_lock;
293
294 /**
295 * Number of changes while solver was locked
296 */
297 int stat_bulk_requests;
298
299 /**
300 * GLPK LP control parameter
301 */
302#if HAVE_LIBGLPK
303 glp_smcp control_param_lp;
304#else
305 void *control_param_lp;
306#endif
307
308 /**
309 * GLPK LP control parameter
310 */
311#if HAVE_LIBGLPK
312 glp_iocp control_param_mlp;
313#else
314 void *control_param_mlp;
315#endif
316
317 /**
318 * Peers with pending address requests
319 */
320 struct GNUNET_CONTAINER_MultiPeerMap *requested_peers;
321
322 /**
323 * Was the problem updated since last solution
324 */
325 int stat_mlp_prob_updated;
326
327 /**
328 * Has the problem size changed since last solution
329 */
330 int stat_mlp_prob_changed;
331
332 /**
333 * Solve the problem automatically when updates occur?
334 * Default: GNUNET_YES
335 * Can be disabled for test and measurements
336 */
337 int opt_mlp_auto_solve;
338
339 /**
340 * Write all MILP problems to a MPS file
341 */
342 int opt_dump_problem_all;
343
344 /**
345 * Write all MILP problem solutions to a file
346 */
347 int opt_dump_solution_all;
348
349 /**
350 * Write MILP problems to a MPS file when solver fails
351 */
352 int opt_dump_problem_on_fail;
353
354 /**
355 * Write MILP problem solutions to a file when solver fails
356 */
357 int opt_dump_solution_on_fail;
358
359 /**
360 * solve feasibility only
361 */
362 int opt_dbg_feasibility_only;
363
364 /**
365 * solve autoscale the problem
366 */
367 int opt_dbg_autoscale_problem;
368
369 /**
370 * use the intopt presolver instead of simplex
371 */
372 int opt_dbg_intopt_presolver;
373
374 /**
375 * Print GLPK output
376 */
377 int opt_dbg_glpk_verbose;
378
379 /**
380 * solve autoscale the problem
381 */
382 int opt_dbg_optimize_relativity;
383
384 /**
385 * solve autoscale the problem
386 */
387 int opt_dbg_optimize_diversity;
388
389 /**
390 * solve autoscale the problem
391 */
392 int opt_dbg_optimize_quality;
393
394 /**
395 * solve autoscale the problem
396 */
397 int opt_dbg_optimize_utility;
398
399
400 /**
401 * Output format
402 */
403 enum MLP_Output_Format opt_log_format;
404};
405
406/**
407 * Address specific MLP information
408 */
409struct MLP_information
410{
411
412 /* Bandwidth assigned */
413 struct GNUNET_BANDWIDTH_Value32NBO b_out;
414 struct GNUNET_BANDWIDTH_Value32NBO b_in;
415
416 /* Address selected */
417 int n;
418
419 /* bandwidth column index */
420 signed int c_b;
421
422 /* address usage column */
423 signed int c_n;
424
425 /* row indexes */
426
427 /* constraint 1: bandwidth capping */
428 unsigned int r_c1;
429
430 /* constraint 3: minimum bandwidth */
431 unsigned int r_c3;
432};
433
434
435/**
436 * Solves the MLP problem
437 *
438 * @param solver the MLP Handle
439 * @return #GNUNET_OK if could be solved, GNUNET_SYSERR on failure
440 */
441int
442GAS_mlp_solve_problem (void *solver);
443
444
445/**
446 * Init the MLP problem solving component
447 *
448 * @param cfg the GNUNET_CONFIGURATION_Handle handle
449 * @param stats the GNUNET_STATISTICS handle
450 * @param addresses Hashmap containing addresses
451 * @param network array of GNUNET_ATS_NetworkType with length dest_length
452 * @param out_dest array of outbound quotas
453 * @param in_dest array of outbound quota
454 * @param dest_length array length for quota arrays
455 * @param bw_changed_cb callback for changed bandwidth amounts
456 * @param bw_changed_cb_cls cls for callback
457 * @param get_preference callback to get relative preferences for a peer
458 * @param get_preference_cls cls for callback to get relative preferences for a peer
459 * @param get_properties callback to get relative properties
460 * @param get_properties_cls cls for callback to get relative properties
461 * @return struct GAS_MLP_Handle on success, NULL on fail
462 */
463void *
464GAS_mlp_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
465 const struct GNUNET_STATISTICS_Handle *stats,
466 const struct GNUNET_CONTAINER_MultiPeerMap *addresses,
467 int *network,
468 unsigned long long *out_dest,
469 unsigned long long *in_dest,
470 int dest_length,
471 GAS_bandwidth_changed_cb bw_changed_cb,
472 void *bw_changed_cb_cls,
473 GAS_get_preferences get_preference,
474 void *get_preference_cls,
475 GAS_get_properties get_properties,
476 void *get_properties_cls);
477
478
479/**
480 * Add a single address within a network to the solver
481 *
482 * @param solver the solver Handle
483 * @param address the address to add
484 * @param network network type of this address
485 */
486void
487GAS_mlp_address_add (void *solver, struct ATS_Address *address,
488 uint32_t network);
489
490
491/**
492 * Transport properties for this address have changed
493 *
494 * @param solver solver handle
495 * @param address the address
496 * @param type the ATSI type in HBO
497 * @param abs_value the absolute value of the property
498 * @param rel_value the normalized value
499 */
500void
501GAS_mlp_address_property_changed (void *solver, struct ATS_Address *address,
502 uint32_t type, uint32_t abs_value, double rel_value);
503
504
505/**
506 * Transport session for this address has changed
507 *
508 * NOTE: values in addresses are already updated
509 *
510 * @param solver solver handle
511 * @param address the address
512 * @param cur_session the current session
513 * @param new_session the new session
514 */
515void
516GAS_mlp_address_session_changed (void *solver, struct ATS_Address *address,
517 uint32_t cur_session, uint32_t new_session);
518
519
520/**
521 * Usage for this address has changed
522 *
523 * NOTE: values in addresses are already updated
524 *
525 * @param solver solver handle
526 * @param address the address
527 * @param in_use usage state
528 */
529void
530GAS_mlp_address_inuse_changed (void *solver, struct ATS_Address *address,
531 int in_use);
532
533/**
534 * Network scope for this address has changed
535 *
536 * NOTE: values in addresses are already updated
537 *
538 * @param solver solver handle
539 * @param address the address
540 * @param current_network the current network
541 * @param new_network the new network
542 */
543void
544GAS_mlp_address_change_network (void *solver, struct ATS_Address *address,
545 uint32_t current_network, uint32_t new_network);
546
547/**
548 * Deletes a single address in the MLP problem
549 *
550 * The MLP problem has to be recreated and the problem has to be resolved
551 *
552 * @param solver the MLP Handle
553 * @param address the address to delete
554 * @param session_only delete only session not whole address
555 */
556void
557GAS_mlp_address_delete (void *solver, struct ATS_Address *address,
558 int session_only);
559
560/**
561 * Changes the preferences for a peer in the MLP problem
562 *
563 * @param solver the MLP Handle
564 * @param peer the peer
565 * @param kind the kind to change the preference
566 * @param pref_rel the relative score
567 */
568void
569GAS_mlp_address_change_preference (void *solver,
570 const struct GNUNET_PeerIdentity *peer, enum GNUNET_ATS_PreferenceKind kind,
571 double pref_rel);
572
573/**
574 * Get application feedback for a peer
575 *
576 * @param solver the solver handle
577 * @param application the application
578 * @param peer the peer to change the preference for
579 * @param scope the time interval for this feedback: [now - scope .. now]
580 * @param kind the kind to change the preference
581 * @param score the score
582 */
583void
584GAS_mlp_address_preference_feedback (void *solver, void *application,
585 const struct GNUNET_PeerIdentity *peer,
586 const struct GNUNET_TIME_Relative scope,
587 enum GNUNET_ATS_PreferenceKind kind, double score);
588
589/**
590 * Start a bulk operation
591 *
592 * @param solver the solver
593 */
594void
595GAS_mlp_bulk_start (void *solver);
596
597/**
598 * Bulk operation done
599 */
600void
601GAS_mlp_bulk_stop (void *solver);
602
603/**
604 * Get the preferred address for a specific peer until
605 * GAS_mlp_stop_get_preferred_address is called
606 *
607 * @param solver the MLP Handle
608 * @param peer the peer
609 * @return suggested address
610 */
611const struct ATS_Address *
612GAS_mlp_get_preferred_address (void *solver,
613 const struct GNUNET_PeerIdentity *peer);
614
615/**
616 * Stop notifying about address and bandwidth changes for this peer
617 *
618 * @param solver the MLP handle
619 * @param peer the peer
620 */
621void
622GAS_mlp_stop_get_preferred_address (void *solver,
623 const struct GNUNET_PeerIdentity *peer);
624
625/**
626 * Shutdown the MLP problem solving component
627 *
628 * @param solver the solver handle
629 */
630void
631GAS_mlp_done (void *solver);
632
633#endif
634/* end of plugin_ats_mlp.h */
diff --git a/src/ats/plugin_ats_ril.c b/src/ats/plugin_ats_ril.c
index fef969a89..03bddad50 100644
--- a/src/ats/plugin_ats_ril.c
+++ b/src/ats/plugin_ats_ril.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 (C) 2011 Christian Grothoff (and other contributing authors) 3 (C) 2011-2014 Christian Grothoff (and other contributing authors)
4 4
5 GNUnet is free software; you can redistribute it and/or modify 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 6 it under the terms of the GNU General Public License as published
@@ -24,7 +24,13 @@
24 * @author Fabian Oehlmann 24 * @author Fabian Oehlmann
25 * @author Matthias Wachs 25 * @author Matthias Wachs
26 */ 26 */
27#include "plugin_ats_ril.h" 27#include "platform.h"
28#include <float.h>
29#include <math.h>
30#include "gnunet_ats_plugin.h"
31#include "gnunet-service-ats_addresses.h"
32
33
28 34
29#define LOG(kind,...) GNUNET_log_from (kind, "ats-ril",__VA_ARGS__) 35#define LOG(kind,...) GNUNET_log_from (kind, "ats-ril",__VA_ARGS__)
30 36
@@ -2130,11 +2136,11 @@ ril_cut_from_vector (void **old,
2130 * @param kind the kind to change the preference 2136 * @param kind the kind to change the preference
2131 * @param pref_rel the normalized preference value for this kind over all clients 2137 * @param pref_rel the normalized preference value for this kind over all clients
2132 */ 2138 */
2133void 2139static void
2134GAS_ril_address_change_preference (void *solver, 2140GAS_ril_address_change_preference (void *solver,
2135 const struct GNUNET_PeerIdentity *peer, 2141 const struct GNUNET_PeerIdentity *peer,
2136 enum GNUNET_ATS_PreferenceKind kind, 2142 enum GNUNET_ATS_PreferenceKind kind,
2137 double pref_rel) 2143 double pref_rel)
2138{ 2144{
2139 LOG(GNUNET_ERROR_TYPE_DEBUG, 2145 LOG(GNUNET_ERROR_TYPE_DEBUG,
2140 "API_address_change_preference() Preference '%s' for peer '%s' changed to %.2f \n", 2146 "API_address_change_preference() Preference '%s' for peer '%s' changed to %.2f \n",
@@ -2147,308 +2153,6 @@ GAS_ril_address_change_preference (void *solver,
2147 ril_step (s); 2153 ril_step (s);
2148} 2154}
2149 2155
2150/**
2151 * Entry point for the plugin
2152 *
2153 * @param cls pointer to the 'struct GNUNET_ATS_PluginEnvironment'
2154 */
2155void *
2156libgnunet_plugin_ats_ril_init (void *cls)
2157{
2158 struct GNUNET_ATS_PluginEnvironment *env = cls;
2159 struct GAS_RIL_Handle *solver = GNUNET_new (struct GAS_RIL_Handle);
2160 struct RIL_Scope * cur;
2161 int c;
2162 char *string;
2163 float f_tmp;
2164
2165 LOG(GNUNET_ERROR_TYPE_DEBUG, "API_init() Initializing RIL solver\n");
2166
2167 GNUNET_assert(NULL != env);
2168 GNUNET_assert(NULL != env->cfg);
2169 GNUNET_assert(NULL != env->stats);
2170 GNUNET_assert(NULL != env->bandwidth_changed_cb);
2171 GNUNET_assert(NULL != env->get_preferences);
2172 GNUNET_assert(NULL != env->get_property);
2173
2174 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number(env->cfg, "ats", "RIL_RBF_DIVISOR", &solver->parameters.rbf_divisor))
2175 {
2176 solver->parameters.rbf_divisor = RIL_DEFAULT_RBF_DIVISOR;
2177 }
2178
2179 if (GNUNET_OK
2180 != GNUNET_CONFIGURATION_get_value_time (env->cfg, "ats", "RIL_STEP_TIME_MIN",
2181 &solver->parameters.step_time_min))
2182 {
2183 solver->parameters.step_time_min = RIL_DEFAULT_STEP_TIME_MIN;
2184 }
2185
2186 if (GNUNET_OK
2187 != GNUNET_CONFIGURATION_get_value_time (env->cfg, "ats", "RIL_STEP_TIME_MAX",
2188 &solver->parameters.step_time_max))
2189 {
2190 solver->parameters.step_time_max = RIL_DEFAULT_STEP_TIME_MAX;
2191 }
2192
2193 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (env->cfg, "ats", "RIL_ALGORITHM", &string))
2194 {
2195 solver->parameters.algorithm = !strcmp (string, "SARSA") ? RIL_ALGO_SARSA : RIL_ALGO_Q;
2196 GNUNET_free (string);
2197 }
2198 else
2199 {
2200 solver->parameters.algorithm = RIL_DEFAULT_ALGORITHM;
2201 }
2202
2203 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (env->cfg, "ats", "RIL_SELECT", &string))
2204 {
2205 solver->parameters.select = !strcmp (string, "EGREEDY") ? RIL_SELECT_EGREEDY : RIL_SELECT_SOFTMAX;
2206 GNUNET_free (string);
2207 }
2208 else
2209 {
2210 solver->parameters.select = RIL_DEFAULT_SELECT;
2211 }
2212
2213
2214 solver->parameters.beta = RIL_DEFAULT_DISCOUNT_BETA;
2215 if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats",
2216 "RIL_DISCOUNT_BETA", &f_tmp))
2217 {
2218 if (f_tmp < 0.0)
2219 {
2220 LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"),
2221 "RIL_DISCOUNT_BETA", f_tmp);
2222 }
2223 else
2224 {
2225 solver->parameters.beta = f_tmp;
2226 LOG (GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n",
2227 "RIL_DISCOUNT_BETA", f_tmp);
2228 }
2229 }
2230
2231 solver->parameters.gamma = RIL_DEFAULT_DISCOUNT_GAMMA;
2232 if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats",
2233 "RIL_DISCOUNT_GAMMA", &f_tmp))
2234 {
2235 if ((f_tmp < 0.0) || (f_tmp > 1.0))
2236 {
2237 LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"),
2238 "RIL_DISCOUNT_GAMMA", f_tmp);
2239 }
2240 else
2241 {
2242 solver->parameters.gamma = f_tmp;
2243 LOG (GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n",
2244 "RIL_DISCOUNT_GAMMA", f_tmp);
2245 }
2246 }
2247
2248 solver->parameters.alpha = RIL_DEFAULT_GRADIENT_STEP_SIZE;
2249 if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats",
2250 "RIL_GRADIENT_STEP_SIZE", &f_tmp))
2251 {
2252 if ((f_tmp < 0.0) || (f_tmp > 1.0))
2253 {
2254 LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"),
2255 "RIL_GRADIENT_STEP_SIZE", f_tmp);
2256 }
2257 else
2258 {
2259 solver->parameters.alpha = f_tmp;
2260 LOG (GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n",
2261 "RIL_GRADIENT_STEP_SIZE", f_tmp);
2262 }
2263 }
2264
2265 solver->parameters.lambda = RIL_DEFAULT_TRACE_DECAY;
2266 if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats",
2267 "RIL_TRACE_DECAY", &f_tmp))
2268 {
2269 if ((f_tmp < 0.0) || (f_tmp > 1.0))
2270 {
2271 LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"),
2272 "RIL_TRACE_DECAY", f_tmp);
2273 }
2274 else
2275 {
2276 solver->parameters.lambda = f_tmp;
2277 LOG (GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n",
2278 "RIL_TRACE_DECAY", f_tmp);
2279 }
2280 }
2281
2282 solver->parameters.epsilon_init = RIL_DEFAULT_EXPLORE_RATIO;
2283 if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats",
2284 "RIL_EXPLORE_RATIO", &f_tmp))
2285 {
2286 if ((f_tmp < 0.0) || (f_tmp > 1.0))
2287 {
2288 LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"),
2289 "RIL_EXPLORE_RATIO", f_tmp);
2290 }
2291 else
2292 {
2293 solver->parameters.epsilon_init = f_tmp;
2294 LOG (GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n",
2295 "RIL_EXPLORE_RATIO", f_tmp);
2296 }
2297 }
2298
2299 solver->parameters.epsilon_decay = RIL_DEFAULT_EXPLORE_DECAY;
2300 if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats",
2301 "RIL_EXPLORE_DECAY", &f_tmp))
2302 {
2303 if ((f_tmp < 0.0) || (f_tmp > 0.0))
2304 {
2305 LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"),
2306 "RIL_EXPLORE_DECAY", f_tmp);
2307 }
2308 else
2309 {
2310 solver->parameters.epsilon_decay = f_tmp;
2311 LOG (GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n",
2312 "RIL_EXPLORE_DECAY", f_tmp);
2313 }
2314 }
2315
2316 solver->parameters.temperature_init = RIL_DEFAULT_TEMPERATURE;
2317 if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats",
2318 "RIL_TEMPERATURE", &f_tmp))
2319 {
2320 if (f_tmp <= 0.0)
2321 {
2322 LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"),
2323 "RIL_TEMPERATURE", f_tmp);
2324 }
2325 else
2326 {
2327 solver->parameters.temperature_init = f_tmp;
2328 LOG (GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n",
2329 "RIL_TEMPERATURE", f_tmp);
2330 }
2331 }
2332
2333 solver->parameters.temperature_decay = RIL_DEFAULT_TEMPERATURE_DECAY;
2334 if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats",
2335 "RIL_TEMPERATURE_DECAY", &f_tmp))
2336 {
2337 if ((f_tmp <= 0.0) || solver->parameters.temperature_decay > 1)
2338 {
2339 LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"),
2340 "RIL_TEMPERATURE_DECAY", f_tmp);
2341 }
2342 else
2343 {
2344 solver->parameters.temperature_decay = f_tmp;
2345 LOG (GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n",
2346 "RIL_TEMPERATURE_DECAY", f_tmp);
2347 }
2348 }
2349
2350 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (env->cfg, "ats", "RIL_SIMULATE", &solver->simulate))
2351 {
2352 solver->simulate = GNUNET_NO;
2353 }
2354
2355 if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno(env->cfg, "ats", "RIL_REPLACE_TRACES"))
2356 {
2357 solver->parameters.eligibility_trace_mode = RIL_E_REPLACE;
2358 }
2359 else
2360 {
2361 solver->parameters.eligibility_trace_mode = RIL_E_ACCUMULATE;
2362 }
2363
2364 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (env->cfg, "ats", "RIL_SOCIAL_WELFARE", &string))
2365 {
2366 solver->parameters.social_welfare = !strcmp (string, "NASH") ? RIL_WELFARE_NASH : RIL_WELFARE_EGALITARIAN;
2367 GNUNET_free (string);
2368 }
2369 else
2370 {
2371 solver->parameters.social_welfare = RIL_DEFAULT_WELFARE;
2372 }
2373
2374 env->sf.s_add = &GAS_ril_address_add;
2375 env->sf.s_address_update_property = &GAS_ril_address_property_changed;
2376 env->sf.s_address_update_session = &GAS_ril_address_session_changed;
2377 env->sf.s_address_update_inuse = &GAS_ril_address_inuse_changed;
2378 env->sf.s_address_update_network = &GAS_ril_address_change_network;
2379 env->sf.s_get = &GAS_ril_get_preferred_address;
2380 env->sf.s_get_stop = &GAS_ril_stop_get_preferred_address;
2381 env->sf.s_pref = &GAS_ril_address_change_preference;
2382 env->sf.s_feedback = &GAS_ril_address_preference_feedback;
2383 env->sf.s_del = &GAS_ril_address_delete;
2384 env->sf.s_bulk_start = &GAS_ril_bulk_start;
2385 env->sf.s_bulk_stop = &GAS_ril_bulk_stop;
2386
2387 solver->plugin_envi = env;
2388 solver->networks_count = env->network_count;
2389 solver->network_entries = GNUNET_malloc (env->network_count * sizeof (struct RIL_Scope));
2390 solver->step_count = 0;
2391 solver->done = GNUNET_NO;
2392
2393 for (c = 0; c < env->network_count; c++)
2394 {
2395 cur = &solver->network_entries[c];
2396 cur->type = env->networks[c];
2397 cur->bw_in_available = env->in_quota[c];
2398 cur->bw_out_available = env->out_quota[c];
2399 LOG(GNUNET_ERROR_TYPE_DEBUG, "init() Quotas for %s network: IN %llu - OUT %llu\n", GNUNET_ATS_print_network_type(cur->type), cur->bw_in_available/1024, cur->bw_out_available/1024);
2400 }
2401
2402 LOG(GNUNET_ERROR_TYPE_DEBUG, "init() Parameters:\n");
2403 LOG(GNUNET_ERROR_TYPE_DEBUG, "init() Algorithm = %s, alpha = %f, beta = %f, lambda = %f\n",
2404 solver->parameters.algorithm ? "Q" : "SARSA",
2405 solver->parameters.alpha,
2406 solver->parameters.beta,
2407 solver->parameters.lambda);
2408 LOG(GNUNET_ERROR_TYPE_DEBUG, "init() exploration_ratio = %f, temperature = %f, ActionSelection = %s\n",
2409 solver->parameters.epsilon,
2410 solver->parameters.temperature,
2411 solver->parameters.select ? "EGREEDY" : "SOFTMAX");
2412 LOG(GNUNET_ERROR_TYPE_DEBUG, "init() RBF_DIVISOR = %llu\n",
2413 solver->parameters.rbf_divisor);
2414
2415 return solver;
2416}
2417
2418/**
2419 * Exit point for the plugin
2420 *
2421 * @param cls the solver handle
2422 */
2423void *
2424libgnunet_plugin_ats_ril_done (void *cls)
2425{
2426 struct GAS_RIL_Handle *s = cls;
2427 struct RIL_Peer_Agent *cur_agent;
2428 struct RIL_Peer_Agent *next_agent;
2429
2430 LOG(GNUNET_ERROR_TYPE_DEBUG, "API_done() Shutting down RIL solver\n");
2431
2432 s->done = GNUNET_YES;
2433
2434 cur_agent = s->agents_head;
2435 while (NULL != cur_agent)
2436 {
2437 next_agent = cur_agent->next;
2438 GNUNET_CONTAINER_DLL_remove(s->agents_head, s->agents_tail, cur_agent);
2439 agent_die (s, cur_agent);
2440 cur_agent = next_agent;
2441 }
2442
2443 if (GNUNET_SCHEDULER_NO_TASK != s->step_next_task_id)
2444 {
2445 GNUNET_SCHEDULER_cancel (s->step_next_task_id);
2446 }
2447 GNUNET_free(s->network_entries);
2448 GNUNET_free(s);
2449
2450 return NULL;
2451}
2452 2156
2453/** 2157/**
2454 * Add a new address for a peer to the solver 2158 * Add a new address for a peer to the solver
@@ -2459,8 +2163,10 @@ libgnunet_plugin_ats_ril_done (void *cls)
2459 * @param address the address to add 2163 * @param address the address to add
2460 * @param network network type of this address 2164 * @param network network type of this address
2461 */ 2165 */
2462void 2166static void
2463GAS_ril_address_add (void *solver, struct ATS_Address *address, uint32_t network) 2167GAS_ril_address_add (void *solver,
2168 struct ATS_Address *address,
2169 uint32_t network)
2464{ 2170{
2465 struct GAS_RIL_Handle *s = solver; 2171 struct GAS_RIL_Handle *s = solver;
2466 struct RIL_Peer_Agent *agent; 2172 struct RIL_Peer_Agent *agent;
@@ -2473,7 +2179,8 @@ GAS_ril_address_add (void *solver, struct ATS_Address *address, uint32_t network
2473 int i; 2179 int i;
2474 unsigned int zero; 2180 unsigned int zero;
2475 2181
2476 LOG (GNUNET_ERROR_TYPE_DEBUG, "API_address_add()\n"); 2182 LOG (GNUNET_ERROR_TYPE_DEBUG,
2183 "API_address_add()\n");
2477 2184
2478 net = ril_get_network (s, network); 2185 net = ril_get_network (s, network);
2479 address->solver_information = net; 2186 address->solver_information = net;
@@ -2545,8 +2252,10 @@ GAS_ril_address_add (void *solver, struct ATS_Address *address, uint32_t network
2545 * @param address the address to remove 2252 * @param address the address to remove
2546 * @param session_only delete only session not whole address 2253 * @param session_only delete only session not whole address
2547 */ 2254 */
2548void 2255static void
2549GAS_ril_address_delete (void *solver, struct ATS_Address *address, int session_only) 2256GAS_ril_address_delete (void *solver,
2257 struct ATS_Address *address,
2258 int session_only)
2550{ 2259{
2551 struct GAS_RIL_Handle *s = solver; 2260 struct GAS_RIL_Handle *s = solver;
2552 struct RIL_Peer_Agent *agent; 2261 struct RIL_Peer_Agent *agent;
@@ -2558,9 +2267,11 @@ GAS_ril_address_delete (void *solver, struct ATS_Address *address, int session_o
2558 int i; 2267 int i;
2559 struct RIL_Scope *net; 2268 struct RIL_Scope *net;
2560 2269
2561 LOG(GNUNET_ERROR_TYPE_DEBUG, "API_address_delete() Delete %s%s %s address %s for peer '%s'\n", 2270 LOG (GNUNET_ERROR_TYPE_DEBUG,
2562 session_only ? "session for " : "", address->active ? "active" : "inactive", address->plugin, 2271 "API_address_delete() Delete %s%s %s address %s for peer '%s'\n",
2563 address->addr, GNUNET_i2s (&address->peer)); 2272 session_only ? "session for " : "", address->active ? "active" : "inactive", address->plugin,
2273 address->addr,
2274 GNUNET_i2s (&address->peer));
2564 2275
2565 agent = ril_get_agent (s, &address->peer, GNUNET_NO); 2276 agent = ril_get_agent (s, &address->peer, GNUNET_NO);
2566 if (NULL == agent) 2277 if (NULL == agent)
@@ -2649,25 +2360,29 @@ GAS_ril_address_delete (void *solver, struct ATS_Address *address, int session_o
2649 * @param abs_value the absolute value of the property 2360 * @param abs_value the absolute value of the property
2650 * @param rel_value the normalized value 2361 * @param rel_value the normalized value
2651 */ 2362 */
2652void 2363static void
2653GAS_ril_address_property_changed (void *solver, 2364GAS_ril_address_property_changed (void *solver,
2654 struct ATS_Address *address, 2365 struct ATS_Address *address,
2655 uint32_t type, 2366 uint32_t type,
2656 uint32_t abs_value, 2367 uint32_t abs_value,
2657 double rel_value) 2368 double rel_value)
2658{ 2369{
2370 struct GAS_RIL_Handle *s = solver;
2371
2659 LOG(GNUNET_ERROR_TYPE_DEBUG, 2372 LOG(GNUNET_ERROR_TYPE_DEBUG,
2660 "API_address_property_changed() Property '%s' for peer '%s' address %s changed " 2373 "API_address_property_changed() Property '%s' for peer '%s' address %s changed "
2661 "to %.2f \n", GNUNET_ATS_print_property_type (type), GNUNET_i2s (&address->peer), 2374 "to %.2f \n",
2375 GNUNET_ATS_print_property_type (type),
2376 GNUNET_i2s (&address->peer),
2662 address->addr, rel_value); 2377 address->addr, rel_value);
2663 2378
2664 struct GAS_RIL_Handle *s = solver;
2665 2379
2666 s->parameters.temperature = s->parameters.temperature_init; 2380 s->parameters.temperature = s->parameters.temperature_init;
2667 s->parameters.epsilon = s->parameters.epsilon_init; 2381 s->parameters.epsilon = s->parameters.epsilon_init;
2668 ril_step (s); 2382 ril_step (s);
2669} 2383}
2670 2384
2385
2671/** 2386/**
2672 * Update the session of an address in the solver 2387 * Update the session of an address in the solver
2673 * 2388 *
@@ -2678,15 +2393,17 @@ GAS_ril_address_property_changed (void *solver,
2678 * @param cur_session the current session 2393 * @param cur_session the current session
2679 * @param new_session the new session 2394 * @param new_session the new session
2680 */ 2395 */
2681void 2396static void
2682GAS_ril_address_session_changed (void *solver, 2397GAS_ril_address_session_changed (void *solver,
2683 struct ATS_Address *address, 2398 struct ATS_Address *address,
2684 uint32_t cur_session, 2399 uint32_t cur_session,
2685 uint32_t new_session) 2400 uint32_t new_session)
2686{ 2401{
2687 LOG(GNUNET_ERROR_TYPE_DEBUG, "API_address_session_changed()\n"); 2402 LOG(GNUNET_ERROR_TYPE_DEBUG,
2403 "API_address_session_changed()\n");
2688} 2404}
2689 2405
2406
2690/** 2407/**
2691 * Notify the solver that an address is (not) actively used by transport 2408 * Notify the solver that an address is (not) actively used by transport
2692 * to communicate with a remote peer 2409 * to communicate with a remote peer
@@ -2697,14 +2414,17 @@ GAS_ril_address_session_changed (void *solver,
2697 * @param address the address 2414 * @param address the address
2698 * @param in_use usage state 2415 * @param in_use usage state
2699 */ 2416 */
2700void 2417static void
2701GAS_ril_address_inuse_changed (void *solver, struct ATS_Address *address, int in_use) 2418GAS_ril_address_inuse_changed (void *solver,
2419 struct ATS_Address *address,
2420 int in_use)
2702{ 2421{
2703 LOG(GNUNET_ERROR_TYPE_DEBUG, 2422 LOG(GNUNET_ERROR_TYPE_DEBUG,
2704 "API_address_inuse_changed() Usage for %s address of peer '%s' changed to %s\n", 2423 "API_address_inuse_changed() Usage for %s address of peer '%s' changed to %s\n",
2705 address->plugin, GNUNET_i2s (&address->peer), (GNUNET_YES == in_use) ? "USED" : "UNUSED"); 2424 address->plugin, GNUNET_i2s (&address->peer), (GNUNET_YES == in_use) ? "USED" : "UNUSED");
2706} 2425}
2707 2426
2427
2708/** 2428/**
2709 * Notify solver that the network an address is located in has changed 2429 * Notify solver that the network an address is located in has changed
2710 * 2430 *
@@ -2715,16 +2435,17 @@ GAS_ril_address_inuse_changed (void *solver, struct ATS_Address *address, int in
2715 * @param current_network the current network 2435 * @param current_network the current network
2716 * @param new_network the new network 2436 * @param new_network the new network
2717 */ 2437 */
2718void 2438static void
2719GAS_ril_address_change_network (void *solver, 2439GAS_ril_address_change_network (void *solver,
2720 struct ATS_Address *address, 2440 struct ATS_Address *address,
2721 uint32_t current_network, 2441 uint32_t current_network,
2722 uint32_t new_network) 2442 uint32_t new_network)
2723{ 2443{
2724 struct GAS_RIL_Handle *s = solver; 2444 struct GAS_RIL_Handle *s = solver;
2725 struct RIL_Peer_Agent *agent; 2445 struct RIL_Peer_Agent *agent;
2726 2446
2727 LOG(GNUNET_ERROR_TYPE_DEBUG, "API_address_change_network() Network type changed, moving " 2447 LOG(GNUNET_ERROR_TYPE_DEBUG,
2448 "API_address_change_network() Network type changed, moving "
2728 "%s address of peer %s from '%s' to '%s'\n", 2449 "%s address of peer %s from '%s' to '%s'\n",
2729 (GNUNET_YES == address->active) ? "active" : "inactive", GNUNET_i2s (&address->peer), 2450 (GNUNET_YES == address->active) ? "active" : "inactive", GNUNET_i2s (&address->peer),
2730 GNUNET_ATS_print_network_type (current_network), GNUNET_ATS_print_network_type (new_network)); 2451 GNUNET_ATS_print_network_type (current_network), GNUNET_ATS_print_network_type (new_network));
@@ -2750,6 +2471,7 @@ GAS_ril_address_change_network (void *solver,
2750 address->solver_information = ril_get_network(solver, new_network); 2471 address->solver_information = ril_get_network(solver, new_network);
2751} 2472}
2752 2473
2474
2753/** 2475/**
2754 * Give feedback about the current assignment 2476 * Give feedback about the current assignment
2755 * 2477 *
@@ -2760,7 +2482,7 @@ GAS_ril_address_change_network (void *solver,
2760 * @param kind the kind to change the preference 2482 * @param kind the kind to change the preference
2761 * @param score the score 2483 * @param score the score
2762 */ 2484 */
2763void 2485static void
2764GAS_ril_address_preference_feedback (void *solver, 2486GAS_ril_address_preference_feedback (void *solver,
2765 void *application, 2487 void *application,
2766 const struct GNUNET_PeerIdentity *peer, 2488 const struct GNUNET_PeerIdentity *peer,
@@ -2774,32 +2496,37 @@ GAS_ril_address_preference_feedback (void *solver,
2774 GNUNET_ATS_print_preference_type (kind), scope.rel_value_us / 1000000); 2496 GNUNET_ATS_print_preference_type (kind), scope.rel_value_us / 1000000);
2775} 2497}
2776 2498
2499
2777/** 2500/**
2778 * Start a bulk operation 2501 * Start a bulk operation
2779 * 2502 *
2780 * @param solver the solver 2503 * @param solver the solver
2781 */ 2504 */
2782void 2505static void
2783GAS_ril_bulk_start (void *solver) 2506GAS_ril_bulk_start (void *solver)
2784{ 2507{
2785 struct GAS_RIL_Handle *s = solver; 2508 struct GAS_RIL_Handle *s = solver;
2786 2509
2787 LOG(GNUNET_ERROR_TYPE_DEBUG, "API_bulk_start() lock: %d\n", s->bulk_lock+1); 2510 LOG (GNUNET_ERROR_TYPE_DEBUG,
2511 "API_bulk_start() lock: %d\n", s->bulk_lock+1);
2788 2512
2789 s->bulk_lock++; 2513 s->bulk_lock++;
2790} 2514}
2791 2515
2516
2792/** 2517/**
2793 * Bulk operation done 2518 * Bulk operation done
2794 * 2519 *
2795 * @param solver the solver handle 2520 * @param solver the solver handle
2796 */ 2521 */
2797void 2522static void
2798GAS_ril_bulk_stop (void *solver) 2523GAS_ril_bulk_stop (void *solver)
2799{ 2524{
2800 struct GAS_RIL_Handle *s = solver; 2525 struct GAS_RIL_Handle *s = solver;
2801 2526
2802 LOG(GNUNET_ERROR_TYPE_DEBUG, "API_bulk_stop() lock: %d\n", s->bulk_lock-1); 2527 LOG(GNUNET_ERROR_TYPE_DEBUG,
2528 "API_bulk_stop() lock: %d\n",
2529 s->bulk_lock - 1);
2803 2530
2804 if (s->bulk_lock < 1) 2531 if (s->bulk_lock < 1)
2805 { 2532 {
@@ -2815,6 +2542,7 @@ GAS_ril_bulk_stop (void *solver)
2815 } 2542 }
2816} 2543}
2817 2544
2545
2818/** 2546/**
2819 * Tell solver to notify ATS if the address to use changes for a specific 2547 * Tell solver to notify ATS if the address to use changes for a specific
2820 * peer using the bandwidth changed callback 2548 * peer using the bandwidth changed callback
@@ -2825,8 +2553,9 @@ GAS_ril_bulk_stop (void *solver)
2825 * @param solver the solver handle 2553 * @param solver the solver handle
2826 * @param peer the identity of the peer 2554 * @param peer the identity of the peer
2827 */ 2555 */
2828const struct ATS_Address * 2556static const struct ATS_Address *
2829GAS_ril_get_preferred_address (void *solver, const struct GNUNET_PeerIdentity *peer) 2557GAS_ril_get_preferred_address (void *solver,
2558 const struct GNUNET_PeerIdentity *peer)
2830{ 2559{
2831 struct GAS_RIL_Handle *s = solver; 2560 struct GAS_RIL_Handle *s = solver;
2832 struct RIL_Peer_Agent *agent; 2561 struct RIL_Peer_Agent *agent;
@@ -2866,13 +2595,15 @@ GAS_ril_get_preferred_address (void *solver, const struct GNUNET_PeerIdentity *p
2866 * @param solver the solver handle 2595 * @param solver the solver handle
2867 * @param peer the peer 2596 * @param peer the peer
2868 */ 2597 */
2869void 2598static void
2870GAS_ril_stop_get_preferred_address (void *solver, const struct GNUNET_PeerIdentity *peer) 2599GAS_ril_stop_get_preferred_address (void *solver,
2600 const struct GNUNET_PeerIdentity *peer)
2871{ 2601{
2872 struct GAS_RIL_Handle *s = solver; 2602 struct GAS_RIL_Handle *s = solver;
2873 struct RIL_Peer_Agent *agent; 2603 struct RIL_Peer_Agent *agent;
2874 2604
2875 LOG(GNUNET_ERROR_TYPE_DEBUG, "API_stop_get_preferred_address()"); 2605 LOG (GNUNET_ERROR_TYPE_DEBUG,
2606 "API_stop_get_preferred_address()");
2876 2607
2877 agent = ril_get_agent (s, peer, GNUNET_NO); 2608 agent = ril_get_agent (s, peer, GNUNET_NO);
2878 2609
@@ -2902,4 +2633,310 @@ GAS_ril_stop_get_preferred_address (void *solver, const struct GNUNET_PeerIdenti
2902 GNUNET_i2s (peer), agent->address_inuse->plugin); 2633 GNUNET_i2s (peer), agent->address_inuse->plugin);
2903} 2634}
2904 2635
2636
2637/**
2638 * Entry point for the plugin
2639 *
2640 * @param cls pointer to the 'struct GNUNET_ATS_PluginEnvironment'
2641 */
2642void *
2643libgnunet_plugin_ats_ril_init (void *cls)
2644{
2645 struct GNUNET_ATS_PluginEnvironment *env = cls;
2646 struct GAS_RIL_Handle *solver = GNUNET_new (struct GAS_RIL_Handle);
2647 struct RIL_Scope * cur;
2648 int c;
2649 char *string;
2650 float f_tmp;
2651
2652 LOG(GNUNET_ERROR_TYPE_DEBUG, "API_init() Initializing RIL solver\n");
2653
2654 GNUNET_assert(NULL != env);
2655 GNUNET_assert(NULL != env->cfg);
2656 GNUNET_assert(NULL != env->stats);
2657 GNUNET_assert(NULL != env->bandwidth_changed_cb);
2658 GNUNET_assert(NULL != env->get_preferences);
2659 GNUNET_assert(NULL != env->get_property);
2660
2661 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number(env->cfg, "ats", "RIL_RBF_DIVISOR", &solver->parameters.rbf_divisor))
2662 {
2663 solver->parameters.rbf_divisor = RIL_DEFAULT_RBF_DIVISOR;
2664 }
2665
2666 if (GNUNET_OK
2667 != GNUNET_CONFIGURATION_get_value_time (env->cfg, "ats", "RIL_STEP_TIME_MIN",
2668 &solver->parameters.step_time_min))
2669 {
2670 solver->parameters.step_time_min = RIL_DEFAULT_STEP_TIME_MIN;
2671 }
2672
2673 if (GNUNET_OK
2674 != GNUNET_CONFIGURATION_get_value_time (env->cfg, "ats", "RIL_STEP_TIME_MAX",
2675 &solver->parameters.step_time_max))
2676 {
2677 solver->parameters.step_time_max = RIL_DEFAULT_STEP_TIME_MAX;
2678 }
2679
2680 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (env->cfg, "ats", "RIL_ALGORITHM", &string))
2681 {
2682 solver->parameters.algorithm = !strcmp (string, "SARSA") ? RIL_ALGO_SARSA : RIL_ALGO_Q;
2683 GNUNET_free (string);
2684 }
2685 else
2686 {
2687 solver->parameters.algorithm = RIL_DEFAULT_ALGORITHM;
2688 }
2689
2690 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (env->cfg, "ats", "RIL_SELECT", &string))
2691 {
2692 solver->parameters.select = !strcmp (string, "EGREEDY") ? RIL_SELECT_EGREEDY : RIL_SELECT_SOFTMAX;
2693 GNUNET_free (string);
2694 }
2695 else
2696 {
2697 solver->parameters.select = RIL_DEFAULT_SELECT;
2698 }
2699
2700
2701 solver->parameters.beta = RIL_DEFAULT_DISCOUNT_BETA;
2702 if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats",
2703 "RIL_DISCOUNT_BETA", &f_tmp))
2704 {
2705 if (f_tmp < 0.0)
2706 {
2707 LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"),
2708 "RIL_DISCOUNT_BETA", f_tmp);
2709 }
2710 else
2711 {
2712 solver->parameters.beta = f_tmp;
2713 LOG (GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n",
2714 "RIL_DISCOUNT_BETA", f_tmp);
2715 }
2716 }
2717
2718 solver->parameters.gamma = RIL_DEFAULT_DISCOUNT_GAMMA;
2719 if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats",
2720 "RIL_DISCOUNT_GAMMA", &f_tmp))
2721 {
2722 if ((f_tmp < 0.0) || (f_tmp > 1.0))
2723 {
2724 LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"),
2725 "RIL_DISCOUNT_GAMMA", f_tmp);
2726 }
2727 else
2728 {
2729 solver->parameters.gamma = f_tmp;
2730 LOG (GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n",
2731 "RIL_DISCOUNT_GAMMA", f_tmp);
2732 }
2733 }
2734
2735 solver->parameters.alpha = RIL_DEFAULT_GRADIENT_STEP_SIZE;
2736 if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats",
2737 "RIL_GRADIENT_STEP_SIZE", &f_tmp))
2738 {
2739 if ((f_tmp < 0.0) || (f_tmp > 1.0))
2740 {
2741 LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"),
2742 "RIL_GRADIENT_STEP_SIZE", f_tmp);
2743 }
2744 else
2745 {
2746 solver->parameters.alpha = f_tmp;
2747 LOG (GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n",
2748 "RIL_GRADIENT_STEP_SIZE", f_tmp);
2749 }
2750 }
2751
2752 solver->parameters.lambda = RIL_DEFAULT_TRACE_DECAY;
2753 if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats",
2754 "RIL_TRACE_DECAY", &f_tmp))
2755 {
2756 if ((f_tmp < 0.0) || (f_tmp > 1.0))
2757 {
2758 LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"),
2759 "RIL_TRACE_DECAY", f_tmp);
2760 }
2761 else
2762 {
2763 solver->parameters.lambda = f_tmp;
2764 LOG (GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n",
2765 "RIL_TRACE_DECAY", f_tmp);
2766 }
2767 }
2768
2769 solver->parameters.epsilon_init = RIL_DEFAULT_EXPLORE_RATIO;
2770 if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats",
2771 "RIL_EXPLORE_RATIO", &f_tmp))
2772 {
2773 if ((f_tmp < 0.0) || (f_tmp > 1.0))
2774 {
2775 LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"),
2776 "RIL_EXPLORE_RATIO", f_tmp);
2777 }
2778 else
2779 {
2780 solver->parameters.epsilon_init = f_tmp;
2781 LOG (GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n",
2782 "RIL_EXPLORE_RATIO", f_tmp);
2783 }
2784 }
2785
2786 solver->parameters.epsilon_decay = RIL_DEFAULT_EXPLORE_DECAY;
2787 if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats",
2788 "RIL_EXPLORE_DECAY", &f_tmp))
2789 {
2790 if ((f_tmp < 0.0) || (f_tmp > 0.0))
2791 {
2792 LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"),
2793 "RIL_EXPLORE_DECAY", f_tmp);
2794 }
2795 else
2796 {
2797 solver->parameters.epsilon_decay = f_tmp;
2798 LOG (GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n",
2799 "RIL_EXPLORE_DECAY", f_tmp);
2800 }
2801 }
2802
2803 solver->parameters.temperature_init = RIL_DEFAULT_TEMPERATURE;
2804 if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats",
2805 "RIL_TEMPERATURE", &f_tmp))
2806 {
2807 if (f_tmp <= 0.0)
2808 {
2809 LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"),
2810 "RIL_TEMPERATURE", f_tmp);
2811 }
2812 else
2813 {
2814 solver->parameters.temperature_init = f_tmp;
2815 LOG (GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n",
2816 "RIL_TEMPERATURE", f_tmp);
2817 }
2818 }
2819
2820 solver->parameters.temperature_decay = RIL_DEFAULT_TEMPERATURE_DECAY;
2821 if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats",
2822 "RIL_TEMPERATURE_DECAY", &f_tmp))
2823 {
2824 if ((f_tmp <= 0.0) || solver->parameters.temperature_decay > 1)
2825 {
2826 LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"),
2827 "RIL_TEMPERATURE_DECAY", f_tmp);
2828 }
2829 else
2830 {
2831 solver->parameters.temperature_decay = f_tmp;
2832 LOG (GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n",
2833 "RIL_TEMPERATURE_DECAY", f_tmp);
2834 }
2835 }
2836
2837 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (env->cfg, "ats", "RIL_SIMULATE", &solver->simulate))
2838 {
2839 solver->simulate = GNUNET_NO;
2840 }
2841
2842 if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno(env->cfg, "ats", "RIL_REPLACE_TRACES"))
2843 {
2844 solver->parameters.eligibility_trace_mode = RIL_E_REPLACE;
2845 }
2846 else
2847 {
2848 solver->parameters.eligibility_trace_mode = RIL_E_ACCUMULATE;
2849 }
2850
2851 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (env->cfg, "ats", "RIL_SOCIAL_WELFARE", &string))
2852 {
2853 solver->parameters.social_welfare = !strcmp (string, "NASH") ? RIL_WELFARE_NASH : RIL_WELFARE_EGALITARIAN;
2854 GNUNET_free (string);
2855 }
2856 else
2857 {
2858 solver->parameters.social_welfare = RIL_DEFAULT_WELFARE;
2859 }
2860
2861 env->sf.s_add = &GAS_ril_address_add;
2862 env->sf.s_address_update_property = &GAS_ril_address_property_changed;
2863 env->sf.s_address_update_session = &GAS_ril_address_session_changed;
2864 env->sf.s_address_update_inuse = &GAS_ril_address_inuse_changed;
2865 env->sf.s_address_update_network = &GAS_ril_address_change_network;
2866 env->sf.s_get = &GAS_ril_get_preferred_address;
2867 env->sf.s_get_stop = &GAS_ril_stop_get_preferred_address;
2868 env->sf.s_pref = &GAS_ril_address_change_preference;
2869 env->sf.s_feedback = &GAS_ril_address_preference_feedback;
2870 env->sf.s_del = &GAS_ril_address_delete;
2871 env->sf.s_bulk_start = &GAS_ril_bulk_start;
2872 env->sf.s_bulk_stop = &GAS_ril_bulk_stop;
2873
2874 solver->plugin_envi = env;
2875 solver->networks_count = env->network_count;
2876 solver->network_entries = GNUNET_malloc (env->network_count * sizeof (struct RIL_Scope));
2877 solver->step_count = 0;
2878 solver->done = GNUNET_NO;
2879
2880 for (c = 0; c < env->network_count; c++)
2881 {
2882 cur = &solver->network_entries[c];
2883 cur->type = env->networks[c];
2884 cur->bw_in_available = env->in_quota[c];
2885 cur->bw_out_available = env->out_quota[c];
2886 LOG(GNUNET_ERROR_TYPE_DEBUG, "init() Quotas for %s network: IN %llu - OUT %llu\n", GNUNET_ATS_print_network_type(cur->type), cur->bw_in_available/1024, cur->bw_out_available/1024);
2887 }
2888
2889 LOG(GNUNET_ERROR_TYPE_DEBUG, "init() Parameters:\n");
2890 LOG(GNUNET_ERROR_TYPE_DEBUG, "init() Algorithm = %s, alpha = %f, beta = %f, lambda = %f\n",
2891 solver->parameters.algorithm ? "Q" : "SARSA",
2892 solver->parameters.alpha,
2893 solver->parameters.beta,
2894 solver->parameters.lambda);
2895 LOG(GNUNET_ERROR_TYPE_DEBUG, "init() exploration_ratio = %f, temperature = %f, ActionSelection = %s\n",
2896 solver->parameters.epsilon,
2897 solver->parameters.temperature,
2898 solver->parameters.select ? "EGREEDY" : "SOFTMAX");
2899 LOG(GNUNET_ERROR_TYPE_DEBUG, "init() RBF_DIVISOR = %llu\n",
2900 solver->parameters.rbf_divisor);
2901
2902 return solver;
2903}
2904
2905
2906/**
2907 * Exit point for the plugin
2908 *
2909 * @param cls the solver handle
2910 */
2911void *
2912libgnunet_plugin_ats_ril_done (void *cls)
2913{
2914 struct GAS_RIL_Handle *s = cls;
2915 struct RIL_Peer_Agent *cur_agent;
2916 struct RIL_Peer_Agent *next_agent;
2917
2918 LOG(GNUNET_ERROR_TYPE_DEBUG, "API_done() Shutting down RIL solver\n");
2919
2920 s->done = GNUNET_YES;
2921
2922 cur_agent = s->agents_head;
2923 while (NULL != cur_agent)
2924 {
2925 next_agent = cur_agent->next;
2926 GNUNET_CONTAINER_DLL_remove(s->agents_head, s->agents_tail, cur_agent);
2927 agent_die (s, cur_agent);
2928 cur_agent = next_agent;
2929 }
2930
2931 if (GNUNET_SCHEDULER_NO_TASK != s->step_next_task_id)
2932 {
2933 GNUNET_SCHEDULER_cancel (s->step_next_task_id);
2934 }
2935 GNUNET_free(s->network_entries);
2936 GNUNET_free(s);
2937
2938 return NULL;
2939}
2940
2941
2905/* end of plugin_ats_ril.c */ 2942/* end of plugin_ats_ril.c */
diff --git a/src/ats/plugin_ats_ril.h b/src/ats/plugin_ats_ril.h
deleted file mode 100644
index 578eb5125..000000000
--- a/src/ats/plugin_ats_ril.h
+++ /dev/null
@@ -1,191 +0,0 @@
1/*
2 This file is part of GNUnet.
3 (C) 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/**
22 * @file ats/plugin_ats_ril.h
23 * @brief ATS reinforcement learning solver
24 * @author Fabian Oehlmann
25 * @author Matthias Wachs
26 */
27#include "platform.h"
28#include <float.h>
29#include <math.h>
30#include "gnunet_ats_plugin.h"
31#include "gnunet-service-ats_addresses.h"
32
33/**
34 * ATS reinforcement learning solver
35 *
36 * General description
37 */
38
39/**
40 * Changes the preferences for a peer in the problem
41 *
42 * @param solver the solver handle
43 * @param peer the peer to change the preference for
44 * @param kind the kind to change the preference
45 * @param pref_rel the normalized preference value for this kind over all clients
46 */
47void
48GAS_ril_address_change_preference (void *solver,
49 const struct GNUNET_PeerIdentity *peer,
50 enum GNUNET_ATS_PreferenceKind kind,
51 double pref_rel);
52
53/**
54 * Add a single address within a network to the solver
55 *
56 * @param solver the solver Handle
57 * @param address the address to add
58 * @param network network type of this address
59 */
60void
61GAS_ril_address_add (void *solver,
62 struct ATS_Address *address,
63 uint32_t network);
64
65/**
66 * Transport properties for this address have changed
67 *
68 * @param solver solver handle
69 * @param address the address
70 * @param type the ATSI type in HBO
71 * @param abs_value the absolute value of the property
72 * @param rel_value the normalized value
73 */
74void
75GAS_ril_address_property_changed (void *solver,
76 struct ATS_Address *address,
77 uint32_t type,
78 uint32_t abs_value,
79 double rel_value);
80
81/**
82 * Transport session for this address has changed
83 *
84 * NOTE: values in addresses are already updated
85 *
86 * @param solver solver handle
87 * @param address the address
88 * @param cur_session the current session
89 * @param new_session the new session
90 */
91void
92GAS_ril_address_session_changed (void *solver,
93 struct ATS_Address *address,
94 uint32_t cur_session,
95 uint32_t new_session);
96
97/**
98 * Usage for this address has changed
99 *
100 * NOTE: values in addresses are already updated
101 *
102 * @param solver solver handle
103 * @param address the address
104 * @param in_use usage state
105 */
106void
107GAS_ril_address_inuse_changed (void *solver,
108 struct ATS_Address *address,
109 int in_use);
110
111/**
112 * Network scope for this address has changed
113 *
114 * NOTE: values in addresses are already updated
115 *
116 * @param solver solver handle
117 * @param address the address
118 * @param current_network the current network
119 * @param new_network the new network
120 */
121void
122GAS_ril_address_change_network (void *solver,
123 struct ATS_Address *address,
124 uint32_t current_network,
125 uint32_t new_network);
126
127/**
128 * Remove an address from the solver
129 *
130 * @param solver the solver handle
131 * @param address the address to remove
132 * @param session_only delete only session not whole address
133 */
134void
135GAS_ril_address_delete (void *solver,
136 struct ATS_Address *address,
137 int session_only);
138
139/**
140 * Get application feedback for a peer
141 *
142 * @param solver the solver handle
143 * @param application the application
144 * @param peer the peer to change the preference for
145 * @param scope the time interval for this feedback: [now - scope .. now]
146 * @param kind the kind to change the preference
147 * @param score the score
148 */
149void
150GAS_ril_address_preference_feedback (void *solver,
151 void *application,
152 const struct GNUNET_PeerIdentity *peer,
153 const struct GNUNET_TIME_Relative scope,
154 enum GNUNET_ATS_PreferenceKind kind,
155 double score);
156
157/**
158 * Start a bulk operation
159 *
160 * @param solver the solver
161 */
162void
163GAS_ril_bulk_start (void *solver);
164
165/**
166 * Bulk operation done
167 */
168void
169GAS_ril_bulk_stop (void *solver);
170
171/**
172 * Stop notifying about address and bandwidth changes for this peer
173 *
174 * @param solver the solver handle
175 * @param peer the peer
176 */
177void
178GAS_ril_stop_get_preferred_address (void *solver,
179 const struct GNUNET_PeerIdentity *peer);
180
181/**
182 * Get the prefered address for a specific peer
183 *
184 * @param solver the solver handle
185 * @param peer the identity of the peer
186 */
187const struct ATS_Address *
188GAS_ril_get_preferred_address (void *solver,
189 const struct GNUNET_PeerIdentity *peer);
190
191/* end of plugin_ats_ril.h */