Initial Commit with loading of cities.
parent
eef444a58f
commit
3445bc151b
|
@ -0,0 +1,2 @@
|
|||
eclipse.preferences.version=1
|
||||
encoding/<project>=UTF-8
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,214 @@
|
|||
Aachen
|
||||
Köln
|
||||
Trier
|
||||
|
||||
Augsburg
|
||||
München
|
||||
Garmisch-Part.
|
||||
Nürnberg
|
||||
Ulm
|
||||
Regensburg
|
||||
Lindau
|
||||
|
||||
Bayreuth
|
||||
Nürnberg
|
||||
Würzburg
|
||||
Erfurt
|
||||
|
||||
Berlin
|
||||
Cottbus
|
||||
Leipzig
|
||||
Frankfurt/Oder
|
||||
Magdeburg
|
||||
Schwerin
|
||||
Rostock
|
||||
Magdeburg
|
||||
Neubrandenburg
|
||||
|
||||
Bremen
|
||||
Hamburg
|
||||
Hannover
|
||||
Osnabrück
|
||||
|
||||
Cottbus
|
||||
Dresden
|
||||
Frankfurt/Oder
|
||||
Berlin
|
||||
|
||||
Dresden
|
||||
Cottbus
|
||||
Erfurt
|
||||
Bayreuth
|
||||
|
||||
Erfurt
|
||||
Magdeburg
|
||||
Fulda
|
||||
Bayreuth
|
||||
Kassel
|
||||
|
||||
Essen
|
||||
Köln
|
||||
Münster
|
||||
Kassel
|
||||
|
||||
Frankfurt/Main
|
||||
Mannheim
|
||||
Würzburg
|
||||
Koblenz
|
||||
Fulda
|
||||
Kassel
|
||||
|
||||
Frankfurt/Oder
|
||||
Dresden
|
||||
Berlin
|
||||
|
||||
Freiburg
|
||||
Karlsruhe
|
||||
Stuttgart
|
||||
Lindau
|
||||
|
||||
Fulda
|
||||
Kassel
|
||||
Erfurt
|
||||
Würzburg
|
||||
|
||||
Garmisch-Part.
|
||||
München
|
||||
Lindau
|
||||
Ulm
|
||||
|
||||
Hamburg
|
||||
Kiel
|
||||
Bremen
|
||||
Magdeburg
|
||||
|
||||
Hannover
|
||||
Osnabrück
|
||||
Bremen
|
||||
Hamburg
|
||||
Magdeburg
|
||||
|
||||
Karlsruhe
|
||||
Stuttgart
|
||||
Mannheim
|
||||
Saarbrücken
|
||||
|
||||
Kassel
|
||||
Frankfurt/Main
|
||||
Essen
|
||||
Fulda
|
||||
Erfurt
|
||||
|
||||
Kiel
|
||||
Hamburg
|
||||
Schwerin
|
||||
|
||||
Koblenz
|
||||
Köln
|
||||
Trier
|
||||
Frankfurt/Main
|
||||
Fulda
|
||||
Kassel
|
||||
|
||||
Köln
|
||||
Koblenz
|
||||
Trier
|
||||
|
||||
Leipzig
|
||||
Berlin
|
||||
Erfurt
|
||||
Magdeburg
|
||||
|
||||
Lindau
|
||||
Ulm
|
||||
Garmisch-Part.
|
||||
|
||||
Magdeburg
|
||||
Hannover
|
||||
Berlin
|
||||
Schwerin
|
||||
Hamburg
|
||||
|
||||
Mannheim
|
||||
Karlsruhe
|
||||
Frankfurt/Main
|
||||
Saarbrücken
|
||||
Trier
|
||||
Koblenz
|
||||
|
||||
München
|
||||
Augsburg
|
||||
Lindau
|
||||
Bayreuth
|
||||
Würzburg
|
||||
Passau
|
||||
|
||||
Münster
|
||||
Osnabrück
|
||||
Essen
|
||||
|
||||
Neubrandenburg
|
||||
Berlin
|
||||
Rostock
|
||||
Schwerin
|
||||
|
||||
Nürnberg
|
||||
München
|
||||
Würzburg
|
||||
Bayreuth
|
||||
Stuttgart
|
||||
|
||||
Osnabrück
|
||||
Hannover
|
||||
Kassel
|
||||
Münster
|
||||
Bremen
|
||||
Wilhelmshaven
|
||||
|
||||
Passau
|
||||
Regensburg
|
||||
München
|
||||
|
||||
Regensburg
|
||||
Nürnberg
|
||||
München
|
||||
Passau
|
||||
|
||||
Rostock
|
||||
Schwerin
|
||||
Neubrandenburg
|
||||
|
||||
Saarbrücken
|
||||
Trier
|
||||
Mannheim
|
||||
Frankfurt/Main
|
||||
Karlsruhe
|
||||
|
||||
Schwerin
|
||||
Rostock
|
||||
Hamburg
|
||||
Berlin
|
||||
|
||||
Stuttgart
|
||||
Karlsruhe
|
||||
Ulm
|
||||
Würzburg
|
||||
|
||||
Trier
|
||||
Saarbrücken
|
||||
Koblenz
|
||||
|
||||
Ulm
|
||||
Stuttgart
|
||||
Augsburg
|
||||
Lindau
|
||||
Nürnberg
|
||||
Würzburg
|
||||
|
||||
Wilhelmshaven
|
||||
Bremen
|
||||
Osnabrück
|
||||
|
||||
Würzburg
|
||||
Osnabrück
|
||||
Bremen
|
|
@ -0,0 +1,13 @@
|
|||
package de.th_mannheim.informatik.routenplaner;
|
||||
|
||||
import de.th_mannheim.informatik.routenplaner.domain.Routeplaner;
|
||||
|
||||
public class NaviApp {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Routeplaner map = new Routeplaner();
|
||||
|
||||
System.out.println(map.getNumberOfCities());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package de.th_mannheim.informatik.routenplaner.domain;
|
||||
|
||||
import java.util.TreeSet;
|
||||
|
||||
public class City {
|
||||
private String name;
|
||||
|
||||
private TreeSet<Street> neighbors = new TreeSet<>();
|
||||
|
||||
public City(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void addVerbindung(City stadt2, int distance) {
|
||||
neighbors.add(new Street(this, stadt2, distance));
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public TreeSet<Street> getNeighbors() {
|
||||
return neighbors;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,118 @@
|
|||
package de.th_mannheim.informatik.routenplaner.domain;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Scanner;
|
||||
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.select.Elements;
|
||||
|
||||
public class Routeplaner {
|
||||
private HashMap<String, City> cities = new HashMap<>();
|
||||
|
||||
public Routeplaner() {
|
||||
loadData();
|
||||
}
|
||||
|
||||
public int getNumberOfCities() {
|
||||
return cities.size();
|
||||
}
|
||||
|
||||
private void loadData() {
|
||||
final String CITIES_DOCUMENT_PATH = "resources/etab.html";
|
||||
|
||||
int[][] matrix;
|
||||
HashMap<String, Integer> cityLookup = new HashMap<>();
|
||||
|
||||
File input = new File(CITIES_DOCUMENT_PATH);
|
||||
Document doc;
|
||||
try {
|
||||
doc = Jsoup.parse(input, "UTF-8");
|
||||
|
||||
String[] cities = parseCities(doc);
|
||||
matrix = new int[cities.length][cities.length];
|
||||
|
||||
Elements cells = doc.select("td");
|
||||
int xIndex = 0;
|
||||
int yIndex = -1;
|
||||
|
||||
for (int i = cities.length + 1; i < cells.size(); i++) {
|
||||
if(i%(cities.length + 1) == 0) {
|
||||
xIndex = 0;
|
||||
yIndex++;
|
||||
|
||||
this.addCity(cities[yIndex]);
|
||||
cityLookup.put(cities[yIndex], yIndex);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
String cityName1 = cities[xIndex];
|
||||
String cityName2 = cities[yIndex];
|
||||
|
||||
xIndex++;
|
||||
|
||||
if(cityName1.equals(cityName2))
|
||||
continue;
|
||||
|
||||
matrix[xIndex - 1][yIndex] = Integer.parseInt(cells.get(i).text());
|
||||
} // for
|
||||
|
||||
loadConnections(matrix, cityLookup);
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void loadConnections(int[][] matrix, HashMap<String, Integer> cityLookup) throws IOException {
|
||||
final Scanner sc = new Scanner(new File("resources/verb.txt"));
|
||||
|
||||
String start = null;
|
||||
while (sc.hasNextLine()) {
|
||||
String line = sc.nextLine();
|
||||
|
||||
if (start == null) {
|
||||
start = line;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (line.isBlank()) {
|
||||
start = null;
|
||||
continue;
|
||||
}
|
||||
|
||||
this.addStreet(start, line, matrix[cityLookup.get(start)][cityLookup.get(line)]);
|
||||
|
||||
} // while
|
||||
|
||||
sc.close();
|
||||
}
|
||||
|
||||
private String[] parseCities(Document doc) {
|
||||
Elements cities = doc.select("td > b");
|
||||
int cityAmount = cities.size();
|
||||
String[] cityNames = new String[cityAmount];
|
||||
|
||||
for (int i = 0; i < cities.size(); i++) {
|
||||
cityNames[i] = cities.get(i).text();
|
||||
}
|
||||
return cityNames;
|
||||
}
|
||||
|
||||
private void addCity(String name) {
|
||||
cities.put(name, new City(name));
|
||||
}
|
||||
|
||||
private void addStreet(String name1, String name2, int distance) {
|
||||
City s1 = cities.get(name1);
|
||||
City s2 = cities.get(name2);
|
||||
|
||||
s1.addVerbindung(s2, distance);
|
||||
s2.addVerbindung(s1, distance);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
package de.th_mannheim.informatik.routenplaner.domain;
|
||||
|
||||
public class Street implements Comparable<Street> {
|
||||
private final City start;
|
||||
private final City target;
|
||||
|
||||
private final int distance;
|
||||
|
||||
public Street(City start, City ziel, int distance) {
|
||||
super();
|
||||
this.start = start;
|
||||
this.target = ziel;
|
||||
this.distance = distance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Street v) {
|
||||
int diff = this.distance - v.distance;
|
||||
|
||||
if (diff != 0)
|
||||
return diff;
|
||||
|
||||
if (this.start.equals(v.start) && this.target.equals(v.target))
|
||||
return 0;
|
||||
|
||||
// wg. Nutzung von TreeSet
|
||||
return 1;
|
||||
}
|
||||
|
||||
public City getStart() {
|
||||
return start;
|
||||
}
|
||||
|
||||
public City getTarget() {
|
||||
return target;
|
||||
}
|
||||
|
||||
public int getDistance() {
|
||||
return distance;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return start.getName() + " -> " + target.getName() + ": " + distance + " km";
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue