-
Notifications
You must be signed in to change notification settings - Fork 4
/
dpsm.cpp
58 lines (53 loc) · 1.53 KB
/
dpsm.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include<iostream>
#include "modes.h"
#include<stdlib.h>
#include<stdio.h>
#define INFINITY 1000
#define MAXNODES 5
using namespace std;
int dist[MAXNODES][MAXNODES]={{0,1,15,11,14},{20,0,INFINITY,22,10},{22,INFINITY,0,40,12},{5,16,11,0,4},{INFINITY,23,13,3,0}};
//int dist[MAXNODES][MAXNODES]={{0,10,5,11,14},{20,0,INFINITY,22,10},{22,INFINITY,0,4,12},{6,16,11,0,4},{INFINITY,23,13,4,0}};
int main()
{
PSM p[MAXNODES];
int r,i,j,s,min;
//randomize();
/*for(i=0;i<MAXNODES;i++)
{
p[i].set_active(); //setting all modes by default to active mode
}*/
/*
for(i=0;i<MAXNODES;i++)
{
r=rand()%MAXNODES;
p[r].PMF=1;
p[r].MPSF=1;
p[r].set_mode_by_field(); //setting variable indexed by r to deep sleep
s=rand()%MAXNODES;
p[s].PMF=1;
p[s].MPSF=0;
p[s].set_mode_by_field(); //setting variable indexed by s to light sleep
}*/
for(i=0;i<MAXNODES;i++)
{
for(j=0;j<MAXNODES;j++)
{
if(i!=j)
{
if((dist[i][j])>15)
{ p[j].set_deep_sleep(); }
else if(((dist[i][j])>7)&&((dist[i][j])<=15))
{ p[j].set_light_sleep(); }
else
{ p[j].set_active(); }
cout<<"\n"<<i<<" -> "<<j<<"\tdistance = "<<dist[i][j]<<"\tmode is\t "<<p[j].mode;
}
}
}
/*for(i=0;i<MAXNODES;i++)
{
cout<<"\n"<<i<<" -> "<<j<<" distance = "<<dist[i][j]<<" mode is "<<p[i].mode;
cout<<"\nfor node \t"<<i+1;
cout<<" Mode:\t"<<p[i].mode<<endl; //print active,deep sleep or light sleep mode of a node
}*/
}