Skip to content

Commit 9c7d5a3

Browse files
committed
working on seg fault
1 parent 195f08f commit 9c7d5a3

File tree

5 files changed

+91
-69
lines changed

5 files changed

+91
-69
lines changed

Makefile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ MAKEFILE = Makefile
1313
CC = gcc
1414
CXX = g++
1515
DEFINES = -DQT_DEPRECATED_WARNINGS -DQT_NO_DEBUG -DQT_CHARTS_LIB -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB
16-
CFLAGS = -pipe -O2 -Wall -W -D_REENTRANT -fPIC $(DEFINES)
17-
CXXFLAGS = -pipe -O2 -Wall -W -D_REENTRANT -fPIC $(DEFINES)
16+
CFLAGS = -pipe -O3 -Wall -W -D_REENTRANT -fPIC $(DEFINES)
17+
CXXFLAGS = -pipe -std=c++17 -O3 -Wall -W -D_REENTRANT -fPIC $(DEFINES)
1818
INCPATH = -I. -I. -isystem /usr/include/x86_64-linux-gnu/qt5 -isystem /usr/include/x86_64-linux-gnu/qt5 -isystem /usr/include/x86_64-linux-gnu/qt5/QtCharts -isystem /usr/include/x86_64-linux-gnu/qt5/QtWidgets -isystem /usr/include/x86_64-linux-gnu/qt5/QtGui -isystem /usr/include/x86_64-linux-gnu/qt5/QtCore -I. -isystem /usr/include/libdrm -I/usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++
1919
QMAKE = /usr/lib/qt5/bin/qmake
2020
DEL_FILE = rm -f
@@ -35,9 +35,9 @@ MOVE = mv -f
3535
TAR = tar -cf
3636
COMPRESS = gzip -9f
3737
DISTNAME = src1.0.0
38-
DISTDIR = /home/kolt/Documents/workspace/fraglets-cpp/src/.tmp/src1.0.0
38+
DISTDIR = /home/kolt/Documents/workspace/fraglets-cpp/.tmp/src1.0.0
3939
LINK = g++
40-
LFLAGS = -Wl,-O1
40+
LFLAGS = -Wl,-O3
4141
LIBS = $(SUBLIBS) -lgvc -lcgraph -lcdt -lQt5Charts -lQt5Widgets -lQt5Gui -lQt5Core -lGL -lpthread
4242
AR = ar cqs
4343
RANLIB =
@@ -366,7 +366,7 @@ compiler_moc_predefs_make_all: moc_predefs.h
366366
compiler_moc_predefs_clean:
367367
-$(DEL_FILE) moc_predefs.h
368368
moc_predefs.h: /usr/lib/x86_64-linux-gnu/qt5/mkspecs/features/data/dummy.cpp
369-
g++ -pipe -O2 -Wall -W -dM -E -o moc_predefs.h /usr/lib/x86_64-linux-gnu/qt5/mkspecs/features/data/dummy.cpp
369+
g++ -pipe -std=c++17 -O3 -Wall -W -dM -E -o moc_predefs.h /usr/lib/x86_64-linux-gnu/qt5/mkspecs/features/data/dummy.cpp
370370

371371
compiler_moc_header_make_all:
372372
compiler_moc_header_clean:

fraglets.cpp

Lines changed: 49 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,31 @@
55
#include <cstddef>
66
#include <fstream>
77
#include <string>
8-
#include <sstream>
98
#include <iterator>
109
#include <cstring>
1110

1211

1312

