diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2013-02-22 16:24:33 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2013-02-22 16:24:33 +0000 |
commit | e96241b427a96832b5f145612dc1e1d5e4f5294f (patch) | |
tree | 8b8a11a478a4d8ba29a2f5848335850eca381059 | |
parent | 230f67b5290a2f16a08160537f68a1e3ed5f0240 (diff) | |
download | gnunet-e96241b427a96832b5f145612dc1e1d5e4f5294f.tar.gz gnunet-e96241b427a96832b5f145612dc1e1d5e4f5294f.zip |
modifications
-rw-r--r-- | src/ats/gnunet-service-ats_addresses_mlp.c | 164 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_addresses_mlp.h | 19 |
2 files changed, 56 insertions, 127 deletions
diff --git a/src/ats/gnunet-service-ats_addresses_mlp.c b/src/ats/gnunet-service-ats_addresses_mlp.c index 6a103c8b3..4358c5cf4 100644 --- a/src/ats/gnunet-service-ats_addresses_mlp.c +++ b/src/ats/gnunet-service-ats_addresses_mlp.c | |||
@@ -154,7 +154,13 @@ mlp_term_hook (void *info, const char *s) | |||
154 | } | 154 | } |
155 | 155 | ||
156 | 156 | ||
157 | 157 | static int | |
158 | reset_peers (void *cls, const struct GNUNET_HashCode * key, void *value) | ||
159 | { | ||
160 | struct ATS_Peer *peer = value; | ||
161 | peer->processed = GNUNET_NO; | ||
162 | return GNUNET_OK; | ||
163 | } | ||
158 | 164 | ||
159 | /** | 165 | /** |
160 | * Delete the MLP problem and free the constrain matrix | 166 | * Delete the MLP problem and free the constrain matrix |
@@ -192,6 +198,7 @@ mlp_delete_problem (struct GAS_MLP_Handle *mlp) | |||
192 | mlp->p.ci = 0; | 198 | mlp->p.ci = 0; |
193 | mlp->p.prob = NULL; | 199 | mlp->p.prob = NULL; |
194 | } | 200 | } |
201 | GNUNET_CONTAINER_multihashmap_iterate (mlp->peers, &reset_peers, NULL); | ||
195 | } | 202 | } |
196 | 203 | ||
197 | 204 | ||
@@ -552,60 +559,6 @@ update_quality (struct GAS_MLP_Handle *mlp, struct ATS_Address * address) | |||
552 | 559 | ||
553 | #endif | 560 | #endif |
554 | 561 | ||
555 | /** | ||
556 | * Add constraints that are iterating over "forall addresses" | ||
557 | * | ||
558 | * @param cls GAS_MLP_Handle | ||
559 | * @param key Hashcode | ||
560 | * @param value ATS_Address | ||
561 | * | ||
562 | * @return GNUNET_OK to continue | ||
563 | */ | ||
564 | static int | ||
565 | mlp_create_constraint_it (void *cls, const struct GNUNET_HashCode * key, void *value) | ||
566 | { | ||
567 | struct GAS_MLP_Handle *mlp = cls; | ||
568 | struct MLP_Problem *p = &mlp->p; | ||
569 | struct ATS_Address *address = value; | ||
570 | struct ATS_Peer *peer = NULL; | ||
571 | struct MLP_information *mlpi; | ||
572 | unsigned int row_index; | ||
573 | char *name; | ||
574 | |||
575 | |||
576 | |||
577 | /* c 10) obey network specific quotas | ||
578 | * (1)*b_1 + ... + (1)*b_m <= quota_n | ||
579 | */ | ||
580 | int cur_row = 0; | ||
581 | int c; | ||
582 | for (c = 0; c < GNUNET_ATS_NetworkTypeCount; c++) | ||
583 | { | ||
584 | if (mlp->pv.quota_index[c] == address->atsp_network_type) | ||
585 | { | ||
586 | cur_row = p->r_quota[c]; | ||
587 | break; | ||
588 | } | ||
589 | } | ||
590 | |||
591 | if (cur_row != 0) | ||
592 | { | ||
593 | p->ia[p->ci] = cur_row; | ||
594 | p->ja[p->ci] = mlpi->c_b; | ||
595 | p->ar[p->ci] = 1; | ||
596 | #if DEBUG_MLP_PROBLEM_CREATION | ||
597 | LOG (GNUNET_ERROR_TYPE_DEBUG, "[P]: Set value [%u,%u] == %.2f\n", | ||
598 | p->ia[p->ci], p->ja[p->ci], p->ar[p->ci]); | ||
599 | #endif | ||
600 | p->ci++; | ||
601 | } | ||
602 | else | ||
603 | { | ||
604 | GNUNET_break (0); | ||
605 | } | ||
606 | |||
607 | return GNUNET_OK; | ||
608 | } | ||
609 | 562 | ||
610 | 563 | ||
611 | /** | 564 | /** |
@@ -706,9 +659,6 @@ mlp_add_constraints_all_addresses (struct GAS_MLP_Handle *mlp, struct GNUNET_CON | |||
706 | */ | 659 | */ |
707 | 660 | ||
708 | 661 | ||
709 | |||
710 | GNUNET_CONTAINER_multihashmap_iterate (addresses, mlp_create_constraint_it, mlp); | ||
711 | |||
712 | /* Adding constraint rows | 662 | /* Adding constraint rows |
713 | * This constraints are kind of "for all peers" | 663 | * This constraints are kind of "for all peers" |
714 | * Feasibility constraints: | 664 | * Feasibility constraints: |
@@ -731,41 +681,6 @@ mlp_add_constraints_all_addresses (struct GAS_MLP_Handle *mlp, struct GNUNET_CON | |||
731 | struct ATS_Address *addr = peer->head; | 681 | struct ATS_Address *addr = peer->head; |
732 | struct MLP_information *mlpi = NULL; | 682 | struct MLP_information *mlpi = NULL; |
733 | 683 | ||
734 | /* Adding rows for c 2) */ | ||
735 | peer->r_c2 = glp_add_rows (p->prob, 1); | ||
736 | GNUNET_asprintf(&name, "c2_%s", GNUNET_i2s(&peer->id)); | ||
737 | glp_set_row_name (p->prob, peer->r_c2, name); | ||
738 | /* Set row bound == 1 */ | ||
739 | glp_set_row_bnds (p->prob, peer->r_c2, GLP_FX, 1.0, 1.0); | ||
740 | #if DEBUG_MLP_PROBLEM_CREATION | ||
741 | LOG (GNUNET_ERROR_TYPE_DEBUG, "[P]: Added row [%u] `%s': %s %u\n", | ||
742 | peer->r_c2, name, | ||
743 | "==", 1); | ||
744 | #endif | ||
745 | GNUNET_free (name); | ||
746 | |||
747 | /* Adding rows for c 9) */ | ||
748 | peer->r_c9 = glp_add_rows (p->prob, 1); | ||
749 | GNUNET_asprintf(&name, "c9_%s", GNUNET_i2s(&peer->id)); | ||
750 | glp_set_row_name (p->prob, peer->r_c9, name); | ||
751 | /* Set row bound == 0 */ | ||
752 | glp_set_row_bnds (p->prob, peer->r_c9, GLP_LO, 0.0, 0.0); | ||
753 | #if DEBUG_MLP_PROBLEM_CREATION | ||
754 | LOG (GNUNET_ERROR_TYPE_DEBUG, "[P]: Added row [%u] `%s': %s %u\n", | ||
755 | peer->r_c9, name, | ||
756 | "<=", 1); | ||
757 | #endif | ||
758 | GNUNET_free (name); | ||
759 | |||
760 | /* Set -r */ | ||
761 | ia[p->ci] = peer->r_c9; | ||
762 | ja[p->ci] = p->c_r; | ||
763 | ar[p->ci] = -peer->f; | ||
764 | #if DEBUG_MLP_PROBLEM_CREATION | ||
765 | LOG (GNUNET_ERROR_TYPE_DEBUG, "[P]: Set value [%u,%u] == %.2f\n", | ||
766 | p->ia[p->ci], p->ja[p->ci], p->ar[p->ci]); | ||
767 | #endif | ||
768 | p->ci++; | ||
769 | 684 | ||
770 | /* For all addresses of this peer */ | 685 | /* For all addresses of this peer */ |
771 | while (addr != NULL) | 686 | while (addr != NULL) |
@@ -897,6 +812,8 @@ mlp_create_problem_set_value (struct MLP_Problem *p, int row, int col, double va | |||
897 | GNUNET_break (0); | 812 | GNUNET_break (0); |
898 | return; | 813 | return; |
899 | } | 814 | } |
815 | if ((0 == row) || (0 == col)) | ||
816 | GNUNET_break (0); | ||
900 | p->ia[p->ci] = row ; | 817 | p->ia[p->ci] = row ; |
901 | p->ja[p->ci] = col; | 818 | p->ja[p->ci] = col; |
902 | p->ar[p->ci] = val; | 819 | p->ar[p->ci] = val; |
@@ -980,6 +897,26 @@ mlp_create_problem_add_address_information (void *cls, const struct GNUNET_HashC | |||
980 | if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains(mlp->peers, key)) | 897 | if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains(mlp->peers, key)) |
981 | return GNUNET_OK; | 898 | return GNUNET_OK; |
982 | 899 | ||
900 | /* Get peer */ | ||
901 | peer = GNUNET_CONTAINER_multihashmap_get (mlp->peers, key); | ||
902 | if (peer->processed == GNUNET_NO) | ||
903 | { | ||
904 | /* Add peer dependent constraints */ | ||
905 | /* Add constraint c2 */ | ||
906 | GNUNET_asprintf(&name, "c2_%s", GNUNET_i2s(&address->peer)); | ||
907 | peer->r_c2 = mlp_create_problem_create_constraint (p, name, GLP_FX, 1.0, 1.0); | ||
908 | GNUNET_free (name); | ||
909 | /* Add constraint c9 */ | ||
910 | GNUNET_asprintf(&name, "c9_%s", GNUNET_i2s(&address->peer)); | ||
911 | peer->r_c9 = mlp_create_problem_create_constraint (p, name, GLP_LO, 0.0, 0.0); | ||
912 | GNUNET_free (name); | ||
913 | /* c 9) set coefficient */ | ||
914 | mlp_create_problem_set_value (p, peer->r_c9, p->c_r, -peer->f); | ||
915 | |||
916 | peer->processed = GNUNET_YES; | ||
917 | } | ||
918 | |||
919 | |||
983 | /* Prepare solver information */ | 920 | /* Prepare solver information */ |
984 | if (NULL != address->solver_information) | 921 | if (NULL != address->solver_information) |
985 | { | 922 | { |
@@ -1030,17 +967,25 @@ mlp_create_problem_add_address_information (void *cls, const struct GNUNET_HashC | |||
1030 | mlp_create_problem_set_value (p, p->r_c4, mlpi->c_n, 1); | 967 | mlp_create_problem_set_value (p, p->r_c4, mlpi->c_n, 1); |
1031 | /* c 6) maximize diversity */ | 968 | /* c 6) maximize diversity */ |
1032 | mlp_create_problem_set_value (p, p->r_c6, mlpi->c_n, 1); | 969 | mlp_create_problem_set_value (p, p->r_c6, mlpi->c_n, 1); |
970 | /* c 2) 1 address peer peer */ | ||
971 | mlp_create_problem_set_value (p, peer->r_c2, mlpi->c_n, 1); | ||
972 | /* c 9) relativity */ | ||
973 | mlp_create_problem_set_value (p, peer->r_c9, mlpi->c_b, 1); | ||
974 | /* c 8) utility */ | ||
975 | mlp_create_problem_set_value (p, p->r_c8, mlpi->c_b, 1); | ||
1033 | 976 | ||
1034 | 977 | /* c 10) obey network specific quotas | |
1035 | /* Get peer */ | 978 | * (1)*b_1 + ... + (1)*b_m <= quota_n |
1036 | peer = GNUNET_CONTAINER_multihashmap_get (mlp->peers, key); | 979 | */ |
1037 | peer->processed = GNUNET_NO; | 980 | int c; |
1038 | 981 | for (c = 0; c < GNUNET_ATS_NetworkTypeCount; c++) | |
1039 | 982 | { | |
1040 | /* Add peer dependent constraints */ | 983 | if (mlp->pv.quota_index[c] == address->atsp_network_type) |
1041 | /* Add constraint c2 */ | 984 | { |
1042 | /* Add constraint c9 */ | 985 | mlp_create_problem_set_value (p, p->r_quota[c], mlpi->c_b, 1); |
1043 | 986 | break; | |
987 | } | ||
988 | } | ||
1044 | 989 | ||
1045 | return GNUNET_OK; | 990 | return GNUNET_OK; |
1046 | } | 991 | } |
@@ -1140,7 +1085,7 @@ mlp_create_problem (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_MultiHas | |||
1140 | p->prob = glp_create_prob (); | 1085 | p->prob = glp_create_prob (); |
1141 | GNUNET_assert (NULL != p->prob); | 1086 | GNUNET_assert (NULL != p->prob); |
1142 | p->num_peers = GNUNET_CONTAINER_multihashmap_size (mlp->peers); | 1087 | p->num_peers = GNUNET_CONTAINER_multihashmap_size (mlp->peers); |
1143 | p->num_addresses = mlp_create_problem_count_addresses (addresses, mlp->peers); | 1088 | p->num_addresses = mlp_create_problem_count_addresses (mlp->peers, addresses); |
1144 | p->num_elements = ((7 * p->num_addresses) + (5 * p->num_addresses + mlp->pv.m_q + p->num_peers + 2) + 1); | 1089 | p->num_elements = ((7 * p->num_addresses) + (5 * p->num_addresses + mlp->pv.m_q + p->num_peers + 2) + 1); |
1145 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Rebuilding problem for %u peer(s) and %u addresse(s) == %u elements\n", | 1090 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Rebuilding problem for %u peer(s) and %u addresse(s) == %u elements\n", |
1146 | p->num_peers, p->num_addresses, p->num_elements); | 1091 | p->num_peers, p->num_addresses, p->num_elements); |
@@ -1172,17 +1117,6 @@ mlp_create_problem (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_MultiHas | |||
1172 | /* Adding address independent constraint rows */ | 1117 | /* Adding address independent constraint rows */ |
1173 | GNUNET_CONTAINER_multihashmap_iterate (addresses, &mlp_create_problem_add_address_information, mlp); | 1118 | GNUNET_CONTAINER_multihashmap_iterate (addresses, &mlp_create_problem_add_address_information, mlp); |
1174 | 1119 | ||
1175 | #if 0 | ||
1176 | /* Add columns for addresses */ | ||
1177 | GNUNET_CONTAINER_multihashmap_iterate (peers, mlp_create_address_columns_it, mlp); | ||
1178 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Problems contains %u peers, %u addresses, %u addresses skipped \n", | ||
1179 | GNUNET_CONTAINER_multihashmap_size(mlp->peers), | ||
1180 | p->num_addresses, GNUNET_CONTAINER_multihashmap_size(peers)- p->num_addresses); | ||
1181 | |||
1182 | /* Add constraints rows */ | ||
1183 | mlp_add_constraints_all_addresses (mlp, peers); | ||
1184 | # endif | ||
1185 | |||
1186 | /* Load the matrix */ | 1120 | /* Load the matrix */ |
1187 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Loading matrix\n"); | 1121 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Loading matrix\n"); |
1188 | glp_load_matrix(p->prob, (p->ci)-1, p->ia, p->ja, p->ar); | 1122 | glp_load_matrix(p->prob, (p->ci)-1, p->ia, p->ja, p->ar); |
diff --git a/src/ats/gnunet-service-ats_addresses_mlp.h b/src/ats/gnunet-service-ats_addresses_mlp.h index ab6681b0b..15e509849 100644 --- a/src/ats/gnunet-service-ats_addresses_mlp.h +++ b/src/ats/gnunet-service-ats_addresses_mlp.h | |||
@@ -58,16 +58,6 @@ struct ATS_Peer | |||
58 | 58 | ||
59 | /* Was this peer already added to the current problem? */ | 59 | /* Was this peer already added to the current problem? */ |
60 | int processed; | 60 | int processed; |
61 | #if 0 | ||
62 | struct ATS_Peer *next; | ||
63 | struct ATS_Peer *prev; | ||
64 | |||
65 | |||
66 | |||
67 | /* Array of quality preferences */ | ||
68 | double f_q[GNUNET_ATS_QualityPropertiesCount]; | ||
69 | /* Legacy preference value */ | ||
70 | double f; | ||
71 | 61 | ||
72 | /* constraint 2: 1 address per peer*/ | 62 | /* constraint 2: 1 address per peer*/ |
73 | unsigned int r_c2; | 63 | unsigned int r_c2; |
@@ -75,8 +65,13 @@ struct ATS_Peer | |||
75 | /* constraint 9: relativity */ | 65 | /* constraint 9: relativity */ |
76 | unsigned int r_c9; | 66 | unsigned int r_c9; |
77 | 67 | ||
78 | struct ATS_Address *head; | 68 | /* Legacy preference value */ |
79 | struct ATS_Address *tail; | 69 | double f; |
70 | |||
71 | #if 0 | ||
72 | /* Array of quality preferences */ | ||
73 | double f_q[GNUNET_ATS_QualityPropertiesCount]; | ||
74 | |||
80 | #endif | 75 | #endif |
81 | }; | 76 | }; |
82 | 77 | ||