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/gui/View.form b/src/main/java/fr/u_paris/gla/project/gui/View.form deleted file mode 100644 index 743fde1..0000000 --- a/src/main/java/fr/u_paris/gla/project/gui/View.form +++ /dev/null @@ -1,324 +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 f664200..f3a4c82 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 @@ -3,6 +3,7 @@ package fr.u_paris.gla.project.gui; import fr.u_paris.gla.project.idfm.CSVImageProvider; import fr.u_paris.gla.project.idfm.IDFMNetworkExtractor; import fr.u_paris.gla.project.idfm.ImagePair; +import fr.u_paris.gla.project.itinerary.Path; import fr.u_paris.gla.project.itinerary.Stop; import javax.swing.*; @@ -21,50 +22,146 @@ public class View extends JFrame { private static final Logger LOGGER = Logger .getLogger(IDFMNetworkExtractor.class.getName()); - 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 JMenuItem Lines; private JPanel LinesPanel; private JLabel lineLabel; private JComboBox linesComboBox; private JButton showLineButton; + private JTextField TextCoord; + private JButton ButtonCoord; + private JPanel SearchCoordPanel; + private JPanel SearchLocationPanel; + private JLabel NetworkLabel; + private JLabel FavLabel; + private JMenuBar ButtonBar; + private ArrayList StopList; private String departureCur; private String arrivalCur; - private String searchCur; + private String searchLocation; + + private String searchCoord; private ArrayList searchRes; + private ArrayList searchResPath; + private int count = 0; public View(ArrayList s) throws HeadlessException { - table = new JTable(); - 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(3, 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; setContentPane(MainPanel); @@ -77,40 +174,42 @@ 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(); + LoadSearchResultItinerary(searchResPath, modelItinerary); + CardPanel.removeAll(); + CardPanel.add(ItineraryPanel); + + CardPanel.repaint(); + CardPanel.revalidate(); } }); Lines.addActionListener(e -> { - Cardpanel.removeAll(); - Cardpanel.add(LinesPanel); - Cardpanel.repaint(); - Cardpanel.revalidate(); + CardPanel.removeAll(); + CardPanel.add(LinesPanel); + CardPanel.repaint(); + CardPanel.revalidate(); }); CSVImageProvider.getLineImageMap().forEach(p -> linesComboBox.addItem(p)); @@ -119,49 +218,66 @@ public class View extends JFrame { openWebpage(item.getValue()); }); - 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); @@ -203,15 +319,11 @@ public class View extends JFrame { View v = new View(s); } - - - - 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 count = 0; @@ -232,32 +344,61 @@ public class View extends JFrame { System.out.println(count); - table.revalidate(); - table.repaint(); - - mypane.setViewportView(table); - mypane.revalidate(); - mypane.repaint(); - + tableStops.revalidate(); + tableStops.repaint(); + paneStops.setViewportView(tableStops); + paneStops.revalidate(); + paneStops.repaint(); NetworkPanel.revalidate(); NetworkPanel.repaint(); - - - this.displayTableValues(); - } - public void displayTableValues() { - TableModel mod = table.getModel(); + 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) { 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(";"); - } System.out.println(); - } private void openWebpage(URI uri) { 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..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. * @@ -98,142 +99,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()) { @@ -245,7 +110,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/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/ItineraryCalculator.java b/src/main/java/fr/u_paris/gla/project/itinerary/Parse.java similarity index 86% 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 d272b77..1fa083f 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()); @@ -42,7 +42,11 @@ public class ItineraryCalculator { 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<>(); + private HashMap> tmp = new HashMap<>(); /** * Returns the coordinates from a String to a double array: @@ -55,6 +59,9 @@ public class ItineraryCalculator { 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 @@ -204,17 +211,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; - } - //IDFMNetworkExtractor.builFiles(); + 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 +229,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(porteivry, chatelet, 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); } } 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; }