Commit 09c5fb2e authored by Michael Keller's avatar Michael Keller
Browse files

thesis NP stuff

parent 19e919fd
No preview for this file type
......@@ -42,39 +42,39 @@ int main()
// {1, 1, 0, 0, 1, 0, 0, 0, 1, 0}};
// int distances[] = {23, 23, 23, 23, 23, 22, 22, 22, 22, 22};
char *name = "Agropol Data";
int x = 5;
int y = 2;
int crops = 10;
double R[10][10] = {
{-1, 0, 0.5, -0.5, 1, 0, 0.5, 1, 0.5, 0},
{0, -1, 0, 1, 0, 0, 0.5, 0.5, 0.5, 0},
{0.5, 0, -1, 0, 0, 0, 0.5, 0.5, 0, -0.5},
{-0.5, 1, 0, -1, 0, 0, -1, 0.5, 0.5, 0.5},
{0, 0, 0, 0, -1, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, -1, 1, 0.5, 0, 0},
{0.5, 0.5, 0.5, -0.5, 0, 0.5, -1, 0.5, 0.5, 0.5},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0.5, 0.5, 0, 1, 0, 0, 0.5, 0.5, -1, 0},
{0, 0, -0.5, 0.5, 0, 0, 1, 0.5, 0.5, -1}};
int distances[] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
// char *name = "Arnold (CAUTION, MATRIX DIFFERENT)";
// int x = 15;
// int y = 15;
// char *name = "Agropol Data";
// int x = 5;
// int y = 2;
// int crops = 10;
// double R[10][10] = {
// {-1, 0, 0.5, -0.5, 0, 1, 0.5, 1, 0, 0.5},
// {0, -1, 0, 1, 0, 0, 0.5, 0.5, 0, 0.5},
// {0.5, 0, -1, 0, 0, 0, 0.5, 0.5, -0.5, 0},
// {-1, 0, 0.5, -0.5, 1, 0, 0.5, 1, 0.5, 0},
// {0, -1, 0, 1, 0, 0, 0.5, 0.5, 0.5, 0},
// {0.5, 0, -1, 0, 0, 0, 0.5, 0.5, 0, -0.5},
// {-0.5, 1, 0, -1, 0, 0, -1, 0.5, 0.5, 0.5},
// {0, 0, 0, 0, -1, 0, 1, 0.5, 0, 0},
// {0, 0, 0, 0, 0, -1, 0, 0, 0, 0},
// {0.5, 0.5, 0.5, -0.5, 0.5, 0, -1, 0.5, 0.5, 0.5},
// {0, 0, 0, 0, -1, 0, 0, 0, 0, 0},
// {0, 0, 0, 0, 0, -1, 1, 0.5, 0, 0},
// {0.5, 0.5, 0.5, -0.5, 0, 0.5, -1, 0.5, 0.5, 0.5},
// {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
// {0, 0, -0.5, 0.5, 0, 0, 1, 0.5, -1, 0.5},
// {0.5, 0.5, 0, 1, 0, 0, 0.5, 0.5, 0, -1}};
// int distances[] = {23, 23, 23, 23, 23, 22, 22, 22, 22, 22};
// {0.5, 0.5, 0, 1, 0, 0, 0.5, 0.5, -1, 0},
// {0, 0, -0.5, 0.5, 0, 0, 1, 0.5, 0.5, -1}};
// int distances[] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
char *name = "Arnold (CAUTION, MATRIX DIFFERENT)";
int x = 15;
int y = 15;
int crops = 10;
double R[10][10] = {
{-1, 0, 0.5, -0.5, 0, 1, 0.5, 1, 0, 0.5},
{0, -1, 0, 1, 0, 0, 0.5, 0.5, 0, 0.5},
{0.5, 0, -1, 0, 0, 0, 0.5, 0.5, -0.5, 0},
{-0.5, 1, 0, -1, 0, 0, -1, 0.5, 0.5, 0.5},
{0, 0, 0, 0, -1, 0, 1, 0.5, 0, 0},
{0, 0, 0, 0, 0, -1, 0, 0, 0, 0},
{0.5, 0.5, 0.5, -0.5, 0.5, 0, -1, 0.5, 0.5, 0.5},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, -0.5, 0.5, 0, 0, 1, 0.5, -1, 0.5},
{0.5, 0.5, 0, 1, 0, 0, 0.5, 0.5, 0, -1}};
int distances[] = {23, 23, 23, 23, 23, 22, 22, 22, 22, 22};
// make the datatypes work
double *r = (double *)malloc(sizeof(double) * crops * crops);
......@@ -109,8 +109,248 @@ int main()
// printf("regular maxscore is: %lf\n", maxScore(x, y));
printf("Started Solving...\n");
int *sol = solve(x, y, r, dist, crops);
// int* sol = malloc(sizeof(int) * x * y);
// int *sol = solve(x, y, r, dist, crops);
int* sol = malloc(sizeof(int) * x * y);
sol[0 * y + 0] = 5;
sol[0 * y + 1] = 4;
sol[0 * y + 2] = 5;
sol[0 * y + 3] = 4;
sol[0 * y + 4] = 5;
sol[0 * y + 5] = 4;
sol[0 * y + 6] = 5;
sol[0 * y + 7] = 4;
sol[0 * y + 8] = 5;
sol[0 * y + 9] = 4;
sol[0 * y + 10] = 5;
sol[0 * y + 11] = 4;
sol[0 * y + 12] = 5;
sol[0 * y + 13] = 4;
sol[0 * y + 14] = 5;
sol[1 * y + 0] = 6;
sol[1 * y + 1] = 0;
sol[1 * y + 2] = 6;
sol[1 * y + 3] = 0;
sol[1 * y + 4] = 6;
sol[1 * y + 5] = 0;
sol[1 * y + 6] = 6;
sol[1 * y + 7] = 0;
sol[1 * y + 8] = 6;
sol[1 * y + 9] = 0;
sol[1 * y + 10] = 6;
sol[1 * y + 11] = 0;
sol[1 * y + 12] = 6;
sol[1 * y + 13] = 0;
sol[1 * y + 14] = 7;
sol[2 * y + 0] = 2;
sol[2 * y + 1] = 4;
sol[2 * y + 2] = 2;
sol[2 * y + 3] = 4;
sol[2 * y + 4] = 2;
sol[2 * y + 5] = 4;
sol[2 * y + 6] = 2;
sol[2 * y + 7] = 4;
sol[2 * y + 8] = 2;
sol[2 * y + 9] = 4;
sol[2 * y + 10] = 2;
sol[2 * y + 11] = 4;
sol[2 * y + 12] = 2;
sol[2 * y + 13] = 4;
sol[2 * y + 14] = 5;
sol[3 * y + 0] = 6;
sol[3 * y + 1] = 0;
sol[3 * y + 2] = 6;
sol[3 * y + 3] = 0;
sol[3 * y + 4] = 6;
sol[3 * y + 5] = 0;
sol[3 * y + 6] = 6;
sol[3 * y + 7] = 0;
sol[3 * y + 8] = 6;
sol[3 * y + 9] = 0;
sol[3 * y + 10] = 6;
sol[3 * y + 11] = 0;
sol[3 * y + 12] = 6;
sol[3 * y + 13] = 0;
sol[3 * y + 14] = 7;
sol[4 * y + 0] = 2;
sol[4 * y + 1] = 4;
sol[4 * y + 2] = 2;
sol[4 * y + 3] = 4;
sol[4 * y + 4] = 2;
sol[4 * y + 5] = 4;
sol[4 * y + 6] = 2;
sol[4 * y + 7] = 4;
sol[4 * y + 8] = 2;
sol[4 * y + 9] = 4;
sol[4 * y + 10] = 2;
sol[4 * y + 11] = 4;
sol[4 * y + 12] = 2;
sol[4 * y + 13] = 4;
sol[4 * y + 14] = 5;
sol[5 * y + 0] = 6;
sol[5 * y + 1] = 7;
sol[5 * y + 2] = 6;
sol[5 * y + 3] = 7;
sol[5 * y + 4] = 6;
sol[5 * y + 5] = 7;
sol[5 * y + 6] = 6;
sol[5 * y + 7] = 7;
sol[5 * y + 8] = 6;
sol[5 * y + 9] = 7;
sol[5 * y + 10] = 6;
sol[5 * y + 11] = 0;
sol[5 * y + 12] = 6;
sol[5 * y + 13] = 0;
sol[5 * y + 14] = 7;
sol[6 * y + 0] = 4;
sol[6 * y + 1] = 8;
sol[6 * y + 2] = 1;
sol[6 * y + 3] = 8;
sol[6 * y + 4] = 1;
sol[6 * y + 5] = 8;
sol[6 * y + 6] = 1;
sol[6 * y + 7] = 8;
sol[6 * y + 8] = 1;
sol[6 * y + 9] = 8;
sol[6 * y + 10] = 9;
sol[6 * y + 11] = 2;
sol[6 * y + 12] = 5;
sol[6 * y + 13] = 2;
sol[6 * y + 14] = 5;
sol[7 * y + 0] = 7;
sol[7 * y + 1] = 3;
sol[7 * y + 2] = 9;
sol[7 * y + 3] = 3;
sol[7 * y + 4] = 9;
sol[7 * y + 5] = 3;
sol[7 * y + 6] = 9;
sol[7 * y + 7] = 3;
sol[7 * y + 8] = 9;
sol[7 * y + 9] = 3;
sol[7 * y + 10] = 7;
sol[7 * y + 11] = 0;
sol[7 * y + 12] = 7;
sol[7 * y + 13] = 0;
sol[7 * y + 14] = 7;
sol[8 * y + 0] = 2;
sol[8 * y + 1] = 8;
sol[8 * y + 2] = 2;
sol[8 * y + 3] = 8;
sol[8 * y + 4] = 2;
sol[8 * y + 5] = 8;
sol[8 * y + 6] = 2;
sol[8 * y + 7] = 8;
sol[8 * y + 8] = 2;
sol[8 * y + 9] = 8;
sol[8 * y + 10] = 9;
sol[8 * y + 11] = 2;
sol[8 * y + 12] = 5;
sol[8 * y + 13] = 2;
sol[8 * y + 14] = 5;
sol[9 * y + 0] = 9;
sol[9 * y + 1] = 3;
sol[9 * y + 2] = 9;
sol[9 * y + 3] = 3;
sol[9 * y + 4] = 9;
sol[9 * y + 5] = 3;
sol[9 * y + 6] = 9;
sol[9 * y + 7] = 3;
sol[9 * y + 8] = 9;
sol[9 * y + 9] = 3;
sol[9 * y + 10] = 7;
sol[9 * y + 11] = 0;
sol[9 * y + 12] = 7;
sol[9 * y + 13] = 0;
sol[9 * y + 14] = 7;
sol[10 * y + 0] = 1;
sol[10 * y + 1] = 8;
sol[10 * y + 2] = 1;
sol[10 * y + 3] = 8;
sol[10 * y + 4] = 1;
sol[10 * y + 5] = 8;
sol[10 * y + 6] = 1;
sol[10 * y + 7] = 8;
sol[10 * y + 8] = 1;
sol[10 * y + 9] = 8;
sol[10 * y + 10] = 9;
sol[10 * y + 11] = 2;
sol[10 * y + 12] = 5;
sol[10 * y + 13] = 2;
sol[10 * y + 14] = 5;
sol[11 * y + 0] = 9;
sol[11 * y + 1] = 3;
sol[11 * y + 2] = 9;
sol[11 * y + 3] = 3;
sol[11 * y + 4] = 9;
sol[11 * y + 5] = 3;
sol[11 * y + 6] = 9;
sol[11 * y + 7] = 3;
sol[11 * y + 8] = 9;
sol[11 * y + 9] = 3;
sol[11 * y + 10] = 7;
sol[11 * y + 11] = 0;
sol[11 * y + 12] = 7;
sol[11 * y + 13] = 0;
sol[11 * y + 14] = 7;
sol[12 * y + 0] = 1;
sol[12 * y + 1] = 8;
sol[12 * y + 2] = 1;
sol[12 * y + 3] = 8;
sol[12 * y + 4] = 1;
sol[12 * y + 5] = 8;
sol[12 * y + 6] = 1;
sol[12 * y + 7] = 8;
sol[12 * y + 8] = 1;
sol[12 * y + 9] = 8;
sol[12 * y + 10] = 9;
sol[12 * y + 11] = 2;
sol[12 * y + 12] = 5;
sol[12 * y + 13] = 2;
sol[12 * y + 14] = 5;
sol[13 * y + 0] = 7;
sol[13 * y + 1] = 3;
sol[13 * y + 2] = 9;
sol[13 * y + 3] = 3;
sol[13 * y + 4] = 9;
sol[13 * y + 5] = 3;
sol[13 * y + 6] = 9;
sol[13 * y + 7] = 3;
sol[13 * y + 8] = 9;
sol[13 * y + 9] = 3;
sol[13 * y + 10] = 7;
sol[13 * y + 11] = 0;
sol[13 * y + 12] = 6;
sol[13 * y + 13] = 0;
sol[13 * y + 14] = 7;
sol[14 * y + 0] = 5;
sol[14 * y + 1] = 8;
sol[14 * y + 2] = 1;
sol[14 * y + 3] = 3;
sol[14 * y + 4] = 1;
sol[14 * y + 5] = 3;
sol[14 * y + 6] = 1;
sol[14 * y + 7] = 3;
sol[14 * y + 8] = 1;
sol[14 * y + 9] = 8;
sol[14 * y + 10] = 5;
sol[14 * y + 11] = 4;
sol[14 * y + 12] = 5;
sol[14 * y + 13] = 2;
sol[14 * y + 14] = 5;
printf("Solution for %s:\n", name);
......
......@@ -14,30 +14,6 @@ sol[0 * y + 12] = 5;
sol[0 * y + 13] = 4;
sol[0 * y + 14] = 5;
sol[1 * y + 0] = 6;
sol[1 * y + 1] = 0;
sol[1 * y + 2] = 6;
sol[1 * y + 3] = 0;
sol[1 * y + 4] = 6;
sol[1 * y + 5] = 0;
sol[1 * y + 6] = 6;
sol[1 * y + 7] = 0;
sol[1 * y + 8] = 6;sol[0 * y + 0] = 5;
sol[0 * y + 1] = 4;
sol[0 * y + 2] = 5;
sol[0 * y + 3] = 4;
sol[0 * y + 4] = 5;
sol[0 * y + 5] = 4;
sol[0 * y + 6] = 5;
sol[0 * y + 7] = 4;
sol[0 * y + 8] = 5;
sol[0 * y + 9] = 4;
sol[0 * y + 10] = 5;
sol[0 * y + 11] = 4;
sol[0 * y + 12] = 5;
sol[0 * y + 13] = 4;
sol[0 * y + 14] = 5;
sol[1 * y + 0] = 6;
sol[1 * y + 1] = 0;
sol[1 * y + 2] = 6;
......@@ -261,6 +237,55 @@ sol[14 * y + 11] = 4;
sol[14 * y + 12] = 5;
sol[14 * y + 13] = 2;
sol[14 * y + 14] = 5;
sol[0 * y + 0] = 5;
sol[0 * y + 1] = 4;
sol[0 * y + 2] = 5;
sol[0 * y + 3] = 4;
sol[0 * y + 4] = 5;
sol[0 * y + 5] = 4;
sol[0 * y + 6] = 5;
sol[0 * y + 7] = 4;
sol[0 * y + 8] = 5;
sol[0 * y + 9] = 4;
sol[0 * y + 10] = 5;
sol[0 * y + 11] = 4;
sol[0 * y + 12] = 5;
sol[0 * y + 13] = 4;
sol[0 * y + 14] = 5;
sol[1 * y + 0] = 6;
sol[1 * y + 1] = 0;
sol[1 * y + 2] = 6;
sol[1 * y + 3] = 0;
sol[1 * y + 4] = 6;
sol[1 * y + 5] = 0;
sol[1 * y + 6] = 6;
sol[1 * y + 7] = 0;
sol[1 * y + 8] = 6;
sol[1 * y + 9] = 0;
sol[1 * y + 10] = 6;
sol[1 * y + 11] = 0;
......
This diff is collapsed.
This diff is collapsed.
......@@ -8,7 +8,7 @@ a decision problem. In a second step we will
show that the problem is in NP. Lastly we will
prove that pixel farming can be used to find
hamiltonian paths, which will imply that finding
perfect solutions for pixel farming is NP complete.
solutions for pixel farming is NP complete.
\section{The decision version of pixel farming}
......@@ -35,8 +35,9 @@ theorem:
\begin{proof}
Assume we are given a field $F$ and a relation
function $R$. By computing $S(F, R)$, which
First we non-deterministically select
a field $F$ for a given relation
function $R$. By computing the score $S(F, R)$, which
can be done in Polynomial time in relation to the field
size $X \cdot Y$, we can easily test is the score
is at least a certain value. Further, testing whether
......@@ -56,19 +57,19 @@ farming is NP complete.
\paragraph{Hamiltonian Paths}
Let $G = (V, E)$ be an undirected graph. We formulate the
decision version of the hamiltonian path problem as follows:
Does there exists a path in $G$ of length at least $l$
where every vertex in the path is visited only once?
Does there exist a path that visits every vertex
in the graph exactly once?
\paragraph{Reduction} We assume we are given a graph $G$,
a length $l$ and a polynomial time algorithm in $X \cdot Y$
\paragraph{Reduction} We assume we are given an undirected
graph $G$ and a polynomial time algorithm in $X \cdot Y$
and $C$ for the pixel farming decision problem. We are asked
to solve the hamiltonian path decision problem in polynomial
time in relation to the size of $G$.
Let us first look at a simple case, when $l = \abs{V}$.
The core idea is that we translate vertices to crops and
edges to crops liking each other. Then, a pixel farming
decision problem with a score that means every pixel
decision problem on a $1 \times \abs{V}$ field
with a score that means every pixel
likes both of its neighbors must imply that there exists
a hamiltonian path in the graph $G$. Formally we build
the following pixel farming decision problem:
......@@ -81,6 +82,7 @@ the following pixel farming decision problem:
s &= 2 \cdot (\abs{V} - 1) && D(c) = \frac{1}{\abs{V}} \quad \forall c \in \Cps
\end{align*}
The following example illustrates this:
\FloatBarrier
\begin{figure}[h]
\centering
\begin{minipage}{0.45\textwidth}
......@@ -110,32 +112,32 @@ The following example illustrates this:
\end{minipage}
\end{figure}
\FloatBarrier
What about the case where $l < \abs{V}$? For this
we need to resort to a trick. Say for example we are
looking for a path of length at least $\abs{V} - 2$.
We can't simply change $s$ to be $4$ less than before,
because we have no guarantees as to where these ``cuts''
will be. We could end up in a situation where our
pixel farming algorithm gives us 3 paths that are all
not of sufficient length.
\begin{figure}[h]
\centering
\begin{tikzpicture}[node distance={0.5cm}, main/.style = {draw, minimum size=0.5cm}]
\node[main] (1) {};
\node[main] (13) [below of =1] {};
\foreach \x in {2,...,12}
{
\pgfmathtruncatemacro{\prev}{\x - 1}
\pgfmathtruncatemacro{\below}{\x + 11}
\node[main] (\x) [right of=\prev] {};
\node[main] (\below) [below of=\x] {};
}
\node[main] (26) [below of=20] {};
\node[main] (27) [below of=22] {};
\end{tikzpicture}
\hfill
\caption{example structure}
\end{figure}
\FloatBarrier
Now we pass the Pixel Farming problem formulated above to our algorithm
that solves pixel farming problems in polynomial time.
If we get the answer that no solution
with value at least $s$ exists we return that no longest path of
length $\abs{V} - 1$ exists. If on the other hand a solution
of at least $s$ exists, we return that a hamiltonian path
must exist in $G$.
The rationale for this is as follows. Let us assume
a solution of value at least $s$ exists. This would
imply that every pixel likes all of their neighbors.
As "crop $a$ likes crop $b$" is the same function as
"vertex $a$ is connected to vertex $b$" and we have
a value for our arrangement of $2 \cdot (\abs{V} - 1)$, we must have
found $n-1$ edges that connect our $\abs{V}$ vertices. Because we also
know that every crop can only appear once in our field and all crops
have two neighbors (except the ends) we must have found a
path of length $\abs{V} - 1$.
If on the other hand no arrangement of value at least $s$
exists, there must be at least one index $i$ for all fields $F$
where $R(F_{1, i}, F_{1, i+1}) = 0$. What this translates
to for our longest path problem is that every order
of vertices has an index $i$ where $\{v_i, v_{i+1}\} \not \in E$,
hence no path of length $\abs{V} - 1$ can exist.
As we now know that pixel farming is in NP and NP-hard,
we can conclude that pixel farming must be NP-complete.
\end{proof}
\ No newline at end of file
No preview for this file type
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment