Skip to content

Commit 6241e33

Browse files
committed
nothing of significance here.
1 parent cf9b1e0 commit 6241e33

File tree

6 files changed

+186
-89
lines changed

6 files changed

+186
-89
lines changed

fraglets.cpp

Lines changed: 83 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,10 @@ const molecule_pointer fraglets::makeUniquePassive(const molecule_pointer mol){
103103
}
104104

105105

106-
void fraglets::addNode(const molecule_pointer mol,const bool& unimol,const bool& matchp,const bool& bimol){
107-
symbol _mol = molToString(mol);
108-
char* c_mol = &_mol[0];//new char[_mol.size() + 1];
109-
106+
void fraglets::addNode(symbol mol,const bool& unimol,const bool& matchp,const bool& bimol){
107+
// auto c_mol = mol.c_str();//new char[_mol.size() + 1];
108+
109+
char *c_mol = &mol[0];
110110
//_mol.copy(c_mol,_mol.size(),_mol.front());
111111
// std::transform(mol->vector.begin(),mol->vector.end(),std::back_inserter(c_mol),convert);
112112

@@ -130,20 +130,19 @@ void fraglets::addNode(const molecule_pointer mol,const bool& unimol,const bool&
130130
}
131131

132132
void fraglets::addEdge(const molecule_pointer mol,const molecule_pointer resultMol,const bool& unimol,const bool& matchp){
133+
std::string molString = molToString(mol);
133134

134-
// std::string molString = molToString(mol);
135-
136-
// std::string resultMolString = molToString(resultMol);
135+
std::string resultMolString = molToString(resultMol);
137136

138137

139-
if (this->nodesTable.find(mol) == this->nodesTable.end()){
140-
this->addNode(mol,isunimol(mol),isperm(mol),isbimol(mol));
138+
if (this->nodesTable.find(molString) == this->nodesTable.end()){
139+
this->addNode(molString,this->isunimol(mol),this->isperm(mol),this->isbimol(mol));
141140
}
142-
if (this->nodesTable.find(resultMol) == this->nodesTable.end()){
143-
this->addNode(resultMol,isunimol(resultMol),isperm(resultMol),isbimol(resultMol));
141+
if (this->nodesTable.find(resultMolString) == this->nodesTable.end()){
142+
this->addNode(resultMolString,this->isunimol(resultMol),this->isperm(resultMol),this->isbimol(resultMol));
144143
}
145-
Agnode_t* tailNode = nodesTable[resultMol];
146-
Agnode_t* headNode = nodesTable[mol];
144+
Agnode_t* tailNode = nodesTable[resultMolString];
145+
Agnode_t* headNode = nodesTable[molString];
147146
Agedge_t* edge = agedge(this->graph,headNode,tailNode,"",true);
148147
if (unimol){
149148
agsafeset(edge,"color","blue","blue");
@@ -152,69 +151,69 @@ void fraglets::addEdge(const molecule_pointer mol,const molecule_pointer resultM
152151
}else{
153152
agsafeset(edge,"color","black","black");
154153
}
155-
this->edgeTable[mol] = edge;
154+
this->edgeTable[molString] = edge;
156155
}
157156

158157

159-
opResult r_plus(const molecule_pointer activeMolecule){
160-
opResult result;
161-
molecule_pointer newMol = std::make_shared<molecule>();
162-
newMol->vector.push_back(activeMolecule->vector[1]);
163-
if (isNumber(*activeMolecule->vector[2]) & isNumber(*activeMolecule->vector[3])){
164-
float one = std::stof(*activeMolecule->vector[2]);
165-
float two = std::stof(*activeMolecule->vector[3]);
166-
float result = one + two;
167-
std::shared_ptr<symbol> s = std::make_shared<symbol>(std::to_string(result));
168-
newMol->vector.push_back(s);
169-
}
170-
else{
171-
newMol->vector.push_back(activeMolecule->vector[2]);
172-
newMol->vector.push_back(activeMolecule->vector[3]);
173-
}
174-
newMol->vector.insert(newMol->vector.begin(),activeMolecule->vector.begin()+4,activeMolecule->vector.end());
175-
result.push_back(newMol);
176-
return result;
177-
}
178-
179-
opResult r_minus(const molecule_pointer activeMolecule){
180-
opResult result;
181-
molecule_pointer newMol = std::make_shared<molecule>();
182-
newMol->vector.push_back(activeMolecule->vector[1]);
183-
if (isNumber(*activeMolecule->vector[2]) & isNumber(*activeMolecule->vector[3])){
184-
float one = std::stof(*activeMolecule->vector[2]);
185-
float two = std::stof(*activeMolecule->vector[3]);
186-
float result = one - two;
187-
std::shared_ptr<symbol> s = std::make_shared<symbol>(std::to_string(result));
188-
newMol->vector.push_back(s);
189-
}
190-
else{
191-
newMol->vector.push_back(activeMolecule->vector[2]);
192-
newMol->vector.push_back(activeMolecule->vector[3]);
193-
}
194-
newMol->vector.insert(newMol->vector.begin(),activeMolecule->vector.begin()+4,activeMolecule->vector.end());
195-
result.push_back(newMol);
196-
return result;
197-
}
198-
199-
opResult r_mult(const molecule_pointer activeMolecule){
200-
opResult result;
201-
molecule_pointer newMol = std::make_shared<molecule>();
202-
newMol->vector.push_back(activeMolecule->vector[1]);
203-
if (isNumber(*activeMolecule->vector[2]) & isNumber(*activeMolecule->vector[3])){
204-
float one = std::stof(*activeMolecule->vector[2]);
205-
float two = std::stof(*activeMolecule->vector[3]);
206-
float result = one * two;
207-
std::shared_ptr<symbol> s = std::make_shared<symbol>(std::to_string(result));
208-
newMol->vector.push_back(s);
209-
}
210-
else{
211-
newMol->vector.push_back(activeMolecule->vector[2]);
212-
newMol->vector.push_back(activeMolecule->vector[3]);
213-
}
214-
newMol->vector.insert(newMol->vector.begin(),activeMolecule->vector.begin()+4,activeMolecule->vector.end());
215-
result.push_back(newMol);
216-
return result;
217-
}
158+
// opResult r_plus(const molecule_pointer activeMolecule){
159+
// opResult result;
160+
// molecule_pointer newMol = std::make_shared<molecule>();
161+
// newMol->vector.push_back(activeMolecule->vector[1]);
162+
// if (isNumber(*activeMolecule->vector[2]) & isNumber(*activeMolecule->vector[3])){
163+
// float one = std::stof(*activeMolecule->vector[2]);
164+
// float two = std::stof(*activeMolecule->vector[3]);
165+
// float result = one + two;
166+
// std::shared_ptr<symbol> s = std::make_shared<symbol>(std::to_string(result));
167+
// newMol->vector.push_back(s);
168+
// }
169+
// else{
170+
// newMol->vector.push_back(activeMolecule->vector[2]);
171+
// newMol->vector.push_back(activeMolecule->vector[3]);
172+
// }
173+
// newMol->vector.insert(newMol->vector.begin(),activeMolecule->vector.begin()+4,activeMolecule->vector.end());
174+
// result.push_back(newMol);
175+
// return result;
176+
// }
177+
178+
// opResult r_minus(const molecule_pointer activeMolecule){
179+
// opResult result;
180+
// molecule_pointer newMol = std::make_shared<molecule>();
181+
// newMol->vector.push_back(activeMolecule->vector[1]);
182+
// if (isNumber(*activeMolecule->vector[2]) & isNumber(*activeMolecule->vector[3])){
183+
// float one = std::stof(*activeMolecule->vector[2]);
184+
// float two = std::stof(*activeMolecule->vector[3]);
185+
// float result = one - two;
186+
// std::shared_ptr<symbol> s = std::make_shared<symbol>(std::to_string(result));
187+
// newMol->vector.push_back(s);
188+
// }
189+
// else{
190+
// newMol->vector.push_back(activeMolecule->vector[2]);
191+
// newMol->vector.push_back(activeMolecule->vector[3]);
192+
// }
193+
// newMol->vector.insert(newMol->vector.begin(),activeMolecule->vector.begin()+4,activeMolecule->vector.end());
194+
// result.push_back(newMol);
195+
// return result;
196+
// }
197+
198+
// opResult r_mult(const molecule_pointer activeMolecule){
199+
// opResult result;
200+
// molecule_pointer newMol = std::make_shared<molecule>();
201+
// newMol->vector.push_back(activeMolecule->vector[1]);
202+
// if (isNumber(*activeMolecule->vector[2]) & isNumber(*activeMolecule->vector[3])){
203+
// float one = std::stof(*activeMolecule->vector[2]);
204+
// float two = std::stof(*activeMolecule->vector[3]);
205+
// float result = one * two;
206+
// std::shared_ptr<symbol> s = std::make_shared<symbol>(std::to_string(result));
207+
// newMol->vector.push_back(s);
208+
// }
209+
// else{
210+
// newMol->vector.push_back(activeMolecule->vector[2]);
211+
// newMol->vector.push_back(activeMolecule->vector[3]);
212+
// }
213+
// newMol->vector.insert(newMol->vector.begin(),activeMolecule->vector.begin()+4,activeMolecule->vector.end());
214+
// result.push_back(newMol);
215+
// return result;
216+
// }
218217

219218

220219

@@ -593,25 +592,27 @@ double random_double(){
593592

594593

595594
void fraglets::inject(const molecule_pointer mol,int mult){
596-
this->reactionCoutTable.inject(mol,1);
597595
if (mol->vector.empty() or mult < 1){return;}
598596
if (mol->vector.size()>= 1){
599597
if (this->isbimol(mol)){
600598
const molecule_pointer newMol = this->makeUniqueActive(mol);
601599
std::shared_ptr<symbol> key = newMol->vector[1];
602600
// could check for invalid fraglets here.
603601
this->active.inject(key,newMol,mult);
602+
this->reactionCoutTable.insert(molToString(newMol));
604603
this->idle = false;
605604
}
606605
else if (this->isunimol(mol)){
607606
const molecule_pointer newMol = this->makeUniqueUnimol(mol);
608607
this->unimol.inject(newMol,mult);
608+
this->reactionCoutTable.insert(molToString(newMol));
609609
}
610610
else{
611-
const molecule_pointer newMol = this->makeUniqueActive(mol);
611+
const molecule_pointer newMol = this->makeUniquePassive(mol);
612612
std::shared_ptr<symbol> key = newMol->vector[0];
613613
// could check for invalid fraglets here.
614614
this->passive.inject(key,newMol,mult);
615+
this->reactionCoutTable.insert(molToString(newMol));
615616
this->idle = false;
616617
}
617618
}
@@ -709,6 +710,7 @@ opResult fraglets::react2(const molecule_pointer activeMolecule,const molecule_p
709710
opResult result;
710711
bimolOp f = bimolOpMap.find(*tag)->second;
711712
result = f(activeMolecule,passiveMolecule);
713+
712714

713715

714716
if (result.size() == 1){
@@ -736,7 +738,6 @@ int fraglets::run_unimol(){
736738
while (!this->unimol.multiset.empty()){
737739
const molecule_pointer mol = this->unimol.expelrnd();
738740
opResult result = this->react1(mol);
739-
const char* const delim = " ";
740741
if (result.size() == 1){
741742

742743
if (!this->quiet){
@@ -894,14 +895,14 @@ void fraglets::run(int niter,int molCap,bool quite = false){
894895
}
895896

896897
if (this->idle){
897-
// this->drawGraphViz();
898+
898899
if (!this->quiet){
899900
std::cout<< "idle\n";
900901
}
901902
return;
902903
}
903904
}
904-
// this->drawGraphViz();
905+
905906
if (!this->quiet){
906907
std::cout<< "done\n";
907908
}
@@ -915,8 +916,10 @@ void fraglets::drawGraphViz(){
915916
for(auto edge : this->edgeTable){
916917

917918
auto t =edge.first;
918-
int reactionCount = this->reactionCoutTable.mult(t)+1/(this->reactionCoutTable.mult()+1)+1;
919-
919+
float reactionCount = float(this->reactionCoutTable.count(t))/float(this->reactionCoutTable.size())*1000;
920+
if (reactionCount < 1){
921+
reactionCount = 1;
922+
}
920923
std::string s = std::to_string(reactionCount);
921924
char *weight = const_cast<char *>(s.c_str());
922925
agsafeset(edge.second,"weight",weight,weight);

fraglets.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,14 @@ class fraglets {
4848
bool idle;
4949
Agraph_t* graph = agopen("G", Agdirected, NULL);
5050
Agraph_t* subgraph = agsubg(graph, "cluster", 1);
51-
std::map <molecule_pointer,Agnode_t*> nodesTable;
52-
std::map <molecule_pointer,Agedge_t*> edgeTable;
51+
std::map <symbol,Agnode_t*> nodesTable;
52+
std::map <symbol,Agedge_t*> edgeTable;
5353
std::map<int,molecule_pointer> stackplotIndexMap;
5454
std::set<molecule_pointer> mappedMols;
5555
int stackplotIndexCounter = 1;
56-
moleculeMultiset reactionCoutTable;
57-
void addNode(const molecule_pointer mol,const bool& unimol,const bool& matchp,const bool& bimol);
58-
void addEdge(const molecule_pointer activeMolecule,const molecule_pointer passiveMolecule,const bool& unimol,const bool& matchp);
56+
std::unordered_multiset<symbol> reactionCoutTable;
57+
void addNode(symbol mol,const bool& unimol,const bool& matchp,const bool& bimol);
58+
void addEdge(molecule_pointer activeMolecule,const molecule_pointer passiveMolecule,const bool& unimol,const bool& matchp);
5959
const molecule_pointer makeUniqueUnimol(const molecule_pointer);
6060
const molecule_pointer makeUniqueActive(const molecule_pointer);
6161
const molecule_pointer makeUniquePassive(const molecule_pointer);

fraglets.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ def parse(self, line):
3131
cFraglets.parse(self.cfraglets,line)
3232

3333

34+
def drawGraphViz(self):
35+
cFraglets.drawGraphViz(self.cfraglets)
36+
37+
3438
def __delete__(self):
3539
cFraglets.delete_object(self.cfraglets)
3640

fragletsToPy.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,21 @@ PyObject* parse(PyObject* self, PyObject* args)
3333
return Py_BuildValue("");
3434
}
3535

36+
PyObject* drawGraphViz(PyObject* self, PyObject* args)
37+
{
38+
39+
PyObject* fragletsCapsule_;
40+
41+
42+
// Process arguments
43+
PyArg_ParseTuple(args, "O",
44+
&fragletsCapsule_);
45+
fraglets* frag = (fraglets*)PyCapsule_GetPointer(fragletsCapsule_, "fragletsPtr");
46+
frag->drawGraphViz();
47+
48+
// Return nothing
49+
return Py_BuildValue("");
50+
}
3651

3752

3853

@@ -128,6 +143,8 @@ static PyMethodDef fragletsFunctions[] =
128143
"gets the unimol tags"},
129144
{"getIter",getIter,METH_VARARGS,
130145
"gets the current number of iterations"},
146+
{"drawGraphViz",drawGraphViz,METH_VARARGS,
147+
"draws graph"},
131148
{"delete_object", // C++/Py Destructor
132149
delete_object, METH_VARARGS,
133150
"Delete `fraglets` object"},

test.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55

66
def getIter(t):
77
frag = getFrag()
8-
frag.run(1000000,3000,True)
8+
frag.run(1000000,2000,True)
99
print(frag.iter)
1010
return frag.iter
1111

1212

1313
def getFrag():
1414
frag = fraglets.fraglets()
15-
for i in range(50):
15+
for i in range(20):
1616
frag.parse("[fork nop z match z split match z fork fork fork nop z * split match z fork fork fork nop z * z]")
1717
frag.parse("[perm z]")
1818

@@ -55,8 +55,26 @@ def getFrag():
5555
return frag
5656
# frag.run(10000,200,True)
5757

58-
pool = Pool(4)
59-
data = pool.map(getIter,range(200))
58+
# pool = Pool(4)
59+
# data = pool.map(getIter,range(100))
60+
61+
frags = []
62+
data = []
63+
64+
for i in range(200):
65+
frag=getFrag()
66+
frag.run(1000,500,True)
67+
print(frag.iter)
68+
frags.append(frag)
69+
70+
greatest = frags[0]
71+
for frag in frags:
72+
if frag.iter > greatest.iter:
73+
greatest = frag
74+
data.append(frag.iter)
75+
76+
greatest.drawGraphViz()
77+
6078

6179

6280

0 commit comments

Comments
 (0)