@@ -103,10 +103,10 @@ const molecule_pointer fraglets::makeUniquePassive(const molecule_pointer mol){
103
103
}
104
104
105
105
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 ];
110
110
// _mol.copy(c_mol,_mol.size(),_mol.front());
111
111
// std::transform(mol->vector.begin(),mol->vector.end(),std::back_inserter(c_mol),convert);
112
112
@@ -130,20 +130,19 @@ void fraglets::addNode(const molecule_pointer mol,const bool& unimol,const bool&
130
130
}
131
131
132
132
void fraglets::addEdge (const molecule_pointer mol,const molecule_pointer resultMol,const bool & unimol,const bool & matchp){
133
+ std::string molString = molToString (mol);
133
134
134
- // std::string molString = molToString(mol);
135
-
136
- // std::string resultMolString = molToString(resultMol);
135
+ std::string resultMolString = molToString (resultMol);
137
136
138
137
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));
141
140
}
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));
144
143
}
145
- Agnode_t* tailNode = nodesTable[resultMol ];
146
- Agnode_t* headNode = nodesTable[mol ];
144
+ Agnode_t* tailNode = nodesTable[resultMolString ];
145
+ Agnode_t* headNode = nodesTable[molString ];
147
146
Agedge_t* edge = agedge (this ->graph ,headNode,tailNode," " ,true );
148
147
if (unimol){
149
148
agsafeset (edge," color" ," blue" ," blue" );
@@ -152,69 +151,69 @@ void fraglets::addEdge(const molecule_pointer mol,const molecule_pointer resultM
152
151
}else {
153
152
agsafeset (edge," color" ," black" ," black" );
154
153
}
155
- this ->edgeTable [mol ] = edge;
154
+ this ->edgeTable [molString ] = edge;
156
155
}
157
156
158
157
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
+ // }
218
217
219
218
220
219
@@ -593,25 +592,27 @@ double random_double(){
593
592
594
593
595
594
void fraglets::inject (const molecule_pointer mol,int mult){
596
- this ->reactionCoutTable .inject (mol,1 );
597
595
if (mol->vector .empty () or mult < 1 ){return ;}
598
596
if (mol->vector .size ()>= 1 ){
599
597
if (this ->isbimol (mol)){
600
598
const molecule_pointer newMol = this ->makeUniqueActive (mol);
601
599
std::shared_ptr<symbol> key = newMol->vector [1 ];
602
600
// could check for invalid fraglets here.
603
601
this ->active .inject (key,newMol,mult);
602
+ this ->reactionCoutTable .insert (molToString (newMol));
604
603
this ->idle = false ;
605
604
}
606
605
else if (this ->isunimol (mol)){
607
606
const molecule_pointer newMol = this ->makeUniqueUnimol (mol);
608
607
this ->unimol .inject (newMol,mult);
608
+ this ->reactionCoutTable .insert (molToString (newMol));
609
609
}
610
610
else {
611
- const molecule_pointer newMol = this ->makeUniqueActive (mol);
611
+ const molecule_pointer newMol = this ->makeUniquePassive (mol);
612
612
std::shared_ptr<symbol> key = newMol->vector [0 ];
613
613
// could check for invalid fraglets here.
614
614
this ->passive .inject (key,newMol,mult);
615
+ this ->reactionCoutTable .insert (molToString (newMol));
615
616
this ->idle = false ;
616
617
}
617
618
}
@@ -709,6 +710,7 @@ opResult fraglets::react2(const molecule_pointer activeMolecule,const molecule_p
709
710
opResult result;
710
711
bimolOp f = bimolOpMap.find (*tag)->second ;
711
712
result = f (activeMolecule,passiveMolecule);
713
+
712
714
713
715
714
716
if (result.size () == 1 ){
@@ -736,7 +738,6 @@ int fraglets::run_unimol(){
736
738
while (!this ->unimol .multiset .empty ()){
737
739
const molecule_pointer mol = this ->unimol .expelrnd ();
738
740
opResult result = this ->react1 (mol);
739
- const char * const delim = " " ;
740
741
if (result.size () == 1 ){
741
742
742
743
if (!this ->quiet ){
@@ -894,14 +895,14 @@ void fraglets::run(int niter,int molCap,bool quite = false){
894
895
}
895
896
896
897
if (this ->idle ){
897
- // this->drawGraphViz();
898
+
898
899
if (!this ->quiet ){
899
900
std::cout<< " idle\n " ;
900
901
}
901
902
return ;
902
903
}
903
904
}
904
- // this->drawGraphViz();
905
+
905
906
if (!this ->quiet ){
906
907
std::cout<< " done\n " ;
907
908
}
@@ -915,8 +916,10 @@ void fraglets::drawGraphViz(){
915
916
for (auto edge : this ->edgeTable ){
916
917
917
918
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
+ }
920
923
std::string s = std::to_string (reactionCount);
921
924
char *weight = const_cast <char *>(s.c_str ());
922
925
agsafeset (edge.second ," weight" ,weight,weight);
0 commit comments