commit cb1201c781b3895b4c35e4dbe5bd9810f07516f6 Author: Ksan Date: Thu Jul 17 16:08:15 2025 +0200 started diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f2851c2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,31 @@ + +### IntelliJ IDEA ### +transport_data.json +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..31e1ebc --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..90a8681 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/PJ2.iml b/PJ2.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/PJ2.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/src/Departure.java b/src/Departure.java new file mode 100644 index 0000000..be1d77d --- /dev/null +++ b/src/Departure.java @@ -0,0 +1,42 @@ +public class Departure { + private TransportType type; + private String from; + private String to; + private int duration; + private int price; + private int minTransferTime; + + public Departure( + TransportType type, String from, String to, int duration, int price, int minTransferTime) { + this.type = type; + this.from = from; + this.to = to; + this.duration = duration; + this.price = price; + this.minTransferTime = minTransferTime; + } + + public TransportType getType() { + return type; + } + + public String getFrom() { + return from; + } + + public String getTo() { + return to; + } + + public int getDuration() { + return duration; + } + + public int getPrice() { + return price; + } + + public int getMinTransferTime() { + return minTransferTime; + } +} diff --git a/src/Main.java b/src/Main.java new file mode 100644 index 0000000..7030f65 --- /dev/null +++ b/src/Main.java @@ -0,0 +1,6 @@ +public class Main { + public static void main(String[] args) { + + System.out.println("Hello World!"); + } +} diff --git a/src/Station.java b/src/Station.java new file mode 100644 index 0000000..a0ff8da --- /dev/null +++ b/src/Station.java @@ -0,0 +1,6 @@ +import java.util.*; + +public class Station { + + private List departures = new ArrayList(); +} diff --git a/src/TransportDataGenerator.java b/src/TransportDataGenerator.java new file mode 100644 index 0000000..02b9c06 --- /dev/null +++ b/src/TransportDataGenerator.java @@ -0,0 +1,219 @@ +import java.io.FileWriter; +import java.io.IOException; +import java.util.*; + +public class TransportDataGenerator { + private static final int SIZE = 10; + private int n; + private int m; + + private static final int DEPARTURES_PER_STATION = 15; + private static final Random random = new Random(); + + public static void main(String[] args) { + TransportDataGenerator generator = new TransportDataGenerator(15, 10); + TransportData data = generator.generateData(); + generator.saveToJson(data, "transport_data.json"); + System.out.println("Podaci su generisani i sacuvani kao transport_data.json"); + } + + TransportDataGenerator() { + this.n = SIZE; + this.m = SIZE; + } + + TransportDataGenerator(int n) { + this.n = n; + this.m = n; + } + + TransportDataGenerator(int n, int m) { + this.n = n; + this.m = m; + } + + // struktura podataka koja sadrzi sve trazene ulazne podatke + public static class TransportData { + public String[][] countryMap; + public List stations; + public List departures; + } + + public static class Station { + public String city; + public String busStation; + public String trainStation; + } + + public static class Departure { + public String type; // "autobus" ili "voz" + public String from; + public String to; + public String departureTime; + public int duration; // u minutama + public int price; + public int minTransferTime; // vrijeme potrebno za transfer (u minutama) + } + + public TransportData generateData() { + TransportData data = new TransportData(); + data.countryMap = generateCountryMap(); + data.stations = generateStations(); + data.departures = generateDepartures(data.stations); + return data; + } + + // generisanje gradova (G_X_Y) + private String[][] generateCountryMap() { + String[][] countryMap = new String[n][m]; + for (int x = 0; x < n; x++) { + for (int y = 0; y < m; y++) { + countryMap[x][y] = "G_" + x + "_" + y; + } + } + return countryMap; + } + + // generisanje autobuskih i zeljeznickih stanica + private List generateStations() { + List stations = new ArrayList<>(); + for (int x = 0; x < n; x++) { + for (int y = 0; y < m; y++) { + Station station = new Station(); + station.city = "G_" + x + "_" + y; + station.busStation = "A_" + x + "_" + y; + station.trainStation = "Z_" + x + "_" + y; + stations.add(station); + } + } + return stations; + } + + // generisanje vremena polazaka + private List generateDepartures(List stations) { + List departures = new ArrayList<>(); + + for (Station station : stations) { + int x = Integer.parseInt(station.city.split("_")[1]); + int y = Integer.parseInt(station.city.split("_")[2]); + + // generisanje polazaka autobusa + for (int i = 0; i < DEPARTURES_PER_STATION; i++) { + departures.add(generateDeparture("autobus", station.busStation, x, y)); + } + + // generisanje polazaka vozova + for (int i = 0; i < DEPARTURES_PER_STATION; i++) { + departures.add(generateDeparture("voz", station.trainStation, x, y)); + } + } + return departures; + } + + private Departure generateDeparture(String type, String from, int x, int y) { + Departure departure = new Departure(); + departure.type = type; + departure.from = from; + + // generisanje susjeda + List neighbors = getNeighbors(x, y); + departure.to = neighbors.isEmpty() ? from : neighbors.get(random.nextInt(neighbors.size())); + + // generisanje vremena + int hour = random.nextInt(24); + int minute = random.nextInt(4) * 15; // 0, 15, 30, 45 + departure.departureTime = String.format("%02d:%02d", hour, minute); + + // geneirsanje cijene + departure.duration = 30 + random.nextInt(151); + departure.price = 100 + random.nextInt(901); + + // generisanje vremena transfera + departure.minTransferTime = 5 + random.nextInt(26); + + return departure; + } + + // pronalazak susjednih gradova + private List getNeighbors(int x, int y) { + List neighbors = new ArrayList<>(); + int[][] directions = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}}; + + for (int[] dir : directions) { + int nx = x + dir[0]; + int ny = y + dir[1]; + if (nx >= 0 && nx < n && ny >= 0 && ny < m) { + neighbors.add("G_" + nx + "_" + ny); + } + } + return neighbors; + } + + // cuvanje podataka u JSON mapu + private void saveToJson(TransportData data, String filename) { + try (FileWriter file = new FileWriter(filename)) { + StringBuilder json = new StringBuilder(); + json.append("{\n"); + + // mapa drzave + json.append(" \"countryMap\": [\n"); + for (int i = 0; i < n; i++) { + json.append(" ["); + for (int j = 0; j < m; j++) { + json.append("\"").append(data.countryMap[i][j]).append("\""); + if (j < m - 1) json.append(", "); + } + json.append("]"); + if (i < n - 1) json.append(","); + json.append("\n"); + } + json.append(" ],\n"); + + // stanice + json.append(" \"stations\": [\n"); + for (int i = 0; i < data.stations.size(); i++) { + Station s = data.stations.get(i); + json.append(" {\"city\": \"") + .append(s.city) + .append("\", \"busStation\": \"") + .append(s.busStation) + .append("\", \"trainStation\": \"") + .append(s.trainStation) + .append("\"}"); + if (i < data.stations.size() - 1) json.append(","); + json.append("\n"); + } + json.append(" ],\n"); + + // vremena polazaka + json.append(" \"departures\": [\n"); + for (int i = 0; i < data.departures.size(); i++) { + Departure d = data.departures.get(i); + json.append(" {\"type\": \"") + .append(d.type) + .append("\", \"from\": \"") + .append(d.from) + .append("\", \"to\": \"") + .append(d.to) + .append("\", \"departureTime\": \"") + .append(d.departureTime) + .append("\", \"duration\": ") + .append(d.duration) + .append(", \"price\": ") + .append(d.price) + .append(", \"minTransferTime\": ") + .append(d.minTransferTime) + .append("}"); + if (i < data.departures.size() - 1) json.append(","); + json.append("\n"); + } + json.append(" ]\n"); + + json.append("}"); + file.write(json.toString()); + } catch (IOException e) { + e.printStackTrace(); + } + } +} + diff --git a/src/TransportType.java b/src/TransportType.java new file mode 100644 index 0000000..4f93d1a --- /dev/null +++ b/src/TransportType.java @@ -0,0 +1,4 @@ +public enum TransportType { + BUS, + TRAIN +}