Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

I'm not sure how to improve the performance, since reading this code is pretty difficult. It's not the worst I've seen, but it could still be improved.

For starters, your main function is way too long. For readability, it's generally recognized that a function should be no longer than what can take up one screen, or one printed page. This helps with readability and maintainability. I like to try to keep mine below about 70 lines.

You're also using a goto, and while this is hotly debatedthis is hotly debated, I'd recommend against using it.

Here's how you might structure this:

class Pieces
{
    [member variables]
};

int aleADN()
{
    [...]
}

string* readFile(string filename){
    [..]
}

int evaluate(Pieces * pieces)
{
    int result = 1;
    [...]
    return result;
}

double selection(Pieces* pieces)
{
    [...]
    return fitness;
}

int reproduction(int geneA, int geneB, int j)
{
    [...]
}

void mate(pieces)
{
    [...]
}

void evolution(Pieces* pieces)
{
    do
    {
        [...]
        
        int done = evaluate(pieces);
        if (done == 0)
            return;
        
        fitness = selection(pieces);
        
        // mating leads to reproduction
        mate(pieces, fitness);
        
        mutate();
        
    } while (1);
}

int main()
{
    string* file_lines = readFile(filename);
    
    checkIntegrity();
    
    initialization();
    
    Pieces * pieces = new Pieces[POPULATION];
    evolution(pieces);
    
    // solution printout here
}

Once you get this structured properly, it will be very easy to set up things like timers or any memory monitoring utility like valgrind to see how much memory each function is using so you can track down what part of your code is taking too long or using too much memory.

I'm not sure how to improve the performance, since reading this code is pretty difficult. It's not the worst I've seen, but it could still be improved.

For starters, your main function is way too long. For readability, it's generally recognized that a function should be no longer than what can take up one screen, or one printed page. This helps with readability and maintainability. I like to try to keep mine below about 70 lines.

You're also using a goto, and while this is hotly debated, I'd recommend against using it.

Here's how you might structure this:

class Pieces
{
    [member variables]
};

int aleADN()
{
    [...]
}

string* readFile(string filename){
    [..]
}

int evaluate(Pieces * pieces)
{
    int result = 1;
    [...]
    return result;
}

double selection(Pieces* pieces)
{
    [...]
    return fitness;
}

int reproduction(int geneA, int geneB, int j)
{
    [...]
}

void mate(pieces)
{
    [...]
}

void evolution(Pieces* pieces)
{
    do
    {
        [...]
        
        int done = evaluate(pieces);
        if (done == 0)
            return;
        
        fitness = selection(pieces);
        
        // mating leads to reproduction
        mate(pieces, fitness);
        
        mutate();
        
    } while (1);
}

int main()
{
    string* file_lines = readFile(filename);
    
    checkIntegrity();
    
    initialization();
    
    Pieces * pieces = new Pieces[POPULATION];
    evolution(pieces);
    
    // solution printout here
}

Once you get this structured properly, it will be very easy to set up things like timers or any memory monitoring utility like valgrind to see how much memory each function is using so you can track down what part of your code is taking too long or using too much memory.

I'm not sure how to improve the performance, since reading this code is pretty difficult. It's not the worst I've seen, but it could still be improved.

For starters, your main function is way too long. For readability, it's generally recognized that a function should be no longer than what can take up one screen, or one printed page. This helps with readability and maintainability. I like to try to keep mine below about 70 lines.

You're also using a goto, and while this is hotly debated, I'd recommend against using it.

Here's how you might structure this:

class Pieces
{
    [member variables]
};

int aleADN()
{
    [...]
}

string* readFile(string filename){
    [..]
}

int evaluate(Pieces * pieces)
{
    int result = 1;
    [...]
    return result;
}

double selection(Pieces* pieces)
{
    [...]
    return fitness;
}

int reproduction(int geneA, int geneB, int j)
{
    [...]
}

void mate(pieces)
{
    [...]
}

void evolution(Pieces* pieces)
{
    do
    {
        [...]
        
        int done = evaluate(pieces);
        if (done == 0)
            return;
        
        fitness = selection(pieces);
        
        // mating leads to reproduction
        mate(pieces, fitness);
        
        mutate();
        
    } while (1);
}

int main()
{
    string* file_lines = readFile(filename);
    
    checkIntegrity();
    
    initialization();
    
    Pieces * pieces = new Pieces[POPULATION];
    evolution(pieces);
    
    // solution printout here
}

Once you get this structured properly, it will be very easy to set up things like timers or any memory monitoring utility like valgrind to see how much memory each function is using so you can track down what part of your code is taking too long or using too much memory.

replaced http://programmers.stackexchange.com/ with https://softwareengineering.stackexchange.com/
Source Link

