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
56 lines (55 loc) · 1.14 KB
/
graph.cpp
File metadata and controls
56 lines (55 loc) · 1.14 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
#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)
{
}
Graph::~Graph()
{
}
Node* Graph::getNamePointer(string str)
{
if(nodes.count(str))return nodes[str];
else return nullptr;
}
Node* Graph::operator[](const string str)
{
return getNamePointer(str);
}
int Graph::push(Node* newnode)
{
if(nodes.count(newnode->name))
{
std::cout<<"Same name!"<<std::endl;
return 1;
}
nodes.insert(std::make_pair(newnode->name,newnode));
return 0;
}
void Graph::reset()
{
for(auto iter = nodes.begin(); iter != nodes.end(); iter++)
{
iter->second->reset();
}
}
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);
}