91 lines
1.6 KiB
C
91 lines
1.6 KiB
C
|
//
|
||
|
// Created by natty on 15.7.23.
|
||
|
//
|
||
|
|
||
|
#ifndef TSP_RENDERWINDOW_H
|
||
|
#define TSP_RENDERWINDOW_H
|
||
|
|
||
|
|
||
|
#include <QApplication>
|
||
|
#include <qmainwindow.h>
|
||
|
#include <qwidget.h>
|
||
|
#include <SDL2/SDL.h>
|
||
|
#include <QHBoxLayout>
|
||
|
|
||
|
#include <unordered_set>
|
||
|
#include <random>
|
||
|
#include <QComboBox>
|
||
|
#include <QLabel>
|
||
|
#include <QPushButton>
|
||
|
|
||
|
struct State;
|
||
|
|
||
|
struct Vertex {
|
||
|
double x;
|
||
|
double y;
|
||
|
};
|
||
|
|
||
|
struct Edge {
|
||
|
size_t from;
|
||
|
size_t to;
|
||
|
|
||
|
double distanceOf(const State& state, const Vertex& vertex) const;
|
||
|
};
|
||
|
|
||
|
struct State {
|
||
|
std::vector<Vertex> vertices;
|
||
|
std::vector<Edge> edges;
|
||
|
};
|
||
|
|
||
|
class Strategy {
|
||
|
public:
|
||
|
virtual ~Strategy() = default;
|
||
|
virtual bool step(State& state) = 0;
|
||
|
};
|
||
|
|
||
|
class AnnaStrategy : public Strategy {
|
||
|
public:
|
||
|
bool step(State& state) override;
|
||
|
private:
|
||
|
bool init;
|
||
|
std::vector<size_t> unvisited;
|
||
|
};
|
||
|
|
||
|
class RenderWindow : public QMainWindow {
|
||
|
Q_OBJECT
|
||
|
|
||
|
public:
|
||
|
RenderWindow();
|
||
|
~RenderWindow() override;
|
||
|
|
||
|
void paintEvent(QPaintEvent* event) override;
|
||
|
|
||
|
public slots:
|
||
|
void render();
|
||
|
void step();
|
||
|
void solve();
|
||
|
|
||
|
private:
|
||
|
QVBoxLayout *layout;
|
||
|
QHBoxLayout *controlsLayout;
|
||
|
QWidget *renderArea;
|
||
|
QWidget *mainWindowWidget;
|
||
|
QLabel *distanceLabel;
|
||
|
QPushButton *playButton;
|
||
|
QComboBox *strategySelector;
|
||
|
QTimer *animTimer;
|
||
|
SDL_Window *window{};
|
||
|
SDL_Renderer* renderer{};
|
||
|
|
||
|
State state;
|
||
|
|
||
|
std::unique_ptr<Strategy> strategy;
|
||
|
|
||
|
private slots:
|
||
|
void resetState();
|
||
|
void hardResetState();
|
||
|
void togglePlay(bool play);
|
||
|
};
|
||
|
|
||
|
#endif //TSP_RENDERWINDOW_H
|