### Mom Notes

parent 586d52a2
 ... ... @@ -116,7 +116,7 @@ results in an upper bound of $1624$. \section{LP bound} We can also use the solution to the following Linear Program as a bound. following linear program as a bound. The variables are all of the possible crop pairings: \begin{align*} ... ... @@ -151,7 +151,7 @@ total relationships between pixels: \begin{align*} \sum_{x_i \in x} 2 \cdot x_i = \text{Basic Bound} \end{align*} as well as that we don't plant too much of a as well as that we do not plant too much of a specific crop. Here we simply enforce an upper bound on the number of possible connections a crop could have: \begin{align*} ... ... @@ -161,9 +161,9 @@ on the number of possible connections a crop could have: As an optimal solution for a pixel farming problem meets these constraints, this is a valid bound. It should be noted that this bound does not enforce any constraints on the shape of the field, or indeed that this score on the shape of the field or that this score is achievable with only one field (and not multiple disjoint fields). The bound for the first benchmark problem is $950$, for The bound for the first benchmark problem is $950$ and for the second benchmark problem $1624$. \ No newline at end of file
 \chapter{Computational Difficulty} We show that the problem of finding a We prove that the problem of finding a solution of a certain quality to a pixel farming problem is NP complete. To do this we will first formulate the problem as 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 Hamiltonian Paths, which will imply that finding solutions for pixel farming is NP complete. \section{The decision version of pixel farming} The decision version of the pixel farming problem we define very similarly to the We define the decision version of the pixel farming problem very similarly to the regular version. However, instead of asking for a field with the maximum score, we ask for a field with a score at least $s$. Formally: for a field with a score of at least $s$. Formally: Does a field $F$ for relation function $R$ exist such that the score $S(F, R)$ is at least $s$: \begin{displaymath} s \leq S(F, R) \end{displaymath} \section{Pixel Farming is NP complete} \section{Pixel Farming is NP Complete} Now that we have defined the decision version of the problem, we formulate and prove the following ... ... @@ -35,11 +35,11 @@ theorem: \begin{proof} First we non-deterministically select 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 can be done in polynomial time in relation to the field size $X \cdot Y$, we can easily test wether the score is at least a certain value. Further, testing whether our field $F$ meets the requirements specified by $D$, our probability distribution specifying how much of ... ... @@ -51,15 +51,15 @@ size $X \cdot Y$ and number of crops $C$. It is known that finding Hamiltonian Paths is NP complete \cite[Page 199, GT39]{alma990005774300205503}. Thus, reducing the decision version of hamiltonian paths (explained below) to the decision of Hamiltonian Paths (explained below) to the decision version of pixel farming demonstrates that pixel 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 exist a path that visits every vertex in the graph exactly once? decision version of the Hamiltonian Path problem as follows: Does a path that visits every vertex in the graph exactly once exist? \paragraph{Reduction} We assume we are given an undirected graph $G$ and a polynomial time algorithm in $X \cdot Y$ ... ... @@ -119,12 +119,12 @@ of crops $C$. Now we pass the pixel farming problem formulated above to our algorithm that solves the decision version of the pixel farming problem. 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 with value at least $s$ exists, we conclude that no longest path of length $\abs{V} - 1$ exists. If, on the other hand, a solution of at least $s$ exists, we know that a hamiltonian path must exist in $G$. The rationale for this is as follows. Let us assume 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 ... ... @@ -134,7 +134,7 @@ 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$ 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 ... ... @@ -143,103 +143,103 @@ 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. \section{Fractional Pixel Farming is NP Complete} We consider the slightly modified version of the standard pixel farming decision problem. Instead of allowing a pixel to only contain a single crop, a pixel may now contain multiple crops, as explained in the problem definition section. One might suspect that such a relaxation might enable us to formulate a convex optimization problem. We show however that this relaxation is also NP complete. We define the decision version of fractional pixel farming analogously to the standard version: Does a field $F'$ for a relation function $R$ exist such that the score $S(F', R)$ is at least $s$: \begin{align*} s \leq S(F', R) \end{align*} \begin{theorem} The fractional pixel farming problem (decision version) is NP complete. \end{theorem} \begin{proof} The problem is obviously in NP, as we can non-deterministically choose a field $F'$ for a given score function $R$ and calculate the score in polynomial time in relation to the size of the field and number of crops. In a next step we verify that the solution meets the requirement for crop distribution given to us. This can also be done in polynomial time relational to field size and number of crop types. Finally we test if the score $S(F', R)$ is at least $s$. For the proof of NP Hardness we again reduce to the hamiltonian paths problem as in the proof that regular pixel farming is NP complete. For this purpose we define the constructed pixel farming problem for a given graph $G = (V, E)$ as follows: \begin{align*} X &= \abs{V} && Y = 1\\ \Cps &= V && R(a, b) = \begin{cases} 1 & \{a, b\} \in E\\ 0 & otherwise. \end{cases}\\ s &= 2 \cdot (\abs{V} - 1) && D(c) = \frac{1}{\abs{V}} \quad \forall c \in \Cps\\ F' &\in R_+^{C \times X \times Y} \end{align*} We show that the following implications hold: \begin{enumerate} \item There exists no optimal fractional solution to the constructed pixel farming problem $\implies$ There exists no Hamiltonian path in $G$ \item There exists an optimal fractional solution to the constructed pixel farming problem $\implies$ There exists a Hamiltonian path in $G$ \end{enumerate} \end{proof} The first implication is obviously true. We prove this indirectly, that is we show that: There exists a hamiltonian path in $G$'' $\implies$ There exists an optimal fractional solution to the constructed pixel farming problem''. This statement is a direct consequence of the NP completeness proof for the standard pixel farming problem. If a Hamiltonian path exists, then an optimal solution for the standard pixel farming problem instance exists. As this standard solution can also be viewed as an optimal fractional solution ($1$'s and $0$'s are fractions too) we are done. The second implication we prove by directly. We assume that there exists an optimal solution to the constructed pixel farming problem for a Graph $G$. An optimal solution in our case means that every crop likes all of the crops in its neighborhood, otherwise the solution would not obtain the maximal possible score $s$. Further there must also exist a sequence of crops such that: \FloatBarrier \begin{enumerate} \item The sequence only contains each crop exactly once \item Every pixel along the proposed sequence of crops contains some of the proposed crop \end{enumerate} \FloatBarrier If these two facts did not hold, then there must exist a crop within our valid solution that is contained less than once, which would mean our solution is invalid. TODO: MAKE MORE FORMAL As a sequence of all crops where every crop likes its neighbors corresponds to $G$ containing a hamiltonian path, we know our statement must be true. \end{proof} \ No newline at end of file % \section{Fractional Pixel Farming is NP Complete} % We consider the slightly modified version of the % standard pixel farming decision problem. Instead of allowing % a pixel to only contain a single crop, % a pixel may now contain multiple crops, as explained % in the problem definition section. One might suspect that % such a relaxation might enable us to formulate a % convex optimization problem. We show however that % this relaxation is also NP complete. % We define the decision version of fractional pixel farming % analogously to the standard version: Does a field $F'$ % for a relation function $R$ exist such that the score % $S(F', R)$ is at least $s$: % \begin{align*} % s \leq S(F', R) % \end{align*} % \begin{theorem} % The fractional pixel farming problem (decision version) is NP complete. % \end{theorem} % \begin{proof} % The problem is obviously in NP, as we can non-deterministically % choose a field $F'$ for a given score function % $R$ and calculate the % score in polynomial time in relation to the size of the % field and number of crops. In a next step we verify % that the solution meets the requirement for crop % distribution given to us. This can also be done in % polynomial time relative to field size and number % of crop types. Finally, we test if the score $S(F', R)$ % is at least $s$. % For the proof of NP Hardness we again reduce to the % Hamiltonian Paths problem as in the proof that % regular pixel farming is NP complete. For this % purpose we define the constructed pixel farming % problem for a given graph $G = (V, E)$ as follows: % \begin{align*} % X &= \abs{V} && Y = 1\\ % \Cps &= V && R(a, b) = \begin{cases} % 1 & \{a, b\} \in E\\ % 0 & otherwise. % \end{cases}\\ % s &= 2 \cdot (\abs{V} - 1) && D(c) = \frac{1}{\abs{V}} \quad \forall c \in \Cps\\ % F' &\in R_+^{C \times X \times Y} % \end{align*} % We show that % the following implications hold: % \begin{enumerate} % \item There exists no optimal fractional solution to % the constructed pixel farming problem $\implies$ % There exists no Hamiltonian path in $G$ % \item There exists an optimal fractional % solution to the constructed pixel farming problem % $\implies$ There exists a Hamiltonian path in $G$ % \end{enumerate} % % The first implication is obviously true. We prove this indirectly, % that is we show that: There exists a hamiltonian path in $G$'' % $\implies$ There exists an optimal fractional solution to the % constructed pixel farming problem''. This statement is a % direct consequence of the NP completeness proof for the standard % pixel farming problem. If a Hamiltonian path exists, then % an optimal solution for the standard pixel farming problem % instance exists. As this standard solution can also be % viewed as an optimal fractional solution ($1$'s and $0$'s % are fractions too) we are done. % The second implication we prove by directly. % We assume that there exists an optimal solution to the % constructed pixel farming problem for a % Graph $G$. An optimal % solution in our case means that every crop likes % all of the crops in its neighborhood, otherwise % the solution would not obtain the maximal % possible score $s$. Further there must also % exist a sequence of crops such that: % \FloatBarrier % \begin{enumerate} % \item The sequence only contains each crop exactly once % \item Every pixel along the proposed sequence of crops contains some of the proposed crop % \end{enumerate} % \FloatBarrier % If these two facts did not hold, then there must % exist a crop within our valid solution that is contained % less than once, which would mean our solution is invalid. % TODO: MAKE MORE FORMAL % As a sequence of all crops where every crop % likes its neighbors corresponds to $G$ % containing a hamiltonian path, we know % our statement must be true. % \end{proof} \ No newline at end of file
 ... ... @@ -179,7 +179,7 @@ on large fields and requires no conditions of $R$. \begin{proof} The key insight for this statement is that the score function changes linearly when swapping crops between non-neighboring pixels. Picture crops between non-neighboring pixels. Imagine two non-neighboring pixels that both contain the crops $c_1$ and $c_2$: \FloatBarrier ... ... @@ -191,7 +191,7 @@ on large fields and requires no conditions of $R$. \node[main node] (2) [right of=1] {V}; \path[every node/.style={font=\sffamily\small}] (1) edge[bend left] node [above] {$\lambda \cdot c_1$} (2); (1) edge[bend left] node [above] {$\lambda \cdot c_1$} (2) (2) edge[bend left] node [below] {$\lambda \cdot c_2$} (1); \end{tikzpicture} \end{figure} ... ... @@ -207,8 +207,9 @@ on large fields and requires no conditions of $R$. swap like this, we eliminate at least one crop from at least one fractional pixel. Next we argue that for this result it is not necessary to swap between neighboring pixels. Consider the field Next we argue that it is not necessary to swap between neighboring pixels for this result. Consider the field below. If we only swap between pixels that have the same color, then we never have to swap between neighboring pixels. It is always possible to color ... ... @@ -228,10 +229,9 @@ on large fields and requires no conditions of $R$. \end{figure} \FloatBarrier Further we argue that iterating this method terminates. While there exist pixels of the same color that both contain the same two crops, we perform the swap as outlined above. Eventually, Further, we argue that iterating this method terminates. While pixels of the same color that both contain the same two crops exist, we perform the swap as outlined above. Eventually, because we get rid of at least one fractional crop every time we swap, we must reach a state for a pixel color where no two pixels contain two of the same crop. Because ... ... @@ -242,7 +242,7 @@ on large fields and requires no conditions of $R$. means in the worst case there are up to $\binom{C}{2}$ pixels that each contain two crops. All other pixels must now contain exactly one unit of one crop. Because there are four colors among which we swap, this means there are four colors among which we swap, in the worst case we end up with $4 \cdot \binom{C}{2}$ pixels that are still fractional. \end{proof} ... ... @@ -253,7 +253,7 @@ on large fields and requires no conditions of $R$. There might be situations where up to $4 \cdot \binom{C}{2}$ still fractional pixels are unacceptable. This might be the case in relatively small fields with relatively large amounts of different crops. Here the following slightly stronger of different crops. Here the following, slightly stronger, statement with a condition on $R$ might be helpful: \begin{theorem} ... ... @@ -272,7 +272,7 @@ statement with a condition on $R$ might be helpful: that we allow swapping of crops between neighboring pixels. We now need to know what condition needs to be We now need to know what condition must be met to ensure that swapping in either direction even among neighboring pixels is never detrimental. ... ... @@ -327,12 +327,12 @@ statement with a condition on $R$ might be helpful: \sum_{c_j \in \Cps \setminus \{c_\alpha, c_\beta \}} R(c_i, c_j) \cdot (u'_i \cdot v'_{j} - u_i \cdot v_{j})\\ \end{align*} We can now use that: We can now utilize that: \begin{align*} u'_\alpha &= u_\alpha - \lambda & v'_\alpha &= v_\alpha + \lambda\\ u'_\beta &= u_\beta + \lambda & v'_\beta &= v_\beta - \lambda\\ \end{align*} Which gives us: which gives us: \begin{align*} &\sum_{c_i \in \Cps} \sum_{c_j \in \Cps} R(c_i, c_j) \cdot (u'_i \cdot v'_{j} - u_i \cdot v_{j})\\ &= \sum_{c_i \in \{c_\alpha, c_\beta \}} ... ... @@ -348,7 +348,7 @@ statement with a condition on $R$ might be helpful: \sum_{c_j \in \Cps \setminus \{c_\alpha, c_\beta \}} R(c_i, c_j) \cdot (u_i \cdot v_{j} - u_i \cdot v_{j}) \end{align*} Where the last term is simply $0$ and the second where the last term is simply $0$ and the second and third terms are linear functions in $\lambda$. We again focus only on the quadratic term: \begin{align*} ... ... @@ -374,7 +374,7 @@ statement with a condition on $R$ might be helpful: &+ \lambda \cdot (R(c_\beta, c_\beta) - R(c_\alpha, c_\beta)) \cdot v_\beta \end{align*} Of special note here is the quadratic term. If every crop likes all other crops If every crop likes all the other crops at least as much as it likes itself, then the quadratic term is positive. The quadratic term being positive means we can always swap ... ... @@ -382,7 +382,7 @@ statement with a condition on $R$ might be helpful: the score getting worse. The optimal swap direction is determined by all of the linear functions in $\lambda$ we put to the side throughout this proof. Therefore throughout this proof. Therefore, a relationship function $R$ fulfilling $R(c_i, c_j) \geq R(c_i, c_i)$ ensures there is always a good way to swap crops among ... ... @@ -391,7 +391,8 @@ statement with a condition on $R$ might be helpful: Being allowed to swap even amongst neighboring pixels allows us to disregard the pattern structure we had for the standard swapping method and we can by the same reasoning conclude that this new method has after termination at most $\binom{C}{2}$ still fractional pixels. and we can, by the same reasoning, conclude that this new method has at most $\binom{C}{2}$ still fractional pixels after terminating. \end{proof} \ No newline at end of file
 ... ... @@ -20,8 +20,8 @@ the following scenario of three non-neighboring pixels: \FloatBarrier Using only swaps involving two pixels will always lead to a pixel containing a crop it strongly dislikes based on it's neighborhood. Instead, swapping between three pixels as seen below leads to every pixel containing based on its neighborhood. Instead, swapping between three pixels, as seen below, leads to every pixel containing their preferred crop: \FloatBarrier \begin{figure}[h] ... ... @@ -33,17 +33,17 @@ their preferred crop: \node[main node] (2) [right of=hidden] {V}; \node[main node] (3) [above of=hidden] {W}; \path[every node/.style={font=\sffamily\small}]; (1) edge[left] node [above] {$b$} (2); (2) edge[left] node [above] {$c$} (3); \path[every node/.style={font=\sffamily\small}] (1) edge[left] node [above] {$b$} (2) (2) edge[left] node [above] {$c$} (3) (3) edge[right] node [above] {$a$} (1); \end{tikzpicture} \end{figure} \FloatBarrier The question is how we find such a multi-way swap. If we allowed swapping between neighboring pixels this would If we allowed swapping between neighboring pixels, this would indeed be tricky. If instead we restrict ourselves to only swapping between non-neighboring pixels however, then the score swapping between non-neighboring pixels, then the score function changes only linearly and we can use linear programming to find the optimal swap. Let the following linear program be defined as the swap LP. ... ... @@ -65,7 +65,7 @@ is planted within the pixel: \end{align*} And the function we are trying to maximize shows for every variable in $x$ how good it would be based on the pixels neighborhood to plant that crop based on the pixel's neighborhood to plant that crop there: \begin{align*} c &= \begin{bmatrix} ... ... @@ -81,10 +81,10 @@ there: Then we are trying to maximize the function $c^T x$ subject to the constraints that: \begin{enumerate} \item We don't allow less than $0$ or more than $1$ of each crop to \item we don't allow less than $0$ or more than $1$ of each crop to be planted in a pixel \item Every Pixel must contain a total amount of crops equaling $1$ \item The amount of each crop in $x$ before the swap and \item every Pixel must contain a total amount of crops equaling $1$ \item the amount of each crop in $x$ before the swap and in $x^*$ after the swap must be the same \end{enumerate} or formally, a solution $x^*$ must satisfy: ... ... @@ -97,7 +97,7 @@ or formally, a solution $x^*$ must satisfy: In theory an optimal solution to this linear program could result in fractional amounts of crop being planted in a pixel. However, the following theorems demonstrates that there is always an optimal integer solution. demonstrate that there is always an optimal integer solution. First we will show the specific case of swapping $k$ different crops among $k$ non-neighboring pixels, ... ... @@ -120,13 +120,13 @@ LP above, or formally: \begin{proof} The essence of our proof is that we first show that when we remap $k$ crops between $k$ pixels there must exist an optimal integer solution, because then we are in a Birkhoff polytope. an optimal integer solution must exist, because then we are in a Birkhoff Polytope. Consider the case where we select $k$ non-neighboring pixels that all contain a different crop. Then we ask how to best remap these $k$ crops among the $k$ pixels. In this case our solution space is the Birkhoff polytope. In this case our solution space is the Birkhoff Polytope. Consider the following representation of our $x$ as a matrix: \begin{align*} ... ... @@ -137,13 +137,13 @@ LP above, or formally: x_{n, 1} & x_{n, 2} & \dots & x_{n, C} \end{bmatrix} \end{align*} In order for a solution to be valid every row In order for a solution to be valid, every row must sum up to $1$ (a pixel contains a total crop amount of $1$) and each column must sum up to $1$ (we only have $1$ of each crop to distribute among the pixels). This is the definition of the Birkhoff polytope. Because the vertices of the Birkhoff polytope are the permutation matrices, Birkhoff Polytope. Because the vertices of the Birkhoff Polytope are the permutation matrices, these correspond exactly to our integer solutions. Lastly, because the function we are maximizing is linear, we know that at least one optimal ... ... @@ -153,7 +153,7 @@ LP above, or formally: \end{proof} Next we use this theorem to prove that the LP for swapping any number of crops types among for swapping any number of crop types among non-neighboring pixels must result in an integer solution. ... ... @@ -170,7 +170,7 @@ solution. We want to use theorem \ref{kByKOptSwap} to show that the swap LP' we are going to construct has an optimal integer solution. Therefore we need has an optimal integer solution. Therefore, we need to have the same number of crops as pixels. Consider again a set $P$ of non-neighboring pixels. For any two pixels $p_1, p_2 \in P$ that contain ... ... @@ -182,8 +182,8 @@ solution. By theorem \ref{kByKOptSwap} it now follows, as we have $k$ distinct crops among $k$ pixels, that there must exist an optimal integer solution $x^* \in F$ for the swap LP'. an optimal integer solution $x^* \in F$ for the swap LP' must exist. We now show that 1) this solution can be translated into an integer solution for the swap LP and 2) that this solution ... ... @@ -193,9 +193,9 @@ solution. `cloned' crops with their originals and we obtain a valid solution for the swap LP. Next we show that an optimal solution $x^*$ for Next, we show that an optimal solution $x^*$ for the swap LP must be $\leq$ an optimal solution for the swap LP'. For this simply iterate through for the swap LP'. For this we simply iterate through all duplicate crops in $x^*$ and replace them with cloned versions. Now again we have the exact same score, as the cloned crop version behave the ... ... @@ -204,7 +204,7 @@ solution. solution for the swap LP' is bounded from below by this solution $x^*$ for the swap LP. Finally we show that an optimal solution $x^*$ for Finally, we show that an optimal solution $x^*$ for the swap LP' must be $\leq$ an optimal solution for the swap LP. Again, we replace all of the cloned crop versions with their original crop. The score ... ... @@ -244,7 +244,7 @@ procedure: \end{algorithm} \FloatBarrier After running this algorithm repeatedly for around 24h on a standard Laptop we were able to generate the on a standard laptop we were able to generate the following solutions for our benchmark problems: \FloatBarrier \begin{figure}[h] ... ...
 ... ... @@ -2,7 +2,7 @@ \section{Integer Version} We assume that we are given four inputs: We are given four inputs: \begin{enumerate} \item The field dimensions, denoted as $X$ for the number of pixels on the x-axis and $Y$ correspondingly. Both $X, Y \in \N$. ... ... @@ -19,7 +19,7 @@ We assume that we are given four inputs: $D(c) \cdot X \cdot Y \in \N \quad \forall c \in \Cps$. \end{enumerate} Further let us define a neighborhood function that gives us all neighboring pixels of a given pixel: us all the neighboring pixels of a given pixel: \begin{displaymath} N((x, y)) = \{(a, b) \in \N^2 \ | \ a < X \land b < Y \land \abs{a - x} \leq 1 \land \abs{b - y} \leq 1 \land (a, b) \neq (x, y) \} \end{displaymath} ... ... @@ -39,22 +39,22 @@ where we also fulfill the distribution constraint: \section{Fractional Version} The fractional version of pixel farming we define analogously to the integer version We define the fractional version of pixel farming analogously to the integer version with the following exception: Instead of searching for a Field $F \in \Cps^{X \times Y}$, we search for an $F' \in \R_+^{C \times X \times Y}$. The idea is that every pixel can contain not only a single crop, but any combination of crops. To this end crop, but any combination of crops. To this end, we introduce $C$ variables for every pixel to denote the amount of each crop a pixel contains. For example a pixel could contain half of an carrot, a quarter of an onion and quarter of broccoli. the amount of each crop a pixel contains. For example, a pixel could contain half of a carrot, a quarter of an onion, and a quarter of broccoli. We stress that we are interested in this version of the pixel farming problem not for it's practical applications, but rather because it enables us to explore more traditional methods for exploring of the pixel farming problem not for its practical applications but rather because it enables us to