Index: src/tspsolver.cpp
===================================================================
--- src/tspsolver.cpp	(revision 85ad815b0b8c79d6ff4221b5724b119d823e5d0e)
+++ src/tspsolver.cpp	(revision 8af59c4aa389691fe923a5215d4be599c4087ff5)
@@ -30,41 +30,155 @@
 }
 
-void CTSPSolver::cleanup()
-{
-	route.clear();
-	mayNotBeOptimal = false;
-}
-
-double CTSPSolver::findMinInRow(int nRow, tMatrix matrix, int exc)
-{
-double min = INFINITY;
-	for (int k = 0; k < nCities; k++)
-		if (((k != exc)) && (min > matrix.at(nRow).at(k)))
-			min = matrix.at(nRow).at(k);
-	return min == INFINITY ? 0 : min;
-}
-
-double CTSPSolver::findMinInCol(int nCol, tMatrix matrix, int exr)
-{
-double min = INFINITY;
-	for (int k = 0; k < nCities; k++)
-		if ((k != exr) && (min > matrix.at(k).at(nCol)))
-			min = matrix.at(k).at(nCol);
-	return min == INFINITY ? 0 : min;
-}
-
-void CTSPSolver::subRow(tMatrix &matrix, int nRow, double val)
-{
-	for (int k = 0; k < nCities; k++)
-		if (k != nRow)
-			matrix[nRow][k] -= val;
-}
-
-void CTSPSolver::subCol(tMatrix &matrix, int nCol, double val)
-{
-	for (int k = 0; k < nCities; k++)
-		if (k != nCol)
-			matrix[k][nCol] -= val;
-}
+/*!
+ * \brief Returns the sorted optimal path, starting from City 1.
+ * \return A string, containing sorted optimal path.
+ */
+QString CTSPSolver::getSortedPath() const
+{
+	if (!root || route.isEmpty() || (route.size() != nCities))
+		return QString();
+
+int i = 0; // We start from City 1
+QString path = trUtf8("City %1").arg(1) + " -> ";
+	while ((i = route[i]) != 0) {
+		path += trUtf8("City %1").arg(i + 1) + " -> ";
+	}
+	// And finish in City 1, too
+	path += trUtf8("City %1").arg(1);
+
+	return path;
+}
+
+/*!
+ * \brief Returns CTSPSolver's version ID.
+ * \return A string: <b>\$Id$</b>.
+ */
+QString CTSPSolver::getVersionId()
+{
+	return QString("$Id$");
+}
+
+/*!
+ * \brief Returns whether or not the solution is definitely optimal.
+ * \return \c true if solution is definitely optimal, otherwise \c false.
+ *
+ *  The solution may need some further interations to determine whether it is optimal.
+ *  In such cases this function returns \c false.
+ */
+bool CTSPSolver::isOptimal() const
+{
+	return !mayNotBeOptimal;
+}
+
+/*!
+ * \brief Solves the given task.
+ * \param numCities Number of cities in the task.
+ * \param task The matrix of city-to-city travel costs.
+ * \param parent The parent widget for displaying messages and dialogs.
+ * \return Pointer to the root of the solution tree.
+ *
+ * \todo TODO: Comment the algorithm.
+ */
+sStep *CTSPSolver::solve(int numCities, tMatrix task, QWidget *parent)
+{
+	if (numCities <= 1)
+		return NULL;
+	cleanup();
+	nCities = numCities;
+QProgressDialog pd(parent);
+QProgressBar *pb = new QProgressBar(&pd);
+	pb->setAlignment(Qt::AlignCenter);
+	pb->setFormat(trUtf8("%v of %m parts found"));
+	pd.setBar(pb);
+	pd.setMaximum(nCities);
+	pd.setMinimumDuration(1000);
+	pd.setLabelText(trUtf8("Calculating optimal route..."));
+	pd.setWindowTitle(trUtf8("Solution Progress"));
+	pd.setWindowModality(Qt::ApplicationModal);
+	pd.setValue(0);
+
+sStep *step = new sStep();
+	step->matrix = task;
+	step->price = align(step->matrix);
+	root = step;
+
+sStep *left, *right;
+int nRow, nCol;
+bool firstStep = true;
+double check;
+	while (this->route.size() < nCities) {
+//		forbidden.clear();
+		step->alts = findCandidate(step->matrix,nRow,nCol);
+		while (hasSubCycles(nRow,nCol)) {
+//			forbidden[nRow] = nCol;
+			step->matrix[nRow][nCol] = INFINITY;
+			step->price += align(step->matrix);
+			step->alts = findCandidate(step->matrix,nRow,nCol);
+		}
+		if ((nRow == -1) || (nCol == -1) || pd.wasCanceled()) {
+			root = NULL;
+			break;
+		}
+
+		// Route with (nRow,nCol) path
+		right = new sStep();
+		right->matrix = step->matrix;
+		for (int k = 0; k < nCities; k++) {
+			if (k != nCol)
+				right->matrix[nRow][k] = INFINITY;
+			if (k != nRow)
+				right->matrix[k][nCol] = INFINITY;
+		}
+		right->price = step->price + align(right->matrix);
+		// Forbid selected route to exclude its reuse in next steps.
+		right->matrix[nCol][nRow] = INFINITY;
+		right->matrix[nRow][nCol] = INFINITY;
+
+		// Route without (nRow,nCol) path
+		left = new sStep();
+		left->matrix = step->matrix;
+		left->matrix[nRow][nCol] = INFINITY;
+ 		left->price = step->price + align(left->matrix);
+
+		step->candidate.nRow = nRow;
+		step->candidate.nCol = nCol;
+		step->plNode = left;
+		step->prNode = right;
+
+		if (right->price <= left->price) {
+			// Route with (nRow,nCol) path is cheaper
+			step = right;
+			this->route[nRow] = nCol;
+			pd.setValue(this->route.size());
+			if (firstStep) {
+				check = left->price;
+				firstStep = false;
+			}
+		} else {
+			// Route without (nRow,nCol) path is cheaper
+			step = left;
+			qApp->processEvents();
+			if (firstStep) {
+				check = right->price;
+				firstStep = false;
+			}
+		}
+	}
+
+	if (!root && !pd.wasCanceled()) {
+		pd.reset();
+		QMessageBox(QMessageBox::Warning,trUtf8("Solution Result"),trUtf8("Unable to find solution.\nMaybe, this task has no solutions."),QMessageBox::Ok,parent).exec();
+	}
+
+	qApp->processEvents();
+
+	if (root) {
+		route = this->route;
+		mayNotBeOptimal = (check < step->price);
+	}
+	return root;
+}
+
+/* Privates **********************************************************/
 
 double CTSPSolver::align(tMatrix &matrix)
