This commit is contained in:
navid.sassan 2020-11-08 12:19:40 +01:00
parent 65125e61d6
commit e8700f39ef
7 changed files with 274 additions and 274 deletions

206
07/gradlew.bat vendored
View File

@ -1,103 +1,103 @@
@rem @rem
@rem Copyright 2015 the original author or authors. @rem Copyright 2015 the original author or authors.
@rem @rem
@rem Licensed under the Apache License, Version 2.0 (the "License"); @rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License. @rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at @rem You may obtain a copy of the License at
@rem @rem
@rem https://www.apache.org/licenses/LICENSE-2.0 @rem https://www.apache.org/licenses/LICENSE-2.0
@rem @rem
@rem Unless required by applicable law or agreed to in writing, software @rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS, @rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and @rem See the License for the specific language governing permissions and
@rem limitations under the License. @rem limitations under the License.
@rem @rem
@if "%DEBUG%" == "" @echo off @if "%DEBUG%" == "" @echo off
@rem ########################################################################## @rem ##########################################################################
@rem @rem
@rem Gradle startup script for Windows @rem Gradle startup script for Windows
@rem @rem
@rem ########################################################################## @rem ##########################################################################
@rem Set local scope for the variables with windows NT shell @rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0 set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=. if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0 set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME% set APP_HOME=%DIRNAME%
@rem Resolve any "." and ".." in APP_HOME to make it shorter. @rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
@rem Find java.exe @rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1 %JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init if "%ERRORLEVEL%" == "0" goto init
echo. echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo. echo.
echo Please set the JAVA_HOME variable in your environment to match the echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation. echo location of your Java installation.
goto fail goto fail
:findJavaFromJavaHome :findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=% set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto init if exist "%JAVA_EXE%" goto init
echo. echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo. echo.
echo Please set the JAVA_HOME variable in your environment to match the echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation. echo location of your Java installation.
goto fail goto fail
:init :init
@rem Get command-line arguments, handling Windows variants @rem Get command-line arguments, handling Windows variants
if not "%OS%" == "Windows_NT" goto win9xME_args if not "%OS%" == "Windows_NT" goto win9xME_args
:win9xME_args :win9xME_args
@rem Slurp the command line arguments. @rem Slurp the command line arguments.
set CMD_LINE_ARGS= set CMD_LINE_ARGS=
set _SKIP=2 set _SKIP=2
:win9xME_args_slurp :win9xME_args_slurp
if "x%~1" == "x" goto execute if "x%~1" == "x" goto execute
set CMD_LINE_ARGS=%* set CMD_LINE_ARGS=%*
:execute :execute
@rem Setup the command line @rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle @rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
:end :end
@rem End local scope for the variables with windows NT shell @rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd if "%ERRORLEVEL%"=="0" goto mainEnd
:fail :fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code! rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1 exit /b 1
:mainEnd :mainEnd
if "%OS%"=="Windows_NT" endlocal if "%OS%"=="Windows_NT" endlocal
:omega :omega

View File

@ -1,54 +1,54 @@
package ch.zhaw.ads; package ch.zhaw.ads;
import java.util.*; import java.util.*;
public class AdjListGraph<N extends Node,E extends Edge> public class AdjListGraph<N extends Node,E extends Edge>
implements Graph<N, E> { implements Graph<N, E> {
private final List<N> nodes = new LinkedList<N>(); private final List<N> nodes = new LinkedList<N>();
private final Class nodeClazz; private final Class nodeClazz;
private final Class edgeClazz; private final Class edgeClazz;
public AdjListGraph(Class nodeClazz, Class edgeClazz) { public AdjListGraph(Class nodeClazz, Class edgeClazz) {
this.nodeClazz = nodeClazz; this.nodeClazz = nodeClazz;
this.edgeClazz = edgeClazz; this.edgeClazz = edgeClazz;
} }
// füge Knoten hinzu, gebe alten zurück falls Knoten schon existiert // füge Knoten hinzu, gebe alten zurück falls Knoten schon existiert
public N addNode(String name) throws Throwable { public N addNode(String name) throws Throwable {
N node = findNode(name); N node = findNode(name);
if (node == null) { if (node == null) {
node = (N) nodeClazz.newInstance(); node = (N) nodeClazz.newInstance();
node.setName(name); node.setName(name);
nodes.add(node); nodes.add(node);
} }
return node; return node;
} }
// füge gerichtete Kante hinzu // füge gerichtete Kante hinzu
public void addEdge(String source, String dest, double weight) throws Throwable { public void addEdge(String source, String dest, double weight) throws Throwable {
N src = addNode(source); N src = addNode(source);
N dst = addNode(dest); N dst = addNode(dest);
try { try {
E edge = (E) edgeClazz.newInstance(); E edge = (E) edgeClazz.newInstance();
edge.setDest(dst); edge.setDest(dst);
edge.setWeight(weight); edge.setWeight(weight);
src.addEdge(edge); src.addEdge(edge);
} catch (Exception e) {} } catch (Exception e) {}
} }
// finde den Knoten anhand seines Namens // finde den Knoten anhand seines Namens
public N findNode(String name) { public N findNode(String name) {
for (N node : nodes) { for (N node : nodes) {
if (node.getName().equals(name)) { if (node.getName().equals(name)) {
return node; return node;
} }
} }
return null; return null;
} }
// Iterator über alle Knoten // Iterator über alle Knoten
public Iterable<N> getNodes() { public Iterable<N> getNodes() {
return nodes; return nodes;
} }
} }

