Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker build #20

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: Create docker images

on: push

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: jwg4/docker-python-poetry@v1a0
- name: Build the Docker image
run: docker build --tag exact_cover/debug:$(date +%s) .
2 changes: 1 addition & 1 deletion .github/workflows/python-validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ jobs:
- name: Lint with flake8
run: poetry run flake8
- name: Lint with black
run: poetry run black --check exact_cover/ tests/ build.py run_tests.py
run: poetry run black --check exact_cover/ tests/ tools/ build.py
- name: Check examples in README
run: poetry run doctest
13 changes: 13 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM etiennenapoleone/docker-python-poetry:3.7-rc

WORKDIR /tmp/working

COPY pyproject.toml .
COPY src .
COPY data/debug_data .
COPY tools/__init__.py .
COPY tools/debug.py .

RUN poetry install --no-dev

RUN poetry debug
19 changes: 9 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ CFLAGS += -O0 -DDEBUG_LEVEL=0
c_tests: note \
note_quad_linked_list run_test_quad_linked_list \
note_sparse_matrix run_test_sparse_matrix \
note_dlx run_test_dlx \
run_munit

tests: c_tests py_tests
Expand Down Expand Up @@ -104,15 +103,22 @@ run_test_m_sparse_matrix: $(TEST_DIR)/test_m_sparse_matrix
$(TEST_DIR)/test_m_dlx: $(OBJ_DIR)/quad_linked_list.o $(OBJ_DIR)/sparse_matrix.o $(OBJ_DIR)/dlx.o $(OBJ_DIR)/munit.o $(TEST_DIR)/test_m_dlx.c
$(CC) $(CFLAGS) $(DEBUG_CFLAGS) -o $@ $^

$(TEST_DIR)/test_debug_algo: $(OBJ_DIR)/quad_linked_list.o $(OBJ_DIR)/sparse_matrix.o $(OBJ_DIR)/dlx.o $(OBJ_DIR)/munit.o $(TEST_DIR)/test_debug_algo.c
$(CC) $(CFLAGS) $(DEBUG_CFLAGS) -o $@ $^

run_test_m_dlx: $(TEST_DIR)/test_m_dlx
$^

run_munit_test_dlx: $(TEST_DIR)/test_dlx
$^

run_test_debug_algo: $(TEST_DIR)/test_debug_algo
$^

run_munit: run_test_m_sparse_matrix \
run_test_m_dlx \
run_munit_test_dlx
run_munit_test_dlx \
run_test_debug_algo

#-----------------------------------------------------------------------------------------

Expand All @@ -126,17 +132,10 @@ $(OBJ_DIR)/sparse_matrix.o: $(SRC_DIR)/sparse_matrix.c
run_test_sparse_matrix: $(TEST_DIR)/test_sparse_matrix
$^

#-----------------------------------------------------------------------------------------

$(TEST_DIR)/test_dlx: $(OBJ_DIR)/quad_linked_list.o $(OBJ_DIR)/sparse_matrix.o $(OBJ_DIR)/dlx.o $(OBJ_DIR)/munit.o $(TEST_DIR)/test_dlx.c
$(CC) $(CFLAGS) $(DEBUG_CFLAGS) -o $@ $^

$(OBJ_DIR)/dlx.o: $(SRC_DIR)/dlx.c
mkdir -pv $(OBJ_DIR)
$(CC) $(CFLAGS) $(DEBUG_CFLAGS) -o $@ -c $^

run_test_dlx: $(TEST_DIR)/test_dlx
$^

#-----------------------------------------------------------------------------------------

exact_cover:
Expand Down
Binary file added data/debug_0003.tar.gz
Binary file not shown.
548 changes: 548 additions & 0 deletions data/debug_data

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "exact_cover"
version = "0.6.1"
version = "0.6.2-alpha.0"
description = "Solve exact cover problems"
readme = "README.md"
authors = ["Moy Easwaran"]
Expand Down Expand Up @@ -28,11 +28,12 @@ black = "^21.4b2"
script = "build.py"

