Skip to content

Commit 5ab41a8

Browse files
committed
minor cleanups, updated constructors, added checks for external minisat, removed unused file, dos2unix some old files , added optimization flag in makefile
1 parent 1c69f32 commit 5ab41a8

File tree

10 files changed

+134
-138
lines changed

10 files changed

+134
-138
lines changed

Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
CXX := -c++
2-
CXXFLAGS := -std=c++17 -pedantic-errors -Wall -Wextra #-Werror
2+
CXXFLAGS := -O2 -std=c++17 -pedantic-errors -Wall -Wextra #-Werror
33
LDFLAGS := -L/usr/lib -lstdc++ -lm -lz
44
BUILD := ./build
55
#do NOT blank this var
@@ -39,4 +39,4 @@ release: all
3939

4040
clean:
4141
-@rm -rv $(OBJ_DIR)/*
42-
-@rm -v $(APP_DIR)/$(TARGET)
42+
-@rm -v $(APP_DIR)/$(TARGET)

TileSAT.cbp

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,13 @@
6060
<Add option="-fexceptions" />
6161
</Compiler>
6262
<Unit filename="include/clausules.h" />
63-
<Unit filename="include/tile" />
6463
<Unit filename="include/tile.h" />
6564
<Unit filename="include/tileSAT.h" />
6665
<Unit filename="include/utils.h" />
6766
<Unit filename="src/clausules.cpp" />
6867
<Unit filename="src/main.cpp" />
6968
<Unit filename="src/tileSAT.cpp" />
69+
<Unit filename="src/utils.cpp" />
7070
<Extensions />
7171
</Project>
7272
</CodeBlocks_project_file>

include/tile

-1
This file was deleted.

include/tileSAT.h

+6-4
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
class TileSAT
88
{
99
public:
10-
TileSAT();
11-
void doTiles(const string &inputTilesFile, bool printSolution, bool checkSolution, bool drawTiles, bool solve=true, int ampladaOverride=-1, int alcadaOverride=-1);
10+
TileSAT(const string &);
11+
TileSAT(const string &, int, int);
12+
void doTiles(bool printSolution, bool drawTiles, bool solve=true);
1213

1314
private:
1415
void generarTiles();
@@ -31,10 +32,11 @@ class TileSAT
3132
return i;
3233
}
3334

35+
const string &inputTilesFile;
3436
int nTiles, nColors, amplada, alcada; //parametres de la instancia
35-
vector<Tile> inputTiles; //tiles d'entrada de la instancia
37+
vector<Tile> inputTiles; //tiles d'entrada de la instancia. Rang 0..nTiles
3638
Clausules clausules; //clausules en CNF generades que representen les restriccions de la instancia
37-
vector<vector<int>> tilesSolucio; //matriu solucio. Cada enter és un index d'una tile
39+
vector<vector<int>> tilesSolucio; //matriu solucio. Cada enter és un index d'una tile. Rang dels index: 1..=nTiles
3840

3941
};
4042

input/aperiodic

+14-14
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
13 5 105 105
2-
2 2 3 1
3-
2 3 2 1
4-
2 3 3 2
5-
1 1 2 2
6-
1 1 3 3
7-
1 2 2 3
8-
4 4 1 4
9-
3 4 2 4
10-
2 5 1 4
11-
2 5 4 4
12-
4 5 1 5
13-
3 5 2 5
14-
2 4 2 5
1+
13 5 40 40
2+
2 2 3 1
3+
2 3 2 1
4+
2 3 3 2
5+
1 1 2 2
6+
1 1 3 3
7+
1 2 2 3
8+
4 4 1 4
9+
3 4 2 4
10+
2 5 1 4
11+
2 5 4 4
12+
4 5 1 5
13+
3 5 2 5
14+
2 4 2 5

input/aperiodic11

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
11 4 20 20
1+
11 4 40 40
22
1 1 1 2
33
3 1 3 2
44
1 2 2 2

input/aritmetica

+36-36
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
1-
34 9 7 14
2-
7 1 1 1
3-
7 7 7 7
4-
7 7 8 4
5-
7 8 7 8
6-
7 8 8 3
7-
3 3 7 8
8-
3 3 8 3
9-
7 2 1 2
10-
4 7 4 7
11-
4 7 3 4
12-
4 8 4 8
13-
4 8 3 3
14-
8 3 4 5
15-
8 3 3 6
16-
8 1 2 1
17-
8 4 7 7
18-
8 4 8 4
19-
4 5 7 8
20-
4 5 8 3
21-
8 6 7 5
22-
8 6 8 6
23-
3 2 2 2
24-
3 4 4 7
25-
3 4 3 4
26-
7 5 4 5
27-
7 5 3 6
28-
3 6 4 5
29-
3 6 3 6
30-
1 9 9 9
31-
2 9 9 9
32-
9 9 9 7
33-
9 9 9 2
34-
9 9 9 8
35-
9 9 9 1
36-
9 9 9 9
1+
34 9 7 14
2+
7 1 1 1
3+
7 7 7 7
4+
7 7 8 4
5+
7 8 7 8
6+
7 8 8 3
7+
3 3 7 8
8+
3 3 8 3
9+
7 2 1 2
10+
4 7 4 7
11+
4 7 3 4
12+
4 8 4 8
13+
4 8 3 3
14+
8 3 4 5
15+
8 3 3 6
16+
8 1 2 1
17+
8 4 7 7
18+
8 4 8 4
19+
4 5 7 8
20+
4 5 8 3
21+
8 6 7 5
22+
8 6 8 6
23+
3 2 2 2
24+
3 4 4 7
25+
3 4 3 4
26+
7 5 4 5
27+
7 5 3 6
28+
3 6 4 5
29+
3 6 3 6
30+
1 9 9 9
31+
2 9 9 9
32+
9 9 9 7
33+
9 9 9 2
34+
9 9 9 8
35+
9 9 9 1
36+
9 9 9 9

input/problem.py

+34-34
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
1-
import sys
2-
from random import randint
3-
"""
4-
Genera tiles diferents de 4 colors, per intentar resoldre el problema de
5-
square tiling.
6-
"""
7-
8-
def rand_tile(colors):
9-
return [str(randint(1, colors)) for x in range(4)]
10-
11-
def main():
12-
if len(sys.argv) < 4:
13-
print("Falten arguments")
14-
return
15-
16-
num_tiles = int(sys.argv[1])
17-
num_colors = int(sys.argv[2])
18-
width = int(sys.argv[3])
19-
height = int(sys.argv[4])
20-
sys.stdout = open("input", "w")
21-
22-
print(num_tiles, num_colors, width, height)
23-
24-
tiles = []
25-
while len(tiles) != num_tiles:
26-
rtile = rand_tile(num_colors)
27-
if not rtile in tiles:
28-
tiles.append(rtile)
29-
30-
for tile in tiles:
31-
print(' '.join(tile))
32-
33-
if __name__ == "__main__":
34-
main()
1+
import sys
2+
from random import randint
3+
"""
4+
Genera tiles diferents de 4 colors, per intentar resoldre el problema de
5+
square tiling.
6+
"""
7+
8+
def rand_tile(colors):
9+
return [str(randint(1, colors)) for x in range(4)]
10+
11+
def main():
12+
if len(sys.argv) < 4:
13+
print("Falten arguments")
14+
return
15+
16+
num_tiles = int(sys.argv[1])
17+
num_colors = int(sys.argv[2])
18+
width = int(sys.argv[3])
19+
height = int(sys.argv[4])
20+
sys.stdout = open("input", "w")
21+
22+
print(num_tiles, num_colors, width, height)
23+
24+
tiles = []
25+
while len(tiles) != num_tiles:
26+
rtile = rand_tile(num_colors)
27+
if not rtile in tiles:
28+
tiles.append(rtile)
29+
30+
for tile in tiles:
31+
print(' '.join(tile))
32+
33+
if __name__ == "__main__":
34+
main()

src/main.cpp

+6-10
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ int main(int argc, char** argv)
88

99
bool parametresOk = true;
1010
bool printSolution = false;
11-
bool checkSolution = true;
1211
bool drawTiles = false;
1312
bool onlyTransform = false;
1413
bool solve = true;
@@ -17,8 +16,7 @@ int main(int argc, char** argv)
1716
cout<<"Usage: " << argv[0] << " [Options]... <TilesProblemFile>" <<endl;
1817
cout<<"Options:"<<endl;
1918
cout<<" -p print solution in console"<<endl;
20-
//cout<<" -c checkSolution (requires python and checkSolution.py)"<<endl;
21-
cout<<" -d drawTiles (requires python3 in PATH, drawTiles.py and it's deps.)"<<endl;
19+
cout<<" -d drawTiles (requires python3, drawTiles.py, tkinter and canvasvg)"<<endl;
2220
cout<<" -g don't solve, only generate cnf. Invalidates other options"<<endl;
2321
//cout<<" -t (special) transform minisat output to tiles solution. format: "<<argv[0]<<" -t <TilesProblemFile> <MiniSAT output>"<<endl;
2422
parametresOk = false;
@@ -30,8 +28,6 @@ int main(int argc, char** argv)
3028
string act = argv[i];
3129
if(act=="-d")
3230
drawTiles = true;
33-
else if(act=="-c")
34-
checkSolution = true;
3531
else if(act=="-p")
3632
printSolution = true;
3733
else if(act=="-g")
@@ -49,8 +45,8 @@ int main(int argc, char** argv)
4945
i++;
5046
}
5147
}
52-
53-
/*if(onlyTransform){ //todo: fix this
48+
/*
49+
if(onlyTransform){ //todo: fix this
5450
inputTilesFile = argv[2];
5551
string minisatFilename = argv[3];
5652
@@ -65,9 +61,9 @@ int main(int argc, char** argv)
6561

6662
if(parametresOk)
6763
try{
68-
TileSAT tileSAT;
69-
tileSAT.doTiles(inputTilesFile, printSolution, checkSolution, drawTiles, solve);
70-
}catch(const char* c){
64+
TileSAT tileSAT(inputTilesFile);
65+
tileSAT.doTiles(printSolution, drawTiles, solve);
66+
} catch(const char* c){
7167
cerr << c << endl;
7268
return 0x10;
7369
} catch(string s){

0 commit comments

Comments
 (0)