#include "stdafx.h"
#include "LA.h"
#include <iostream>
#include<conio.h>
using namespace std;
class ListNode
{
public:
int data1;
float data2;
bool action;
ListNode* link;
ListNode(int &a,float &b,bool &c,ListNode* p=NULL):data1(a),data2(b),action(c),link(p){}
};
class List :public ListNode
{
protected:
ListNode* newNode(int &a,float &b,bool &c,ListNode* p)
{
ListNode* q=new ListNode(a,b,c,p);
return q;
}
public:
ListNode* first;
List(int element1=0,float element2=0,bool element3=true,ListNode* p=NULL):ListNode(element1,element2,element3,p){}
///////////////////////
void InsertFirst(int element1,float element2=0,bool element3=true)
{
ListNode* p=newNode(element1,element2,element3,first);
first=p;
}
//////////////////////
void deleteNode(int element)
{
ListNode* t,* h;
t = first;
if(t->data1 == element)
{
first = t->link;
delete t;
return;
}
h=t;
while(t != NULL)
{
if(t->data1 == element)
{
h->link = t->link ;
delete t;
return;
}
h=t;
t=t->link ;
}
cout<<"\n element" <<" "<<element<<" "<<"Not found"<<endl;
}
//////////////////////
int Count()
{
ListNode *t;
int count=0;
for(t=first;t!=NULL;t=t->link)
{
count++;
}
return count-1;
}
//////////////////////
void Display()
{
ListNode* current;
current = first;
while(current != NULL)
{
cout<<current->data1<<endl;
current = current->link;
}
}
/////////////////////
~List()
{
ListNode* t,* h;
t = first;
while(t != NULL)
{
h = t;
t = t->link ;
delete h;
}
}
};
/////////////////////////////////////////////////////////////////////////
class Graph:public List
{
protected:
int num,number,temp,ID,NV;
List* headNodes;
public:
Graph(int v=0)
{
headNodes = new List[v+1];
}
/////////////////
int CountNeighborNodes(int v)
{
int count=0;
ListNode* t;
t = headNodes[v].first;
for(t; t->link; t = t->link)
{
count++;
}
return count;
}
void DisplayNeighbourNodes(int v)
{
ListNode* t;
t = headNodes[v].first;
cout<<"[";
for(t; t->link; t=t->link)
{cout<< t->data1 <<" ";}
cout<<"]";
}
/////////////////////
void Display()
{
int i;
for(i=1;i<=NV;i++)
{
cout<<"node "<<i<<" adjacent: ";
DisplayNeighbourNodes(i);
cout<<endl;
}
}
////////////////////
ListNode operator = (ListNode* x)
{
ListNode* t;
t->data1 = x->data1;
t->data2 = x->data2;
t->action = x->action;
t->link = x->link ;
}
///////////////////////////////////////////////////////end of operator =
List operator = (List x)
{ int k =x.Count();// felan
List t((x.first)->data1,(x.first)->data2);
ListNode* s;
s = x.first;
for(int i=1; i<k; i++)
{
s = s->link;
t.InsertFirst(s->data1,s->data2,s->action);
}
return t;
}
///////////////////////////////////////////////////////end of operator =
ListNode* NeighborNodes(int v)
{
ListNode* t;
t = headNodes[v].first;
return t ;
}
///////////////////////////////////////////////////////end of NeighborNodes with poniter
void Display(ListNode* s)
{
while(s!=NULL)
{
cout<<s->data1;
s=s->link;
}
}
///////////////////////////////////////////////////////end of Display with poniter
List AllNodesList()
{
List AllNodes;
for(int i=1;i<NV;i++)
{
AllNodes.InsertFirst(i);
}
return AllNodes;
}
//////////////////////////////////////////////////////end of AllNodesList
List NoneNeighborNodes(int v)
{
List NNeighbor;
ListNode* s;
NNeighbor = AllNodesList();
s = NeighborNodes(v);
for(s;s!=NULL;s=s->link)
{
NNeighbor.deleteNode(s->data1);
}
return NNeighbor;
}
///////////////////////////////////////////////////////end of NoneNeighborNodes
};
class LA:public Graph
{
public:
LA(int ID)
{
int k;
ListNode* t;
t=first;
List alphaANDp;
alphaANDp = NoneNeighborNodes(ID);
k=NoneNeighborNodes(ID).Count();
for(t;t->link;t=t->link)
t->data2= 1/k;
}
List operator = (List x)
{
List t;
ListNode* s;
int k = x.Count();
s = x.first;
for(int i=1;i<=k;i++)
{
t.InsertFirst(s->data1,s->data2,s->action);
s = s->link;
}
return t;
}
////////////////////////////////////////////////////end of operator =
void Reward(int ID,int actionselect,float a)
{
ListNode* t;
List temp;
temp = headNodes[ID];
t = temp.first;
for(t;t->link;t=t->link)
{
if(t->data1 == ID)
t->data2 = t->data2 + a*(1-t->data2);
else
t->data2 = t->data2 * (1-a);
}
}
////////////////////////////////////////////////////end of Reward
void Penalty(int ID,int actionselect,float b)
{
int r;
ListNode* t;
r = NoneNeighborNodes(ID).Count();
t = headNodes[ID].first;
for(t;t->link;t=t->link)
{
if(t->data1 == ID)
t->data2 = t->data2 * (1-b);
else
t->data2 = b/(1-r) + t->data2 * (1-b);
}
}
////////////////////////////////////////////////////end of Penalty
int GetNextNode(int ID)
{
float A=0;
ListNode* t;
t = headNodes[ID].first;
while(t!=NULL)
{
if((t->data2) >= A && t->action == true)
{
A = t->data2;
ID = t->data1;
}
}
return ID;
}
};
int main()
{
return 0;
}