View File

@ -1,36 +1,36 @@
package ch.zhaw.ads; package ch.zhaw.ads;
class DijkstraNode<E> extends Node<E> implements Comparable<DijkstraNode> { class DijkstraNode<E> extends Node<E> implements Comparable<DijkstraNode> {
boolean mark; boolean mark;
DijkstraNode<E> prev; DijkstraNode<E> prev;
double dist; double dist;
public double getDist() { public double getDist() {
return dist; return dist;
} }
public void setDist(double dist) { public void setDist(double dist) {
this.dist = dist; this.dist = dist;
} }
public void setMark(boolean m) { public void setMark(boolean m) {
mark = m; mark = m;
} }
public boolean getMark() { public boolean getMark() {
return mark; return mark;
} }
public void setPrev(DijkstraNode<E> p) { public void setPrev(DijkstraNode<E> p) {
prev = p; prev = p;
} }
public DijkstraNode<E> getPrev() { public DijkstraNode<E> getPrev() {
return prev; return prev;
} }
public int compareTo(DijkstraNode n) { public int compareTo(DijkstraNode n) {
// TODO: implement // TODO: implement
return 0; return 0;
} }
} }

View File

@ -1,20 +1,20 @@
package ch.zhaw.ads; package ch.zhaw.ads;
public class Edge<N> public class Edge<N>
{ {
protected N dest; // Zielknoten der Kante protected N dest; // Zielknoten der Kante
protected double weight; // Kantengewicht protected double weight; // Kantengewicht
public Edge() {} public Edge() {}
public Edge(N dest, double weight) { public Edge(N dest, double weight) {
this.dest = dest; this.dest = dest;
this.weight = weight; this.weight = weight;
} }
public void setDest(N node) {this.dest = node;} public void setDest(N node) {this.dest = node;}
public N getDest() {return dest;} public N getDest() {return dest;}
public void setWeight(double w) {this.weight = w;} public void setWeight(double w) {this.weight = w;}
double getWeight() {return weight;} double getWeight() {return weight;}
} }

View File

@ -1,20 +1,20 @@
package ch.zhaw.ads; package ch.zhaw.ads;
import java.util.*; import java.util.*;
public interface Graph<N,E> { public interface Graph<N,E> {
// füge Knoten hinzu, tue nichts, falls Knoten schon existiert // füge Knoten hinzu, tue nichts, falls Knoten schon existiert
N addNode (String name) throws Throwable; N addNode (String name) throws Throwable;
// finde den Knoten anhand seines Namens // finde den Knoten anhand seines Namens
N findNode(String name); N findNode(String name);
// Iterator über alle Knoten des Graphen // Iterator über alle Knoten des Graphen
Iterable<N> getNodes(); Iterable<N> getNodes();
// füge gerichtete und gewichtete Kante hinzu // füge gerichtete und gewichtete Kante hinzu
void addEdge(String source, String dest, double weight) throws Throwable ; void addEdge(String source, String dest, double weight) throws Throwable ;
} }

View File

@ -1,34 +1,34 @@
package ch.zhaw.ads; package ch.zhaw.ads;
import java.util.*; import java.util.*;
public class Node<E> { public class Node<E> {
protected String name; // Name protected String name; // Name
protected List<E> edges; // Kanten protected List<E> edges; // Kanten
public Node() { public Node() {
edges = new LinkedList<E>(); edges = new LinkedList<E>();
} }
public Node(String name) { public Node(String name) {
super(); super();
this.name = name; this.name = name;
} }
public String getName() { public String getName() {
return name; return name;
} }
public void setName(String name) { public void setName(String name) {
this.name = name; this.name = name;
} }
public Iterable<E> getEdges() { public Iterable<E> getEdges() {
return edges; return edges;
} }
public void addEdge(E edge) { public void addEdge(E edge) {
edges.add(edge); edges.add(edge);
} }
} }

View File

@ -1,14 +1,14 @@
Winterthur Zürich 25 Winterthur Zürich 25
Zürich Bern 126 Zürich Bern 126
Zürich Genf 277 Zürich Genf 277
Zürich Luzern 54 Zürich Luzern 54
Zürich Chur 121 Zürich Chur 121
Zürich Berikon 16 Zürich Berikon 16
Bern Genf 155 Bern Genf 155
Genf Lugano 363 Genf Lugano 363
Lugano Luzern 206 Lugano Luzern 206
Lugano Chur 152 Lugano Chur 152
Chur Luzern 146 Chur Luzern 146
Luzern Bern 97 Luzern Bern 97
Bern Berikon 102 Bern Berikon 102
Luzern Berikon 41 Luzern Berikon 41