aboutsummaryrefslogtreecommitdiff
path: root/src/transport
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2011-03-30 15:16:00 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2011-03-30 15:16:00 +0000
commit5d665839858da08ee47cd724faed399b6bfde7fd (patch)
tree5eda20e44410a89cf8b6f39106f256f9e4387c0b /src/transport
parent02f95346373949f78389a83a81ae3b9f6c379187 (diff)
downloadgnunet-5d665839858da08ee47cd724faed399b6bfde7fd.tar.gz
gnunet-5d665839858da08ee47cd724faed399b6bfde7fd.zip
optimazitaion constrain 6 works
Diffstat (limited to 'src/transport')
-rw-r--r--src/transport/gnunet-service-transport.c55
1 files changed, 45 insertions, 10 deletions
diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c
index 795cb0682..e75720aaa 100644
--- a/src/transport/gnunet-service-transport.c
+++ b/src/transport/gnunet-service-transport.c
@@ -5600,7 +5600,9 @@ static int ats_create_problem (int max_it, int max_dur )
5600 5600
5601 double v_b_min = 100; 5601 double v_b_min = 100;
5602 double v_n_min = 1; 5602 double v_n_min = 1;
5603 double M = 109951162777600; // 100 TB 5603
5604 //double M = 10000000000; // ~10 GB
5605 double M = 1000;
5604 5606
5605 // This are values that are later set from extern 5607 // This are values that are later set from extern
5606 double D = 1; 5608 double D = 1;
@@ -5675,6 +5677,9 @@ static int ats_create_problem (int max_it, int max_dur )
5675 c_mechs--; 5677 c_mechs--;
5676 c_peers--; 5678 c_peers--;
5677 5679
5680 if (v_n_min > c_peers)
5681 v_n_min = c_peers;
5682
5678 /* number of variables == coloumns */ 5683 /* number of variables == coloumns */
5679 //int c_cols = 2 * c_mechs + 3 + c_q_metrics; 5684 //int c_cols = 2 * c_mechs + 3 + c_q_metrics;
5680 /* number of constraints == rows */ 5685 /* number of constraints == rows */
@@ -5682,7 +5687,7 @@ static int ats_create_problem (int max_it, int max_dur )
5682 5687
5683 if (VERBOSE_ATS) GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Creating problem with: %i peers, %i mechanisms\n", c_peers, c_mechs); 5688 if (VERBOSE_ATS) GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Creating problem with: %i peers, %i mechanisms\n", c_peers, c_mechs);
5684 5689
5685 int size = 1 + 6 *c_mechs; 5690 int size = 1 + 7 *c_mechs +1;
5686 int row_index; 5691 int row_index;
5687 int array_index=1; 5692 int array_index=1;
5688 int * ia = GNUNET_malloc (size * sizeof (int)); 5693 int * ia = GNUNET_malloc (size * sizeof (int));
@@ -5703,7 +5708,7 @@ static int ats_create_problem (int max_it, int max_dur )
5703 glp_set_col_name(prob, c, name); 5708 glp_set_col_name(prob, c, name);
5704 GNUNET_free (name); 5709 GNUNET_free (name);
5705 glp_set_col_bnds(prob, c, GLP_LO, 0.0, 0.0); 5710 glp_set_col_bnds(prob, c, GLP_LO, 0.0, 0.0);
5706 glp_set_obj_coef(prob, c, 1.0); 5711 glp_set_obj_coef(prob, c, 1);
5707 5712
5708 } 5713 }
5709 /* adding n_t cols */ 5714 /* adding n_t cols */
@@ -5714,7 +5719,7 @@ static int ats_create_problem (int max_it, int max_dur )
5714 GNUNET_free (name); 5719 GNUNET_free (name);
5715 glp_set_col_bnds(prob, c, GLP_DB, 0.0, 1.0); 5720 glp_set_col_bnds(prob, c, GLP_DB, 0.0, 1.0);
5716 glp_set_col_kind(prob, c, GLP_IV); 5721 glp_set_col_kind(prob, c, GLP_IV);
5717 glp_set_obj_coef(prob, c, 1.0); 5722 glp_set_obj_coef(prob, c, 0);
5718 } 5723 }
5719 5724
5720 /* feasibility constraints */ 5725 /* feasibility constraints */
@@ -5724,7 +5729,7 @@ static int ats_create_problem (int max_it, int max_dur )
5724 glp_add_rows(prob, c_peers); 5729 glp_add_rows(prob, c_peers);
5725 for (c=1; c<=c_peers; c++) 5730 for (c=1; c<=c_peers; c++)
5726 { 5731 {
5727 glp_set_row_bnds(prob, row_index, GLP_DB, 0.0, 1.0); 5732 glp_set_row_bnds(prob, row_index, GLP_FX, 1.0, 1.0);
5728 5733
5729 struct ATS_mechanism *m = peers[c].m_head; 5734 struct ATS_mechanism *m = peers[c].m_head;
5730 while (m!=NULL) 5735 while (m!=NULL)
@@ -5840,15 +5845,15 @@ static int ats_create_problem (int max_it, int max_dur )
5840 glp_add_cols(prob, 3 + c_q_metrics); 5845 glp_add_cols(prob, 3 + c_q_metrics);
5841 glp_set_col_name(prob, (2*c_mechs) + 1, "d"); 5846 glp_set_col_name(prob, (2*c_mechs) + 1, "d");
5842 glp_set_obj_coef(prob, (2*c_mechs) + 1, D); 5847 glp_set_obj_coef(prob, (2*c_mechs) + 1, D);
5843 //glp_set_col_bnds(prob, c, GLP_DB, 0.0, 1.0); 5848 glp_set_col_bnds(prob, (2*c_mechs) + 1, GLP_LO, 0.0, 0);
5844 //glp_set_col_kind(prob, c, GLP_IV); 5849 //glp_set_col_kind(prob, c, GLP_IV);
5845 glp_set_col_name(prob, (2*c_mechs) + 2, "u"); 5850 glp_set_col_name(prob, (2*c_mechs) + 2, "u");
5846 glp_set_obj_coef(prob, (2*c_mechs) + 2, U); 5851 glp_set_obj_coef(prob, (2*c_mechs) + 2, 0);
5847 //glp_set_col_bnds(prob, c, GLP_DB, 0.0, 1.0); 5852 //glp_set_col_bnds(prob, c, GLP_DB, 0.0, 1.0);
5848 //glp_set_col_kind(prob, c, GLP_IV); 5853 //glp_set_col_kind(prob, c, GLP_IV);
5849 glp_set_col_name(prob, (2*c_mechs) + 3, "r"); 5854 glp_set_col_name(prob, (2*c_mechs) + 3, "r");
5850 glp_set_obj_coef(prob, (2*c_mechs) + 3, R); 5855 glp_set_obj_coef(prob, (2*c_mechs) + 3, 0);
5851 //glp_set_col_bnds(prob, c, GLP_DB, 0.0, 1.0); 5856 //glp_set_col_bnds(prob, (2*c_mechs) + 3, GLP_DB, 0.0, 100.0);
5852 //glp_set_col_kind(prob, c, GLP_IV); 5857 //glp_set_col_kind(prob, c, GLP_IV);
5853 for (c=1; c<= c_q_metrics; c++) 5858 for (c=1; c<= c_q_metrics; c++)
5854 { 5859 {
@@ -5858,6 +5863,36 @@ static int ats_create_problem (int max_it, int max_dur )
5858 GNUNET_free (name); 5863 GNUNET_free (name);
5859 glp_set_obj_coef(prob, (2*c_mechs) + 3 +c, Q[c]); 5864 glp_set_obj_coef(prob, (2*c_mechs) + 3 +c, Q[c]);
5860 } 5865 }
5866
5867 // Constraint 6: optimize for diversity
5868 if (VERBOSE_ATS) GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Constraint 6\n");
5869 glp_add_rows(prob, 1);
5870 if (VERBOSE_ATS) GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bounds [row]=[%i] \n",row_index);
5871 glp_set_row_bnds(prob, row_index, GLP_FX, 0.0, 0.0);
5872 //glp_set_row_bnds(prob, row_index, GLP_UP, 0.0, 0.0);
5873 for (c=1; c<=c_mechs; c++)
5874 {
5875 // b_t - n_t * b_min >= 0
5876 ia[array_index] = row_index;
5877 ja[array_index] = c_mechs + mechanisms[c].col_index;
5878 ar[array_index] = 1;
5879 if (VERBOSE_ATS) GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n",array_index, ia[array_index], ja[array_index], ar[array_index]);
5880 array_index++;
5881 }
5882
5883 ia[array_index] = row_index;
5884 ja[array_index] = (2*c_mechs) + 1;
5885 ar[array_index] = -1;
5886
5887 if (VERBOSE_ATS) GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n",array_index, ia[array_index], ja[array_index], ar[array_index]);
5888 array_index++;
5889 row_index ++;
5890
5891 GNUNET_assert (row_index-1==c_peers+(2*c_mechs)+2);
5892 GNUNET_assert (array_index-1==7*c_mechs+1);
5893
5894
5895
5861 glp_load_matrix(prob, array_index-1, ia, ja, ar); 5896 glp_load_matrix(prob, array_index-1, ia, ja, ar);
5862 5897
5863 5898
@@ -5936,7 +5971,7 @@ static int ats_create_problem (int max_it, int max_dur )
5936 5971
5937 char * debug_solution = NULL; 5972 char * debug_solution = NULL;
5938 char * old = NULL; 5973 char * old = NULL;
5939 for (c=1; c<= 2*c_mechs; c++ ) 5974 for (c=1; c<= (2*c_mechs) +3; c++ )
5940 { 5975 {
5941 old = debug_solution; 5976 old = debug_solution;
5942 GNUNET_asprintf(&debug_solution, "%s %s = %g;", (debug_solution!=NULL) ? debug_solution : "", glp_get_col_name(prob,c), glp_get_col_prim(prob, c)); 5977 GNUNET_asprintf(&debug_solution, "%s %s = %g;", (debug_solution!=NULL) ? debug_solution : "", glp_get_col_name(prob,c), glp_get_col_prim(prob, c));