\documentclass[a4paper,10pt,ngerman]{scrartcl} \usepackage{babel} \usepackage[a4paper,margin=2.5cm]{geometry} % automatische Quotes \usepackage{csquotes} \MakeOuterQuote{"} % Die nächsten drei Felder bitte anpassen: \newcommand{\Name}{Arne Keller} % Teamname oder eigenen Namen angeben \newcommand{\TeilnahmeId}{50966} \newcommand{\Aufgabe}{Aufgabe 1: Lisa rennt} % Kopf- und Fußzeilen \usepackage{scrlayer-scrpage, lastpage} \setkomafont{pageheadfoot}{\textrm} \lohead{\Aufgabe} \chead{\thepage{}/\pageref{LastPage}} \rohead{\Name/Teilnahme-Id: \TeilnahmeId} \cfoot{} % Für mathematische Befehle und Symbole \usepackage{amsmath,amsthm,amssymb,gensymb} % Für Bilder \usepackage{graphicx,subcaption,float} % Für Skizzen \usepackage{tkz-euclide} \usetkzobj{all} % Für Quelltext \usepackage{listings} \usepackage{color} \definecolor{mygreen}{rgb}{0,0.6,0} \definecolor{mygray}{rgb}{0.5,0.5,0.5} \definecolor{mymauve}{rgb}{0.58,0,0.82} \lstset{ keywordstyle=\color{blue},commentstyle=\color{mygreen}, stringstyle=\color{mymauve},rulecolor=\color{black}, basicstyle=\footnotesize\ttfamily,numberstyle=\tiny\color{mygray}, captionpos=b, % sets the caption-position to bottom keepspaces=true, % keeps spaces in text numbers=left, numbersep=5pt, showspaces=false,showstringspaces=false, showtabs=false, stepnumber=2, tabsize=2, title=\lstname } \lstdefinelanguage{Rust}{ keywords={break, match, continue, else, for, fn, if, return, self, let, mut, loop, while, extern, crate, use, static, enum, struct, impl, as, type, derive, mod}, morecomment=[l]{//}, morecomment=[s]{/*}{*/}, morestring=[b]", sensitive=true } % Diese beiden Pakete müssen als letztes geladen werden %\usepackage{hyperref} % Anklickbare Links im Dokument %\usepackage{cleveref} % Daten für die Titelseite \title{\Aufgabe} \author{\Name\\Teilnahme-ID: \TeilnahmeId} \date{29. April 2019} \begin{document} \maketitle \tableofcontents \section{Lösungsidee} Zunächst kann man feststellen, dass der letzte Abschnitt jeder Route zum Bus immer exakt gerade ist. In einer Kurve würde Lisa länger laufen, ohne am Ende auf der y-Achse weiter zu sein. Es gibt keinen, einen oder zwei Treffpunkte, bei denen Lisa (ohne zu warten) den Bus erwischt: \begin{figure}[H] \centering \begin{subfigure}{.33\textwidth} \centering \begin{tikzpicture} \tkzInit[xmax=3.5,ymax=7.5] \tkzAxeXY \tkzGrid \tkzDefPoint(0,0){B} \tkzDefPoint(1.25,3.5){L} \tkzDefPoint(0,2.83333){M1} \tkzDefPoint(0,6.5){M2} \tkzDrawSegment(L,M1) \tkzDrawSegment(L,M2) \tkzDrawPoints(B,L,M1,M2) \tkzLabelPoints(B,L,M1,M2) \end{tikzpicture} \caption{Zwei Treffpunkte} \label{abb:fall1} \end{subfigure}% \begin{subfigure}{.33\textwidth} \centering \begin{tikzpicture} \tkzInit[xmax=3.5,ymax=7.5] \tkzAxeXY \tkzGrid \tkzDefPoint(0,0){B} \tkzDefPoint(2.020725942,3.5){L} \tkzDefPoint(0,4.614){M} \tkzDrawSegment(L,M) \tkzDrawPoints(B,L,M) \tkzLabelPoints[yshift=14pt](M) \tkzLabelPoints(B,L) \end{tikzpicture} \caption{Ein Treffpunkt} \label{abb:fall2} \end{subfigure}% \begin{subfigure}{.33\textwidth} \centering \begin{tikzpicture} \tkzInit[xmax=3.5,ymax=7.5] \tkzAxeXY \tkzGrid \tkzDefPoint(0,0){B} \tkzDefPoint(3,3.5){L} \tkzDrawPoints(B,L) \tkzLabelPoints(B,L) \end{tikzpicture} \caption{Kein Treffpunkt} \label{abb:fall3} \end{subfigure} \caption{Mögliche Treffpunktanzahlen} \label{fig:treffpunkte} \end{figure} \begin{proof} Sei Lisa bei $L(x_{L},y_{L})$ und der Bus bei $B(x_{B},y_{B})$. $M(x_{M},y_{M})$ sei der Treffpunkt von Lisa mit dem Bus. $d$ sei der Weg, den Lisa zu diesem Punkt geht. \begin{align*} d &= \sqrt{(x_{L}-x_{M})^2 + (y_{L}-y_{M})^2} &&\text{(Satz des Pythagoras)} \\ &= \sqrt{x_{L}^2 + (y_{L}-y_{M})^2} &&\text{($x_{B} = x_{M} = 0$)} \\ d^2 &= x_{L}^2 + (y_{L}-y_{M})^2 \\ &= x_{L}^2 + (y_{L}-y_{B}-2d)^2 &&\text{($y_{M} = y_{B} + 2d$)} \\ &= x_{L}^2 + y_{L}^2 + y_{B}^2 + 4d^2 - 2y_{B}y_{L} - 4dy_{L} + 4dy_{B} \\ -3d^2 + 4\cdot(y_{L}-y_{B})\cdot{}d &= x_{L}^2 + y_{L}^2 + y_{B}^2 - 2y_{B}y_{L} \\ d &= \frac{-b\pm\sqrt{b^2 + 12\cdot{}(-x_{L}^2 - y_{L}^2 - y_{B}^2 + 2y_{B}y_{L})}}{-6} &&\text{($b = 4\cdot(y_{L}-y_{B})$)} \end{align*} Für diese Gleichung gibt es maximal zwei nicht-negative Lösungen.\qedhere \end{proof} Um den letzten Zeitpunkt, bei dem sie den Bus gerade noch erwischt, zu bestimmen, kann man die Wurzel in der letzen Gleichung gleich Null setzen. Wenn man nach $y_{B}$ auflöst, erhält man die Position des Busses, bei dessen Durchquerung Lisa anfangen sollte zu laufen. So kann man für jeden Startpunkt berechnen, wann Lisa spätestens von dort loslaufen müsste. Außerdem wird Lisa auf einer optimalen Route vor dem letzten Abschnitt immer von einer Polygonecke zur nächsten gehen. Andernfalls würde sie in Kurven um jene Ecken wertvolle Zeit verschwenden. Der letzte Abschnitt ihrer Route trifft die y-Achse immer in einem 60\degree-Winkel ($cos(60\degree) = \frac{1}{2}$): \begin{figure}[H] \centering \begin{subfigure}{.33\textwidth} \centering \begin{tikzpicture} \tkzInit[xmax=3.5,ymax=7.5] \tkzAxeXY \tkzGrid \tkzDefPoint(0,0.3){B} \tkzDefPoint(2,4){L} \tkzDefPoint(0,4.36667){M} \tkzMarkAngle[fill=orange,size=0.8cm,opacity=.4](B,M,L) \tkzDrawSegment(L,M) \tkzDrawSegment(B,M) \tkzDrawPoints(B,L,M) \tkzLabelAngle[pos=0.5](B,M,L){$\alpha$} \tkzLabelPoints[yshift=14pt](M,B) \tkzLabelPoints(L) \end{tikzpicture} \caption{$\alpha > 60\degree$} \label{abb:winkel1} \end{subfigure}% \begin{subfigure}{.33\textwidth} \centering \begin{tikzpicture} \tkzInit[xmax=3.5,ymax=7.5] \tkzAxeXY \tkzGrid \tkzDefPoint(0,0.5359){B} \tkzDefPoint(2,4){L} \tkzDefPoint(0,5.155){M} \tkzMarkAngle[fill=orange,size=0.8cm,opacity=.4](B,M,L) \tkzDrawSegment(L,B) \tkzDrawSegment(B,M) \tkzDrawSegment(L,M) \tkzMarkRightAngle(M,L,B) \tkzDrawPoints(B,L,M) \tkzLabelAngle[pos=0.5](B,M,L){$\alpha$} \tkzLabelPoints[yshift=14pt](M) \tkzLabelPoints(B,L) \end{tikzpicture} \caption{$\alpha = 60\degree$} \label{abb:winkel2} \end{subfigure}% \begin{subfigure}{.33\textwidth} \centering \begin{tikzpicture} \tkzInit[xmax=3.5,ymax=7.5] \tkzAxeXY \tkzGrid \tkzDefPoint(0,0.3){B} \tkzDefPoint(2,4){L} \tkzDefPoint(0,6.1){M} \tkzMarkAngle[fill=orange,size=0.8cm,opacity=.4](B,M,L) \tkzDrawSegment(L,M) \tkzDrawSegment(B,M) \tkzDrawPoints(B,L,M) \tkzLabelAngle[pos=0.5](B,M,L){$\alpha$} \tkzLabelPoints[yshift=14pt](M,B) \tkzLabelPoints(L) \end{tikzpicture} \caption{$\alpha < 60\degree$} \label{abb:winkel3} \end{subfigure} \caption{Mögliche Winkel} \label{fig:winkel} \end{figure} \subsection{Laufzeitanalyse} Wenn in jedem Schritt jede andere Polygonecke berücksichtigt wird, hat der Algorithmus im schlechtesten Fall eine Laufzeit von $O(n!)$, wobei $n$ die Anzahl der Ecken der Polygone ist. Effektiv können allerdings in jedem Schritt nur eine kleine Anzahl anderer Ecken erreicht werden. Das Programm durchsucht auch erst Möglichkeiten, die eher zu einer Lösung führen, was die Laufzeit weiter verringert. \section{Umsetzung} Das Programm durchsucht in einer optimierten Breitensuche alle Wege, die über Polygonecken führen. Priorisiert (mit einem binären Max-Heap) werden jene Wege, bei denen Lisa theoretisch am längsten warten könnte. Um die Route abzuschließen, probiert das Programm danach immer, einen optimalen Weg zur y-Achse zu finden (dieser trifft sie im 60\degree-Winkel, wie oben beschrieben). Die Route, bei dem Lisa sich am meisten Zeit lassen kann, wird gespeichert, falls nicht schon eine bessere Lösung gefunden wurde. Die Suche ist beendet, sobald alle unvollständigen Routen die beste Wartezeit nicht mehr verbessern können. Die so gefundene Route kann in einer svg-Datei gespeichert werden. Während der Suche gefundene Lösungen werden automatisch so gespeichert. Der Weg von Lisa und dem Bus ist animiert. Zusätzlich zu den unbedingt benötigten Ausgaben wie z.B. der Start- und Zielzeit gibt das Programm auch noch die theoretisch (ohne Hindernisse) beste Startzeit und während der Suche gefundene Verbesserungen aus. \section{Beispiele} Alle Beispiele sind im Maßstab 1:70m. \lstinputlisting[caption=Lösung für lisarennt1.txt,frame=single,breaklines=true]{run1.txt} \begin{figure}[H] \centering \input{run1.tkz} \caption{Beispiel 1} \label{fig:bsp1} \end{figure} \lstinputlisting[caption=Lösung für lisarennt2.txt,frame=single,breaklines=true]{run2.txt} \begin{figure}[H] \centering \input{run2.tkz} \caption{Beispiel 2} \label{fig:bsp2} \end{figure} \lstinputlisting[caption=Lösung für lisarennt3.txt,frame=single,breaklines=true]{run3.txt} \begin{figure}[H] \centering \input{run3.tkz} \caption{Beispiel 3} \label{fig:bsp3} \end{figure} \lstinputlisting[caption=Lösung für lisarennt4.txt,frame=single,breaklines=true]{run4.txt} \begin{figure}[H] \centering \input{run4.tkz} \caption{Beispiel 4} \label{fig:bsp4} \end{figure} \lstinputlisting[caption=Lösung für lisarennt5.txt,frame=single,breaklines=true]{run5.txt} \begin{figure}[H] \centering \input{run5.tkz} \caption{Beispiel 5} \label{fig:bsp5} \end{figure} \section{Quellcode (Hauptalgorithmus)} \lstinputlisting[frame=single,language=Rust,breaklines=true]{src/main.rs} \end{document}