From 2dd7abcc0c790cf0a71e811f2685f5ae848bcfe4 Mon Sep 17 00:00:00 2001 From: AngeHerman Date: Mon, 29 Apr 2024 17:13:17 +0200 Subject: [PATCH 1/8] =?UTF-8?q?Vitesse=20des=20transports=20adapt=C3=A9e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../project/idfm/CSVSchedulesProvider.java | 2 + .../gla/project/idfm/CSVStreamProvider.java | 39 +++++++++++++++++-- .../project/idfm/IDFMNetworkExtractor.java | 2 +- .../itinerary/ItineraryCalculator.java | 4 +- 4 files changed, 40 insertions(+), 7 deletions(-) diff --git a/src/main/java/fr/u_paris/gla/project/idfm/CSVSchedulesProvider.java b/src/main/java/fr/u_paris/gla/project/idfm/CSVSchedulesProvider.java index 52835d3..4f993ce 100644 --- a/src/main/java/fr/u_paris/gla/project/idfm/CSVSchedulesProvider.java +++ b/src/main/java/fr/u_paris/gla/project/idfm/CSVSchedulesProvider.java @@ -21,6 +21,8 @@ public class CSVSchedulesProvider { put("Subway", new int[]{4, 2, 6,3,3,4}); }}; + + // Time between 2 passages for the transports with a new type we don't know yet private static int DEFAULT_TIMING = 6; private static final NumberFormat MINUTES_SECOND_FORMATTER = NumberFormat diff --git a/src/main/java/fr/u_paris/gla/project/idfm/CSVStreamProvider.java b/src/main/java/fr/u_paris/gla/project/idfm/CSVStreamProvider.java index d09754f..5163011 100644 --- a/src/main/java/fr/u_paris/gla/project/idfm/CSVStreamProvider.java +++ b/src/main/java/fr/u_paris/gla/project/idfm/CSVStreamProvider.java @@ -23,6 +23,23 @@ import fr.u_paris.gla.project.utils.GPS; * CSV Stream Provider class */ public final class CSVStreamProvider { + + private static final HashMap two_acceleration_distance_by_type = new HashMap(){{ + put("Bus", 0.1); + put("Funicular", 0.1); + put("Tram", 0.1); + put("Rail", 0.2); + put("Subway", 0.1); + }}; + + private static final HashMap max_speed_by_type = new HashMap(){{ + put("Bus", 10.0); + put("Funicular", 5.0); + put("Tram", 20.0); + put("Rail", 50.0); + put("Subway", 30.0); + }}; + /** * Formatter from numbers into GPS Coordinates */ @@ -201,7 +218,7 @@ public final class CSVStreamProvider { this.line[NetworkFormat.DISTANCE_INDEX] = NumberFormat.getInstance(Locale.ENGLISH) .format(distance); this.line[NetworkFormat.DURATION_INDEX] = formatTime( - (long) Math.ceil(distanceToTime(distance) * SECONDS_IN_HOURS)); + (long) Math.ceil(distanceToTime(distance,this.traceType) * SECONDS_IN_HOURS)); int bifurcation = this.lineSegments.get(this.start).size() - 1; this.line[NetworkFormat.VARIANT_INDEX] = Integer .toString(bifurcation); @@ -231,6 +248,18 @@ public final class CSVStreamProvider { MINUTES_SECOND_FORMATTER.format(time / SECONDS_IN_MINUTES), MINUTES_SECOND_FORMATTER.format(time % SECONDS_IN_MINUTES)); } + // /** A tool method to give a delay to go through a certain distance. + // *

+ // * This is a model with an linear acceleration and deceleration periods and a + // * constant speed in between. + // * + // * @param distance the distance (in km) + // * @return the duration of the trip (in hours) */ + // private static double distanceToTime(double distance) { + // return Math.max(0, distance - TWO_ACCELERATION_DISTANCE) / MAX_SPEED + // + Math.pow(Math.min(distance, TWO_ACCELERATION_DISTANCE) / MAX_SPEED, 2); + // } + /** A tool method to give a delay to go through a certain distance. *

