forked from FantasqueX/Computing_Graph
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgraph.cpp
More file actions
68 lines (67 loc) · 1.32 KB
/
graph.cpp
File metadata and controls
68 lines (67 loc) · 1.32 KB
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
#include "graph.h"
#include<iostream>
#include <string>
int Graph::getid(std::string str)
{
for (int i = 0;i < used; ++i)
{
if(str == nodes[i]->name)
return i;
}
return -1;
}
Graph::Graph(int sz)
{
maxsize=sz;
nodes=new Node*[sz];
}
Graph::~Graph()
{
delete[] nodes;
}
Node* Graph::getNamePointer(string str)
{
for(int i=0; i<used; i++)
{
if(str==nodes[i]->name)
return nodes[i];
}
return nullptr;
}
Node* Graph::operator[](const string str)
{
return getNamePointer(str);
}
int Graph::push(Node* newnode)
{
if(getid(newnode->name)!=-1)
{
std::cout<<"Same name!"<<std::endl;
}
if(used==maxsize)
{
std::cout<<"Max size!"<<std::endl;
return 1;
}
nodes[used]=newnode;
used++;
return 0;
}
void Graph::reset()
{
for(int i=0; i<used; i++)
{
nodes[i]->reset();//����variable��constant
}
}
float Graph::eval(string nodename,int placeholdernum,string* placeholdernames,float* placeholdervalue)
{
reset();
for(int i=0;i<placeholdernum;i++)
getNamePointer(placeholdernames[i])->setvalue(placeholdervalue[i]);
return getNamePointer(nodename)->geteval();
}
void Graph::setvariable(string vname,float value)
{
getNamePointer(vname)->setvalue(value);
}