Comments added for java doc
This commit is contained in:
parent
62fd2e8bcd
commit
ce8a801322
5 changed files with 179 additions and 163 deletions
|
@ -1,11 +1,18 @@
|
|||
package fr.u_paris.gla.project.idfm;
|
||||
|
||||
/**
|
||||
* A representation of a stop with the bifurcation that is needed. All stops
|
||||
* have a list of bifstop called connected. BifStop is just composed of a
|
||||
* connected stop and the bifurcation used to go from the first stop to the
|
||||
* connected one.
|
||||
*/
|
||||
public class BifStop {
|
||||
// The bifurcation
|
||||
public int bifurc;
|
||||
public Stop stop;
|
||||
|
||||
public BifStop(int bif, Stop s){
|
||||
public BifStop(int bif, Stop stop){
|
||||
bifurc = bif;
|
||||
stop = s;
|
||||
this.stop = stop;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,16 +10,9 @@ import java.time.LocalDateTime;
|
|||
import java.text.NumberFormat;
|
||||
import java.util.*;
|
||||
|
||||
import org.apache.commons.lang3.ObjectUtils.Null;
|
||||
public class CSVSchedulesProvider {
|
||||
private static final DateTimeFormatter HOUR_MINUTE_FORMATTER = ScheduleFormat.getTimeFormatter();
|
||||
// private static final HashMap<String, int[]> timings = new HashMap<String, int[]>(){{
|
||||
// put("Bus", new int[]{45, 50});
|
||||
// put("Funicular", new int[]{120, 70});
|
||||
// put("Tram", new int[]{72, 60});
|
||||
// put("Rail", new int[]{120, 60,50});
|
||||
// put("Subway", new int[]{50, 45});
|
||||
// }};
|
||||
|
||||
private static final HashMap<String, int[]> timings = new HashMap<String, int[]>(){{
|
||||
put("Bus", new int[]{11, 8, 7});
|
||||
put("Funicular", new int[]{15, 25, 20});
|
||||
|
@ -28,8 +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 int MINUTES_BEFORE_LAST_DEPARTURE = 6;
|
||||
private static final NumberFormat MINUTES_SECOND_FORMATTER = NumberFormat
|
||||
.getInstance(Locale.ENGLISH);
|
||||
|
||||
|
@ -75,16 +68,15 @@ public class CSVSchedulesProvider {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Move to the the nextDescription of a Transport line
|
||||
*/
|
||||
private void skipToNextDescription() {
|
||||
if (this.currentDescription.hasNext()) {
|
||||
TraceDescription description = this.currentDescription.next();
|
||||
// hours_count = 0;
|
||||
// current_time = description.first;
|
||||
// last_time = description.last;
|
||||
|
||||
currentHour = convertIntoLocalDateTime(description.first);
|
||||
lastHour = convertIntoLocalDateTime(description.last);
|
||||
// System.out.println("** SkipTOnextD: last hour est "+lastHour+" first est "+currentHour+" desc.last est "+description.last+ " et desc.first est "+description.first);
|
||||
|
||||
|
||||
if(lastHour.compareTo(currentHour) <= 0){
|
||||
lastHour = lastHour.plusDays(1);
|
||||
|
@ -98,18 +90,18 @@ public class CSVSchedulesProvider {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Move to the next Transport line
|
||||
*/
|
||||
private void skipToNextTransport() {
|
||||
if (this.currentTransport.hasNext()) {
|
||||
Transport transport = this.currentTransport.next();
|
||||
this.line[ScheduleFormat.LINE_INDEX] = transport.name;
|
||||
// System.out.println("Changement de transport"+transport.name);
|
||||
|
||||
// transport.buildBifurcation();
|
||||
current_tansport_type = transport.type;
|
||||
this.currentDescription = transport.descriptions.iterator();
|
||||
skipToNextDescription();
|
||||
} else {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -122,6 +114,10 @@ public class CSVSchedulesProvider {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Add random minutes for the next passage of a transport.
|
||||
* The random minutes depends on the type of the transport
|
||||
*/
|
||||
private void addRandomMinutes() {
|
||||
// System.out.println("** addM: AVANT: "+currentHour);
|
||||
currentHour = currentHour.plusMinutes(pickMinute(current_tansport_type));
|
||||
|
@ -131,14 +127,11 @@ public class CSVSchedulesProvider {
|
|||
// if(debut == 7) throw new IllegalArgumentException();
|
||||
}
|
||||
|
||||
private static long calculateDuration(String debut, String dernier) {
|
||||
LocalTime debutTime = LocalTime.parse(debut, HOUR_MINUTE_FORMATTER);
|
||||
LocalTime dernierTime = LocalTime.parse(dernier, HOUR_MINUTE_FORMATTER);
|
||||
|
||||
Duration difference = Duration.between(debutTime, dernierTime);
|
||||
return difference.toMinutes();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param transportType the type of a transport
|
||||
* @return a random minute depending on the type of the transport
|
||||
*/
|
||||
public static int pickMinute(String transportType) {
|
||||
if (!timings.containsKey(transportType)) {
|
||||
return DEFAULT_TIMING;
|
||||
|
@ -149,9 +142,14 @@ public class CSVSchedulesProvider {
|
|||
return temps[indexAleatoire];
|
||||
}
|
||||
|
||||
public static LocalDateTime convertIntoLocalDateTime(String heureMinute) {
|
||||
/**
|
||||
*
|
||||
* @param hourMinute hour and minute representation. Ex: "14:03"
|
||||
* @return a datetime of today but using hourMinute
|
||||
*/
|
||||
public static LocalDateTime convertIntoLocalDateTime(String hourMinute) {
|
||||
LocalDateTime aujourdHui = LocalDateTime.now();
|
||||
LocalTime time = LocalTime.parse(heureMinute, HOUR_MINUTE_FORMATTER);
|
||||
LocalTime time = LocalTime.parse(hourMinute, HOUR_MINUTE_FORMATTER);
|
||||
|
||||
return aujourdHui.withHour(time.getHour()).withMinute(time.getMinute()).withSecond(0).withNano(0);
|
||||
}
|
||||
|
|
|
@ -5,45 +5,41 @@ import java.util.Map;
|
|||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* A representation of a stop with its connected stop and which bifurcation
|
||||
* is needed to go to each connected stop
|
||||
*/
|
||||
public class Stop {
|
||||
|
||||
Map<String, BifStop> connected = new HashMap<>();
|
||||
public String name;
|
||||
|
||||
public Stop(String n){
|
||||
name = n;
|
||||
public Stop(String name){
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
// public boolean isStopConnected(String stopName) {
|
||||
// // for (BifStop b : connected) {
|
||||
// // if (b.stop.name.equals(stopName)) {
|
||||
// // return true;
|
||||
// // }
|
||||
// // }
|
||||
// // return false;
|
||||
// return getStop(stopName) != null;
|
||||
// }
|
||||
|
||||
// public Stop getStop(String stopName) {
|
||||
// // if (this.name.equals(stopName)) {
|
||||
// // return this;
|
||||
// // }
|
||||
// // for (BifStop b : connected) {
|
||||
// // if (b.stop.name.equals(stopName)) {
|
||||
// // return b.stop;
|
||||
// // }
|
||||
// // }
|
||||
// // return null;
|
||||
// return transport.getStopFromIndex(stopName);
|
||||
// }
|
||||
/**
|
||||
* Checks is stopName is connected to this one
|
||||
* @param stopName
|
||||
* @return True if stopName is connected to the current stop
|
||||
*/
|
||||
public boolean isStopConnected(String stopName) {
|
||||
return connected.containsKey(stopName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add Connected stop
|
||||
* @param stop connected stop with the bifurcation needed
|
||||
*/
|
||||
public void addConnectedStop(BifStop stop) {
|
||||
connected.put(stop.stop.name, stop);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the connected stop with the name : stopName
|
||||
* @param stopName
|
||||
* @return the connected stop with the name : stopName
|
||||
*/
|
||||
public BifStop getConnectedStop(String stopName) {
|
||||
return connected.get(stopName);
|
||||
}
|
||||
|
|
|
@ -3,6 +3,11 @@ package fr.u_paris.gla.project.idfm;
|
|||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* A representation of a transport description encompansing its first and last
|
||||
* stop in all of its direction, the first and last schedule and all the
|
||||
* bifurcation that direction takes. The description comes from the fourth column * of the stop csv file.
|
||||
*/
|
||||
public class TraceDescription {
|
||||
public String from;
|
||||
public String to;
|
||||
|
@ -10,11 +15,11 @@ public class TraceDescription {
|
|||
public String last;
|
||||
List<Integer> bifurcation = new ArrayList<>();
|
||||
|
||||
public TraceDescription(String fr,String t, String f, String l){
|
||||
from = fr;
|
||||
to = t;
|
||||
first = f;
|
||||
last = l;
|
||||
public TraceDescription(String from,String to, String first, String last){
|
||||
this.from = from;
|
||||
this.to = to;
|
||||
this.first = first;
|
||||
this.last = last;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -9,30 +9,39 @@ import java.util.HashSet;
|
|||
import java.util.LinkedHashMap;
|
||||
import java.util.AbstractMap.SimpleEntry;
|
||||
|
||||
|
||||
/**
|
||||
* Representation of a line with its description and stops
|
||||
*/
|
||||
public class Transport {
|
||||
//All the stops of the line
|
||||
Map<String, Stop> stopsMap = new HashMap<>();
|
||||
public String name;
|
||||
public String type;
|
||||
|
||||
//All the line descriptions (directions and schedules)
|
||||
List <TraceDescription> descriptions = new ArrayList<>();
|
||||
|
||||
|
||||
public Transport(String n,String t_type){
|
||||
name = n;
|
||||
type = t_type;
|
||||
public Transport(String name,String type){
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Build the bifurcation for all the descriptions
|
||||
*/
|
||||
public void buildBifurcation(){
|
||||
int found = 0;
|
||||
// int found = 0;
|
||||
for(TraceDescription d : descriptions){
|
||||
// System.out.println("Debut est "+d.first);
|
||||
|
||||
Stop debut = stopsMap.get(d.from);
|
||||
Stop fin = stopsMap.get(d.to);
|
||||
if (debut != null && fin != null) {
|
||||
SimpleEntry<Boolean, List<Integer>> sol = roadToLast(debut.name, debut.name, fin.name, new ArrayList<String>(), new ArrayList<Integer>());
|
||||
SimpleEntry<Boolean, List<Integer>> sol = roadToLast(debut.name, fin.name, new ArrayList<String>(), new ArrayList<Integer>());
|
||||
if (sol.getKey()) {
|
||||
found++;
|
||||
// found++;
|
||||
d.bifurcation = sol.getValue();
|
||||
}
|
||||
}
|
||||
|
@ -40,23 +49,33 @@ public class Transport {
|
|||
// System.out.println("J'en ai trouvé "+found);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Build the bifurcation for all the descriptions but optimized
|
||||
*/
|
||||
public void buildBifurcationOptimzed() {
|
||||
int found = 0;
|
||||
for (TraceDescription d : descriptions) {
|
||||
Stop debut = stopsMap.get(d.from);
|
||||
Stop fin = stopsMap.get(d.to);
|
||||
if (debut != null && fin != null) {
|
||||
Set<String> alreadyVisited = new HashSet<>(); // Utiliser un HashSet pour les arrêts déjà visités
|
||||
SimpleEntry<Boolean, List<Integer>> sol = roadToLastOptimized(debut.name, debut.name, fin.name, alreadyVisited, new ArrayList<Integer>());
|
||||
if (sol.getKey()) {
|
||||
found++;
|
||||
d.bifurcation = sol.getValue();
|
||||
// int found = 0;
|
||||
for (TraceDescription d : descriptions) {
|
||||
Stop debut = stopsMap.get(d.from);
|
||||
Stop fin = stopsMap.get(d.to);
|
||||
if (debut != null && fin != null) {
|
||||
Set<String> alreadyVisited = new HashSet<>();
|
||||
SimpleEntry<Boolean, List<Integer>> sol = roadToLastOptimized(debut.name, fin.name, alreadyVisited, new ArrayList<Integer>());
|
||||
if (sol.getKey()) {
|
||||
// found++;
|
||||
d.bifurcation = sol.getValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
// System.out.println("J'en ai trouvé " + found);
|
||||
}
|
||||
// System.out.println("J'en ai trouvé " + found);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if the stop is a terminus
|
||||
* @param stop the name of a Stop
|
||||
* @return True if the stop is a terminus
|
||||
*/
|
||||
public boolean isTerminus(String stop){
|
||||
for(TraceDescription t: descriptions){
|
||||
if(stop.equals(t.first) || stop.equals(t.last))
|
||||
|
@ -65,15 +84,26 @@ public class Transport {
|
|||
return false;
|
||||
}
|
||||
|
||||
public SimpleEntry<Boolean,List<Integer> > roadToLast(String currentStop,String first, String last, List<String> alreadyVisited, List<Integer> bif){
|
||||
|
||||
/**
|
||||
* Find the road from the currentStop to the last stop
|
||||
* @param currentStop the current stop we are visiting
|
||||
* @param last The last stop we are trying to go to
|
||||
* @param alreadyVisited All the stop we already have visisted
|
||||
* @param bif All the bifurcation encountered from the first stop to the current
|
||||
* one
|
||||
* @return True and the bifurcation if we found our road to the last stop and
|
||||
* false if we didn't
|
||||
*/
|
||||
public SimpleEntry<Boolean,List<Integer> > roadToLast(String currentStop, String last, List<String> alreadyVisited, List<Integer> bifurcation){
|
||||
|
||||
if(currentStop.equals(last)){
|
||||
return new SimpleEntry<>(true,bif);
|
||||
return new SimpleEntry<>(true,bifurcation);
|
||||
}
|
||||
|
||||
//Checker if the current stop is the bad terminus
|
||||
if(isTerminus(currentStop)){
|
||||
return new SimpleEntry<>(false,bif);
|
||||
return new SimpleEntry<>(false,null);
|
||||
}
|
||||
List<String> visitedCopy = new ArrayList<>(alreadyVisited);
|
||||
visitedCopy.add(currentStop);
|
||||
|
@ -82,13 +112,13 @@ public class Transport {
|
|||
List <SimpleEntry<Boolean,List<Integer>> > solutions = new ArrayList<>();
|
||||
for(BifStop b: current.connected.values()){
|
||||
if(!visitedCopy.contains(b.stop.name)){
|
||||
List<Integer> bifCopy = new ArrayList<>(bif);
|
||||
List<Integer> bifCopy = new ArrayList<>(bifurcation);
|
||||
if(b.bifurc!= 0)
|
||||
bifCopy.add(b.bifurc);
|
||||
solutions.add(roadToLast(b.stop.name, first, last, visitedCopy, bifCopy));
|
||||
solutions.add(roadToLast(b.stop.name, last, visitedCopy, bifCopy));
|
||||
}
|
||||
}
|
||||
//Todo: Send a list on list of integer in case there is a lot of path for the same direction
|
||||
//TODo: Send a list on list of integer in case there is a lot of path for the same direction
|
||||
List<Integer> bifSol = new ArrayList<>();
|
||||
boolean trouve = false;
|
||||
for(SimpleEntry<Boolean,List<Integer>> se: solutions){
|
||||
|
@ -100,47 +130,64 @@ public class Transport {
|
|||
return new SimpleEntry<>(trouve,bifSol) ;
|
||||
}
|
||||
|
||||
public SimpleEntry<Boolean, List<Integer>> roadToLastOptimized(String currentStop, String first, String last, Set<String> alreadyVisited, List<Integer> bif) {
|
||||
if (currentStop.equals(last)) {
|
||||
return new SimpleEntry<>(true, bif);
|
||||
}
|
||||
|
||||
// Checker if the current stop is the bad terminus
|
||||
if (isTerminus(currentStop)) {
|
||||
return new SimpleEntry<>(false, bif);
|
||||
}
|
||||
/**
|
||||
* Find the road from the currentStop to the last stop
|
||||
* @param currentStop the current stop we are visiting
|
||||
* @param last The last stop we are trying to go to
|
||||
* @param alreadyVisited All the stop we already have visisted
|
||||
* @param bif All the bifurcation encountered from the first stop to the current
|
||||
* one
|
||||
* @return True and the bifurcation if we found our road to the last stop and
|
||||
* false if we didn't
|
||||
*/
|
||||
public SimpleEntry<Boolean, List<Integer>> roadToLastOptimized(String currentStop, String last, Set<String> alreadyVisited, List<Integer> bifurcation) {
|
||||
if (currentStop.equals(last)) {
|
||||
return new SimpleEntry<>(true, bifurcation);
|
||||
}
|
||||
|
||||
alreadyVisited.add(currentStop);
|
||||
// Checker if the current stop is the bad terminus
|
||||
if (isTerminus(currentStop)) {
|
||||
return new SimpleEntry<>(false, null);
|
||||
}
|
||||
|
||||
Stop current = stopsMap.get(currentStop);
|
||||
List<SimpleEntry<Boolean, List<Integer>>> solutions = new ArrayList<>();
|
||||
for (BifStop b : current.connected.values()) {
|
||||
if (!alreadyVisited.contains(b.stop.name)) {
|
||||
List<Integer> bifCopy = new ArrayList<>(bif);
|
||||
if (b.bifurc != 0) {
|
||||
bifCopy.add(b.bifurc);
|
||||
alreadyVisited.add(currentStop);
|
||||
|
||||
Stop current = stopsMap.get(currentStop);
|
||||
List<SimpleEntry<Boolean, List<Integer>>> solutions = new ArrayList<>();
|
||||
for (BifStop b : current.connected.values()) {
|
||||
if (!alreadyVisited.contains(b.stop.name)) {
|
||||
List<Integer> bifCopy = new ArrayList<>(bifurcation);
|
||||
if (b.bifurc != 0) {
|
||||
bifCopy.add(b.bifurc);
|
||||
}
|
||||
solutions.add(roadToLastOptimized(b.stop.name, last, alreadyVisited, bifCopy));
|
||||
}
|
||||
solutions.add(roadToLastOptimized(b.stop.name, first, last, alreadyVisited, bifCopy));
|
||||
}
|
||||
|
||||
// Todo: Send a list on list of integer in case there is a lot of path for the same direction
|
||||
List<Integer> bifSol = new ArrayList<>();
|
||||
boolean trouve = false;
|
||||
for (SimpleEntry<Boolean, List<Integer>> se : solutions) {
|
||||
if (se.getKey()) {
|
||||
trouve = true;
|
||||
bifSol = se.getValue();
|
||||
break; // Exit loop if a solution is found
|
||||
}
|
||||
}
|
||||
|
||||
alreadyVisited.remove(currentStop); // Remove current stop from visited after processing
|
||||
|
||||
return new SimpleEntry<>(trouve, bifSol);
|
||||
}
|
||||
|
||||
// Todo: Send a list on list of integer in case there is a lot of path for the same direction
|
||||
List<Integer> bifSol = new ArrayList<>();
|
||||
boolean trouve = false;
|
||||
for (SimpleEntry<Boolean, List<Integer>> se : solutions) {
|
||||
if (se.getKey()) {
|
||||
trouve = true;
|
||||
bifSol = se.getValue();
|
||||
break; // Exit loop if a solution is found
|
||||
}
|
||||
}
|
||||
|
||||
alreadyVisited.remove(currentStop); // Remove current stop from visited after processing
|
||||
|
||||
return new SimpleEntry<>(trouve, bifSol);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Connect 2 stops (start, end) and add them in stopMap if they are not already in
|
||||
* @param start The name of a stop
|
||||
* @param end The name of the stop connected to the start
|
||||
* @param bifurcation The bifurcation taken to go from start stop to end stop
|
||||
*/
|
||||
public void addStop(String start, String end, int bifurcation){
|
||||
Stop startStop = stopsMap.computeIfAbsent(start, Stop::new);
|
||||
Stop endStop = stopsMap.computeIfAbsent(end, Stop::new);
|
||||
|
@ -149,58 +196,21 @@ public class Transport {
|
|||
startStop.addConnectedStop(connectedStop);
|
||||
}
|
||||
|
||||
// public void addStop(String start,String end,int bifurcation){
|
||||
// Stop start_stop;
|
||||
// Stop end_stop;
|
||||
// if (!stopsMap.containsKey(start)){
|
||||
// start_stop = new Stop(start);
|
||||
// stopsMap.put(start, start_stop);
|
||||
// }else{
|
||||
// start_stop = stopsMap.get(start);
|
||||
// }
|
||||
|
||||
// if (!stopsMap.containsKey(end)){
|
||||
// end_stop = new Stop(end);
|
||||
// stopsMap.put(end, end_stop);
|
||||
// }else{
|
||||
// end_stop = stopsMap.get(end);
|
||||
// }
|
||||
// start_stop.connected.add( new BifStop(bifurcation,end_stop) );
|
||||
|
||||
// }
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param stopsMap
|
||||
* @param start
|
||||
* @param end
|
||||
* @return true if the start stop has been added before the end stop
|
||||
* Print every stops of the line and its connections
|
||||
*/
|
||||
public boolean startBeforeEnd( String start, String end) {
|
||||
for (String key : stopsMap.keySet()) {
|
||||
if (key.equals(start)) {
|
||||
return true;
|
||||
}
|
||||
if (key.equals(end)) {
|
||||
return false;
|
||||
public void printAllConnectionStops() {
|
||||
System.out.println("Affichage des couples (stop, next du stop):");
|
||||
for (Map.Entry<String, Stop> entry : stopsMap.entrySet()) {
|
||||
Stop stop = entry.getValue();
|
||||
System.out.println("Stop: " + stop.name);
|
||||
System.out.println("Next:");
|
||||
for (BifStop nextEntry : stop.connected.values()) {
|
||||
System.out.println(nextEntry.bifurc + ": " + nextEntry.stop.name);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// public void printAllConnectionStops() {
|
||||
// System.out.println("Affichage des couples (stop, next du stop):");
|
||||
// for (Map.Entry<String, Stop> entry : stopsMap.entrySet()) {
|
||||
// Stop stop = entry.getValue();
|
||||
// System.out.println("Stop: " + stop.name);
|
||||
// System.out.println("Next:");
|
||||
// for (BifStop nextEntry : stop.connected) {
|
||||
// System.out.println(nextEntry.bifurc + ": " + nextEntry.stop.name);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
/**
|
||||
* Add all the description to the current one
|
||||
|
|
Reference in a new issue