14-
std::string match = "match" ;
15-
std::string matchp = "matchp";
16-
std::string dup = "dup";
17-
std::string exch = "exch";
18-
std::string pop = "pop";
19-
std::string nop = "nop";
20-
std::string nul = "nul";
21-
std::string split = "split";
22-
std::string send = "send";
23-
std::string fork = "fork";
24-
std::string empty = "empty";
25-
std::string length = "length";
26-
std::string lt = "lt";
27-
std::string pop2 = "pop2";
28-
std::string copy = "copy";
13+
symbol match = "match" ;
14+
symbol matchp = "matchp";
15+
symbol dup = "dup";
16+
symbol exch = "exch";
17+
symbol pop = "pop";
18+
symbol nop = "nop";
19+
symbol nul = "nul";
20+
symbol split = "split";
21+
symbol send = "send";
22+
symbol fork = "fork";
23+
symbol empty = "empty";
24+
symbol length = "length";
25+
symbol lt = "lt";
26+
symbol pop2 = "pop2";
27+
symbol copy = "copy";
28+
symbol perm = "perm";
29+
30+
std::unordered_set<std::string> bimolTags = {match,matchp,perm};
31+
std::unordered_set<std::string> unimolTags = {exch,pop,nop,split,length,fork,empty,pop2,copy,lt};
32+
2933

3034

