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;
|
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 {
|
public class BifStop {
|
||||||
|
// The bifurcation
|
||||||
public int bifurc;
|
public int bifurc;
|
||||||
public Stop stop;
|
public Stop stop;
|
||||||
|
|
||||||
public BifStop(int bif, Stop s){
|
public BifStop(int bif, Stop stop){
|
||||||
bifurc = bif;
|
bifurc = bif;
|
||||||
stop = s;
|
this.stop = stop;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,16 +10,9 @@ import java.time.LocalDateTime;
|
||||||
import java.text.NumberFormat;
|
import java.text.NumberFormat;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import org.apache.commons.lang3.ObjectUtils.Null;
|
|
||||||
public class CSVSchedulesProvider {
|
public class CSVSchedulesProvider {
|
||||||
private static final DateTimeFormatter HOUR_MINUTE_FORMATTER = ScheduleFormat.getTimeFormatter();
|
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[]>(){{
|
private static final HashMap<String, int[]> timings = new HashMap<String, int[]>(){{
|
||||||
put("Bus", new int[]{11, 8, 7});
|
put("Bus", new int[]{11, 8, 7});
|
||||||
put("Funicular", new int[]{15, 25, 20});
|
put("Funicular", new int[]{15, 25, 20});
|
||||||
|
@ -28,8 +21,8 @@ public class CSVSchedulesProvider {
|
||||||
put("Subway", new int[]{4, 2, 6,3,3,4});
|
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 DEFAULT_TIMING = 6;
|
||||||
// private static int MINUTES_BEFORE_LAST_DEPARTURE = 6;
|
|
||||||
private static final NumberFormat MINUTES_SECOND_FORMATTER = NumberFormat
|
private static final NumberFormat MINUTES_SECOND_FORMATTER = NumberFormat
|
||||||
.getInstance(Locale.ENGLISH);
|
.getInstance(Locale.ENGLISH);
|
||||||
|
|
||||||
|
@ -75,16 +68,15 @@ public class CSVSchedulesProvider {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Move to the the nextDescription of a Transport line
|
||||||
|
*/
|
||||||
private void skipToNextDescription() {
|
private void skipToNextDescription() {
|
||||||
if (this.currentDescription.hasNext()) {
|
if (this.currentDescription.hasNext()) {
|
||||||
TraceDescription description = this.currentDescription.next();
|
TraceDescription description = this.currentDescription.next();
|
||||||
// hours_count = 0;
|
|
||||||
// current_time = description.first;
|
|
||||||
// last_time = description.last;
|
|
||||||
currentHour = convertIntoLocalDateTime(description.first);
|
currentHour = convertIntoLocalDateTime(description.first);
|
||||||
lastHour = convertIntoLocalDateTime(description.last);
|
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){
|
if(lastHour.compareTo(currentHour) <= 0){
|
||||||
lastHour = lastHour.plusDays(1);
|
lastHour = lastHour.plusDays(1);
|
||||||
|
@ -98,18 +90,18 @@ public class CSVSchedulesProvider {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Move to the next Transport line
|
||||||
|
*/
|
||||||
private void skipToNextTransport() {
|
private void skipToNextTransport() {
|
||||||
if (this.currentTransport.hasNext()) {
|
if (this.currentTransport.hasNext()) {
|
||||||
Transport transport = this.currentTransport.next();
|
Transport transport = this.currentTransport.next();
|
||||||
this.line[ScheduleFormat.LINE_INDEX] = transport.name;
|
this.line[ScheduleFormat.LINE_INDEX] = transport.name;
|
||||||
// System.out.println("Changement de transport"+transport.name);
|
|
||||||
|
|
||||||
// transport.buildBifurcation();
|
|
||||||
current_tansport_type = transport.type;
|
current_tansport_type = transport.type;
|
||||||
this.currentDescription = transport.descriptions.iterator();
|
this.currentDescription = transport.descriptions.iterator();
|
||||||
skipToNextDescription();
|
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() {
|
private void addRandomMinutes() {
|
||||||
// System.out.println("** addM: AVANT: "+currentHour);
|
// System.out.println("** addM: AVANT: "+currentHour);
|
||||||
currentHour = currentHour.plusMinutes(pickMinute(current_tansport_type));
|
currentHour = currentHour.plusMinutes(pickMinute(current_tansport_type));
|
||||||
|
@ -131,14 +127,11 @@ public class CSVSchedulesProvider {
|
||||||
// if(debut == 7) throw new IllegalArgumentException();
|
// 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);
|
* @param transportType the type of a transport
|
||||||
|
* @return a random minute depending on the type of the transport
|
||||||
Duration difference = Duration.between(debutTime, dernierTime);
|
*/
|
||||||
return difference.toMinutes();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int pickMinute(String transportType) {
|
public static int pickMinute(String transportType) {
|
||||||
if (!timings.containsKey(transportType)) {
|
if (!timings.containsKey(transportType)) {
|
||||||
return DEFAULT_TIMING;
|
return DEFAULT_TIMING;
|
||||||
|
@ -149,9 +142,14 @@ public class CSVSchedulesProvider {
|
||||||
return temps[indexAleatoire];
|
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();
|
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);
|
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.ArrayList;
|
||||||
import java.util.HashMap;
|
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 {
|
public class Stop {
|
||||||
|
|
||||||
Map<String, BifStop> connected = new HashMap<>();
|
Map<String, BifStop> connected = new HashMap<>();
|
||||||
public String name;
|
public String name;
|
||||||
|
|
||||||
public Stop(String n){
|
public Stop(String name){
|
||||||
name = n;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
// public boolean isStopConnected(String stopName) {
|
/**
|
||||||
// // for (BifStop b : connected) {
|
* Checks is stopName is connected to this one
|
||||||
// // if (b.stop.name.equals(stopName)) {
|
* @param stopName
|
||||||
// // return true;
|
* @return True if stopName is connected to the current stop
|
||||||
// // }
|
*/
|
||||||
// // }
|
|
||||||
// // 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);
|
|
||||||
// }
|
|
||||||
public boolean isStopConnected(String stopName) {
|
public boolean isStopConnected(String stopName) {
|
||||||
return connected.containsKey(stopName);
|
return connected.containsKey(stopName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add Connected stop
|
||||||
|
* @param stop connected stop with the bifurcation needed
|
||||||
|
*/
|
||||||
public void addConnectedStop(BifStop stop) {
|
public void addConnectedStop(BifStop stop) {
|
||||||
connected.put(stop.stop.name, 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) {
|
public BifStop getConnectedStop(String stopName) {
|
||||||
return connected.get(stopName);
|
return connected.get(stopName);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,11 @@ package fr.u_paris.gla.project.idfm;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.ArrayList;
|
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 class TraceDescription {
|
||||||
public String from;
|
public String from;
|
||||||
public String to;
|
public String to;
|
||||||
|
@ -10,11 +15,11 @@ public class TraceDescription {
|
||||||
public String last;
|
public String last;
|
||||||
List<Integer> bifurcation = new ArrayList<>();
|
List<Integer> bifurcation = new ArrayList<>();
|
||||||
|
|
||||||
public TraceDescription(String fr,String t, String f, String l){
|
public TraceDescription(String from,String to, String first, String last){
|
||||||
from = fr;
|
this.from = from;
|
||||||
to = t;
|
this.to = to;
|
||||||
first = f;
|
this.first = first;
|
||||||
last = l;
|
this.last = last;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -9,30 +9,39 @@ import java.util.HashSet;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.AbstractMap.SimpleEntry;
|
import java.util.AbstractMap.SimpleEntry;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Representation of a line with its description and stops
|
||||||
|
*/
|
||||||
public class Transport {
|
public class Transport {
|
||||||
|
//All the stops of the line
|
||||||
Map<String, Stop> stopsMap = new HashMap<>();
|
Map<String, Stop> stopsMap = new HashMap<>();
|
||||||
public String name;
|
public String name;
|
||||||
public String type;
|
public String type;
|
||||||
|
|
||||||
|
//All the line descriptions (directions and schedules)
|
||||||
List <TraceDescription> descriptions = new ArrayList<>();
|
List <TraceDescription> descriptions = new ArrayList<>();
|
||||||
|
|
||||||
|
|
||||||
public Transport(String n,String t_type){
|
public Transport(String name,String type){
|
||||||
name = n;
|
this.name = name;
|
||||||
type = t_type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build the bifurcation for all the descriptions
|
||||||
|
*/
|
||||||
public void buildBifurcation(){
|
public void buildBifurcation(){
|
||||||
int found = 0;
|
// int found = 0;
|
||||||
for(TraceDescription d : descriptions){
|
for(TraceDescription d : descriptions){
|
||||||
// System.out.println("Debut est "+d.first);
|
// System.out.println("Debut est "+d.first);
|
||||||
|
|
||||||
Stop debut = stopsMap.get(d.from);
|
Stop debut = stopsMap.get(d.from);
|
||||||
Stop fin = stopsMap.get(d.to);
|
Stop fin = stopsMap.get(d.to);
|
||||||
if (debut != null && fin != null) {
|
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()) {
|
if (sol.getKey()) {
|
||||||
found++;
|
// found++;
|
||||||
d.bifurcation = sol.getValue();
|
d.bifurcation = sol.getValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,23 +49,33 @@ public class Transport {
|
||||||
// System.out.println("J'en ai trouvé "+found);
|
// System.out.println("J'en ai trouvé "+found);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build the bifurcation for all the descriptions but optimized
|
||||||
|
*/
|
||||||
public void buildBifurcationOptimzed() {
|
public void buildBifurcationOptimzed() {
|
||||||
int found = 0;
|
// int found = 0;
|
||||||
for (TraceDescription d : descriptions) {
|
for (TraceDescription d : descriptions) {
|
||||||
Stop debut = stopsMap.get(d.from);
|
Stop debut = stopsMap.get(d.from);
|
||||||
Stop fin = stopsMap.get(d.to);
|
Stop fin = stopsMap.get(d.to);
|
||||||
if (debut != null && fin != null) {
|
if (debut != null && fin != null) {
|
||||||
Set<String> alreadyVisited = new HashSet<>(); // Utiliser un HashSet pour les arrêts déjà visités
|
Set<String> alreadyVisited = new HashSet<>();
|
||||||
SimpleEntry<Boolean, List<Integer>> sol = roadToLastOptimized(debut.name, debut.name, fin.name, alreadyVisited, new ArrayList<Integer>());
|
SimpleEntry<Boolean, List<Integer>> sol = roadToLastOptimized(debut.name, fin.name, alreadyVisited, new ArrayList<Integer>());
|
||||||
if (sol.getKey()) {
|
if (sol.getKey()) {
|
||||||
found++;
|
// found++;
|
||||||
d.bifurcation = sol.getValue();
|
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){
|
public boolean isTerminus(String stop){
|
||||||
for(TraceDescription t: descriptions){
|
for(TraceDescription t: descriptions){
|
||||||
if(stop.equals(t.first) || stop.equals(t.last))
|
if(stop.equals(t.first) || stop.equals(t.last))
|
||||||
|
@ -65,15 +84,26 @@ public class Transport {
|
||||||
return false;
|
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)){
|
if(currentStop.equals(last)){
|
||||||
return new SimpleEntry<>(true,bif);
|
return new SimpleEntry<>(true,bifurcation);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Checker if the current stop is the bad terminus
|
//Checker if the current stop is the bad terminus
|
||||||
if(isTerminus(currentStop)){
|
if(isTerminus(currentStop)){
|
||||||
return new SimpleEntry<>(false,bif);
|
return new SimpleEntry<>(false,null);
|
||||||
}
|
}
|
||||||
List<String> visitedCopy = new ArrayList<>(alreadyVisited);
|
List<String> visitedCopy = new ArrayList<>(alreadyVisited);
|
||||||
visitedCopy.add(currentStop);
|
visitedCopy.add(currentStop);
|
||||||
|
@ -82,13 +112,13 @@ public class Transport {
|
||||||
List <SimpleEntry<Boolean,List<Integer>> > solutions = new ArrayList<>();
|
List <SimpleEntry<Boolean,List<Integer>> > solutions = new ArrayList<>();
|
||||||
for(BifStop b: current.connected.values()){
|
for(BifStop b: current.connected.values()){
|
||||||
if(!visitedCopy.contains(b.stop.name)){
|
if(!visitedCopy.contains(b.stop.name)){
|
||||||
List<Integer> bifCopy = new ArrayList<>(bif);
|
List<Integer> bifCopy = new ArrayList<>(bifurcation);
|
||||||
if(b.bifurc!= 0)
|
if(b.bifurc!= 0)
|
||||||
bifCopy.add(b.bifurc);
|
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<>();
|
List<Integer> bifSol = new ArrayList<>();
|
||||||
boolean trouve = false;
|
boolean trouve = false;
|
||||||
for(SimpleEntry<Boolean,List<Integer>> se: solutions){
|
for(SimpleEntry<Boolean,List<Integer>> se: solutions){
|
||||||
|
@ -100,14 +130,25 @@ public class Transport {
|
||||||
return new SimpleEntry<>(trouve,bifSol) ;
|
return new SimpleEntry<>(trouve,bifSol) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SimpleEntry<Boolean, List<Integer>> roadToLastOptimized(String currentStop, String first, String last, Set<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>> roadToLastOptimized(String currentStop, String last, Set<String> alreadyVisited, List<Integer> bifurcation) {
|
||||||
if (currentStop.equals(last)) {
|
if (currentStop.equals(last)) {
|
||||||
return new SimpleEntry<>(true, bif);
|
return new SimpleEntry<>(true, bifurcation);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Checker if the current stop is the bad terminus
|
// Checker if the current stop is the bad terminus
|
||||||
if (isTerminus(currentStop)) {
|
if (isTerminus(currentStop)) {
|
||||||
return new SimpleEntry<>(false, bif);
|
return new SimpleEntry<>(false, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
alreadyVisited.add(currentStop);
|
alreadyVisited.add(currentStop);
|
||||||
|
@ -116,11 +157,11 @@ public class Transport {
|
||||||
List<SimpleEntry<Boolean, List<Integer>>> solutions = new ArrayList<>();
|
List<SimpleEntry<Boolean, List<Integer>>> solutions = new ArrayList<>();
|
||||||
for (BifStop b : current.connected.values()) {
|
for (BifStop b : current.connected.values()) {
|
||||||
if (!alreadyVisited.contains(b.stop.name)) {
|
if (!alreadyVisited.contains(b.stop.name)) {
|
||||||
List<Integer> bifCopy = new ArrayList<>(bif);
|
List<Integer> bifCopy = new ArrayList<>(bifurcation);
|
||||||
if (b.bifurc != 0) {
|
if (b.bifurc != 0) {
|
||||||
bifCopy.add(b.bifurc);
|
bifCopy.add(b.bifurc);
|
||||||
}
|
}
|
||||||
solutions.add(roadToLastOptimized(b.stop.name, first, last, alreadyVisited, bifCopy));
|
solutions.add(roadToLastOptimized(b.stop.name, last, alreadyVisited, bifCopy));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,9 +179,15 @@ public class Transport {
|
||||||
alreadyVisited.remove(currentStop); // Remove current stop from visited after processing
|
alreadyVisited.remove(currentStop); // Remove current stop from visited after processing
|
||||||
|
|
||||||
return new SimpleEntry<>(trouve, bifSol);
|
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){
|
public void addStop(String start, String end, int bifurcation){
|
||||||
Stop startStop = stopsMap.computeIfAbsent(start, Stop::new);
|
Stop startStop = stopsMap.computeIfAbsent(start, Stop::new);
|
||||||
Stop endStop = stopsMap.computeIfAbsent(end, Stop::new);
|
Stop endStop = stopsMap.computeIfAbsent(end, Stop::new);
|
||||||
|
@ -149,58 +196,21 @@ public class Transport {
|
||||||
startStop.addConnectedStop(connectedStop);
|
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) );
|
|
||||||
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Print every stops of the line and its connections
|
||||||
* @param stopsMap
|
|
||||||
* @param start
|
|
||||||
* @param end
|
|
||||||
* @return true if the start stop has been added before the end stop
|
|
||||||
*/
|
*/
|
||||||
public boolean startBeforeEnd( String start, String end) {
|
public void printAllConnectionStops() {
|
||||||
for (String key : stopsMap.keySet()) {
|
System.out.println("Affichage des couples (stop, next du stop):");
|
||||||
if (key.equals(start)) {
|
for (Map.Entry<String, Stop> entry : stopsMap.entrySet()) {
|
||||||
return true;
|
Stop stop = entry.getValue();
|
||||||
}
|
System.out.println("Stop: " + stop.name);
|
||||||
if (key.equals(end)) {
|
System.out.println("Next:");
|
||||||
return false;
|
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
|
* Add all the description to the current one
|
||||||
|
|
Reference in a new issue