Fix circular
This commit is contained in:
parent
95e06a3f18
commit
46e0756949
14
src/Tour.cpp
14
src/Tour.cpp
@ -50,10 +50,10 @@ void Tour::draw(QGraphicsScene *scene) const {
|
||||
return;
|
||||
|
||||
Node *node = m_startNode;
|
||||
do {
|
||||
while (node->next != nullptr) {
|
||||
node->point.drawTo(node->next->point, scene);
|
||||
node = node->next;
|
||||
} while (node != m_startNode);
|
||||
}
|
||||
}
|
||||
|
||||
int Tour::size() const {
|
||||
@ -89,6 +89,11 @@ void Tour::insertNearest(Point p) {
|
||||
m_startNode = new Node(p);
|
||||
return;
|
||||
}
|
||||
if (m_startNode->next == nullptr) {
|
||||
auto newNode = new Node(p, m_startNode);
|
||||
m_startNode->next = newNode;
|
||||
return;
|
||||
}
|
||||
|
||||
Node *nearest = m_startNode;
|
||||
double minDistance = INFINITY;
|
||||
@ -112,6 +117,11 @@ void Tour::insertSmallest(Point p) {
|
||||
m_startNode = new Node(p);
|
||||
return;
|
||||
}
|
||||
if (m_startNode->next == nullptr) {
|
||||
auto newNode = new Node(p, m_startNode);
|
||||
m_startNode->next = newNode;
|
||||
return;
|
||||
}
|
||||
|
||||
Node *bestNode = m_startNode;
|
||||
double minIncrease = INFINITY;
|
||||
|
@ -19,6 +19,10 @@ int main(int argc, char *argv[]) {
|
||||
QApplication a(argc, argv);
|
||||
|
||||
string filename = "tsp10.txt";
|
||||
#ifdef __APPLE__
|
||||
filename.insert(0, "../../../");
|
||||
#endif
|
||||
|
||||
ifstream input;
|
||||
input.open(filename);
|
||||
|
||||
@ -45,7 +49,7 @@ int main(int argc, char *argv[]) {
|
||||
tour.insertNearest(p);
|
||||
//uncomment the 4 lines below to animate
|
||||
//tour.draw(scene);
|
||||
//std::chrono::milliseconds dura(50);
|
||||
//std::chrono::milliseconds dura(150);
|
||||
//std::this_thread::sleep_for(dura);
|
||||
//a.processEvents();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user