[tool.poetry.scripts]
test = 'run_tests:test'
doctest = 'run_tests:run_doctest'
test = 'tools.run_tests:test'
doctest = 'tools.run_tests:run_doctest'
debug = 'tools.debug:run_debug'

[build-system]
requires = ["setuptools", "numpy>=1.19.4,<2.0", "poetry-core>=1.0.0"]
requires = ["setuptools>=51.1.2,<52.0", "numpy>=1.19.4,<2.0", "poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

[tool.black]
Expand Down
15 changes: 11 additions & 4 deletions src/dlx.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/


int search(list sparse_matrix, int k, int max, int *solution) {
int search(list sparse_matrix, int k, int max, int *solution, int is_debug) {
list col, row, next;
int result = 0;

Expand All @@ -27,12 +27,19 @@ int search(list sparse_matrix, int k, int max, int *solution) {
if (get_data(col)->data == 0) return 0;

// Main algorithm:
if (is_debug != 0){
for (int i = 0; i < k; i++){
printf("%d|", solution[i]);
}
}
printf("\n");

cover_column(col);
for (row = col; (row = get_down(row)) != col; ) {
solution[k] = get_data(row)->data; // save the row number
for (next = row; (next = get_right(next)) != row; )
cover_column(get_data(next)->list_data);
result = search(sparse_matrix, k+1, max, solution);
result = search(sparse_matrix, k+1, max, solution, is_debug);
// If result > 0 we're done, but we should still clean up.
for (next = row; (next = get_left(next)) != row; )
uncover_column(get_data(next)->list_data);
Expand All @@ -42,12 +49,12 @@ int search(list sparse_matrix, int k, int max, int *solution) {
return result;
}

int dlx_get_exact_cover(int rows, int cols, int matrix[], int *solution) {
int dlx_get_exact_cover(int rows, int cols, int matrix[], int *solution, int is_debug) {
list sparse_matrix;
int solution_length;

sparse_matrix = create_sparse(rows, cols, matrix);
solution_length = search(sparse_matrix, 0, rows, solution);
solution_length = search(sparse_matrix, 0, rows, solution, is_debug);
destroy_entire_grid(sparse_matrix);

while (rows > solution_length) {
Expand Down
4 changes: 2 additions & 2 deletions src/dlx.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#include "quad_linked_list.h"
#include "sparse_matrix.h"

int search(list, int, int, int *);
int dlx_get_exact_cover(int, int, int [], int*);
int search(list, int, int, int *, int);
int dlx_get_exact_cover(int, int, int [], int*, int);

#endif

6 changes: 3 additions & 3 deletions src/exact_cover.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ static PyObject* get_exact_cover(PyObject* self, PyObject* args)
PyArrayObject *in_array;
PyObject *out_array;
npy_intp *dims;
int *in_array_data, rows, cols, result;
int *in_array_data, rows, cols, result, is_debug;

/* Parse single numpy array argument */
if (!PyArg_ParseTuple(args, "O!", &PyArray_Type, &in_array)) return NULL;
if (!PyArg_ParseTuple(args, "O!|p", &PyArray_Type, &in_array, &is_debug)) return NULL;

/* Construct the output array, like the input array */
out_array = PyArray_NewLikeArray(in_array, NPY_ANYORDER, NULL, 0);
Expand All @@ -54,7 +54,7 @@ static PyObject* get_exact_cover(PyObject* self, PyObject* args)

/* Calculate the exact cover. */
int nd = 1, *solution = malloc(rows * sizeof(*solution));
result = dlx_get_exact_cover(rows, cols, in_array_data, solution);
result = dlx_get_exact_cover(rows, cols, in_array_data, solution, is_debug);

dims = malloc(nd * sizeof(*dims));
dims[0] = result;
Expand Down
1 change: 1 addition & 0 deletions tests/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ test_quad_linked_list
test_sparse_matrix
test_m_dlx
test_m_sparse_matrix
test_debug_algo
Loading