3135
bool isNumber(const std::string& mol){
@@ -56,9 +60,6 @@ symbol molToString(const molecule_pointer mol){
5660
}
5761

5862

59-
std::unordered_set<std::string> bimolTags = {match,matchp};
60-
std::unordered_set<std::string> unimolTags = {exch,pop,nop,split,length,fork,empty,pop2,copy,lt};
61-
6263

6364

6465
const molecule_pointer fraglets::makeUniqueUnimol(const molecule_pointer mol){
@@ -126,10 +127,10 @@ void fraglets::addEdge(const molecule_pointer mol,const molecule_pointer resultM
126127

127128

128129
if (this->nodesTable.find(mol) == this->nodesTable.end()){
129-
this->addNode(mol,isunimol(mol),isMatchp(mol),isbimol(mol));
130+
this->addNode(mol,isunimol(mol),isperm(mol),isbimol(mol));
130131
}
131132
if (this->nodesTable.find(resultMol) == this->nodesTable.end()){
132-
this->addNode(resultMol,isunimol(resultMol),isMatchp(resultMol),isbimol(resultMol));
133+
this->addNode(resultMol,isunimol(resultMol),isperm(resultMol),isbimol(resultMol));
133134
}
134135
Agnode_t* tailNode = nodesTable[resultMol];
135136
Agnode_t* headNode = nodesTable[mol];
@@ -156,6 +157,13 @@ opResult r_match(const molecule_pointer activeMolecule, const molecule_pointer p
156157
}
157158

158159

160+
opResult r_perm(const molecule_pointer activeMolecule, const molecule_pointer passiveMolecule){
161+
opResult result = r_match(activeMolecule,passiveMolecule);
162+
// molecule newMol = std::make_shared<molecule_pointer( activeMolecule);
163+
result.emplace(result.begin(),activeMolecule);
164+
return result;
165+
}
166+
159167
opResult r_matchp(const molecule_pointer activeMolecule, const molecule_pointer passiveMolecule){
160168
opResult result = r_match(activeMolecule,passiveMolecule);
161169
// molecule newMol = std::make_shared<molecule_pointer( activeMolecule);
@@ -415,7 +423,7 @@ opResult r_pop2(const molecule_pointer mol){
415423
}
416424

417425

418-
std::unordered_map<std::string,bimolOp> const bimolOpMap = {{match,r_match},{matchp,r_matchp}};
426+
std::unordered_map<std::string,bimolOp> const bimolOpMap = {{match,r_match},{matchp,r_matchp},{perm,r_perm}};
419427
std::unordered_map<std::string,unimolOp> const unimolOpMap = {{dup,r_dup},
420428
{exch,r_exch},
421429
{pop,r_pop},
@@ -453,7 +461,6 @@ double random_double(){
453461
void fraglets::inject(const molecule_pointer mol,int mult){
454462
if (mol->vector.empty() or mult < 1){return;}
455463
if (mol->vector.size()>= 1){
456-
457464
if (this->isbimol(mol)){
458465
const molecule_pointer newMol = this->makeUniqueActive(mol);
459466
std::shared_ptr<symbol> key = newMol->vector[1];
@@ -482,10 +489,16 @@ void fraglets::inject(const molecule_pointer mol,int mult){
482489
}
483490

484491
bool fraglets::isbimol(const molecule_pointer mol){
492+
if (mol->vector.size() < 2){ return false;}
493+
std::shared_ptr<symbol> tag = mol->vector[0];
494+
return (*tag == match) or (*tag == matchp) or (*tag == perm);
495+
}
496+
497+
bool fraglets::isperm(const molecule_pointer mol){
485498
if (mol->vector.empty()){ return false;}
486499

487500
std::shared_ptr<symbol> tag = mol->vector[0];
488-
return (*tag == match) or (*tag == matchp);
501+
return (*tag == perm);
489502
}
490503

491504
bool fraglets::isMatchp(const molecule_pointer mol){
@@ -617,6 +630,7 @@ int fraglets::run_unimol(){
617630

618631
void fraglets::run_bimol(){
619632
if (this->wt <= 0){return;}
633+
std::cout << "test2\n";
620634
double w = random_double() * this->wt;
621635
this->react(w);
622636
}
@@ -634,6 +648,7 @@ void fraglets::inject_list(opResult result){
634648

635649
void fraglets::iterate(){
636650
this->propensity();
651+
std::cout << "test\n";
637652
if (!this->idle){
638653
this->run_bimol();
639654
}
@@ -728,12 +743,12 @@ void fraglets::run(int niter,int molCap){
728743
// total = this->active.total + this->passive.total;
729744
// }
730745
if (this->idle){
731-
//this->drawGraphViz();
746+
this->drawGraphViz();
732747
std::cout<< "idle\n";
733748
return;
734749
}
735750
}
736-
//this->drawGraphViz();
751+
this->drawGraphViz();
737752
std::cout<< "done\n";
738753
return;
739754
}
@@ -742,16 +757,16 @@ void fraglets::run(int niter,int molCap){
742757

743758
void fraglets::drawGraphViz(){
744759

745-
for(auto edge : this->edgeTable){
760+
// for(auto edge : this->edgeTable){
746761

747-
auto t =edge.first;
748-
int reactionCount = ((this->reactionCoutTable.mult()/(this->reactionCoutTable.mult(t)+1)))+1;
762+
// auto t =edge.first;
763+
// int reactionCount = ((this->reactionCoutTable.mult()/(this->reactionCoutTable.mult(t)+1)))+1;
749764

750-
std::string s = std::to_string(reactionCount);
751-
char *weight = const_cast<char *>(s.c_str());
752-
agsafeset(edge.second,"weight",weight,weight);
753-
agsafeset(edge.second,"penwidth",weight,weight);
754-
}
765+
// std::string s = std::to_string(reactionCount);
766+
// char *weight = const_cast<char *>(s.c_str());
767+
// agsafeset(edge.second,"weight",weight,weight);
768+
// agsafeset(edge.second,"penwidth",weight,weight);
769+
// }
755770

756771
GVC_t* graphContext = gvContext();
757772

fraglets.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ class fraglets {
7575
double propensity();
7676
int run_unimol();
7777
bool isbimol(const molecule_pointer mol);
78+
bool isperm(const molecule_pointer mol);
7879
bool isMatchp(const molecule_pointer mol);
7980
bool isunimol(const molecule_pointer mol);
8081
void react(double w);

main.cpp

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -13,48 +13,54 @@ int main(int argc, char *argv[]) {
1313

1414

1515
fraglets frag;
16+
symbol mol = "fork nop z match z split match z fork fork fork nop z * split match z fork fork fork nop z * copy z";
17+
frag.parse(mol);
1618

17-
// molecule mol = {"fork nop z match z split match z fork fork fork nop z * split match z fork fork fork nop z * copy z"};
18-
// frag.inject(mol);
19+
for (int i = 0; i< 50; i++){
20+
frag.parse(mol);
1921

20-
// for (int i = 0; i< 50; i++){
21-
// frag.inject(mol);
22+
frag.parse("z");
2223

23-
// frag.inject({"z"});
24+
}
25+
symbol mol2 = "perm z ";
26+
std::string::iterator alphaIt2;
27+
std::unordered_set<std::string>::iterator uIt;
28+
for (alphaIt2 = alphabet.begin();alphaIt2!=alphabet.end();alphaIt2++){
29+
symbol newMol = mol2 + *alphaIt2;
30+
frag.parse(newMol);
31+
newMol = mol2 + " z " + *alphaIt2;
32+
frag.parse(newMol);
2433

25-
// }
26-
// molecule mol2 = {"matchp","z"};
27-
// std::string::iterator alphaIt2;
28-
// std::unordered_set<std::string>::iterator uIt;
29-
// for (alphaIt2 = alphabet.begin();alphaIt2!=alphabet.end();alphaIt2++){
30-
// molecule newMol = mol2 + *alphaIt2;
31-
// frag.inject(newMol);
32-
// newMol = mol2 + "z " + *alphaIt2;
33-
// frag.inject(newMol);
34+
}
35+
for (uIt = unimolTags.begin();uIt!=unimolTags.end();uIt++){
3436

35-
// }
36-
// for (uIt = unimolTags.begin();uIt!=unimolTags.end();uIt++){
37+
symbol newMolTag = mol2 + *uIt;
38+
frag.parse(newMolTag);
39+
newMolTag = mol2 + " z " +*uIt;
40+
frag.parse(newMolTag);
41+
}
42+
for (alphaIt2 = alphabet.begin();alphaIt2!=alphabet.end();alphaIt2++){
43+
symbol newMol2 = mol2 + " match " + *alphaIt2;
44+
frag.parse(newMol2);
45+
newMol2 = mol2 + " z " + "match " + *alphaIt2;
46+
frag.parse(newMol2);
47+
48+
symbol newMol3 = mol2 + " matchp " + *alphaIt2;
49+
frag.parse(newMol3);
50+
newMol3 = mol2 + " z " + "matchp " + *alphaIt2;
51+
frag.parse(newMol3);
52+
53+
}
3754

38-
// molecule newMolTag = mol2 + *uIt;
39-
// frag.inject(newMolTag);
40-
// newMolTag = mol2 + "z " +*uIt;
41-
// frag.inject(newMolTag);
42-
// }
43-
// for (alphaIt2 = alphabet.begin();alphaIt2!=alphabet.end();alphaIt2++){
44-
// molecule newMol2 = mol2 + "match ";// + *alphaIt2;
45-
// frag.inject(newMol2);
46-
// newMol2 = mol2 + "z " + "match"; //+ *alphaIt2;
47-
// frag.inject(newMol2);
4855

49-
// }
5056

5157

5258

5359

5460

55-
frag.interpret("sort.fra");
61+
// frag.interpret("sort.fra");
5662

57-
frag.run(5000,5000);
63+
frag.run(1000,1400);
5864

5965

6066
// QtCharts::QLineSeries *series = new QtCharts::QLineSeries();

sort.fra

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@
3434

3535
# test:
3636

37-
[sort -200 -684 408 716 780 -22 -433 15 416 -922 480 -68 -819 42 -844 -863 -540 -958 246 -858 -378 -537 -755 -580 487 -705 -497 533 811 -430 -754 -188 385]
37+
[sort 203 -200 989 -446 -927 962 -485 714 -351 226 -791 55 448 -32 -477 261 529 38 922 -419 822 -395 -757 -951 757 -521 88]
3838

3939
# [pop2 pop2 pop2]

0 commit comments

Comments
 (0)