Ejemplo n.º 1
0
def handle_block(new_block_size, E, K):
    # Simulator.simulate returns the number of bit errors in each block
    bit_errors = Simulator.simulate(new_block_size, E)

    Statistics.update(Statistics.total_transmitions)
    if (bit_errors != 0):
        Statistics.update(Statistics.block_errors)
    try:
        Receiver.receive(bit_errors)
        Statistics.update(Statistics.no_error)
        Statistics.update(Statistics.correctly_received_blocks)
        return 0
    except OneBitError:
        Statistics.update(Statistics.one_bit_error)
        if (K != 0):
            Statistics.update(Statistics.correctly_received_blocks)
            # Assume: Fixing the error requires 0 trials_time units
            return 0
        return bit_errors
    except MultipleBitErrors:
        Statistics.update(Statistics.multiple_bit_errors)
        return bit_errors
Ejemplo n.º 2
0
def handle_block(new_block_size, E, K):
    # Simulator.simulate returns the number of bit errors in each block
    bit_errors = Simulator.simulate(new_block_size, E)

    Statistics.update(Statistics.total_transmitions)
    if (bit_errors != 0):
        Statistics.update(Statistics.block_errors)
    try:
        Receiver.receive(bit_errors)
        Statistics.update(Statistics.no_error)
        Statistics.update(Statistics.correctly_received_blocks)
        return 0
    except OneBitError:
        Statistics.update(Statistics.one_bit_error)
        if (K != 0):
            Statistics.update(Statistics.correctly_received_blocks)
            # Assume: Fixing the error requires 0 trials_time units
            return 0
        return bit_errors
    except MultipleBitErrors:
        Statistics.update(Statistics.multiple_bit_errors)
        return bit_errors
Ejemplo n.º 3
0
def start():
    get_arguments()

    # Transmitter.transmit returns the new size of a block
    new_block_size = Transmitter.transmit(parameter_dict[K],
                                          parameter_dict[F])

    # for T trials, repeat the simulation
    for i in range(parameter_dict[T]):
        # clear this trial's variables
        trials_time = 0
        trials_received_frames = 0
        trials_failed_frames = 0

        # Set the first seed for the simulation
        Simulator.set_seed(parameter_dict[TSeeds][i])

        while (trials_time <= parameter_dict[R]):
            trials_received_blocks = 0  # new frame
            trials_failed_blocks = 0    # new frame

            # set the number of blocks to be transmitted in this frame
            transmissions = parameter_dict[K]

            if (parameter_dict[K] == 0):
                transmissions = 1

            # For K blocks (or 1 if K == 0), simulate the transmission
            for j in range(transmissions):  # range starts at 0
                # frame_failure = 0 if block was transmitted successfully
                block_failure = handle_block(new_block_size,
                                             parameter_dict[E],
                                             parameter_dict[K])

                # record block success or failure
                if (block_failure > 0):
                    trials_failed_blocks += 1
                else:
                    trials_received_blocks += 1

            # set trials_time to number of bits and response overhead
            trials_time += (parameter_dict[F] +
                            (parameter_dict[K] * Transmitter.r)
                            + parameter_dict[A])
            # update number of transmitted frames
            Statistics.update(Statistics.total_frames)
            # frame failed, resend the frame
            if(trials_failed_blocks >= 1):
                trials_failed_frames += 1
            # the last frame being sent (no longer needed) see forums
            #elif(trials_time > parameter_dict[R]):
            #    pass
            # successful transmition
            else:
                Statistics.update(Statistics.correctly_received_frames)
                trials_received_frames += 1

        #a print("Trial number:", i)
        #a print("Received Frames", trials_received_frames)
        #a print("Failed Frames", trials_failed_frames)

        # Assume: Take all K*(F+r) trials_time units into account
        # even if in last frame
        Statistics.append(Statistics.throughput_averages,
                          ((parameter_dict[F] * trials_received_frames)
                           / trials_time))

        if(trials_received_frames != 0):
            # Assume: Take all frames into account, even last frame
            Statistics.append(Statistics.frame_averages,
                              (trials_received_frames + trials_failed_frames) /
                              trials_received_frames)
        else:
            Statistics.append(Statistics.frame_averages, 0)

        # Add to total time
        Statistics.statistics_dict[Statistics.total_time] += trials_time

    # Call Print Statements
    #a print()
    #a print("----------------------------------------------")
    print_input(sys.argv)
    Statistics.set_final_values(parameter_dict[F], parameter_dict[R])
    Statistics.print_frame_ci()
    Statistics.print_throughput_ci()
Ejemplo n.º 4
0
def start():
    get_arguments()

    # Transmitter.transmit returns the new size of a block
    new_block_size = Transmitter.transmit(parameter_dict[K], parameter_dict[F])

    # for T trials, repeat the simulation
    for i in range(parameter_dict[T]):
        # clear this trial's variables
        trials_time = 0
        trials_received_frames = 0
        trials_failed_frames = 0

        # Set the first seed for the simulation
        Simulator.set_seed(parameter_dict[TSeeds][i])

        while (trials_time <= parameter_dict[R]):
            trials_received_blocks = 0  # new frame
            trials_failed_blocks = 0  # new frame

            # set the number of blocks to be transmitted in this frame
            transmissions = parameter_dict[K]

            if (parameter_dict[K] == 0):
                transmissions = 1

            # For K blocks (or 1 if K == 0), simulate the transmission
            for j in range(transmissions):  # range starts at 0
                # frame_failure = 0 if block was transmitted successfully
                block_failure = handle_block(new_block_size, parameter_dict[E],
                                             parameter_dict[K])

                # record block success or failure
                if (block_failure > 0):
                    trials_failed_blocks += 1
                else:
                    trials_received_blocks += 1

            # set trials_time to number of bits and response overhead
            trials_time += (parameter_dict[F] +
                            (parameter_dict[K] * Transmitter.r) +
                            parameter_dict[A])
            # update number of transmitted frames
            Statistics.update(Statistics.total_frames)
            # frame failed, resend the frame
            if (trials_failed_blocks >= 1):
                trials_failed_frames += 1
            # the last frame being sent (no longer needed) see forums
            #elif(trials_time > parameter_dict[R]):
            #    pass
            # successful transmition
            else:
                Statistics.update(Statistics.correctly_received_frames)
                trials_received_frames += 1

        #a print("Trial number:", i)
        #a print("Received Frames", trials_received_frames)
        #a print("Failed Frames", trials_failed_frames)

        # Assume: Take all K*(F+r) trials_time units into account
        # even if in last frame
        Statistics.append(
            Statistics.throughput_averages,
            ((parameter_dict[F] * trials_received_frames) / trials_time))

        if (trials_received_frames != 0):
            # Assume: Take all frames into account, even last frame
            Statistics.append(Statistics.frame_averages,
                              (trials_received_frames + trials_failed_frames) /
                              trials_received_frames)
        else:
            Statistics.append(Statistics.frame_averages, 0)

        # Add to total time
        Statistics.statistics_dict[Statistics.total_time] += trials_time

    # Call Print Statements
    #a print()
    #a print("----------------------------------------------")
    print_input(sys.argv)
    Statistics.set_final_values(parameter_dict[F], parameter_dict[R])
    Statistics.print_frame_ci()
    Statistics.print_throughput_ci()