const int NODES = 4; // number of nodes in the network
const int SLOTS = 5; // number of slots in a frame
const int frame = SLOTS;
const int maxk = 3; // max number of frames to wait for initially
typedef int[0,NODES-1] nodeid_t;// used to identify node
typedef int[-1,NODES-1] node_t; // used to transfer node info where -1 means no node
typedef int[0,SLOTS-1] slotid_t;// used to identify slot
typedef int[-1,SLOTS-1] slot_t; // used to transfer slot info where -1 means no slot
typedef int[0, maxk] frame_t;
typedef int weight_t[frame_t];
typedef bool topology_t[nodeid_t][nodeid_t];
typedef int power_t[nodeid_t];
typedef bool used_slot_t[slotid_t];
const used_slot_t zero_vec = { 0, 0, 0, 0, 0};
const used_slot_t max_vec = { 1, 1, 1, 1, 1};
// energy consumption levels in 10^-5 W, based on 107page of PhD thesis by Lodewijk F.W. van Hoesel:
const int SEND = 21, RECV = 22, LISTEN = 2, SLEEP=1;
Nodeconst nodeid_t id, const weight_t weight, const topology_t can_hear, broadcast chan &sendWM, nodeid_t &aux_node, slot_t &aux_slot, used_slot_t &first[nodeid_t], used_slot_t &second[nodeid_t], slot_t &slot_no[nodeid_t], int &col_count, power_t &powerclock t;
int[-1, maxk*SLOTS] counter;
slot_t curr=-1, detected=-1, col=-1;
used_slot_t aux_vec;
used_slot_t rec_vec;
bool got_info=0;
bool sent_info=0;
void acc(used_slot_t& usage, const used_slot_t& info)
{
for(i: nodeid_t) usage[i] |= info[i];
}sendingsentdonerec_onelisteningnormalreadychoicedone0rec_one0listening0waitinginitialGlobalclock &energy, int &power[nodeid_t]// the number of separate networks:
const int NETCOUNT = 2;
typedef int[1, NETCOUNT] net_t;
const weight_t expw = {4, 2, 1, 1}; // exponential weights
const weight_t uni = {1, 1, 1, 1}; // uniform weights
const topology_t ring =
{// 0 1 2 3
{ 0, 1, 1, 0}, // 0
{ 1, 0, 0, 1}, // 1
{ 1, 0, 0, 1}, // 2
{ 0, 1, 1, 0} // 3
};
const topology_t chain =
{// 0 1 2 3
{ 0, 1, 1, 0}, // 0
{ 1, 0, 0, 1}, // 1
{ 1, 0, 0, 0}, // 2
{ 0, 1, 0, 0} // 3
};
// Medium model with variables that contain data sent from a node;
broadcast chan sendWM[net_t];
nodeid_t aux_node[net_t]; // the sender id
slot_t aux_slot[net_t]; // id of slot that had collision (-1 means no collision)
// neighbor information for how nodes use slots
used_slot_t first[net_t][nodeid_t];
used_slot_t second[net_t][nodeid_t];
// currently used slot by a node:
slot_t slot_no[net_t][nodeid_t] = { {0, -1, -1, -1}, {0, -1, -1, -1} };
// total count of collisions:
int col_count[net_t] = { 0, 0};
power_t power[net_t] = {{ LISTEN, LISTEN, LISTEN, LISTEN }, { LISTEN, LISTEN, LISTEN, LISTEN }};
const weight_t weights[net_t] = { expw, uni };
const topology_t top[net_t] = { ring, ring };
// workaround for Pr[energy[1]<=10000] bug in property parser
clock energy1, energy2;
clock time;
/*
clock energy[net_t];
node(const net_t n, const nodeid_t id) =
Node(id, weights[n], top[n], sendWM[n], aux_node[n], aux_slot[n],
first[n], second[n], slot_no[n], col_count[n], power[n]);
inv(const net_t n) = Global(energy[n], power[n]);
*/
node1(const nodeid_t id) =
Node(id, weights[1], top[1], sendWM[1], aux_node[1], aux_slot[1],
first[1], second[1], slot_no[1], col_count[1], power[1]);
node2(const nodeid_t id) =
Node(id, weights[2], top[2], sendWM[2], aux_node[2], aux_slot[2],
first[2], second[2], slot_no[2], col_count[2], power[2]);
inv1 = Global(energy1, power[1]);
inv2 = Global(energy2, power[2]);
system node1, node2, inv1, inv2;