Commit 5a3680fb authored by Michael Keller's avatar Michael Keller
Browse files

Worked on growning sol

parent 6e6da168
...@@ -22,6 +22,19 @@ def growA(field): ...@@ -22,6 +22,19 @@ def growA(field):
newField.append(newRow) newField.append(newRow)
return newField return newField
# Grow method A (alt def)
def growA_alt(field, f):
x = len(field)
y = len(field[0])
newField = [[-1 for _ in range(f * (y-1)+1)] for _ in range(f * (x-1)+1)]
for i in range(f * (x-1)+1):
for j in range(f * (y-1)+1):
a = int( floor(i / f) + ((i + floor(i / f)) % 2))
b = int( floor(j / f) + ((j + floor(j / f)) % 2))
newField[i][j] = field[a][b]
return newField
def growB(field, fx, fy): def growB(field, fx, fy):
newField = [] newField = []
y = len(field) y = len(field)
......
from bruteForce import solver from bruteForce import solver
from greedy import solver_greedy from greedy import solver_greedy
from scorer import score, maxScore, maxScoreAlt, maxScoreGaertner from scorer import score, maxScore, maxScoreAlt, maxScoreGaertner
from grower import growA, growB, fix from grower import growA, growA_alt, growB, fix
from simulatedAnealing import simulatedAnnealing, simulatedAnnealingMultiple, simulatedAnnealingField from simulatedAnealing import simulatedAnnealing, simulatedAnnealingMultiple, simulatedAnnealingField
import numpy as np import numpy as np
import copy import copy
...@@ -60,6 +60,12 @@ def main(): ...@@ -60,6 +60,12 @@ def main():
# [0, -1, -1, -1], # [0, -1, -1, -1],
# [-1, 0, -1, -1] # [-1, 0, -1, -1]
# ][a][b] # ][a][b]
sol = [[1,2,3],[4,5,6],[7,8,9]]
sol_prime = growA_alt(sol, 3)
print(sol_prime)
# generate random 1d field # generate random 1d field
fieldStretched = [] fieldStretched = []
......
\chapter{Benchmark Problems} \chapter{Benchmark Problems}
TODO: Add arnold scores
Our goal is to develop methods that work well in Our goal is to develop methods that work well in
many or all cases. However, data that is based many or all cases. However, data that is based
on real observations is of particular interest. on real observations is of particular interest.
......
...@@ -2,6 +2,116 @@ ...@@ -2,6 +2,116 @@
\section{Growing solutions} \section{Growing solutions}
We have seen that the general problem is
NP complete. However, small problems can
still be computed by simply testing out
all possible solutions. We aim to demonstrate
that we can build solutions for larger fields
with the same score to field size ratio. These
solutions may not be optimal, but in some
situations may lead to good quality results quickly.
For the sake of a clearer presentation
we present a method that stretches the
solution by the same factor in both the $x$
and $y$ direction. Consider an algorithm
that is given a small optimal solution $sol$
of size $X \times Y$ that we would like to
stretch by an odd factor of $f$. We propose
the following method for generating
a larger solution $sol'$. We use $0$ indexing
for cleaner formulas:
\begin{align*}
sol'_{i, j} &= sol_{a, b} & & i \in \{0, \dots, f \cdot (X-1)\} & j \in \{0, \dots, f \cdot (Y-1)\}
\end{align*}
\begin{displaymath}
a = \lfloor i / f \rfloor + ((i + \lfloor i / f \rfloor) \text{ mod } 2)
\end{displaymath}
\begin{displaymath}
b = \lfloor j / f \rfloor + ((j + \lfloor j / f \rfloor) \text{ mod } 2)
\end{displaymath}
which is a bit puzzling in its formal form.
The idea is that we want to multiply the
connections for all non-border pixels the
same amount of time. To achieve
this we try to reuse all of the good
intercrop relationships that are hopefully
present in the small field. We essentially
"ping pong" between all of the connections
$f$ times. Here is an example
for $f = 3$:
\begin{displaymath}
\begin{bmatrix}
1 & 2 & 3\\
4 & 5 & 6\\
7 & 8 & 9\\
\end{bmatrix}
\to
\begin{bmatrix}
1 & 2 & 1 & 2 & 3 & 2 & 3\\
4 & 5 & 4 & 5 & 6 & 5 & 6\\
1 & 2 & 1 & 2 & 3 & 2 & 3\\
4 & 5 & 4 & 5 & 6 & 5 & 6\\
7 & 8 & 7 & 8 & 9 & 8 & 9\\
4 & 5 & 4 & 5 & 6 & 5 & 6\\
7 & 8 & 7 & 8 & 9 & 8 & 9\\
\end{bmatrix}
\end{displaymath}
Here the only non-border pixel is
pixel $5$. In the small solution
it is connected to all other
pixels exactly once. The reader
is invited to verify that pixel
$5$ in the grown solution is connected
to every other pixel exactly $f^2 = 9$
times.
Next we introduce the concept of relative
score. We define it as:
\begin{displaymath}
\text{Relative Score} := \frac{\text{score}}{\text{maximum possible score}}
\end{displaymath}
where for the maximum possible score we use
the standard bound discussed in the section
on bounds. Hence if the score for our
small field is $s$ then the relative score
is:
\begin{displaymath}
\frac{s}{8XY - 6X - 6Y + 4}
\end{displaymath}
Further we can bound the score $s'$ for the
grown field by:
\begin{align*}
s'
&\geq f^2 \cdot s - 3 \cdot (f \cdot (X-1) + 1) - 3 \cdot (f \cdot (Y-1) + 1) + 4\\
&\geq f^2 \cdot s - 3 \cdot (f \cdot X - f + 1) - 3 \cdot (f \cdot Y - f + 1) + 4\\
&\geq f^2 \cdot s - 3f \cdot X + 3f - 3 - 3f \cdot Y + 3f - 3 + 4\\
&\geq f^2 \cdot s - 3f \cdot (X + Y - 2) -2\\
&\geq f^2 \cdot s - 3f \cdot (X + Y - 1)
\end{align*}
which means our new relative
score can be bounded from below by:
\begin{align*}
&\frac{s'}{8 \cdot (f (X-1) + 1) \cdot (f (Y-1) + 1) - 6 \cdot (f (X-1) + 1) - 6 \cdot (f (Y-1) + 1) + 4}\\
&= \frac{s'}{8 \cdot (f X - f + 1) \cdot (f Y - f + 1) - 6 \cdot (f X - f + 1) - 6 \cdot (f Y - f + 1) + 4}\\
&= \frac{s'}{8f^2XY - 8f^2X - 8f^2Y + 2fX + 2fY - 4f + 8f^2}\\
&= \frac{s'}{8f^2XY - 8f^2X - 8f^2Y + 2f \cdot (X + Y - 2) + 8f^2}\\
&= \frac{s'}{8f^2 (XY - X - Y + 1) + 2f \cdot (X + Y - 2)}\\
&\geq \frac{f^2 \cdot s - 3f \cdot (X + Y - 1)}{8f^2 (XY - X - Y + 1) + 2f \cdot (X + Y - 2)}
\end{align*}
Which in turn allows us to find
the following condition on $f$
that guarantees our property:
\begin{align*}
\frac{s}{8XY - 6X - 6Y + 4} &\leq \frac{f^2 \cdot s - 3f \cdot (X + Y - 1)}{8f^2 (XY - X - Y + 1) + 2f \cdot (X + Y - 2)}\\
\frac{s}{8XY - 6X - 6Y + 4} &\leq \frac{f \cdot s - 3 \cdot (X + Y - 1)}{8f (XY - X - Y + 1) + 2 \cdot (X + Y - 2)}\\
-2fsX -2fsY + 4fs &\leq (3 - 3X -3Y) \cdot (8XY - 6X - 6Y + 4) - 2s \cdot (X + Y - 2)\\
-2fs \cdot (X + Y - 2) &\leq - (3X + 3Y - 3) \cdot (8XY - 6X - 6Y + 4) - 2s \cdot (X + Y - 2)\\
2fs \cdot (X + Y - 2) &\geq (3X + 3Y - 3) \cdot (8XY - 6X - 6Y + 4) + 2s \cdot (X + Y - 2)\\
f &\geq \frac{(3X + 3Y - 3) \cdot (8XY - 6X - 6Y + 4)}{2s \cdot (X + Y - 2)} + 1
\end{align*}
\section{Creating integer solutions from fractional solutions} \section{Creating integer solutions from fractional solutions}
If we were able to take a field that can If we were able to take a field that can
......
No preview for this file type
...@@ -2,11 +2,11 @@ ...@@ -2,11 +2,11 @@
\contentsline {proof}{{Proof}{1}{}}{7}{proof.1}% \contentsline {proof}{{Proof}{1}{}}{7}{proof.1}%
\contentsline {theorem}{{Theorem}{4.{2}}{}}{9}{theorem.4.3.2}% \contentsline {theorem}{{Theorem}{4.{2}}{}}{9}{theorem.4.3.2}%
\contentsline {proof}{{Proof}{2}{}}{9}{proof.2}% \contentsline {proof}{{Proof}{2}{}}{9}{proof.2}%
\contentsline {theorem}{{Theorem}{7.{1}}{}}{19}{theorem.7.2.1}% \contentsline {theorem}{{Theorem}{7.{1}}{}}{21}{theorem.7.2.1}%
\contentsline {proof}{{Proof}{3}{}}{19}{proof.3}% \contentsline {proof}{{Proof}{3}{}}{21}{proof.3}%
\contentsline {theorem}{{Theorem}{7.{2}}{}}{20}{theorem.7.2.2}% \contentsline {theorem}{{Theorem}{7.{2}}{}}{22}{theorem.7.2.2}%
\contentsline {proof}{{Proof}{4}{}}{21}{proof.4}% \contentsline {proof}{{Proof}{4}{}}{22}{proof.4}%
\contentsline {theorem}{{Theorem}{8.{1}}{}}{27}{theorem.8.1.1}% \contentsline {theorem}{{Theorem}{8.{1}}{}}{29}{theorem.8.1.1}%
\contentsline {proof}{{Proof}{5}{}}{27}{proof.5}% \contentsline {proof}{{Proof}{5}{}}{29}{proof.5}%
\contentsline {theorem}{{Theorem}{8.{2}}{}}{27}{theorem.8.1.2}% \contentsline {theorem}{{Theorem}{8.{2}}{}}{29}{theorem.8.1.2}%
\contentsline {proof}{{Proof}{6}{}}{27}{proof.6}% \contentsline {proof}{{Proof}{6}{}}{29}{proof.6}%
...@@ -19,13 +19,13 @@ ...@@ -19,13 +19,13 @@
\contentsline {section}{\numberline {6.3}LP bound}{17}{section.6.3}% \contentsline {section}{\numberline {6.3}LP bound}{17}{section.6.3}%
\contentsline {chapter}{\chapternumberline {7}Helpful Statements}{19}{chapter.7}% \contentsline {chapter}{\chapternumberline {7}Helpful Statements}{19}{chapter.7}%
\contentsline {section}{\numberline {7.1}Growing solutions}{19}{section.7.1}% \contentsline {section}{\numberline {7.1}Growing solutions}{19}{section.7.1}%
\contentsline {section}{\numberline {7.2}Creating integer solutions from fractional solutions}{19}{section.7.2}% \contentsline {section}{\numberline {7.2}Creating integer solutions from fractional solutions}{21}{section.7.2}%
\contentsline {subsection}{\numberline {7.2.1}The standard method}{19}{subsection.7.2.1}% \contentsline {subsection}{\numberline {7.2.1}The standard method}{21}{subsection.7.2.1}%
\contentsline {subsection}{\numberline {7.2.2}The advanced method}{20}{subsection.7.2.2}% \contentsline {subsection}{\numberline {7.2.2}The advanced method}{22}{subsection.7.2.2}%
\contentsline {chapter}{\chapternumberline {8}The Linear Programming Method}{25}{chapter.8}% \contentsline {chapter}{\chapternumberline {8}The Linear Programming Method}{27}{chapter.8}%
\contentsline {section}{\numberline {8.1}Problem Setup}{25}{section.8.1}% \contentsline {section}{\numberline {8.1}Problem Setup}{27}{section.8.1}%
\contentsline {section}{\numberline {8.2}Method}{28}{section.8.2}% \contentsline {section}{\numberline {8.2}Method}{30}{section.8.2}%
\contentsline {chapter}{\chapternumberline {9}Gradient Descent}{31}{chapter.9}% \contentsline {chapter}{\chapternumberline {9}Gradient Descent}{33}{chapter.9}%
\contentsline {chapter}{\chapternumberline {10}Conclusion}{33}{chapter.10}% \contentsline {chapter}{\chapternumberline {10}Conclusion}{35}{chapter.10}%
\contentsline {appendix}{\chapternumberline {A}Calculations Appendix}{35}{appendix.A}% \contentsline {appendix}{\chapternumberline {A}Calculations Appendix}{37}{appendix.A}%
\contentsline {chapter}{Bibliography}{37}{appendix*.4}% \contentsline {chapter}{Bibliography}{39}{appendix*.4}%
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