* This is a model with an linear acceleration and deceleration periods and a @@ -238,9 +267,11 @@ public final class CSVStreamProvider { * * @param distance the distance (in km) * @return the duration of the trip (in hours) */ - private static double distanceToTime(double distance) { - return Math.max(0, distance - TWO_ACCELERATION_DISTANCE) / MAX_SPEED - + Math.pow(Math.min(distance, TWO_ACCELERATION_DISTANCE) / MAX_SPEED, 2); + private static double distanceToTime(double distance, String type) { + Double max_speed = max_speed_by_type.get(type); + Double two_acc_distance = two_acceleration_distance_by_type.get(type); + return Math.max(0, distance - two_acc_distance) / max_speed + + Math.pow(Math.min(distance, two_acc_distance) / max_speed, 2); } private void fillTransports(int bif) { diff --git a/src/main/java/fr/u_paris/gla/project/idfm/IDFMNetworkExtractor.java b/src/main/java/fr/u_paris/gla/project/idfm/IDFMNetworkExtractor.java index 2e4db84..e323f42 100644 --- a/src/main/java/fr/u_paris/gla/project/idfm/IDFMNetworkExtractor.java +++ b/src/main/java/fr/u_paris/gla/project/idfm/IDFMNetworkExtractor.java @@ -245,7 +245,7 @@ public class IDFMNetworkExtractor { } } - public static void builFiles() { + public static void buildFiles() { if (checkFileExistence("./"+HOURS_FILE_NAME) && checkFileExistence("./"+TRACE_FILE_NAME)) { LOGGER.severe("Files already exists."); diff --git a/src/main/java/fr/u_paris/gla/project/itinerary/ItineraryCalculator.java b/src/main/java/fr/u_paris/gla/project/itinerary/ItineraryCalculator.java index d272b77..666dbf3 100644 --- a/src/main/java/fr/u_paris/gla/project/itinerary/ItineraryCalculator.java +++ b/src/main/java/fr/u_paris/gla/project/itinerary/ItineraryCalculator.java @@ -209,7 +209,7 @@ public class ItineraryCalculator { LOGGER.severe("Invalid command line. Target file names are in the main file for now."); return; } - //IDFMNetworkExtractor.builFiles(); + IDFMNetworkExtractor.buildFiles(); try { HashSet nodes = new HashSet<>(); @@ -244,7 +244,7 @@ public class ItineraryCalculator { //System.out.println(graph.getConnections(porteivry)); Finder finder = new Finder(graph); - List res = finder.findPath(porteivry, chatelet, 43200); + List res = finder.findPath(chatelet, garenord, 43200); for (Path element : res) { System.out.println(element.getCurrentStop()); } From 8b6c78ca75be1c263606c81da9b2fc9220aee916 Mon Sep 17 00:00:00 2001 From: HU helene Date: Mon, 29 Apr 2024 17:31:17 +0200 Subject: [PATCH 2/8] remove main from parse --- pom.xml | 2 +- .../{ItineraryCalculator.java => Parse.java} | 45 ++++++------------- 2 files changed, 15 insertions(+), 32 deletions(-) rename src/main/java/fr/u_paris/gla/project/itinerary/{ItineraryCalculator.java => Parse.java} (87%) diff --git a/pom.xml b/pom.xml index da0f1b0..ffe1949 100644 --- a/pom.xml +++ b/pom.xml @@ -62,7 +62,7 @@ true ${project.build.finalName}.lib/ - fr.u_paris.gla.project.itinerary.ItineraryCalculator + fr.u_paris.gla.project.App diff --git a/src/main/java/fr/u_paris/gla/project/itinerary/ItineraryCalculator.java b/src/main/java/fr/u_paris/gla/project/itinerary/Parse.java similarity index 87% rename from src/main/java/fr/u_paris/gla/project/itinerary/ItineraryCalculator.java rename to src/main/java/fr/u_paris/gla/project/itinerary/Parse.java index 666dbf3..1b9f257 100644 --- a/src/main/java/fr/u_paris/gla/project/itinerary/ItineraryCalculator.java +++ b/src/main/java/fr/u_paris/gla/project/itinerary/Parse.java @@ -9,7 +9,7 @@ import java.util.*; import java.util.logging.Level; import java.util.logging.Logger; -public class ItineraryCalculator { +public class Parse { private static final Logger LOGGER = Logger .getLogger(IDFMNetworkExtractor.class.getName()); @@ -44,6 +44,10 @@ public class ItineraryCalculator { //Walking speed in m/s private static final double WALK_SPEED = 1.; + private HashSet nodes = new HashSet<>(); + private HashMap> connections = new HashMap<>(); + private HashMap> tmp = new HashMap<>(); + /** * Returns the coordinates from a String to a double array: * "49.08, 3.07" -> {49.08, 3.07} @@ -204,17 +208,12 @@ public class ItineraryCalculator { } } - public static void main(String[] args){ - if (args.length != 0) { - LOGGER.severe("Invalid command line. Target file names are in the main file for now."); - return; - } + public void parseFiles(){ + IDFMNetworkExtractor.buildFiles(); try { - HashSet nodes = new HashSet<>(); - HashMap> connections = new HashMap<>(); - HashMap> tmp = new HashMap<>(); + CSVTools.readCSVFromFile(TRACE_FILE_NAME, (String[] line) -> addLine(line, nodes, tmp, connections)); @@ -227,32 +226,16 @@ public class ItineraryCalculator { } } - - Stop porteivry = tmp.get("Porte d'Ivry").get(0); - Stop repu = tmp.get("République").get(0); - - Graph graph = new Graph(nodes, connections); - int cpt = 0; - for (Map.Entry> entry : graph.getConnections().entrySet()) { - if (entry.getValue() == null) cpt +=1; - } - Stop garenord = tmp.get("Gare du Nord").get(0); - - Stop chatelet = tmp.get("Châtelet").get(0); - //System.out.println(graph.getConnections(garenord)); - //System.out.println(cpt); - //System.out.println(graph.getConnections(porteivry)); - Finder finder = new Finder(graph); - - List res = finder.findPath(chatelet, garenord, 43200); - for (Path element : res) { - System.out.println(element.getCurrentStop()); - } - } catch (IOException e) { LOGGER.log(Level.SEVERE, "Error while reading the line paths", e); } + } + + public List getItinerary(Stop src, Stop dst, double startTime ){ + Graph graph = new Graph(nodes, connections); + Finder finder = new Finder(graph); + return finder.findPath(src, dst, startTime); } } From 541d5a2542eff89d7a44c3c4c5875e4165b9dd14 Mon Sep 17 00:00:00 2001 From: HU helene Date: Mon, 29 Apr 2024 17:35:37 +0200 Subject: [PATCH 3/8] remove main from IDFMNetworkExtractor --- .../project/idfm/IDFMNetworkExtractor.java | 136 ------------------ 1 file changed, 136 deletions(-) diff --git a/src/main/java/fr/u_paris/gla/project/idfm/IDFMNetworkExtractor.java b/src/main/java/fr/u_paris/gla/project/idfm/IDFMNetworkExtractor.java index e323f42..c3add40 100644 --- a/src/main/java/fr/u_paris/gla/project/idfm/IDFMNetworkExtractor.java +++ b/src/main/java/fr/u_paris/gla/project/idfm/IDFMNetworkExtractor.java @@ -98,142 +98,6 @@ public class IDFMNetworkExtractor { // Well named constants private static final double QUARTER_KILOMETER = .25; - /** - * Main entry point for the extractor of IDF mobilité data into a network as - * defined by this application. - * - * @param args the arguments (expected one for the destination file) - */ - public static void main(String[] args) { - - if (args.length != 2) { - LOGGER.severe("Invalid command line. Missing target files."); - return; - } - - Map traces = new HashMap<>(); - try { - CSVTools.readCSVFromFile(TRACE_FILE_DOWNLOADED_NAME, - (String[] line) -> addLine(line, traces)); - } catch (IOException e) { - LOGGER.log(Level.SEVERE, "Error while reading the line paths", e); - } - - List stops = new ArrayList<>(traces.size() * GUESS_STOPS_BY_LINE); - try { - CSVTools.readCSVFromFile(STOPS_FILE_DOWNLOADED_NAME, - (String[] line) -> addStop(line, traces, stops)); - } catch (IOException e) { - LOGGER.log(Level.SEVERE, "Error while reading the stops", e); - } - - cleanTraces(traces); - - Map transports = new HashMap<>(); - CSVStreamProvider provider = new CSVStreamProvider(traces.values().iterator(), transports); - - // Write into args[0] - try { - CSVTools.writeCSVToFile(args[0], Stream.iterate(provider.next(), - t -> provider.hasNext(), t -> provider.next())); - } catch (IOException e) { - LOGGER.log(Level.SEVERE, e, - () -> MessageFormat.format("Could not write in file {0}", args[0])); - } - - /*CSVStreamSchedulesProvider providerschedules = new CSVStreamSchedulesProvider(traces.values().iterator()); - - // TraceEntry tmp = traces.values().iterator().next(); - // tmp.getTerminus() - // .forEach(m -> LOGGER.log(Level.INFO, m)); - - // Write into args[1] - try { - CSVTools.writeCSVToFile(args[1], Stream.iterate(providerschedules.next(), - t -> providerschedules.hasNext(), t -> providerschedules.next())); - } catch (IOException e) { - LOGGER.log(Level.SEVERE, e, - () -> MessageFormat.format("Could not write in file {0}", args[1])); - }*/ - // System.out.println("****** END ******"); - // System.out.println(transports.size()); - // System.out.println(transports.get("IDFM:C01371").name); - // System.out.println(transports.get("IDFM:C02060").name); - // Transport ligne_1 = transports.get("IDFM:C01371"); - // Transport ligne_7 = transports.get("IDFM:C01377"); - // Transport rerd = transports.get("IDFM:C01728"); - // Transport b54b = transports.get("IDFM:C00940"); - - - // System.out.println("****** AFFICHAGE LIGNE ******"); - - // Stop maisonBlanche = ligne_7.stopsMap.get("Maison Blanche"); - // System.out.println(maisonBlanche.name); - - // for (BifStop nextEntry : maisonBlanche.connected.values()) { - // System.out.println(nextEntry.bifurc+ nextEntry.stop.name); - // } - // System.out.println("****** AFFICHAGE LIGNE ******"); - - // Stop corientin = ligne_7.stopsMap.get("Corentin Cariou"); - // System.out.println(corientin.name); - - // for (BifStop nextEntry : corientin.connected.values()) { - // System.out.println(nextEntry.bifurc+ nextEntry.stop.name); - // } - // System.out.println("***************************"); - // System.out.println("****** AFFICHAGE Description ******"); - // System.out.println(traces.get("IDFM:C01377").descriptions); - // System.out.println("****** AFFICHAGE Description False ******"); - // System.out.println(ligne_7.descriptions); - // System.out.println("****************** Build la path ***********************"); - // System.out.println(ligne_7.type); - // System.out.println(rerd.type); - // ligne_7.buildBifurcation(); - // rerd.buildBifurcation(); - // System.out.println("******************Derniere description ***********************"); - // System.out.println(ligne_7.descriptions); - // System.out.println("******************Description 54B ************************"); - // b54b.buildBifurcation(); - // System.out.println(b54b.descriptions); - System.out.println("******************Building bifurcations ************************"); - long startTime = System.currentTimeMillis(); - - for (Transport entry : transports.values()) { - entry.buildBifurcationOptimzed(); - } - - long endTime = System.currentTimeMillis(); - long tempsPasse = endTime - startTime; - - long minutes = (tempsPasse / 1000) / 60; - long seconds = (tempsPasse / 1000) % 60; - long milliseconds = tempsPasse % 1000; - - System.out.println("Temps écoulé : " + minutes + " minutess, " + seconds + " secndes et " + milliseconds + " millis"); - - System.out.println("******************Fin Building bifurcations ************************"); - - CSVSchedulesProvider providerschedules = new CSVSchedulesProvider(transports.values().iterator()); - try { - CSVTools.writeCSVToFile(args[1], Stream.iterate(providerschedules.next(), - t -> providerschedules.hasNext(), t -> providerschedules.next())); - } catch (IOException e) { - LOGGER.log(Level.SEVERE, e, - () -> MessageFormat.format("Could not write in file {0}", args[1])); - } - - CSVImageProvider providerimage = new CSVImageProvider(transports.values().iterator()); - String imageCSV = "image.csv"; - try { - CSVTools.writeCSVToFile(imageCSV, Stream.iterate(providerimage.next(), - t -> providerimage.hasNext(), t -> providerimage.next())); - } catch (IOException e) { - LOGGER.log(Level.SEVERE, e, - () -> MessageFormat.format("Could not write in file {0}", imageCSV)); - } - } - public static boolean checkFileExistence(String filePath) { File file = new File(filePath); if (file.exists()) { From ce69a218e308dbacb3c5e345a46007e55a687dd9 Mon Sep 17 00:00:00 2001 From: MAMBILA TETE jean philipp <@mambilat> Date: Mon, 29 Apr 2024 17:39:55 +0200 Subject: [PATCH 4/8] [feat] itinerary works and table display, no more jform --- .../java/fr/u_paris/gla/project/gui/View.form | 270 ------------------ .../java/fr/u_paris/gla/project/gui/View.java | 238 +++++++++++---- 2 files changed, 181 insertions(+), 327 deletions(-) delete mode 100644 src/main/java/fr/u_paris/gla/project/gui/View.form diff --git a/src/main/java/fr/u_paris/gla/project/gui/View.form b/src/main/java/fr/u_paris/gla/project/gui/View.form deleted file mode 100644 index 928c8a8..0000000 --- a/src/main/java/fr/u_paris/gla/project/gui/View.form +++ /dev/null @@ -1,270 +0,0 @@ - -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
diff --git a/src/main/java/fr/u_paris/gla/project/gui/View.java b/src/main/java/fr/u_paris/gla/project/gui/View.java index e6bc8ef..88e9738 100644 --- a/src/main/java/fr/u_paris/gla/project/gui/View.java +++ b/src/main/java/fr/u_paris/gla/project/gui/View.java @@ -8,29 +8,41 @@ import javax.swing.table.TableModel; import java.awt.*; import java.awt.event.*; import java.util.ArrayList; -import java.util.stream.Collectors; public class View extends JFrame { - private JPanel Cardpanel; + private JPanel CardPanel; private JMenuItem Home; private JMenuItem Network; private JMenuItem Favorites; private JPanel NetworkPanel; - private JPanel FavoritesPanel; - private JTextField textField1; - private JButton searchButton; + + private JTextField TextLocation; + private JButton ButtonLocation; private JPanel HomePanel; private JPanel MainPanel; - private DefaultTableModel model; + private DefaultTableModel modelStops; - private JTable table; + private JTable tableStops; - private JScrollPane mypane; + private JTable tableItinerary; + + private DefaultTableModel modelItinerary; + + private JScrollPane paneStops; + + private JScrollPane paneItinerary; private JPanel ItineraryPanel; private JMenuItem Itinerary; private JPanel stationsPanel; private JLabel departText; private JLabel arrText; + private JTextField TextCoord; + private JButton ButtonCoord; + private JPanel SearchCoordPanel; + private JPanel SearchLocationPanel; + private JLabel NetworkLabel; + private JLabel FavLabel; + private JMenuBar ButtonBar; private ArrayList StopList; @@ -38,7 +50,9 @@ public class View extends JFrame { private String arrivalCur; - private String searchCur; + private String searchLocation; + + private String searchCoord; private ArrayList searchRes; @@ -46,9 +60,87 @@ public class View extends JFrame { public View(ArrayList s) throws HeadlessException { - model = (DefaultTableModel) table.getModel(); - model.setColumnCount(2); - model.setColumnIdentifiers(new Object[]{"Line", "Stop"}); + MainPanel = new JPanel(); + GridLayout MainLayout = new GridLayout(1, 2, 50, 0); + MainPanel.setLayout(MainLayout); + CardLayout CardLay = new CardLayout(); + CardPanel = new JPanel(CardLay); + + HomePanel = new JPanel(); + CardPanel.add(HomePanel); + SearchCoordPanel = new JPanel(); + SearchLocationPanel = new JPanel(); + GridLayout SearchLayout = new GridLayout(1, 2); + HomePanel.setLayout(SearchLayout); + HomePanel.add(SearchCoordPanel); + HomePanel.add(SearchLocationPanel); + GridLayout SearchCoordLayout = new GridLayout(2, 1); + GridLayout SearchLocationLayout = new GridLayout(2, 1); + SearchCoordPanel.setLayout(SearchCoordLayout); + SearchLocationPanel.setLayout(SearchLocationLayout); + TextCoord = new JTextField(); + ButtonCoord = new JButton("Look for coords"); + SearchCoordPanel.add(TextCoord); + SearchCoordPanel.add(ButtonCoord); + TextLocation = new JTextField(); + ButtonLocation = new JButton("Look for string"); + SearchLocationPanel.add(TextLocation); + SearchLocationPanel.add(ButtonLocation); + + NetworkPanel = new JPanel(); + CardPanel.add(NetworkPanel); + GridLayout NetworkLayout = new GridLayout(3, 1); + NetworkPanel.setLayout(NetworkLayout); + NetworkLabel = new JLabel("Network"); + NetworkPanel.add(NetworkLabel); + stationsPanel = new JPanel(); + NetworkPanel.add(stationsPanel); + GridLayout StationsLayout = new GridLayout(2, 1); + departText = new JLabel("Départ: "); + arrText = new JLabel("Arivée: "); + stationsPanel.setLayout(StationsLayout); + stationsPanel.add(departText); + stationsPanel.add(arrText); + paneStops = new JScrollPane(); + tableStops = new JTable(); + paneStops.add(tableStops); + NetworkPanel.add(paneStops); + + + + ItineraryPanel = new JPanel(); + CardPanel.add(ItineraryPanel); + GridLayout ItineraryLayout = new GridLayout(2, 1); + ItineraryPanel.setLayout(ItineraryLayout); + paneItinerary = new JScrollPane(); + tableItinerary = new JTable(); + paneItinerary.add(tableItinerary); + ItineraryPanel.add(paneItinerary); + + + ButtonBar = new JMenuBar(); + GridLayout ButtonLayout = new GridLayout(4, 1); + ButtonBar.setLayout(ButtonLayout); + Home = new JMenuItem("Home"); + ButtonBar.add(Home); + Network = new JMenuItem("Network"); + ButtonBar.add(Network); + + Itinerary = new JMenuItem("Itinerary"); + ButtonBar.add(Itinerary); + ButtonBar.setPreferredSize(new Dimension(50, 500)); + + MainPanel.add(ButtonBar); + MainPanel.add(CardPanel); + + + modelStops = (DefaultTableModel) tableStops.getModel(); + modelStops.setColumnCount(2); + modelStops.setColumnIdentifiers(new Object[]{"Line", "Stop"}); + + modelItinerary = (DefaultTableModel) tableItinerary.getModel(); + modelItinerary.setColumnCount(3); + modelItinerary.setColumnIdentifiers(new Object[]{"Line", "Stop", "Time"}); this.StopList = s; @@ -63,79 +155,98 @@ public class View extends JFrame { Home.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - Cardpanel.removeAll(); - Cardpanel.add(HomePanel); - Cardpanel.repaint(); - Cardpanel.revalidate(); + CardPanel.removeAll(); + CardPanel.add(HomePanel); + CardPanel.repaint(); + CardPanel.revalidate(); } }); Network.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - showSearch(s); - Cardpanel.removeAll(); - Cardpanel.add(NetworkPanel); + LoadSearchResult(s, modelStops); + CardPanel.removeAll(); + CardPanel.add(NetworkPanel); - Cardpanel.repaint(); - Cardpanel.revalidate(); + CardPanel.repaint(); + CardPanel.revalidate(); } }); - Favorites.addActionListener(new ActionListener() { + Itinerary.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - Cardpanel.removeAll(); - Cardpanel.add(FavoritesPanel); - Cardpanel.repaint(); - Cardpanel.revalidate(); + LoadSearchResult(s, modelItinerary); + CardPanel.removeAll(); + CardPanel.add(ItineraryPanel); + + CardPanel.repaint(); + CardPanel.revalidate(); } }); - textField1.addKeyListener(new KeyAdapter() { + + + TextLocation.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { super.keyReleased(e); if (e.getKeyCode() == KeyEvent.VK_ENTER) { - searchCur = textField1.getText(); - showSearch(s); - System.out.println("Enter key released with text " + searchCur); - Cardpanel.removeAll(); - Cardpanel.add(NetworkPanel); + searchLocation = TextLocation.getText(); + LoadSearchResult(s, modelStops); + System.out.println("Enter key released with text " + searchLocation); + CardPanel.removeAll(); + CardPanel.add(NetworkPanel); - Cardpanel.repaint(); - Cardpanel.revalidate(); + CardPanel.repaint(); + CardPanel.revalidate(); } } }); - searchButton.addActionListener(new ActionListener() { + ButtonLocation.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - Cardpanel.removeAll(); - searchCur = textField1.getText(); - showSearch(s); - System.out.println("search button clicked with text " + searchCur); - Cardpanel.add(NetworkPanel); + CardPanel.removeAll(); + searchLocation = TextLocation.getText(); + LoadSearchResult(s, modelStops); + System.out.println("search location clicked with text " + searchLocation); + CardPanel.add(NetworkPanel); - Cardpanel.repaint(); - Cardpanel.revalidate(); + CardPanel.repaint(); + CardPanel.revalidate(); } }); - table.addMouseListener(new MouseAdapter() { + + ButtonCoord.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + CardPanel.removeAll(); + searchCoord = TextCoord.getText(); + LoadSearchResult(s, modelStops); + System.out.println("search coord clicked with text " + searchCoord); + CardPanel.add(NetworkPanel); + + CardPanel.repaint(); + CardPanel.revalidate(); + } + }); + tableStops.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { super.mouseClicked(e); System.out.println("MouseClick: " + e.getX() + ";" + e.getY()); - showOptionsDialog(table, e.getX(), e.getY()); + showOptionsDialog(tableStops, e.getX(), e.getY()); } }); - mypane.addMouseListener(new MouseAdapter() { + + paneStops.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { super.mouseClicked(e); @@ -182,11 +293,11 @@ public class View extends JFrame { - public void showSearch(ArrayList stops) { + public void LoadSearchResult(ArrayList stops, DefaultTableModel model) { // Clear existing rows from the table - + int cols = model.getColumnCount(); model.setRowCount(0); - model.setColumnCount(2); + model.setColumnCount(cols); // Add new rows based on the search results @@ -208,26 +319,39 @@ public class View extends JFrame { System.out.println(count); - table.revalidate(); - table.repaint(); + tableStops.revalidate(); + tableStops.repaint(); + + tableItinerary.revalidate(); + tableItinerary.repaint(); + + paneStops.setViewportView(tableStops); + paneStops.revalidate(); + paneStops.repaint(); + + + paneItinerary.setViewportView(tableItinerary); + paneItinerary.revalidate(); + paneItinerary.repaint(); - mypane.setViewportView(table); - mypane.revalidate(); - mypane.repaint(); NetworkPanel.revalidate(); NetworkPanel.repaint(); + ItineraryPanel.revalidate(); + ItineraryPanel.repaint(); - this.displayTableValues(); + + this.displayTableValues(model); } - public void displayTableValues() { - TableModel mod = table.getModel(); + public void displayTableValues(TableModel mod) { + for (int row = 0; row < mod.getRowCount(); row++) { for (int column = 0; column < mod.getColumnCount(); column++) { - System.out.print(mod.getValueAt(row, column).toString() + " "); + + if (mod.getValueAt(row, column) != null) System.out.print(mod.getValueAt(row, column).toString() + " "); } System.out.print(";"); From 70ad25019bb6f85245f115697296064c086baca3 Mon Sep 17 00:00:00 2001 From: MAMBILA TETE jean philipp <@mambilat> Date: Mon, 29 Apr 2024 17:44:07 +0200 Subject: [PATCH 5/8] [feat] itinerary works and table display, no more jform --- src/main/java/fr/u_paris/gla/project/gui/View.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/fr/u_paris/gla/project/gui/View.java b/src/main/java/fr/u_paris/gla/project/gui/View.java index 88e9738..3db7c01 100644 --- a/src/main/java/fr/u_paris/gla/project/gui/View.java +++ b/src/main/java/fr/u_paris/gla/project/gui/View.java @@ -119,7 +119,7 @@ public class View extends JFrame { ButtonBar = new JMenuBar(); - GridLayout ButtonLayout = new GridLayout(4, 1); + GridLayout ButtonLayout = new GridLayout(3, 1); ButtonBar.setLayout(ButtonLayout); Home = new JMenuItem("Home"); ButtonBar.add(Home); From 29e95072f3f59d31344950ae5581460e189a52f5 Mon Sep 17 00:00:00 2001 From: AngeHerman Date: Mon, 29 Apr 2024 18:10:38 +0200 Subject: [PATCH 6/8] Test release added --- src/main/java/fr/u_paris/gla/project/App.java | 28 +++++++++++++++++++ .../u_paris/gla/project/itinerary/Parse.java | 3 ++ 2 files changed, 31 insertions(+) diff --git a/src/main/java/fr/u_paris/gla/project/App.java b/src/main/java/fr/u_paris/gla/project/App.java index 08e16a4..ca83602 100644 --- a/src/main/java/fr/u_paris/gla/project/App.java +++ b/src/main/java/fr/u_paris/gla/project/App.java @@ -7,6 +7,7 @@ import java.awt.image.BufferedImage; import java.io.IOException; import java.io.InputStream; import java.io.PrintStream; +import java.util.List; import java.util.Properties; import javax.imageio.ImageIO; @@ -15,6 +16,11 @@ import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.WindowConstants; +import fr.u_paris.gla.project.itinerary.Finder; +import fr.u_paris.gla.project.itinerary.Parse; +import fr.u_paris.gla.project.itinerary.Path; +import fr.u_paris.gla.project.itinerary.Stop; + /** Simple application model. * * @author Emmanuel Bigeon */ @@ -60,9 +66,31 @@ public class App { showLogo(); } } + }else{ + testRelease(); } } + public static void testRelease(){ + Parse parse = new Parse(); + parse.parseFiles(); + Stop source = parse.getTmp().get("Porte d'Ivry").get(0); + Stop destination = parse.getTmp().get("Châtelet").get(0); + System.out.println("Itinéraire de Porte d'Ivry à Châtelet"); + List result = parse.getItinerary(source, destination, 43200); + for(Path element : result){ + System.out.println(element.getCurrentStop()); + } + System.out.println("°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°"); + System.out.println("Itinéraire de Porte d'Ivry à Châtelet"); + source = parse.getTmp().get("Saint-Jacques").get(0); + destination = parse.getTmp().get("Porte d'Ivry").get(0); + result = parse.getItinerary(source, destination, 43200); + for(Path element : result){ + System.out.println(element.getCurrentStop()); + } + + } /** @param out the output stream */ public static void printAppInfos(PrintStream out) { Properties props = readApplicationProperties(); diff --git a/src/main/java/fr/u_paris/gla/project/itinerary/Parse.java b/src/main/java/fr/u_paris/gla/project/itinerary/Parse.java index 1b9f257..5f97384 100644 --- a/src/main/java/fr/u_paris/gla/project/itinerary/Parse.java +++ b/src/main/java/fr/u_paris/gla/project/itinerary/Parse.java @@ -59,6 +59,9 @@ public class Parse { return new double[] {Double.parseDouble(stringCoords[0]), Double.parseDouble(stringCoords[1])}; } + public HashMap> getTmp(){ + return tmp; + } /** * Searchs for a stop with the same name and GPS coordinates in the graph, and creates it if non existant * @param nodes a graph of the stops From 9c04f4f95c472485f3713a0e8a7615eec35eaec5 Mon Sep 17 00:00:00 2001 From: MAMBILA TETE jean philipp <@mambilat> Date: Mon, 29 Apr 2024 18:11:37 +0200 Subject: [PATCH 7/8] [feat] itinerary support in API calls maybe --- .../java/fr/u_paris/gla/project/gui/View.java | 58 ++++++++++++++----- 1 file changed, 44 insertions(+), 14 deletions(-) diff --git a/src/main/java/fr/u_paris/gla/project/gui/View.java b/src/main/java/fr/u_paris/gla/project/gui/View.java index 3db7c01..bd7ec1c 100644 --- a/src/main/java/fr/u_paris/gla/project/gui/View.java +++ b/src/main/java/fr/u_paris/gla/project/gui/View.java @@ -1,5 +1,6 @@ package fr.u_paris.gla.project.gui; +import fr.u_paris.gla.project.itinerary.Path; import fr.u_paris.gla.project.itinerary.Stop; import javax.swing.*; @@ -56,6 +57,8 @@ public class View extends JFrame { private ArrayList searchRes; + private ArrayList searchResPath; + private int count = 0; @@ -177,7 +180,7 @@ public class View extends JFrame { Itinerary.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - LoadSearchResult(s, modelItinerary); + LoadSearchResultItinerary(searchResPath, modelItinerary); CardPanel.removeAll(); CardPanel.add(ItineraryPanel); @@ -321,29 +324,56 @@ public class View extends JFrame { tableStops.revalidate(); tableStops.repaint(); - - tableItinerary.revalidate(); - tableItinerary.repaint(); - paneStops.setViewportView(tableStops); paneStops.revalidate(); paneStops.repaint(); - - - paneItinerary.setViewportView(tableItinerary); - paneItinerary.revalidate(); - paneItinerary.repaint(); - - NetworkPanel.revalidate(); NetworkPanel.repaint(); + + } + + public void LoadSearchResultItinerary(ArrayList paths, DefaultTableModel model){ + // Clear existing rows from the table + int cols = model.getColumnCount(); + model.setRowCount(0); + model.setColumnCount(cols); + + + // Add new rows based on the search results + count = 0; + Path last = null; + for (Path path : paths) { + // Add a row to the table with Stop's line in the first column and Stop's name in the second column + model.addRow(new Object[]{path.getLine(), path.getCurrentStop(), path.getStartTime()}); + + ++count; + last = path; + } + if (last != null) model.addRow(new Object[]{last.getLine(), last.getNextStop()}); + + System.out.println(paths); + for (int i = 0; i < model.getRowCount(); i++) { + for (int j = 0; j < model.getColumnCount(); j++) { + System.out.print("valeur at coord " + i +";" + j +": " + model.getValueAt(i, j) + "\t"); + } + System.out.println(); + } + + System.out.println(count); + + + tableItinerary.revalidate(); + tableItinerary.repaint(); + paneItinerary.setViewportView(tableItinerary); + paneItinerary.revalidate(); + paneItinerary.repaint(); ItineraryPanel.revalidate(); ItineraryPanel.repaint(); - - this.displayTableValues(model); + + } public void displayTableValues(TableModel mod) { From d44b8496e1b76631356e0c0d64a788e153f9be13 Mon Sep 17 00:00:00 2001 From: RODRIGUEZ lucas Date: Mon, 29 Apr 2024 18:20:48 +0200 Subject: [PATCH 8/8] Add a way to find a path from a location --- pom.xml | 2 +- .../project/idfm/IDFMNetworkExtractor.java | 1 + .../u_paris/gla/project/itinerary/Finder.java | 27 ++++++++++++++++--- .../u_paris/gla/project/itinerary/Graph.java | 23 +++++++++++++++- .../gla/project/itinerary/GraphNode.java | 14 ---------- .../u_paris/gla/project/itinerary/Parse.java | 2 +- .../u_paris/gla/project/itinerary/Stop.java | 7 +---- 7 files changed, 49 insertions(+), 27 deletions(-) delete mode 100644 src/main/java/fr/u_paris/gla/project/itinerary/GraphNode.java diff --git a/pom.xml b/pom.xml index ffe1949..ad0ad37 100644 --- a/pom.xml +++ b/pom.xml @@ -62,7 +62,7 @@ true ${project.build.finalName}.lib/ - fr.u_paris.gla.project.App + fr.u_paris.gla.project.itinerary.Parse diff --git a/src/main/java/fr/u_paris/gla/project/idfm/IDFMNetworkExtractor.java b/src/main/java/fr/u_paris/gla/project/idfm/IDFMNetworkExtractor.java index c3add40..263e9fd 100644 --- a/src/main/java/fr/u_paris/gla/project/idfm/IDFMNetworkExtractor.java +++ b/src/main/java/fr/u_paris/gla/project/idfm/IDFMNetworkExtractor.java @@ -18,6 +18,7 @@ import java.util.logging.Level; import java.util.logging.Logger; import java.util.stream.Stream; + /** * Code of an extractor for the data from IDF mobilite. * diff --git a/src/main/java/fr/u_paris/gla/project/itinerary/Finder.java b/src/main/java/fr/u_paris/gla/project/itinerary/Finder.java index bef9d63..31fe948 100644 --- a/src/main/java/fr/u_paris/gla/project/itinerary/Finder.java +++ b/src/main/java/fr/u_paris/gla/project/itinerary/Finder.java @@ -1,23 +1,43 @@ package fr.u_paris.gla.project.itinerary; +import fr.u_paris.gla.project.utils.GPS; + import java.util.*; public class Finder { - private Graph graph; + public Finder(Graph graph) { this.graph = graph; } + public List findPath(double from_x, double from_y, double to_x, double to_y, double startTime) { + Stop fromNode = new Stop("", "tmp_from", from_x, from_y); + Stop toNode = new Stop("", "tmp_to", to_x, to_y); + + for (Stop node : graph.getNodes()) { + double from_dst = GPS.distance(from_x, from_y, node.getLatitude(), node.getLongitude()); + double to_dst = GPS.distance(to_x, to_y, node.getLatitude(), node.getLongitude()); + Connection from_c = new Connection(node, "", from_dst, (int) ((from_dst * 1000) / Parse.WALK_SPEED)); + Connection to_c = new Connection(toNode, "", to_dst, (int) ((to_dst * 1000) / Parse.WALK_SPEED)); + graph.addConnection(fromNode, from_c); + graph.addConnection(node, to_c); + } + graph.addNode(fromNode); + graph.addNode(toNode); + + List res = findPath(fromNode, toNode, startTime); + return res; + } + /** * return a path from startNode to goalNode using A* algorithm * @param startNode * @param goalNode */ public List findPath(Stop startNode, Stop goalNode, double startTime) { - - PriorityQueue openSet = new PriorityQueue<>(Comparator.comparingDouble(GraphNode::getF)); + PriorityQueue openSet = new PriorityQueue<>(Comparator.comparingDouble(Stop::getF)); HashSet closedSet = new HashSet<>(); HashMap cameFrom = new HashMap<>(); HashMap gScore = new HashMap<>(); @@ -111,6 +131,5 @@ public class Finder { node.setF(newF); openSet.add(node); } - } diff --git a/src/main/java/fr/u_paris/gla/project/itinerary/Graph.java b/src/main/java/fr/u_paris/gla/project/itinerary/Graph.java index 795add9..2fdfa21 100644 --- a/src/main/java/fr/u_paris/gla/project/itinerary/Graph.java +++ b/src/main/java/fr/u_paris/gla/project/itinerary/Graph.java @@ -1,6 +1,6 @@ package fr.u_paris.gla.project.itinerary; -import java.util.HashMap; +import java.util.HashSet; import java.util.Map; import java.util.Set; @@ -25,4 +25,25 @@ public class Graph{ public Map> getConnections() { return connections; } + + public void addNode(Stop s) { + nodes.add(s); + } + + public void addConnection(Stop stop, Connection con) { + Set currentConnections = connections.get(stop); + if (currentConnections == null) { + HashSet set = new HashSet<>(); + set.add(con); + connections.put(stop, set); + } + else { + currentConnections.add(con); + } + } + + public void removeNode(Stop s) { + nodes.remove(s); + connections.remove(s); + } } diff --git a/src/main/java/fr/u_paris/gla/project/itinerary/GraphNode.java b/src/main/java/fr/u_paris/gla/project/itinerary/GraphNode.java deleted file mode 100644 index 175db6e..0000000 --- a/src/main/java/fr/u_paris/gla/project/itinerary/GraphNode.java +++ /dev/null @@ -1,14 +0,0 @@ -package fr.u_paris.gla.project.itinerary; - -import java.util.List; -import java.util.Set; - -public interface GraphNode { - int getId(); - double getHeuristicCost(Stop goalNode); - - Set getNeighbors(); - double getCost(Stop neighbor); - double getF(); - void setF(double value); -} diff --git a/src/main/java/fr/u_paris/gla/project/itinerary/Parse.java b/src/main/java/fr/u_paris/gla/project/itinerary/Parse.java index 5f97384..1fa083f 100644 --- a/src/main/java/fr/u_paris/gla/project/itinerary/Parse.java +++ b/src/main/java/fr/u_paris/gla/project/itinerary/Parse.java @@ -42,7 +42,7 @@ public class Parse { private static final int STOP_TIME = 30; //Walking speed in m/s - private static final double WALK_SPEED = 1.; + public static final double WALK_SPEED = 1.; private HashSet nodes = new HashSet<>(); private HashMap> connections = new HashMap<>(); diff --git a/src/main/java/fr/u_paris/gla/project/itinerary/Stop.java b/src/main/java/fr/u_paris/gla/project/itinerary/Stop.java index 6d9169c..bae0289 100644 --- a/src/main/java/fr/u_paris/gla/project/itinerary/Stop.java +++ b/src/main/java/fr/u_paris/gla/project/itinerary/Stop.java @@ -3,7 +3,7 @@ package fr.u_paris.gla.project.itinerary; import java.util.HashSet; import java.util.Set; -public class Stop implements GraphNode { +public class Stop { // The total number of stops private static int counter = 0; @@ -41,27 +41,22 @@ public class Stop implements GraphNode { '}'; } - @Override public int getId(){ return id; } - @Override public double getHeuristicCost(Stop goalNode) { return 0; } - @Override public Set getNeighbors() { return null; } - @Override public double getCost(Stop neighbor) { return 0; } - @Override public double getF() { return f; }