ok, so i've been working on this one for quite a while, and the code is very big so i'm just going to give the relevant parts. this is a program that builds polymers (chemical structures of repeated monomers) which are represented as doubly pointed noncomplete binary trees. There are three different types of monomers (hence the three different constructer calling functions) the first one is the "leaves" of the tree, the second adds length between branch points and the third actually branches the tree (making it binary). There are two vectors which hold the reactive species, they are vectors of pointers which only hold the pointer to the last element in the tree (i.e. the last reactive element of the polymer). At the end of the program one of the vectors is empty, and the other one holds the pointers to the last monomer of each polymer formed. The program works most of the time, but when i run it with large numbers of monomers it fails by saying "polymer44. exe has encountered a problem and needs to close. We are sorry for the inconvenience." and gives me the option to debug, or send microsoft an error report. I've spent a lot of debugging time just to realize that this is probably a problem having to do with my vector "shuffling" , or my use of new to create the monomers in the first place. so here is a basic outline of what is happening. any suggestions are welcome and I appreciate your time and effort greatly. :) -
-
//initialize the queue to hold pointers to the polymer chain ends
-
vector<monomer*> nucleophiles;
-
//initialize the queue to hold pointer to the reactive monomers
-
vector<monomer*> electrophiles;
-
-
//function to dynamically allocate memory for the "leaf" monomers
-
void initializechains(vector<monomer*>& nucs, int& chainum, int& namenum)
-
{
-
if(chainum > 0)
-
{
-
for(int i=0; i< chainum; i++)
-
{
-
//pointers for the initialization of the correct monomer
-
monomer* pointforward = NULL;
-
-
//creating and initializing the monomer
-
monomer* monomeri = new monomer(pointforward, namenum);
-
monomeri->namenumber = namenum;
-
-
//inserting the monomer onto its vector
-
nucs.insert(nucs.begin(), monomeri);
-
-
//deleting pointers
-
delete pointforward;
-
monomeri = NULL;
-
-
//resetting namenumber
-
namenum = namenum - 1;
-
}
-
-
}
-
else
-
{
-
cout << "there are no original chains to initialize." <<endl;
-
}
-
-
}
-
-
//same thing but for the additive monomers
-
void initializeaddmons(vector<monomer*>& elecs, int& adds, int& namenum)
-
{
-
if(adds > 0)
-
{
-
for(int i =0; i<adds; i++)
-
{
-
//pointers for the initialization of the correct monomer
-
monomer* pointforward = NULL;
-
monomer* pointbackward = NULL;
-
-
//creating and initializing the monomer
-
monomer* addmonomeri = new monomer(pointforward, pointbackward);
-
addmonomeri->namenumber = namenum;
-
-
//inserting the monomer onto its vector
-
elecs.insert(elecs.begin(), addmonomeri);
-
-
//deleting pointers
-
delete pointforward;
-
delete pointbackward;
-
addmonomeri = NULL;
-
-
//resetting namenumber
-
namenum = namenum + 1;
-
}
-
}
-
else
-
{
-
//cout << "there are no additive monomers to initialize." <<endl;
-
}
-
-
}
-
-
//same thing again but for the branching monomers
-
void initializebranchmons(vector<monomer*>& elecs, int& branchers, int& namenum)
-
{
-
if(branchers > 0)
-
{
-
for(int i = 0; i<branchers; i++)
-
{
-
//pointers for the initialization of the correct monomer
-
monomer* pointforward = NULL;
-
monomer* pointbackward = NULL;
-
monomer* pointbranch = NULL;
-
-
//creating and initializing the monomer
-
monomer* branchmoni = new monomer(pointforward, pointbackward, pointbranch);
-
branchmoni->namenumber = namenum;
-
-
//inserting the monomer onto its vector
-
elecs.insert(elecs.begin(), branchmoni);
-
-
//deleting pointers
-
delete pointforward;
-
delete pointbackward;
-
delete pointbranch;
-
branchmoni = NULL;
-
-
//resetting namenumber
-
namenum = namenum + 1;
-
}
-
}
-
else
-
{
-
cout << "there are no branching monomers to initialize." <<endl;
-
}
-
-
}
-
-
void addmonomer(vector<monomer*>& nucs, vector<monomer*>& elecs, int& nucount, int& elecount, double addrate_4, double branchrate1_4, double branchrate2_4, double alpha_6, int iter3)
-
{
-
//checks
-
//int elesizecheck = elecs.size();
-
//int nucsizecheck = nucs.size();
-
-
//declare the iterators
-
vector<monomer*>::iterator nuchooser = nucs.begin();
-
vector<monomer*>::iterator elechooser = elecs.begin();
-
-
//set the iterators
-
for(int nucount2 = 0; nucount2 != nucount; ++nucount2)
-
{
-
++nuchooser;
-
}
-
-
for(int elecount2 = 0; elecount2 != elecount; ++elecount2)
-
{
-
++elechooser;
-
}
-
-
//see if the nucleophile and electrophile are in the same polymer
-
bool loopy = 0;
-
looper(nucs[nucount], loopy, elecs[elecount]->namenumber);
-
if(elecs.size()==1 && nucs.size()==1 && (elecs[elecount]->namenumber == nucs[nucount]->namenumber || loopy ==1))
-
{
-
nucs.erase(nuchooser);
-
}
-
else
-
{
-
-
//protection against a monomer reacting with itself
-
if(nucs.size()==1 && elecs.size()>1 && (elecs[elecount]->namenumber == nucs[nucount]->namenumber || loopy ==1))
-
{
-
while(elecs[elecount]->namenumber == nucs[nucount]->namenumber)
-
{
-
determine_electrophile(elecs, elecount, addrate_4, branchrate1_4, branchrate2_4, alpha_6);
-
}
-
-
//reset the electrophile iterator
-
elechooser = elecs.begin();
-
-
for(int elecount2 = 0; elecount2 != elecount; ++elecount2)
-
{
-
++elechooser;
-
}
-
}
-
else if(elecs.size()==1 && nucs.size()>1 && (elecs[elecount]->namenumber == nucs[nucount]->namenumber || loopy ==1))
-
{
-
while(elecs[elecount]->namenumber == nucs[nucount]->namenumber)
-
{
-
determine_nucleophile(nucs, nucount, alpha_6, iter3);
-
}
-
-
//reset the nucleophile iterator
-
nuchooser = nucs.begin();
-
-
for(int nucount2 = 0; nucount2 != nucount; ++nucount2)
-
{
-
++nuchooser;
-
}
-
}
-
-
//additive monomer reaction
-
if(elecs[elecount]->tag == 2)
-
{
-
//reaction
-
nucs[nucount]->next = &*(elecs[elecount]);
-
elecs[elecount]->previous = &*(nucs[nucount]);
-
-
//reset the molecular weight, number of nodes, number of original chains
-
elecs[elecount]->molweight = elecs[elecount]->molweight + nucs[nucount]->molweight;
-
elecs[elecount]->nodes = elecs[elecount]->nodes + nucs[nucount]->nodes;
-
elecs[elecount]->originalchains = elecs[elecount]->originalchains + nucs[nucount]->originalchains;
-
-
//vector shuffling
-
nuchooser = nucs.erase(nuchooser);
-
nuchooser = nucs.insert(nuchooser, elecs[elecount]);
-
elechooser = elecs.erase(elechooser);
-
}
-
-
//branching monomer reaction
-
else if(elecs[elecount]->tag == 3)
-
{
-
//fast site
-
if(elecs[elecount]->nextbranchtag == 2)
-
{
-
bool loopy2 = 0;
-
looper(nucs[nucount], loopy2, elecs[elecount]->namenumber);
-
-
if(loopy2==0)
-
{
-
//set the monomers fast site as reacted
-
elecs[elecount]->branchfull = 1;
-
-
//reaction
-
nucs[nucount]->next = &*(elecs[elecount]);
-
elecs[elecount]->branch = &*(nucs[nucount]);
-
-
//reset the molecular weight, number of nodes, number of original chains
-
elecs[elecount]->molweight = elecs[elecount]->molweight + nucs[nucount]->molweight;
-
elecs[elecount]->nodes = elecs[elecount]->nodes + nucs[nucount]->nodes;
-
elecs[elecount]->originalchains = elecs[elecount]->originalchains + nucs[nucount]->originalchains;
-
-
//vector shuffling
-
nuchooser = nucs.erase(nuchooser);
-
//if electrophile has no electrophilic sites left
-
if(elecs[elecount]->nextfull)
-
elechooser = elecs.erase(elechooser);
-
}
-
}
-
-
//slow site
-
else if(elecs[elecount]->nextbranchtag == 1)
-
{
-
//set the monomers slowsite as reacted
-
elecs[elecount]->nextfull = 1;
-
-
//reaction
-
elecs[elecount]->previous = &*(nucs[nucount]);
-
nucs[nucount]->next = &*(elecs[elecount]);
-
-
//reset the molecular weight, number of nodes, number of original chains
-
elecs[elecount]->molweight = elecs[elecount]->molweight + nucs[nucount]->molweight;
-
elecs[elecount]->nodes = elecs[elecount]->nodes + nucs[nucount]->nodes;
-
elecs[elecount]->originalchains = elecs[elecount]->originalchains + nucs[nucount]->originalchains;
-
-
//vector shuffling
-
nuchooser = nucs.erase(nuchooser);
-
nuchooser = nucs.insert(nuchooser, elecs[elecount]);
-
//electrophile has no electrophilic sites left
-
if(elecs[elecount]->branchfull)
-
elechooser = elecs.erase(elechooser);
-
-
}
-
}
-
}
-
}
-
-
//the basic run algorithm is as follows
-
while(nucleophiles.size()!=0)
-
{
-
//reinitialize counters
-
nucounter = 0;
-
elecounter = 0;
-
-
if(!electrophiles.empty())//if the elecrophiles queue is not empty there are still more monomers to react
-
{
-
determine_electrophile(electrophiles, elecounter, addprob, branchprob1, branchprob2, alpha);
-
determine_nucleophile(nucleophiles, nucounter, alpha, iter);
-
-
addmonomer(nucleophiles, electrophiles, nucounter, elecounter, addprob, branchprob1, branchprob2, alpha, iter);
-
}
-
else//if the electrophiles queue is empty we add more monomers to react
-
{
-
initializeaddmons(electrophiles, addnum, namenumber);
-
initializebranchmons(electrophiles, branchnum, namenumber);
-
}
-
iter = iter+1;
-
}
-
0 2604 Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Fred Ma |
last post by:
Hello,
I was looking at Meyers's "Effective STL", item 23
about choosing between vectors and maps (at least
that the choice for me). In many cases, using
sorted vectors is faster for lookups. The two
reasons are (1) that vector elements are smaller,
since map elements need at least 3 pointers, and
(2) contiguity of vector elements in memory ensure
fewer page faults.
|
by: Amit |
last post by:
Hello.
I am having some problem organizing a set of vectors. The vectors itself,
could contain a pointer( say integer pointer) or could contain another
object MyClass.
1>So, first of all, is there anyway where I can accomodate both the vector
types into a single set. Something like a set<vector<void*>, my_compare func
>.
Right now, I am having them as two different set dayatypes.
|
by: mp |
last post by:
I am doing pairwise comparisons between 2 vectors of chars and
permuting one vector and storing the resulting calculations in a
vector<float> then I find a p-value among other stats. I have to do
1,000,000 permuations for each pair, with a total of 2000 pairs to
compare. Is a vector the appropriate container for such a job? Or is
this a newbie mistake?
Currently I am using a vector of pointers to an object which contains
my pair of...
|
by: Pieter |
last post by:
Hi,
Something strange is happing with my Windowf Forms application (VB.NET
2005): The users had all local Administrator-rights on there pc. We changed
it to the 'normal' users, and now they can't run our V.NET application
anymore!
The application starts (you can see the screen and caption etc), and than
they get the well known error "MyApplication has encountered a problem and
needs to close" with the "send error report"-button etc.
|
by: Jeff |
last post by:
Hello-
Ive never used a vector or vectors in C++ so I have a question for you
all.
I know I can dynamically create the size I need upfront, but is it
possible to
create them on the fly dynamically? That is, for a 2 dim array, I want
to create
the first element and then push_back the columns after that:
| |
by: M O J O |
last post by:
Often when I run my aspnet 2.0 vb application, I get this exception....
"Microsoft (R) Visual Basic Compiler has encountered a problem and needs
to close. We are sorry for the inconvenience."
Error signature:
AppName: devenv.exe AppVer: 8.0.50727.42 AppStamp:4333e699
ModName: ntdll.dll ModVer: 5.1.2600.2180 ModStamp:412e8603
fDebug: 0 Offset: 00018fea
|
by: wuzertheloser |
last post by:
Use the program skeleton below (starting with #include <stdio.h>)
as the starting point for quiz4. Add the necessary code to the
functions prob1() and prob2(), and add the other 2 functions, as
described in the text below.
You do not need to change anything in main().
In void prob1(void), take a double floating-point number x from
the keyboard and compute the function f(x), which is defined by:
|
by: John A. Bailo |
last post by:
I just got a new server built by my network group with Windows 2003.
I updated a c# console app that was running under 2000/.NET 1.1
to .NET 2.0
When running it on the new machine it runs to completion (based on
trace messages) and at the end of Main() the OS puts up a dialog that
read ".exe has encountered a problem and needs to close. We are sorry
for the inconvenience."
|
by: amscompit |
last post by:
I have a written the following code.
#include<iomanip>
#include<fstream>
#include<vector>
#include<cctype>
using namespace std;
|
by: =?Utf-8?B?Um9iZXJ0IFN0eW1h?= |
last post by:
Hello All,
I am new to these forums and reasonably new to Visual Basic.net.
I have been converting a couple of visual basic 6 programs to VB.NET.
The programs began failing under windows Vista, so I used the facilities
of Visual Studio 2005 to convert them to .NET and then cleaned up the
errors. The applications now use both Flexgrid and the printing compatablity
library.
The applications run great under Vista (where they were...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |