-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
80 lines (68 loc) · 2.47 KB
/
Copy pathmain.cpp
File metadata and controls
80 lines (68 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include <iostream>
using namespace std;
#include "src/solver.h"
#include "src/argument_parser.h"
#include "src/timer.h"
#include "src/examples/pipes.h"
#include "src/examples/pipes_colored.h"
#include "src/examples/patterns.h"
int main( int argc, char* argv[]){
ArgumentParser parser(argc, argv);
// Load arguments
int sx = std::stoi(parser.getArgument("sx","20"));
int sy = std::stoi(parser.getArgument("sy","20"));
string pattern_file = parser.getArgument("pattern","./patterns/bricks.png"); // only when working with patterns
string output_file = parser.getArgument("o","output_pattern.png");
int tile_size = std::stoi(parser.getArgument("stile","3"));
// Example problems are listed here
// 1) Pipes
//Pipes problem = Pipes();
//problem.create_pipes();
// 2) Pipes non crossing
//PipesColored problem = PipesColored();
//problem.create_pipes();
// 3) Texture problem
Patterns problem = Patterns();
problem.include_rotations = false;
problem.create_patterns_from_image(pattern_file,tile_size);
// Get adjancency matrices
AdjacencyRulesMatrix adjacency = AdjacencyRulesMatrix(
problem.get_adjacency_matrix_x(),
problem.get_adjacency_matrix_y(),
sx,sy);
// Define state space for all options
WFCDataStructure data = WFCDataStructure(
sx,sy,
problem.get_number_of_options(),adjacency,
new MersenneRNG(1));
data.set_options_weights(problem.get_weights());
// Configure the solver
WFCSolver solver = WFCSolver();
solver.log_progress = true;
solver.log_result = false;
solver.periodic = true;
#ifdef BENCHMARK
solver.log_progress = false;
solver.log_result = false;
#endif
#ifndef BENCHMARK
cout << "Array size: " << sx << " x " << sy << endl;
std::cout << "Number of options: " << problem.get_number_of_options() << std::endl;
#endif
Timer t; // TIMER START
// Perform wave function collapse (different method for sequential and parallel)
#ifdef _OPENMP
Matrix2D<int> result = solver.solve(data);
#else
Matrix2D<int> result = solver.solve_sequential(data);
#endif
float time_elapsed = t.elapsed(); // TIMER END
problem.output_file = output_file;
#ifdef BENCHMARK
problem.render_tiles_with_sdl(data.get_result(),tile_size,1);
#else
problem.render_tiles_with_sdl(data.get_result(),20);
#endif
cout << time_elapsed << endl; // Output solver time
return 0;
}