-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvariable.h
77 lines (55 loc) · 1.66 KB
/
variable.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
#ifndef VARIABLE_H
#define VARIABLE_H
#include <vector>
#include <string>
#define PI 3.14159265
#define INF 0x3f3f3f3f
using namespace std;
class Function;
/*
Node class is created in order to construct directed graph structure
*/
class Node{
public:
// represents id of the node
int id;
// represents name of the node
string name;
// returns the incomming edges of the node
virtual vector<Node *> getIncomings() = 0;
// returns the outgoing edges of the node
virtual vector<Node *> getOutgoings() = 0;
// destructor
~Node();
};
/*
Subclass of node class and represents the variables.
Due to the different functionality, we have variable and function classes.
*/
class Variable : public Node{
public:
// represents the value of the variable
double value;
// represents the partial derivative value of the variable
// i.e. (d output/ d variable)
double derivative;
//if a value is assigned to a
bool initialized = 0;
bool isNum = 0;
// represents that which function determines the variable
// it will be null for inputs or constants
Function *from;
// represents the list of functions that takes the variable as input
vector<Function *> to;
Variable(); // default constructor
Variable(int _id, string _name, double _value = INF); // custom constructor
~Variable(); // destructor
// sets the from pointer
void setFrom(Function *_from);
// adds the given function to 'to' vector
void addTo(Function *_to);
// these functions are inherited features from node class
vector<Node *> getIncomings();
vector<Node *> getOutgoings();
};
#endif // VARIABLE