I'm not sure how to improve the performance, since reading this code is pretty difficult. It's not the worst I've seen, but it could still be improved.

For starters, your main function is way too long. For readability, it's generally recognized that a function should be no longer than what can take up one screen, or one printed pagea function should be no longer than what can take up one screen, or one printed page. This helps with readability and maintainability. I like to try to keep mine below about 70 lines.

You're also using a goto, and while this is hotly debated, I'd recommend against using it.

Here's how you might structure this:

class Pieces
{
    [member variables]
};

int aleADN()
{
    [...]
}

string* readFile(string filename){
    [..]
}

int evaluate(Pieces * pieces)
{
    int result = 1;
    [...]
    return result;
}

double selection(Pieces* pieces)
{
    [...]
    return fitness;
}

int reproduction(int geneA, int geneB, int j)
{
    [...]
}

void mate(pieces)
{
    [...]
}

void evolution(Pieces* pieces)
{
    do
    {
        [...]
        
        int done = evaluate(pieces);
        if (done == 0)
            return;
        
        fitness = selection(pieces);
        
        // mating leads to reproduction
        mate(pieces, fitness);
        
        mutate();
        
    } while (1);
}

int main()
{
    string* file_lines = readFile(filename);
    
    checkIntegrity();
    
    initialization();
    
    Pieces * pieces = new Pieces[POPULATION];
    evolution(pieces);
    
    // solution printout here
}

Once you get this structured properly, it will be very easy to set up things like timers or any memory monitoring utility like valgrind to see how much memory each function is using so you can track down what part of your code is taking too long or using too much memory.

I'm not sure how to improve the performance, since reading this code is pretty difficult. It's not the worst I've seen, but it could still be improved.

For starters, your main function is way too long. For readability, it's generally recognized that a function should be no longer than what can take up one screen, or one printed page. This helps with readability and maintainability. I like to try to keep mine below about 70 lines.

You're also using a goto, and while this is hotly debated, I'd recommend against using it.

Here's how you might structure this:

class Pieces
{
    [member variables]
};

int aleADN()
{
    [...]
}

string* readFile(string filename){
    [..]
}

int evaluate(Pieces * pieces)
{
    int result = 1;
    [...]
    return result;
}

double selection(Pieces* pieces)
{
    [...]
    return fitness;
}

int reproduction(int geneA, int geneB, int j)
{
    [...]
}

void mate(pieces)
{
    [...]
}

void evolution(Pieces* pieces)
{
    do
    {
        [...]
        
        int done = evaluate(pieces);
        if (done == 0)
            return;
        
        fitness = selection(pieces);
        
        // mating leads to reproduction
        mate(pieces, fitness);
        
        mutate();
        
    } while (1);
}

int main()
{
    string* file_lines = readFile(filename);
    
    checkIntegrity();
    
    initialization();
    
    Pieces * pieces = new Pieces[POPULATION];
    evolution(pieces);
    
    // solution printout here
}

Once you get this structured properly, it will be very easy to set up things like timers or any memory monitoring utility like valgrind to see how much memory each function is using so you can track down what part of your code is taking too long or using too much memory.

I'm not sure how to improve the performance, since reading this code is pretty difficult. It's not the worst I've seen, but it could still be improved.

For starters, your main function is way too long. For readability, it's generally recognized that a function should be no longer than what can take up one screen, or one printed page. This helps with readability and maintainability. I like to try to keep mine below about 70 lines.

You're also using a goto, and while this is hotly debated, I'd recommend against using it.

Here's how you might structure this:

class Pieces
{
    [member variables]
};

int aleADN()
{
    [...]
}

string* readFile(string filename){
    [..]
}

int evaluate(Pieces * pieces)
{
    int result = 1;
    [...]
    return result;
}

double selection(Pieces* pieces)
{
    [...]
    return fitness;
}

int reproduction(int geneA, int geneB, int j)
{
    [...]
}

void mate(pieces)
{
    [...]
}

void evolution(Pieces* pieces)
{
    do
    {
        [...]
        
        int done = evaluate(pieces);
        if (done == 0)
            return;
        
        fitness = selection(pieces);
        
        // mating leads to reproduction
        mate(pieces, fitness);
        
        mutate();
        
    } while (1);
}

int main()
{
    string* file_lines = readFile(filename);
    
    checkIntegrity();
    
    initialization();
    
    Pieces * pieces = new Pieces[POPULATION];
    evolution(pieces);
    
    // solution printout here
}

Once you get this structured properly, it will be very easy to set up things like timers or any memory monitoring utility like valgrind to see how much memory each function is using so you can track down what part of your code is taking too long or using too much memory.

