Skip to content

Commit 06210c7

Browse files
committed
A* 휴리스틱 수정
1 parent bdd8118 commit 06210c7

File tree

10 files changed

+37
-23
lines changed

10 files changed

+37
-23
lines changed

SPA/ASBQ.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,15 +133,16 @@ void ASBQ::makeDistTable() {
133133

134134
for (int i = 0; i < MAX_COLUMN; i++) {
135135
for (int j = 0; j < MAX_ROW; j++) {
136-
#if WEIGHT_STD_DIV
136+
if (maze->getStandardDeviation() != 0) {
137137
distanceTable[i][j] =
138-
((std::abs(end->getRow() - j)) * WEIGHT_MIN) + ((std::abs(end->getColumn() - i)) * WEIGHT_MIN);
139-
#else
138+
((std::abs(end->getRow() - j)) * WEIGHT_MIN) +
139+
((std::abs(end->getColumn() - i)) * WEIGHT_MIN);
140+
} else {
140141
distanceTable[i][j] =
141-
((std::abs(end->getRow() - j)) * WEIGHT_MEAN) + ((std::abs(end->getColumn() - i)) * WEIGHT_MEAN);
142-
#endif
142+
((std::abs(end->getRow() - j)) * WEIGHT_MEAN) +
143+
((std::abs(end->getColumn() - i)) * WEIGHT_MEAN);
144+
}
143145
}
144146
}
145147
}
146148

147-

SPA/ASPQ.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,15 @@ void ASPQ::makeDistTable() {
130130

131131
for (int i = 0; i < MAX_COLUMN; i++) {
132132
for (int j = 0; j < MAX_ROW; j++) {
133-
#if WEIGHT_STD_DIV
133+
if (maze->getStandardDeviation() != 0) {
134134
distanceTable[i][j] =
135-
((std::abs(end->getRow() - j)) * WEIGHT_MIN) + ((std::abs(end->getColumn() - i)) * WEIGHT_MIN);
136-
#else
135+
((std::abs(end->getRow() - j)) * WEIGHT_MIN) +
136+
((std::abs(end->getColumn() - i)) * WEIGHT_MIN);
137+
} else {
137138
distanceTable[i][j] =
138-
((std::abs(end->getRow() - j)) * WEIGHT_MEAN) + ((std::abs(end->getColumn() - i)) * WEIGHT_MEAN);
139-
#endif
139+
((std::abs(end->getRow() - j)) * WEIGHT_MEAN) +
140+
((std::abs(end->getColumn() - i)) * WEIGHT_MEAN);
141+
}
140142
}
141143
}
142144
}

cmake-build-debug/SPA_compare

176 Bytes
Binary file not shown.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
Start testing: Jul 29 01:54 KST
1+
Start testing: Jul 29 02:36 KST
22
----------------------------------------------------------
3-
End testing: Jul 29 01:54 KST
3+
End testing: Jul 29 02:36 KST

declaration.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313

1414
#define INF 10000000 // Maximum weight of edges.
15-
#define WEIGHT_STD_DIV 0 // Standard deviation of weight.
1615
#define WEIGHT_MEAN 10 // Mean of weight.
1716
#define WEIGHT_MAX 20
1817
#define WEIGHT_MIN 5

main.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,17 @@ int main(int argc, char * argv []){
1919
int mainLoopCount = 1;
2020
int mazeRowSize = DEFAULT_ROW;
2121
int mazeColumnSize = DEFAULT_COLUMN;
22-
if (argc == 4){
22+
int standardDeviation = 0;
23+
if (argc == 5){
2324
mainLoopCount = int(std::strtol(argv[1], nullptr, 10));
2425
mazeRowSize = int(std::strtol(argv[2], nullptr, 10));
2526
mazeColumnSize = int(std::strtol(argv[3], nullptr, 10));
27+
standardDeviation = int(std::strtol(argv[4], nullptr, 10));
2628
} else if (argc == 2){
2729
mainLoopCount = int(std::strtol(argv[1], nullptr, 10));
2830
} else if (argc != 1){
29-
std::cout<<"Wrong arguments! The number of arguments must be 1(loop count) or 3(maze row size, maze column size, loop count)."<<std::endl;
31+
std::cout<<"Wrong arguments! The number of arguments must be 1(loop count) or 4(maze row size, maze column size, loop count, standard deviation)."<<std::endl;
32+
return 1;
3033
}
3134

3235

@@ -45,7 +48,7 @@ int main(int argc, char * argv []){
4548

4649
// Make a new maze.
4750
timer.SetStart();
48-
Maze maze(mazeRowSize, mazeColumnSize);
51+
Maze maze(mazeRowSize, mazeColumnSize, standardDeviation);
4952
Eller eller(maze);
5053
eller.MakeMaze();
5154
timer.SetEnd();

map/Eller.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,12 @@ bool Eller::ChoiceRandomly() {
6262
int Eller::GenerateWeightND(){
6363
std::random_device rd;
6464
std::mt19937 gen(rd());
65-
std::normal_distribution<double> weight_int(WEIGHT_MEAN, WEIGHT_STD_DIV);
66-
int weight = -1;
65+
std::normal_distribution<double> weight_int(WEIGHT_MEAN, tempMaze->getStandardDeviation());
66+
int weight;
6767
// The Maximum weight is below (mean*2)
68-
while (weight <= WEIGHT_MIN || weight >= WEIGHT_MAX) {
68+
do {
6969
weight = (int)std::round(weight_int(gen));
70-
}
70+
} while (weight <= WEIGHT_MIN || weight >= WEIGHT_MAX);
7171
return weight;
7272
}
7373

map/Eller.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ class Eller{
1818
private:
1919
Maze *tempMaze;
2020

21+
int STD;
22+
2123
std::set<int> existingSet;
2224

2325
/*

map/Maze.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
#include "Maze.h"
66

77

8-
Maze::Maze(int rowSize, int columnSize) {
8+
Maze::Maze(int rowSize, int columnSize, int stdInput) {
99
maxRow = rowSize;
1010
maxColumn = columnSize;
11+
standardDeviation = stdInput;
1112
for (int column = 0; column < maxColumn; column++){
1213
for (int row = 0; row < maxRow; ++row) {
1314
location[column][row].setRow(row);
@@ -130,5 +131,9 @@ Location *Maze::getLocation(int row, int column) {
130131
return &(location[column][row]);
131132
}
132133

134+
int Maze::getStandardDeviation() const {
135+
return standardDeviation;
136+
}
137+
133138

134139

map/Maze.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@ class Maze{
1919

2020
int maxRow, maxColumn;
2121
Location location[MAX_COLUMN][MAX_ROW];
22+
int standardDeviation;
2223

2324
public:
24-
Maze(int maxRow, int maxColumn);
25+
Maze(int maxRow, int maxColumn, int stdInput);
2526
Maze(const Maze&) = delete;
2627
int getRowSize();
2728
int getColumnSize();
2829
Location* getLocation(int row, int column);
30+
int getStandardDeviation() const;
2931

3032
void InitializeMaze();
3133

0 commit comments

Comments
 (0)