[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r28824 - gnunet/src/testbed
From: |
gnunet |
Subject: |
[GNUnet-SVN] r28824 - gnunet/src/testbed |
Date: |
Fri, 23 Aug 2013 17:34:50 +0200 |
Author: harsha
Date: 2013-08-23 17:34:50 +0200 (Fri, 23 Aug 2013)
New Revision: 28824
Modified:
gnunet/src/testbed/test_testbed_api_sd.c
gnunet/src/testbed/testbed_api_operations.c
gnunet/src/testbed/testbed_api_sd.c
gnunet/src/testbed/testbed_api_sd.h
Log:
- negative deviation factor
Modified: gnunet/src/testbed/test_testbed_api_sd.c
===================================================================
--- gnunet/src/testbed/test_testbed_api_sd.c 2013-08-23 15:24:41 UTC (rev
28823)
+++ gnunet/src/testbed/test_testbed_api_sd.c 2013-08-23 15:34:50 UTC (rev
28824)
@@ -48,24 +48,26 @@
const struct GNUNET_CONFIGURATION_Handle *config)
{
struct SDHandle *h = GNUNET_TESTBED_SD_init_ (20);
+ int sd;
ret = 0;
GNUNET_TESTBED_SD_add_data_ (h, 40);
- if (GNUNET_SYSERR != GNUNET_TESTBED_SD_deviation_factor_ (h, 10))
+ if (GNUNET_SYSERR != GNUNET_TESTBED_SD_deviation_factor_ (h, 10, &sd))
{
GNUNET_break (0);
ret = 1;
goto err;
}
GNUNET_TESTBED_SD_add_data_ (h, 30);
- if (GNUNET_SYSERR == GNUNET_TESTBED_SD_deviation_factor_ (h, 80))
+ if (GNUNET_SYSERR == GNUNET_TESTBED_SD_deviation_factor_ (h, 80, &sd))
{
GNUNET_break (0);
ret = 1;
goto err;
}
GNUNET_TESTBED_SD_add_data_ (h, 40);
- if (0 != GNUNET_TESTBED_SD_deviation_factor_ (h, 10))
+ if ((GNUNET_SYSERR == GNUNET_TESTBED_SD_deviation_factor_ (h, 30, &sd))
+ || (-2 != sd))
{
GNUNET_break (0);
ret = 1;
@@ -73,7 +75,8 @@
}
GNUNET_TESTBED_SD_add_data_ (h, 10);
GNUNET_TESTBED_SD_add_data_ (h, 30);
- if (3 != GNUNET_TESTBED_SD_deviation_factor_ (h, 60))
+ if ((GNUNET_SYSERR == GNUNET_TESTBED_SD_deviation_factor_ (h, 60, &sd))
+ || (3 != sd))
{
GNUNET_break (0);
ret = 1;
Modified: gnunet/src/testbed/testbed_api_operations.c
===================================================================
--- gnunet/src/testbed/testbed_api_operations.c 2013-08-23 15:24:41 UTC (rev
28823)
+++ gnunet/src/testbed/testbed_api_operations.c 2013-08-23 15:34:50 UTC (rev
28824)
@@ -854,17 +854,19 @@
}
GNUNET_assert (nvals >= queue->max_active);
avg = GNUNET_TIME_relative_divide (avg, nvals);
- sd = GNUNET_TESTBED_SD_deviation_factor_ (fctx->sd, (unsigned int)
- avg.rel_value_us);
- if ( (sd <= 5) ||
- (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
- queue->max_active)) )
+ if (GNUNET_SYSERR ==
+ GNUNET_TESTBED_SD_deviation_factor_ (fctx->sd,
+ (unsigned int) avg.rel_value_us,
+ &sd))
+ {
GNUNET_TESTBED_SD_add_data_ (fctx->sd, (unsigned int) avg.rel_value_us);
- if (GNUNET_SYSERR == sd)
- {
adaptive_queue_set_max_active (queue, queue->max_active); /* no change */
return;
}
+ if ((0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
queue->max_active)))
+ GNUNET_TESTBED_SD_add_data_ (fctx->sd, (unsigned int) avg.rel_value_us);
+ if (sd < 0)
+ sd = 0;
GNUNET_assert (0 <= sd);
if ((0 == sd) && (! fail))
{
Modified: gnunet/src/testbed/testbed_api_sd.c
===================================================================
--- gnunet/src/testbed/testbed_api_sd.c 2013-08-23 15:24:41 UTC (rev 28823)
+++ gnunet/src/testbed/testbed_api_sd.c 2013-08-23 15:34:50 UTC (rev 28824)
@@ -173,33 +173,40 @@
/**
- * Returns the factor by which the given amount differs from the standard
deviation
+ * Calculates the factor by which the given amount differs
*
* @param h the SDhandle
* @param amount the value for which the deviation is returned
-
- * @return the deviation from the average; GNUNET_SYSERR if the deviation
cannot
- * be calculated OR 0 if the given amount is less than or equal to
the
- * average; a maximum of 4 is returned for deviations equal to or
- * larger than 4
+ * @param factor the factor by which the given amont differs
+ * @return GNUNET_SYSERR if the deviation cannot
+ * be calculated; GNUNET_OK if the deviation is returned through factor
*/
int
-GNUNET_TESTBED_SD_deviation_factor_ (struct SDHandle *h, unsigned int amount)
+GNUNET_TESTBED_SD_deviation_factor_ (struct SDHandle *h, unsigned int amount,
+ int *factor)
{
double diff;
- unsigned int n;
+ int f;
+ int n;
if (h->cnt < 2)
return GNUNET_SYSERR;
if (((float) amount) > h->avg)
+ {
diff = ((float) amount) - h->avg;
+ f = 1;
+ }
else
- return 0; //diff = h->avg - ((float) amount);
+ {
+ diff = h->avg - ((float) amount);
+ f = -1;
+ }
diff *= diff;
for (n = 1; n < 4; n++)
if (diff < (((double) (n * n)) * h->vr))
break;
- return n;
+ *factor = f * n;
+ return GNUNET_OK;
}
/* end of testbed_api_sd.c */
Modified: gnunet/src/testbed/testbed_api_sd.h
===================================================================
--- gnunet/src/testbed/testbed_api_sd.h 2013-08-23 15:24:41 UTC (rev 28823)
+++ gnunet/src/testbed/testbed_api_sd.h 2013-08-23 15:34:50 UTC (rev 28824)
@@ -68,13 +68,14 @@
*
* @param h the SDhandle
* @param amount the value for which the deviation is returned
-
+ * @param factor the factor by which the given amont differs
* @return the deviation from the average; GNUNET_SYSERR if the deviation
cannot
* be calculated OR 0 if the deviation is less than the average; a
* maximum of 4 is returned for deviations equal to or larger than 4
*/
int
-GNUNET_TESTBED_SD_deviation_factor_ (struct SDHandle *h, unsigned int amount);
+GNUNET_TESTBED_SD_deviation_factor_ (struct SDHandle *h, unsigned int amount,
+ int *factor);
#endif
/* end of testbed_api.h */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r28824 - gnunet/src/testbed,
gnunet <=