added 338 characters in body
Source Link

I'm not sure how to improve the performance, since reading this code is pretty difficult. It's not the worst I've seen, but it could still be improved.

For starters, your main function is way too long. For readability, it's generally recognized that a function should be no longer than what can take up one screen, or one printed page. This helps with readability and maintainability. I like to try to keep mine below about 70 lines.

You're also using a goto, and while this is hotly debatedthis is hotly debated, I'd recommend against using it.

Here's how you might structure this:

class Pieces
{
    [member variables]
};

int reproduction(int geneA, int geneB, int j)
{
    [...]
}

int aleADN()
{
    [...]
}

string* readFile(string filename){
    [..]
}

int evaluate(Pieces * pieces)
{
    int result = 1;
    [...]
    return result;
}

double selection(Pieces* pieces)
{
    [...]
    return fitness;
}

voidint matereproduction(piecesint geneA, int geneB, int j)
{
    [...]
}

void evolutionmate(Pieces* pieces)
{
    int done[...]
}

void =evolution(Pieces* 1;pieces)
{
    do
    {
        [...]
        
        int done = evaluate(pieces);
        if (done == 0)
            return;
        
        fitness = selection(pieces);
        
        // mating leads to reproduction
        mate(pieces, fitness);
        
        mutate();
        
    } while (done != 01);
}

int main()
{
    string* file_lines = readFile(filename);
    
    checkIntegrity();
    
    initialization();
    
    Pieces * pieces = new Pieces[POPULATION];
    evolution(pieces);
    
    // solution printout here
}

Once you get this structured properly, it will be very easy to set up things like timers or any memory monitoring utility like valgrind to see how much memory each function is using so you can track down what part of your code is taking too long or using too much memory.

I'm not sure how to improve the performance, since reading this code is pretty difficult. It's not the worst I've seen, but it could still be improved.

For starters, your main function is way too long. For readability, it's generally recognized that a function should be no longer than what can take up one screen, or one printed page. This helps with readability and maintainability. I like to try to keep mine below about 70 lines.

You're also using a goto, and while this is hotly debated, I'd recommend against using it.

Here's how you might structure this:

class Pieces
{
    [member variables]
};

int reproduction(int geneA, int geneB, int j)
{
    [...]
}

int aleADN()
{
    [...]
}

string* readFile(string filename){
    [..]
}

int evaluate(Pieces * pieces)
{
    int result = 1;
    [...]
    return result;
}

double selection(Pieces* pieces)
{
    [...]
    return fitness;
}

void mate(pieces)
{
    [...]
}

void evolution(Pieces* pieces)
{
    int done = 1;
    do
    {
        [...]
        
        done = evaluate(pieces);
        
        fitness = selection(pieces);
        
        // mating leads to reproduction
        mate(pieces, fitness);
        
        mutate();
        
    } while (done != 0);
}

int main()
{
    string* file_lines = readFile(filename);
    
    checkIntegrity();
    
    initialization();
    
    Pieces * pieces = new Pieces[POPULATION];
    evolution(pieces);
    
    // solution printout here
}

I'm not sure how to improve the performance, since reading this code is pretty difficult. It's not the worst I've seen, but it could still be improved.

For starters, your main function is way too long. For readability, it's generally recognized that a function should be no longer than what can take up one screen, or one printed page. This helps with readability and maintainability. I like to try to keep mine below about 70 lines.

You're also using a goto, and while this is hotly debated, I'd recommend against using it.

Here's how you might structure this:

class Pieces
{
    [member variables]
};

int aleADN()
{
    [...]
}

string* readFile(string filename){
    [..]
}

int evaluate(Pieces * pieces)
{
    int result = 1;
    [...]
    return result;
}

double selection(Pieces* pieces)
{
    [...]
    return fitness;
}

int reproduction(int geneA, int geneB, int j)
{
    [...]
}

void mate(pieces)
{
    [...]
}

void evolution(Pieces* pieces)
{
    do
    {
        [...]
        
        int done = evaluate(pieces);
        if (done == 0)
            return;
        
        fitness = selection(pieces);
        
        // mating leads to reproduction
        mate(pieces, fitness);
        
        mutate();
        
    } while (1);
}

int main()
{
    string* file_lines = readFile(filename);
    
    checkIntegrity();
    
    initialization();
    
    Pieces * pieces = new Pieces[POPULATION];
    evolution(pieces);
    
    // solution printout here
}

Once you get this structured properly, it will be very easy to set up things like timers or any memory monitoring utility like valgrind to see how much memory each function is using so you can track down what part of your code is taking too long or using too much memory.

deleted 38 characters in body
Source Link
Loading
Source Link
Loading