Changeset 13 in tspsg-svn for trunk/src/tspsolver.cpp


Ignore:
Timestamp:
Oct 21, 2007, 3:07:21 PM (17 years ago)
Author:
laleppa
Message:

Writing solving algorithm...

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/tspsolver.cpp

    r12 r13  
    2424#include "tspsolver.h"
    2525
    26 // Temoporary matrix for testing algorithm
    27 double testmatrix[] = {
    28                 infinity, 6, 7, 3, 4,
    29                 9, infinity, 6, 9, 10,
    30                 6, 9, infinity, 5, 3,
    31                 3, 10, 4, infinity, 2,
    32                 5, 1, 1, 9, infinity
    33         };
    34 
    35 
    3626CTSPSolver::CTSPSolver()
    3727{
    3828}
    3929
    40 sStep *CTSPSolver::solve(int numCities, double *task)
     30double CTSPSolver::findMinInRow(int nRow, tMatrix matrix)
     31{
     32double min = infinity;
     33        for (int k = 0; k < nCities; k++)
     34                if (min > matrix[nRow][k])
     35                        min = matrix[nRow][k];
     36        return min == infinity ? 0 : min;
     37}
     38
     39double CTSPSolver::findMinInCol(int nCol, tMatrix matrix)
     40{
     41double min = infinity;
     42        for (int k = 0; k < nCities; k++)
     43                if (min > matrix[k][nCol])
     44                        min = matrix[k][nCol];
     45        return min == infinity ? 0 : min;
     46}
     47
     48sStep *CTSPSolver::solve(int numCities, tMatrix task)
    4149{
    4250        if (numCities <= 1)
    4351                return NULL;
    44 // Temporary debug code :-)
    45         task = &testmatrix[0];
    46         numCities = 5;
    47 //*/
    48 sStep step;
    49         step.matrix = new double(numCities * numCities);
    50         memcpy(step.matrix,task,sizeof(double) * numCities * numCities);
     52        nCities = numCities;
     53sStep *step = new sStep();
     54        step->matrix = task;
     55        root = step;
    5156
    52         return NULL;
     57        return step;
    5358}
    5459
Note: See TracChangeset for help on using the changeset viewer.