Skip to main content
. 2019 Feb 18;19(4):835. doi: 10.3390/s19040835
Algorithm 1: Q-learning-based Backoff Mechanism
1 Initialization:
2   NCCA = 0, load_Q_table() // load a previously learned value
3 Input: medium channel state by CCA (idle or busy), packet transmission (success of failure)
4 Output: backoff duration (backofftime)
5 while mac_protocol do
6 if active_mode
7   busy_count += CCA(is_busy) or busy_count −= CCA(is_idle)
8   // channel mode is set to 4 levels according to busy_count
9   ch_mode = channel_mode(busy_count);
10 end if
11 if event_send_request
12   while NCCA < macMaxCSMABackoffs or packet_transmitted
13    // set the largest value in the Q table to next CW
14    CWt = Max_Q_table(ch_mode, CWt − 1)
15    Backoff(backofftime = uniform_random(0, 2CWt − 1) )
16    if CCA(is_busy)
17     busy_count += 1; NCCA += 1;
18    else if CCA(is_idle)
19     transmit(packet) and wait(Ack)
20     busy_count −= 1; NCCA = 0;
21    end if
22    ch_mode = channel_mode(busy_count)
23    if learning_mode
24     Q(st[ch_mode]: CWt − 1, at: CWt) - Equation(2)
25    end if
26     // network parameter measurement
27     transmission_success_ratio (rt) = # of received_ack / # of requested packet,
28     average_latency (la) = ack_timetransmit_time (about only transmitted packet)
29     // other parameters else (e.g., meanBackoffduration, channelAccessratio, etc.)
30   end while
31   delete_queue(packet) // transmitted or dropped
32 end if
33 end while