#!/usr/bin/env python

# Load ESDS
import sys
sys.path.append("../../")
import esds
import numpy as np

########## Scenario ##########
# Notations:
#   - Remaining communication duration (last communication ends minus current simulated time) = C
#   - Last communication duration (previous row) = U
#   - Last remaining data size (previous row) = D
#   - Current remaining data (current row) = R
#   - Initial data size (first row) = I
#   - Bandwidth = BW
#   - Latency = L
# |----------------------------------------+------------+----------------+----------------------+---------------------------+-------------------------|
# | This table is the same for both sender |            |                |                      |                           |                         |
# |----------------------------------------+------------+----------------+----------------------+---------------------------+-------------------------|
# |                      Simulated time(s) | Latency(s) | Bandwidth(bps) | Remaining data (bit) | Communication duration(s) | Communcation ends at(s) |
# |----------------------------------------+------------+----------------+----------------------+---------------------------+-------------------------|
# |                                      0 |          0 | 8/2            | 8                    | 2                         |                       2 |
# |                                      1 |        0.5 | 8/2            | C/U*D=4              | R/BW + R/I*L = 1.25       |                    2.25 |
# |                                      2 |          1 | 8/2            | C/U*D=0.8            | R/BW + R/I*L = 0.3        |                     2.3 |
# |                                    2.3 |          1 | 8/2            | 0                    |                           |                         |
# |----------------------------------------+------------+----------------+----------------------+---------------------------+-------------------------|
##############################

B=np.full((3,3),8)
L=np.full((3,3),0)
s=esds.Simulator(B,L)

s.create_node("sender")
s.create_node("sender")
s.create_node("receiver")

def callback(simulator):
    simulator.log("Network update!")
    simulator.update_network(simulator.B,simulator.L+0.5)

s.run(breakpoints_every=1,breakpoint_callback=callback,debug=True)