forked from euschn/ingpu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathagent_struct.h
113 lines (94 loc) · 2.13 KB
/
agent_struct.h
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#pragma once
#ifndef __host__
#define __host__
#endif
#ifndef __device__
#define __device__
#endif
#include <thrust/version.h>
#include <iomanip>
#define MAX_PORTS 4
namespace ingpu {
enum EQUATION_TUPLE{LHS, RHS};
// Agents/Variables
struct Agent
{
int id; // unique id of the agent
char name; // name of the agent - determines agent (upper case) or variable (lower case)
int arity; // maximum arity = 4
int ports[4]; // contains ids of connected agents
//dummy constructor
__host__ __device__
Agent() : id(0), name('Z'), arity(0) {
for (int i=0; i<arity; i++)
ports[i] = 0;
}
//copy ctor
__host__ __device__
Agent(const Agent& a) : id(a.id), name(a.name), arity(a.arity) {
for (int i=0; i<arity; i++)
ports[i] = a.ports[i];
}
__host__ __device__
Agent(int _id, char _name, int _arity) : id(_id), name(_name), arity(_arity) {
for (int i=0; i<arity; i++)
ports[i] = 0;
}
__host__ __device__
Agent(int _id, char _name, int _arity, int p0, int p1 = 0, int p2 = 0, int p3 = 0) : id(_id), name(_name), arity(_arity) {
ports[0] = p0;
ports[1] = p1;
ports[2] = p2;
ports[3] = p3;
}
__host__ __device__
Agent(int _id) : id(_id), name('v'), arity(0) {
for (int i=0; i<arity; i++)
ports[i] = 0;
}
__host__ __device__
bool operator==(const Agent& other)
{
if (name != other.name)
return false;
if (arity != other.arity)
return false;
if (id != other.id)
return false;
for (int i=0; i < arity; ++i) {
if (ports[i] != other.ports[i])
return false;
}
return true;
}
__host__ __device__
bool operator!=(const Agent& other)
{
if (name != other.name)
return true;
if (arity != other.arity)
return true;
if (id != other.id)
return true;
for (int i=0; i < arity; ++i) {
if (ports[i] != other.ports[i])
return true;
}
return false;
}
__host__ __device__
Agent& operator=( const Agent& a)
{
this->id = a.id;
this->name = a.name;
this->arity = a.arity;
for (int i=0; i < a.arity; ++i) {
this->ports[i] = a.ports[i];
}
return *this;
}
};
}
// print an agent
__host__
std::ostream& operator<< (std::ostream& os, const ingpu::Agent& a);