Skip to content

Commit 307e23f

Browse files
authored
Merge pull request #9 from mhuendorf/exp/refactor
Last-minute Refactoring :D
2 parents c5e5db8 + 5bad7b5 commit 307e23f

28 files changed

+380
-747
lines changed

AE_PunktBeschriftung/CMakeLists.txt

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
11
cmake_minimum_required(VERSION 3.17)
2-
project(labelpoints)
2+
project(label_map)
33

44
set(CMAKE_CXX_STANDARD 20)
55

66
add_executable(label_map src/main/main.cpp
77
src/main/generator/InstanceGenerator.cpp
88
src/main/representations/Instance.cpp
9-
src/main/representations/PointWithLabel.cpp
10-
src/main/representations/Box.cpp
11-
src/main/representations/Point2D.cpp
12-
src/main/representations/Solution.cpp
13-
src/main/representations/Rectangle.cpp
14-
src/main/representations/PlacedRectangle.cpp
15-
src/main/representations/Defs.cpp src/main/solver/TrivialSolver.cpp include/solver/TrivialSolver.hpp
9+
src/main/representations/Point.cpp
10+
src/main/solver/TrivialSolver.cpp
1611
src/main/io/InstanceReader.cpp)
1712

1813
target_include_directories(label_map PUBLIC include)
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
#ifndef UNTITLED_INSTANCEGENERATOR_HPP
2-
#define UNTITLED_INSTANCEGENERATOR_HPP
1+
#pragma once
2+
3+
#include <representations/Instance.hpp>
34

45
#include <iostream>
5-
#include "../representations/Instance.hpp"
66

77
class InstanceGenerator {
88

@@ -11,4 +11,3 @@ class InstanceGenerator {
1111
unsigned int seed);
1212
};
1313

14-
#endif //UNTITLED_INSTANCEGENERATOR_HPP
Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
1-
#ifndef INSTANCE_READER_HPP
2-
#define INSTANCE_READER_HPP
3-
4-
#include <string>
1+
#pragma once
52

63
#include <representations/Instance.hpp>
7-
#include <representations/Solution.hpp>
4+
#include <representations/Point.hpp>
85

9-
void readInstance(Instance& instance, const std::string& filename);
6+
#include <string>
107

11-
void readInstanceAndSolution(Instance& instance, Solution& solution, const std::string& filename);
8+
Instance readInstance(const std::string& filename);
129

13-
std::shared_ptr<PointWithLabel> parseLine(std::string const& line);
10+
void parseLine(Instance& instance, const std::string& line);
1411

1512
int parsePositiveInteger(const std::string& line);
1613

1714
void checkBoxConsistency(int x, int y, int width, int height, int upperLeftX, int upperLeftY);
18-
#endif //INSTANCE_READER_HPP
15+
16+
Point::Corner parseCornerPlacement(int x, int y, int upperLeftX, int upperLeftY);

AE_PunktBeschriftung/include/representations/Box.hpp

Lines changed: 0 additions & 23 deletions
This file was deleted.

AE_PunktBeschriftung/include/representations/Defs.hpp

Lines changed: 0 additions & 16 deletions
This file was deleted.

AE_PunktBeschriftung/include/representations/Instance.hpp

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,36 @@
1-
#ifndef UNTITLED_INSTANCE_HPP
2-
#define UNTITLED_INSTANCE_HPP
1+
#pragma once
32

4-
#include <stack>
3+
#include <representations/Point.hpp>
54
#include <vector>
6-
#include <representations/PointWithLabel.hpp>
75

86
class Instance {
7+
98
private:
10-
std::vector<std::shared_ptr<PointWithLabel> > points;
119

12-
friend std::ostream &operator<<(std::ostream &ostream, const Instance &instance);
10+
std::vector<Point> points; // contains all points of the instance
11+
12+
std::vector<int> labelled_points; // contains all indices of points with actual labels
13+
14+
friend std::ostream& operator<<(std::ostream &ostream, const Instance &instance);
1315

1416
public:
15-
Instance();
17+
18+
Instance(int size);
1619

1720
void reserve(int num);
1821

19-
void operator+(std::shared_ptr<PointWithLabel> point2D);
22+
void add(const Point& point);
2023

2124
int size() const;
2225

23-
const std::shared_ptr<PointWithLabel>& getPoint(int idx) const;
26+
void setLabel(int idx, Point::Corner corner);
27+
28+
const Point& getPoint(int idx) const;
29+
30+
std::vector<int>& getLabelledPoints();
31+
32+
int countLabelledPoints() const;
33+
34+
bool isFeasible() const;
2435
};
2536

26-
#endif //UNTITLED_INSTANCE_HPP

AE_PunktBeschriftung/include/representations/PlacedRectangle.hpp

Lines changed: 0 additions & 36 deletions
This file was deleted.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#pragma once
2+
3+
#include <string>
4+
#include <tuple>
5+
6+
using Point2D = std::tuple<int, int>;
7+
8+
class Point {
9+
10+
public:
11+
12+
enum Corner {
13+
NOT_PLACED = 0, TOP_LEFT, TOP_RIGHT, BOTTOM_LEFT, BOTTOM_RIGHT
14+
};
15+
16+
private:
17+
18+
int x;
19+
int y;
20+
int width;
21+
int height;
22+
std::string label;
23+
Corner placement;
24+
25+
std::tuple<int, int> upperLeft;
26+
std::tuple<int, int> lowerRight;
27+
28+
friend std::ostream &operator<<(std::ostream &ostream, const Point &point);
29+
30+
public:
31+
32+
Point(int x, int y, int width, int height, std::string label);
33+
34+
int getX() const;
35+
36+
int getY() const;
37+
38+
std::string getName() const;
39+
40+
void setPlacement(Corner placement);
41+
42+
const Corner& getPlacement() const;
43+
44+
bool checkCollision(const Point& other, Corner corner) const;
45+
46+
bool checkCollision(const Point& other) const;
47+
48+
std::tuple< Point2D, Point2D > getCoordsForPlacement(Corner corner) const;
49+
50+
};

AE_PunktBeschriftung/include/representations/Point2D.hpp

Lines changed: 0 additions & 18 deletions
This file was deleted.

AE_PunktBeschriftung/include/representations/PointWithLabel.hpp

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)