@@ -87,4 +201,10 @@
 	}
 	return r;
+}
+
+void CTSPSolver::cleanup()
+{
+	route.clear();
+	mayNotBeOptimal = false;
 }
 
@@ -112,4 +232,22 @@
 }
 
+double CTSPSolver::findMinInCol(int nCol, tMatrix matrix, int exr)
+{
+double min = INFINITY;
+	for (int k = 0; k < nCities; k++)
+		if ((k != exr) && (min > matrix.at(k).at(nCol)))
+			min = matrix.at(k).at(nCol);
+	return min == INFINITY ? 0 : min;
+}
+
+double CTSPSolver::findMinInRow(int nRow, tMatrix matrix, int exc)
+{
+double min = INFINITY;
+	for (int k = 0; k < nCities; k++)
+		if (((k != exc)) && (min > matrix.at(nRow).at(k)))
+			min = matrix.at(nRow).at(k);
+	return min == INFINITY ? 0 : min;
+}
+
 bool CTSPSolver::hasSubCycles(int nRow, int nCol)
 {
@@ -126,151 +264,15 @@
 }
 
-/*!
- * \brief Solves the given task.
- * \param numCities Number of cities in the task.
- * \param task The matrix of city-to-city travel costs.
- * \param parent The parent widget for displaying messages and dialogs.
- * \return Pointer to the root of the solution tree.
- *
- * \todo TODO: Comment the algorithm.
- */
-sStep *CTSPSolver::solve(int numCities, tMatrix task, QWidget *parent)
-{
-	if (numCities <= 1)
-		return NULL;
-	cleanup();
-	nCities = numCities;
-QProgressDialog pd(parent);
-QProgressBar *pb = new QProgressBar(&pd);
-	pb->setAlignment(Qt::AlignCenter);
-	pb->setFormat(trUtf8("%v of %m parts found"));
-	pd.setBar(pb);
-	pd.setMaximum(nCities);
-	pd.setMinimumDuration(1000);
-	pd.setLabelText(trUtf8("Calculating optimal route..."));
-	pd.setWindowTitle(trUtf8("Solution Progress"));
-	pd.setWindowModality(Qt::ApplicationModal);
-	pd.setValue(0);
-
-sStep *step = new sStep();
-	step->matrix = task;
-	step->price = align(step->matrix);
-	root = step;
-
-sStep *left, *right;
-int nRow, nCol;
-bool firstStep = true;
-double check;
-	while (this->route.size() < nCities) {
-//		forbidden.clear();
-		step->alts = findCandidate(step->matrix,nRow,nCol);
-		while (hasSubCycles(nRow,nCol)) {
-//			forbidden[nRow] = nCol;
-			step->matrix[nRow][nCol] = INFINITY;
-			step->price += align(step->matrix);
-			step->alts = findCandidate(step->matrix,nRow,nCol);
-		}
-		if ((nRow == -1) || (nCol == -1) || pd.wasCanceled()) {
-			root = NULL;
-			break;
-		}
-
-		// Route with (nRow,nCol) path
-		right = new sStep();
-		right->matrix = step->matrix;
-		for (int k = 0; k < nCities; k++) {
-			if (k != nCol)
-				right->matrix[nRow][k] = INFINITY;
-			if (k != nRow)
-				right->matrix[k][nCol] = INFINITY;
-		}
-		right->price = step->price + align(right->matrix);
-		// Forbid selected route to exclude its reuse in next steps.
-		right->matrix[nCol][nRow] = INFINITY;
-		right->matrix[nRow][nCol] = INFINITY;
-
-		// Route without (nRow,nCol) path
-		left = new sStep();
-		left->matrix = step->matrix;
-		left->matrix[nRow][nCol] = INFINITY;
- 		left->price = step->price + align(left->matrix);
-
-		step->candidate.nRow = nRow;
-		step->candidate.nCol = nCol;
-		step->plNode = left;
-		step->prNode = right;
-
-		if (right->price <= left->price) {
-			// Route with (nRow,nCol) path is cheaper
-			step = right;
-			this->route[nRow] = nCol;
-			pd.setValue(this->route.size());
-			if (firstStep) {
-				check = left->price;
-				firstStep = false;
-			}
-		} else {
-			// Route without (nRow,nCol) path is cheaper
-			step = left;
-			qApp->processEvents();
-			if (firstStep) {
-				check = right->price;
-				firstStep = false;
-			}
-		}
-	}
-
-	if (!root && !pd.wasCanceled()) {
-		pd.reset();
-		QMessageBox(QMessageBox::Warning,trUtf8("Solution Result"),trUtf8("Unable to find solution.\nMaybe, this task has no solutions."),QMessageBox::Ok,parent).exec();
-	}
-
-	qApp->processEvents();
-
-	if (root) {
-		route = this->route;
-		mayNotBeOptimal = (check < step->price);
-	}
-	return root;
-}
-
-/*!
- * \brief Returns the sorted optimal path, starting from City 1.
- * \return A string, containing sorted optimal path.
- */
-QString CTSPSolver::getSortedPath() const
-{
-	if (!root || route.isEmpty() || (route.size() != nCities))
-		return QString();
-
-int i = 0; // We start from City 1
-QString path = trUtf8("City %1").arg(1) + " -> ";
-	while ((i = route[i]) != 0) {
-		path += trUtf8("City %1").arg(i + 1) + " -> ";
-	}
-	// And finish in City 1, too
-	path += trUtf8("City %1").arg(1);
-
-	return path;
-}
-
-/*!
- * \brief Returns CTSPSolver's version ID.
- * \return A string: <b>\$Id$</b>.
- */
-QString CTSPSolver::getVersionId()
-{
-	return QString("$Id$");
-}
-
-/*!
- * \brief Returns whether or not the solution is definitely optimal.
- * \return \c true if solution is definitely optimal, otherwise \c false.
- *
- *  The solution may need some further interations to determine whether it is optimal.
- *  In such cases this function returns \c false.
- */
-bool CTSPSolver::isOptimal() const
-{
-	return !mayNotBeOptimal;
-}
+void CTSPSolver::subCol(tMatrix &matrix, int nCol, double val)
+{
+	for (int k = 0; k < nCities; k++)
+		if (k != nCol)
+			matrix[k][nCol] -= val;
+}
+
+void CTSPSolver::subRow(tMatrix &matrix, int nRow, double val)
+{
+	for (int k = 0; k < nCities; k++)
+		if (k != nRow)
+			matrix[nRow][k] -= val;
+}
