예제 #1
0
  /**
   * <br>
   * In the first round,</br> <br>
   * In the paper the server is supposed to ask sensors for uncoded data.</br> <br>
   * We sent the maximum number of bits: 63 bits = "111111"</br> <br>
   * Sensor will encode in IEEE double format</br> <br>
   * Calculates the i (number of requested bits), as given in the paper</br>
   */
  @Override
  public String sendRequest(int sensor_id) {

    if (is_first_round[sensor_id] || sensor_id == 0 || round_number < M) {

      requested_bits[sensor_id] = maximum_number_of_bits_askable;

      return "111111";
    }

    double delta = code_book.getD();

    int i =
        (int)
            Math.ceil(
                (0.5
                        * (Math.log((sigma[sensor_id] * sigma[sensor_id]) / (delta * delta * P_e))
                            / Math.log(2.0)))
                    + 1);
    i = Math.min(i, maximum_number_of_bits_askable); // request not more that 63 bits
    i = Math.max(0, i); // request no less than 0 bits

    requested_bits[sensor_id] = i;

    String bit_string =
        tools.pad0ToFront(
            Integer.toBinaryString(i),
            bits_needed_to_represent_maximum_askable); // pad it to make length 6

    return tools.reverse(bit_string);
  }
예제 #2
0
  public static void main(String[] args) {
    double delta = 0.0001;
    double sigma = 0.005;
    double P_e = 0.01;

    int i =
        (int)
            Math.ceil(
                (0.5 * (Math.log((sigma * sigma) / (delta * delta * P_e)) / Math.log(2.0))) + 1);
    i = Math.min(i, 63); // request not more that 63 bits
    i = Math.max(0, i); // request no less than 0 bits
  }