diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2011-03-29 19:46:22 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2011-03-29 19:46:22 +0000 |
commit | ea7acd3217a45c4d3e6794ca51252cc4be3c36e8 (patch) | |
tree | cf9badcc3573b96a2657bf9dcfa7594eeb6488f5 /src/transport | |
parent | fcddae5473b65ebd13e5e5c9b8eec22a74d3dca0 (diff) | |
download | gnunet-ea7acd3217a45c4d3e6794ca51252cc4be3c36e8.tar.gz gnunet-ea7acd3217a45c4d3e6794ca51252cc4be3c36e8.zip |
the new formulation including feasibility constraints
Diffstat (limited to 'src/transport')
-rw-r--r-- | src/transport/gnunet-service-transport.c | 480 |
1 files changed, 241 insertions, 239 deletions
diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c index 1f3ed74f3..839e3fd38 100644 --- a/src/transport/gnunet-service-transport.c +++ b/src/transport/gnunet-service-transport.c | |||
@@ -42,11 +42,11 @@ | |||
42 | #include <glpk.h> | 42 | #include <glpk.h> |
43 | #endif | 43 | #endif |
44 | 44 | ||
45 | #define DEBUG_BLACKLIST GNUNET_YES | 45 | #define DEBUG_BLACKLIST GNUNET_NO |
46 | 46 | ||
47 | #define DEBUG_PING_PONG GNUNET_YES | 47 | #define DEBUG_PING_PONG GNUNET_NO |
48 | 48 | ||
49 | #define DEBUG_TRANSPORT_HELLO GNUNET_YES | 49 | #define DEBUG_TRANSPORT_HELLO GNUNET_NO |
50 | 50 | ||
51 | #define DEBUG_ATS GNUNET_NO | 51 | #define DEBUG_ATS GNUNET_NO |
52 | #define VERBOSE_ATS GNUNET_NO | 52 | #define VERBOSE_ATS GNUNET_NO |
@@ -5551,290 +5551,295 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
5551 | GNUNET_break (bc_head == NULL); | 5551 | GNUNET_break (bc_head == NULL); |
5552 | } | 5552 | } |
5553 | 5553 | ||
5554 | struct ATS_transports | 5554 | struct ATS_mechanism |
5555 | { | 5555 | { |
5556 | struct ATS_mechanism * prev; | ||
5557 | struct ATS_mechanism * next; | ||
5558 | struct ForeignAddressList * addr; | ||
5559 | struct TransportPlugin * plugin; | ||
5560 | struct ATS_peer * peer; | ||
5561 | int col_index; | ||
5556 | int id; | 5562 | int id; |
5557 | double c_max; | 5563 | double c_max; |
5558 | double c_1; | 5564 | double c_1; |
5559 | }; | 5565 | }; |
5560 | 5566 | ||
5561 | 5567 | struct ATS_peer | |
5562 | #if HAVE_LIBGLPK | ||
5563 | static glp_prob * | ||
5564 | ats_create_problem (int peers, | ||
5565 | int transports, | ||
5566 | double b_min, | ||
5567 | double b_max, | ||
5568 | double r, double R, | ||
5569 | const struct ATS_peer * pl, | ||
5570 | const struct ATS_transports * tl, | ||
5571 | int max_it, | ||
5572 | int max_dur, int mlp) | ||
5573 | { | 5568 | { |
5569 | int id; | ||
5570 | struct GNUNET_PeerIdentity peer; | ||
5571 | struct NeighbourList * n; | ||
5572 | struct ATS_mechanism * m_head; | ||
5573 | struct ATS_mechanism * m_tail; | ||
5574 | |||
5575 | /* preference value f */ | ||
5576 | double f; | ||
5577 | int t; | ||
5578 | }; | ||
5574 | 5579 | ||
5575 | int result = GLP_UNDEF; | ||
5576 | int c1, c2; | ||
5577 | glp_prob *lp; | ||
5578 | char * peer_n; | ||
5579 | 5580 | ||
5580 | int rows = 1 + (3*peers) + (transports); | 5581 | static void ats_create_problem (int max_it, int max_dur ) |
5581 | int cols = peers; | 5582 | { |
5582 | int index = 1; | 5583 | #if !HAVE_LIBGLPK |
5583 | int cur_row = 0; | 5584 | if (DEBUG_ATS) GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "no glpk installed\n"); |
5584 | int size = 1+(rows*cols); | 5585 | return; |
5586 | #else | ||
5587 | if (DEBUG_ATS) GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "glpk installed\n"); | ||
5588 | #endif | ||
5585 | 5589 | ||
5590 | glp_prob *prob; | ||
5586 | 5591 | ||
5587 | int * ia = GNUNET_malloc (size * sizeof (int)); | 5592 | int c_peers = 0; |
5588 | int * ja = GNUNET_malloc (size * sizeof (int)); | 5593 | int c_mechs = 0; |
5589 | double * ar = GNUNET_malloc(size* sizeof (double)); | 5594 | |
5595 | int c_c_ressources = 0; | ||
5596 | int c_q_metrics = 0; | ||
5590 | 5597 | ||
5591 | double value; | 5598 | double v_b_min = 100; |
5599 | double v_n_min = 2; | ||
5600 | double M = 1000000000; | ||
5592 | 5601 | ||
5593 | if (DEBUG_ATS) GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Creating LP problem: %i peers, relativity r %3.2f, b_max %5.2f, b_min %5.2f, \n",peers, r, b_max, b_min); | 5602 | struct NeighbourList *next = neighbours; |
5594 | if (DEBUG_ATS) GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Current memory consumption %i\n",(1+(rows*cols) * (2*sizeof(int) + sizeof(double)))); | 5603 | while (next!=NULL) |
5595 | lp = glp_create_prob(); | ||
5596 | glp_set_prob_name(lp, "gnunet ats bandwidth distribution"); | ||
5597 | glp_set_obj_dir(lp, GLP_MAX); | ||
5598 | /* Adding transports and objective function coefficients*/ | ||
5599 | glp_add_cols(lp, cols); | ||
5600 | for (c1=1; c1<=cols; c1++) | ||
5601 | { | 5604 | { |
5602 | GNUNET_asprintf(&peer_n,"%s",GNUNET_i2s(&pl[c1-1].peer)); | 5605 | struct ReadyList *r_next = next->plugins; |
5603 | if (DEBUG_ATS) GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Peer[%i] , transport %i, %s: f: %f\n",c1-1 , pl[c1-1].t, peer_n, pl[c1-1].f); | 5606 | while (r_next != NULL) |
5604 | /* add a single transport*/ | 5607 | { |
5605 | glp_set_col_name(lp, c1, peer_n); | 5608 | struct ForeignAddressList * a_next = r_next->addresses; |
5606 | /* add a lower bound */ | 5609 | while (a_next != NULL) |
5607 | glp_set_col_bnds(lp, c1, GLP_LO, 0.0, 0.0); | 5610 | { |
5608 | /* set coefficient function */ | 5611 | c_mechs++; |
5609 | value = pl[c1-1].f/b_max; | 5612 | a_next = a_next->next; |
5610 | value = 1.0; | 5613 | } |
5611 | glp_set_obj_coef(lp, c1, value); | 5614 | r_next = r_next->next; |
5612 | GNUNET_free(peer_n); | 5615 | } |
5616 | next = next->next; | ||
5617 | c_peers++; | ||
5613 | } | 5618 | } |
5614 | 5619 | ||
5615 | /* Adding constraints */ | 5620 | if (c_mechs==0) |
5616 | glp_add_rows(lp, rows); | ||
5617 | cur_row = 1; | ||
5618 | |||
5619 | /* constraint 1: Maximum bandwidth for all peers | ||
5620 | * sum(b_i) <= b_max | ||
5621 | */ | ||
5622 | glp_set_row_bnds(lp, cur_row, GLP_UP, 0.0, b_max); | ||
5623 | for (index=1; index<=cols; index++) | ||
5624 | { | 5621 | { |
5625 | ia[index] = 1, ja[index] = index, ar[index] = 1.0; | 5622 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "No addresses for bw distribution available\n", c_peers); |
5623 | return; | ||
5626 | } | 5624 | } |
5627 | 5625 | ||
5628 | /* constraint 2: Maximum bandwidth per peer | 5626 | struct ATS_mechanism * mechanisms = GNUNET_malloc((1+c_mechs) * sizeof (struct ATS_mechanism)); |
5629 | * V b_i in B: b_i <= b_max | 5627 | struct ATS_peer * peers = GNUNET_malloc((1+c_peers) * sizeof (struct ATS_peer)); |
5630 | */ | 5628 | |
5631 | cur_row = 2; | 5629 | if (VERBOSE_ATS) GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Found mechanisms: %i\n", c_mechs); |
5632 | for (c1=0; c1<peers; c1++) | 5630 | c_mechs = 1; |
5631 | c_peers = 1; | ||
5632 | next = neighbours; | ||
5633 | while (next!=NULL) | ||
5633 | { | 5634 | { |
5634 | //GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "row: %i \n", cur_row); | 5635 | peers[c_peers].peer = next->id; |
5635 | glp_set_row_bnds(lp, cur_row , GLP_UP, 0.0, b_max); | 5636 | peers[c_peers].m_head = NULL; |
5637 | peers[c_peers].m_tail = NULL; | ||
5636 | 5638 | ||
5637 | for (c2 = 1; c2 <= cols; c2++) | 5639 | struct ReadyList *r_next = next->plugins; |
5640 | while (r_next != NULL) | ||
5638 | { | 5641 | { |
5639 | ia[index] = cur_row; | 5642 | struct ForeignAddressList * a_next = r_next->addresses; |
5640 | ja[index] = c2; | 5643 | while (a_next != NULL) |
5641 | ar[index] = ((c1+1 == c2) ? 1.0 : 0.0); | 5644 | { |
5642 | index++; | 5645 | if (DEBUG_ATS) GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%i Peer: `%s' %x:\n", c_mechs, GNUNET_i2s(&next->id), |
5646 | a_next); | ||
5647 | mechanisms[c_mechs].addr = a_next; | ||
5648 | mechanisms[c_mechs].col_index = c_mechs; | ||
5649 | mechanisms[c_mechs].peer = &peers[c_peers]; | ||
5650 | mechanisms[c_mechs].next = NULL; | ||
5651 | |||
5652 | GNUNET_CONTAINER_DLL_insert_tail(peers[c_peers].m_head, peers[c_peers].m_tail, &mechanisms[c_mechs]); | ||
5653 | c_mechs++; | ||
5654 | a_next = a_next->next; | ||
5655 | } | ||
5656 | r_next = r_next->next; | ||
5643 | } | 5657 | } |
5644 | cur_row++; | 5658 | c_peers++; |
5659 | next = next->next; | ||
5645 | } | 5660 | } |
5661 | c_mechs--; | ||
5662 | c_peers--; | ||
5646 | 5663 | ||
5647 | /* constraint 3: Minimum bandwidth | 5664 | /* number of variables == coloumns */ |
5648 | * V b_i in B: b_i >= b_min | 5665 | //int c_cols = 2 * c_mechs + 3 + c_q_metrics; |
5649 | */ | 5666 | /* number of constraints == rows */ |
5650 | for (c1=0; c1<peers; c1++) | 5667 | //int c_rows = 2 * c_peers + 2 * c_mechs + c_c_ressources + c_q_metrics + 3; |
5651 | { | ||
5652 | glp_set_row_bnds(lp, cur_row , GLP_LO, b_min, 0.0); | ||
5653 | 5668 | ||
5654 | for (c2 = 1; c2 <= cols; c2++) | 5669 | if (VERBOSE_ATS) GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Creating problem with: %i peers, %i mechanisms\n", c_peers, c_mechs); |
5655 | { | ||
5656 | ia[index] = cur_row; | ||
5657 | ja[index] = c2; | ||
5658 | ar[index] = ((c1+1 == c2) ? 1.0 : 0.0); | ||
5659 | index++; | ||
5660 | } | ||
5661 | cur_row++; | ||
5662 | } | ||
5663 | 5670 | ||
5664 | /* constraint 4: Bandwidth assignment relativity to peer preference | 5671 | int size = 6 *c_mechs; |
5665 | * bi/ {bmax, cmax } >= r*f | 5672 | int row_index; |
5666 | */ | 5673 | int array_index=0; |
5667 | for (c1=0; c1<peers; c1++) | 5674 | int * ia = GNUNET_malloc (size * sizeof (int)); |
5675 | int * ja = GNUNET_malloc (size * sizeof (int)); | ||
5676 | double * ar = GNUNET_malloc(size* sizeof (double)); | ||
5677 | |||
5678 | prob = glp_create_prob(); | ||
5679 | glp_set_prob_name(prob, "gnunet ats bandwidth distribution"); | ||
5680 | glp_set_obj_dir(prob, GLP_MAX); | ||
5681 | |||
5682 | /* adding columns */ | ||
5683 | int c; | ||
5684 | char * name; | ||
5685 | glp_add_cols(prob, 2 * c_mechs); | ||
5686 | for (c=1; c <= c_mechs; c++) | ||
5668 | { | 5687 | { |
5688 | GNUNET_asprintf(&name, "b%i",c); | ||
5689 | glp_set_col_name(prob, c, name); | ||
5690 | GNUNET_free (name); | ||
5691 | glp_set_col_bnds(prob, c, GLP_LO, 0.0, 0.0); | ||
5692 | glp_set_obj_coef(prob, c, 1.0); | ||
5669 | 5693 | ||
5670 | value = pl[c1].f * r; | ||
5671 | glp_set_row_bnds(lp, cur_row , GLP_LO, value, 0.0); | ||
5672 | for (c2 = 1; c2 <= cols; c2++) | ||
5673 | { | ||
5674 | //GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "c1: %i c2 %i index: %i \n",c1 , c2, index); | ||
5675 | ia[index] = cur_row; | ||
5676 | ja[index] = c2; | ||
5677 | /* This is something to verify */ | ||
5678 | if (tl[pl[c1].t].c_max < b_max) | ||
5679 | value = tl[pl[c1].t].c_max; | ||
5680 | else | ||
5681 | value = b_max; | ||
5682 | ar[index] = ((c1+1 == c2) ? (1/value) : 0.0); | ||
5683 | //GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "ia: %i ja %i ar: %f \n",cur_row , c2, ((c1+1 == c2) ? (1/value) : 0.0)); | ||
5684 | index++; | ||
5685 | } | ||
5686 | cur_row++; | ||
5687 | } | 5694 | } |
5688 | 5695 | for (c=c_mechs; c <= 2*c_mechs; c++) | |
5689 | /* constraint 4: transport capacity | ||
5690 | * sum of b * c_i < c_max */ | ||
5691 | for (c1=0; c1<transports; c1++) | ||
5692 | { | 5696 | { |
5697 | GNUNET_asprintf(&name, "n%i",c); | ||
5698 | glp_set_col_name(prob, c, "n1"); | ||
5699 | glp_set_col_bnds(prob, c, GLP_LO, 0.0, 0.0); | ||
5700 | glp_set_col_bnds(prob, c, GLP_LO, 0.0, 1.0); | ||
5701 | glp_set_col_kind(prob, c, GLP_IV); | ||
5702 | glp_set_obj_coef(prob, c, 1.0); | ||
5703 | GNUNET_free (name); | ||
5704 | } | ||
5693 | 5705 | ||
5694 | value = tl[c1].c_max; | 5706 | /* feasibility constraints */ |
5695 | if (DEBUG_ATS) GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Transport %i: c_max %5.2f c_1 %5.2f \n", c1, value, tl[c1].c_1); | 5707 | /* one address per peer*/ |
5696 | glp_set_row_bnds(lp, cur_row , GLP_UP, 0.0 , value); | 5708 | if (VERBOSE_ATS) GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Constraint 1\n"); |
5709 | row_index = 1; | ||
5710 | glp_add_rows(prob, c_peers); | ||
5711 | for (c=1; c<=c_peers; c++) | ||
5712 | { | ||
5713 | glp_set_row_bnds(prob, row_index, GLP_DB, 0.0, 1.0); | ||
5697 | 5714 | ||
5698 | for (c2 = 1; c2 <= cols; c2++) | 5715 | struct ATS_mechanism *m = peers[c].m_head; |
5716 | while (m!=NULL) | ||
5699 | { | 5717 | { |
5700 | 5718 | ia[array_index] = row_index; | |
5701 | ia[index] = cur_row; | 5719 | ja[array_index] = (c_mechs + m->col_index); |
5702 | ja[index] = c2; | 5720 | ar[array_index] = 1; |
5703 | if (pl[c2-1].t == tl[c1].id) | 5721 | 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]); |
5704 | value = tl[c1].c_1; | 5722 | array_index++; |
5705 | else value = 0; | 5723 | m = m->next; |
5706 | ar[index] = value; | ||
5707 | index++; | ||
5708 | } | 5724 | } |
5709 | cur_row++; | 5725 | row_index++; |
5710 | } | 5726 | } |
5727 | GNUNET_assert (row_index-1==c_peers); | ||
5728 | GNUNET_assert (array_index==c_mechs); | ||
5711 | 5729 | ||
5712 | glp_load_matrix(lp, rows * cols, ia, ja, ar); | 5730 | /* Constraint 1: only active mechanism gets bandwidth assigned */ |
5713 | 5731 | if (VERBOSE_ATS) GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Constraint 2\n"); | |
5714 | /* Solve the MLP problem */ | 5732 | glp_add_rows(prob, c_mechs); |
5715 | 5733 | for (c=1; c<=c_mechs; c++) | |
5716 | if (mlp == GNUNET_YES) | ||
5717 | { | 5734 | { |
5718 | #if 0 | 5735 | /* b_t - n_t * M <= 0 */ |
5719 | glp_iocp opt; | 5736 | if (VERBOSE_ATS) GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bounds [row]=[%i] \n",row_index); |
5720 | glp_init_iocp(&opt); | 5737 | glp_set_row_bnds(prob, row_index, GLP_UP, 0.0, 0.0); |
5721 | 5738 | ||
5722 | /* Use LP presolver (if not, valid LP solution has to be provided)*/ | 5739 | ia[array_index] = row_index; |
5723 | opt.presolve =GLP_ON; | 5740 | ja[array_index] = mechanisms[c].col_index; |
5724 | /* maximum duration */ | 5741 | ar[array_index] = 1; |
5725 | opt.tm_lim = max_dur; | 5742 | 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]); |
5726 | /* output level */ | 5743 | array_index++; |
5727 | if (VERBOSE_ATS) | 5744 | ia[array_index] = row_index; |
5728 | opt.msg_lev = GLP_MSG_ALL; | 5745 | ja[array_index] = c_mechs + mechanisms[c].col_index; |
5729 | else | 5746 | ar[array_index] = -M; |
5730 | opt.msg_lev = GLP_MSG_OFF; | 5747 | 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]); |
5731 | result = glp_intopt(lp, &opt); | 5748 | array_index++; |
5732 | #endif | 5749 | row_index ++; |
5733 | } | 5750 | } |
5734 | /* Solve the LP problem */ | 5751 | GNUNET_assert (row_index-1==c_peers+c_mechs); |
5752 | GNUNET_assert (array_index==c_mechs+(2*c_mechs)); | ||
5753 | |||
5754 | /* Constraint 3: minimum bandwidth*/ | ||
5755 | if (VERBOSE_ATS) GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Constraint 3\n"); | ||
5756 | glp_add_rows(prob, c_mechs); | ||
5757 | for (c=1; c<=c_mechs; c++) | ||
5735 | { | 5758 | { |
5736 | glp_smcp opt ; | 5759 | /* b_t - n_t * b_min <= 0 */ |
5737 | glp_init_smcp(&opt); | 5760 | if (VERBOSE_ATS) GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bounds [row]=[%i] \n",row_index); |
5738 | 5761 | glp_set_row_bnds(prob, row_index, GLP_UP, 0.0, 0.0); | |
5739 | /* maximum iterations */ | 5762 | |
5740 | opt.it_lim = max_it; | 5763 | ia[array_index] = row_index; |
5741 | /* maximum duration */ | 5764 | ja[array_index] = mechanisms[c].col_index; |
5742 | opt.tm_lim = max_dur; | 5765 | ar[array_index] = 1; |
5743 | opt.presolve = GLP_ON; | 5766 | 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]); |
5744 | /* output level */ | 5767 | array_index++; |
5745 | if (VERBOSE_ATS) | 5768 | ia[array_index] = row_index; |
5746 | opt.msg_lev = GLP_MSG_ALL; | 5769 | ja[array_index] = c_mechs + mechanisms[c].col_index; |
5747 | else | 5770 | ar[array_index] = -v_b_min; |
5748 | opt.msg_lev = GLP_MSG_OFF; | 5771 | 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]); |
5749 | 5772 | array_index++; | |
5750 | result = glp_simplex(lp, &opt); | 5773 | row_index ++; |
5751 | } | 5774 | } |
5775 | GNUNET_assert (row_index-1==c_peers+(2*c_mechs)); | ||
5776 | GNUNET_assert (array_index==c_mechs+(4*c_mechs)); | ||
5752 | 5777 | ||
5753 | if (DEBUG_ATS) | 5778 | /* Constraint 4: max ressource capacity */ |
5779 | /* | ||
5780 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Constraint 3\n"); | ||
5781 | glp_add_rows(prob, c_mechs); | ||
5782 | for (c=1; c<=c_mechs; c++) | ||
5754 | { | 5783 | { |
5755 | switch (result) { | 5784 | // b_t - n_t * b_min >= 0 |
5756 | case GLP_ESTOP : /* search terminated by application */ | 5785 | if (VERBOSE_ATS) GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bounds [row]=[%i] \n",row_index); |
5757 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Search terminated by application "); | 5786 | glp_set_row_bnds(prob, row_index, GLP_LO, 0.0, 0.0); |
5758 | break; | 5787 | |
5759 | case GLP_EITLIM : /* iteration limit exceeded */ | 5788 | ia[array_index] = row_index; |
5760 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Iteration limit exceeded "); | 5789 | ja[array_index] = mechanisms[c].col_index; |
5761 | break; | 5790 | ar[array_index] = 1; |
5762 | break; | 5791 | 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]); |
5763 | case GLP_ETMLIM : /* time limit exceeded */ | 5792 | array_index++; |
5764 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Time limit exceeded "); | 5793 | ia[array_index] = row_index; |
5765 | break; | 5794 | ja[array_index] = c_mechs + mechanisms[c].col_index; |
5766 | case GLP_ENOFEAS: /* no primal/dual feasible solution */ | 5795 | ar[array_index] = -v_b_min; |
5767 | case GLP_ENOCVG : /* no convergence */ | 5796 | 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]); |
5768 | case GLP_ERANGE : /* result out of range */ | 5797 | array_index++; |
5769 | case GLP_ENOPFS : /* no primal feasible solution */ | 5798 | row_index ++; |
5770 | case GLP_ENODFS : /* no dual feasible solution */ | ||
5771 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No feasible solution"); | ||
5772 | break; | ||
5773 | |||
5774 | case GLP_EBADB : /* invalid basis */ | ||
5775 | case GLP_ESING : /* singular matrix */ | ||
5776 | case GLP_ECOND : /* ill-conditioned matrix */ | ||
5777 | case GLP_EBOUND : /* invalid bounds */ | ||
5778 | case GLP_EFAIL : /* solver failed */ | ||
5779 | case GLP_EOBJLL : /* objective lower limit reached */ | ||
5780 | case GLP_EOBJUL : /* objective upper limit reached */ | ||
5781 | case GLP_EROOT : /* root LP optimum not provided */ | ||
5782 | case GLP_EMIPGAP: /* relative mip gap tolerance reached */ | ||
5783 | case GLP_EINSTAB: /* numerical instability */ | ||
5784 | case GLP_EDATA : /* invalid data */ | ||
5785 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Invalid Input data\n"); | ||
5786 | break; | ||
5787 | |||
5788 | break; | ||
5789 | default: | ||
5790 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Optimal solution\n"); | ||
5791 | break; | ||
5792 | } | ||
5793 | } | 5799 | } |
5800 | GNUNET_assert (row_index-1==c_peers+(2*c_mechs)); | ||
5801 | GNUNET_assert (array_index==5*c_mechs); | ||
5802 | */ | ||
5794 | 5803 | ||
5795 | char * debug_solution = NULL; | 5804 | /* Constraint 5: min number of connections*/ |
5796 | char * old = NULL; | 5805 | if (VERBOSE_ATS) GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Constraint 5\n"); |
5797 | for (c1=1; c1<= peers; c1++ ) | 5806 | glp_add_rows(prob, 1); |
5807 | for (c=1; c<=c_mechs; c++) | ||
5798 | { | 5808 | { |
5799 | old = debug_solution; | 5809 | // b_t - n_t * b_min >= 0 |
5800 | GNUNET_asprintf(&debug_solution, "%s %s = %g;", (debug_solution!=NULL) ? debug_solution : "", GNUNET_i2s(&pl[c1-1].peer), glp_get_col_prim(lp, c1)); | 5810 | if (VERBOSE_ATS) GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bounds [row]=[%i] \n",row_index); |
5801 | if (old!=NULL) GNUNET_free(old); | 5811 | glp_set_row_bnds(prob, row_index, GLP_LO, v_n_min, 0.0); |
5812 | |||
5813 | ia[array_index] = row_index; | ||
5814 | ja[array_index] = c_mechs + mechanisms[c].col_index; | ||
5815 | ar[array_index] = 1; | ||
5816 | 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]); | ||
5817 | array_index++; | ||
5802 | } | 5818 | } |
5803 | old = debug_solution; | 5819 | row_index ++; |
5804 | GNUNET_asprintf(&debug_solution, "%s z = %g; \n", debug_solution, glp_get_obj_val(lp)); | 5820 | GNUNET_assert (row_index-1==c_peers+(2*c_mechs)+1); |
5805 | if (old!=NULL) GNUNET_free(old); | 5821 | GNUNET_assert (array_index==6*c_mechs); |
5806 | if (DEBUG_ATS) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%s \n",debug_solution); | ||
5807 | GNUNET_free(debug_solution); | ||
5808 | 5822 | ||
5809 | glp_delete_prob(lp); | 5823 | glp_load_matrix(prob, array_index-1, ia, ja, ar); |
5810 | 5824 | ||
5811 | GNUNET_free(ar); | 5825 | glp_delete_prob(prob); |
5812 | GNUNET_free(ia); | ||
5813 | GNUNET_free(ja); | ||
5814 | 5826 | ||
5815 | return lp; | 5827 | /* clean up */ |
5816 | } | 5828 | |
5817 | #else | 5829 | GNUNET_free (ja); |
5818 | static void * | 5830 | GNUNET_free (ia); |
5819 | ats_create_problem (int peers, | 5831 | GNUNET_free (ar); |
5820 | int transports, | 5832 | |
5821 | double b_min, | 5833 | GNUNET_free(mechanisms); |
5822 | double b_max, | 5834 | GNUNET_free(peers); |
5823 | double r, double R, | ||
5824 | const struct ATS_peer * pl, | ||
5825 | const struct ATS_transports * tl, | ||
5826 | int max_it, | ||
5827 | int max_dur, int mlp) | ||
5828 | { | ||
5829 | return NULL; | ||
5830 | } | 5835 | } |
5831 | #endif | ||
5832 | 5836 | ||
5833 | /* To remove: just for testing */ | 5837 | /* To remove: just for testing */ |
5834 | void ats_benchmark (int peers, int transports, int start_peers, int end_peers) | 5838 | void ats_benchmark (int peers, int transports, int start_peers, int end_peers) |
5835 | { | 5839 | { |
5836 | struct GNUNET_TIME_Absolute start; | 5840 | struct GNUNET_TIME_Absolute start; |
5837 | struct GNUNET_TIME_Relative duration; | 5841 | struct GNUNET_TIME_Relative duration; |
5842 | /* | ||
5838 | int test = 11; | 5843 | int test = 11; |
5839 | int mlp = GNUNET_NO; | 5844 | int mlp = GNUNET_NO; |
5840 | 5845 | ||
@@ -5856,7 +5861,7 @@ void ats_benchmark (int peers, int transports, int start_peers, int end_peers) | |||
5856 | dur = (int) ats->max_exec_duration.rel_value; | 5861 | dur = (int) ats->max_exec_duration.rel_value; |
5857 | 5862 | ||
5858 | 5863 | ||
5859 | struct ATS_transports * tl = GNUNET_malloc(transports * sizeof (struct ATS_peer)); | 5864 | struct ATS_mechanism * tl = GNUNET_malloc(transports * sizeof (struct ATS_peer)); |
5860 | 5865 | ||
5861 | struct ATS_peer * pl = GNUNET_malloc(peers * sizeof (struct ATS_peer)); | 5866 | struct ATS_peer * pl = GNUNET_malloc(peers * sizeof (struct ATS_peer)); |
5862 | int c = 0; | 5867 | int c = 0; |
@@ -5885,19 +5890,16 @@ void ats_benchmark (int peers, int transports, int start_peers, int end_peers) | |||
5885 | //pl[2].f = 0.43; | 5890 | //pl[2].f = 0.43; |
5886 | //pl[1].f = 0.33; | 5891 | //pl[1].f = 0.33; |
5887 | // test // | 5892 | // test // |
5893 | * | ||
5894 | */ | ||
5888 | start = GNUNET_TIME_absolute_get(); | 5895 | start = GNUNET_TIME_absolute_get(); |
5889 | ats_create_problem(peers, transports, b_min, b_max, r, R, pl, tl, it, dur, mlp); | 5896 | ats_create_problem(5000,5000); |
5890 | 5897 | ||
5891 | duration = GNUNET_TIME_absolute_get_difference(start,GNUNET_TIME_absolute_get()); | 5898 | duration = GNUNET_TIME_absolute_get_difference(start,GNUNET_TIME_absolute_get()); |
5892 | 5899 | ||
5893 | if (DEBUG_ATS) GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "benchmark result ({LP/MLP},peers,duration,mem):%s,%i,%llu,%i\n", | 5900 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "benchmark result: %llu\n", duration); |
5894 | (mlp)?"mlp":"lp", (int )peers, duration.rel_value, | ||
5895 | (1+(peers*transports) * (2*sizeof(int) + sizeof(double)))); | ||
5896 | 5901 | ||
5897 | GNUNET_STATISTICS_set (stats, "ATS execution time 100 peers", duration.rel_value, GNUNET_NO); | 5902 | GNUNET_STATISTICS_set (stats, "ATS execution time 100 peers", duration.rel_value, GNUNET_NO); |
5898 | GNUNET_free (pl); | ||
5899 | GNUNET_free (tl); | ||
5900 | } | ||
5901 | } | 5903 | } |
5902 | 5904 | ||
5903 | void ats_calculate_bandwidth_distribution () | 5905 | void ats_calculate_bandwidth_distribution () |
@@ -5930,7 +5932,7 @@ void ats_calculate_bandwidth_distribution () | |||
5930 | else | 5932 | else |
5931 | dur = (int) ats->max_exec_duration.rel_value; | 5933 | dur = (int) ats->max_exec_duration.rel_value; |
5932 | 5934 | ||
5933 | struct ATS_transports * tl = NULL; | 5935 | struct ATS_mechanism * tl = NULL; |
5934 | struct ATS_peer * pl = NULL; | 5936 | struct ATS_peer * pl = NULL; |
5935 | 5937 | ||
5936 | start = GNUNET_TIME_absolute_get(); | 5938 | start = GNUNET_TIME_absolute_get(); |