build bifurcation optimized
This commit is contained in:
parent
80d31927ae
commit
e97a517f1f
4 changed files with 146 additions and 52 deletions
|
@ -24,7 +24,7 @@ public class CSVSchedulesProvider {
|
|||
put("Bus", new int[]{11, 8, 7});
|
||||
put("Funicular", new int[]{15, 25, 20});
|
||||
put("Tram", new int[]{6, 7, 8, 9});
|
||||
put("Rail", new int[]{10, 11,15,12});
|
||||
put("Rail", new int[]{10, 11,15,12,20});
|
||||
put("Subway", new int[]{4, 2, 6,3,3,4});
|
||||
}};
|
||||
|
||||
|
|
|
@ -127,7 +127,7 @@ public class IDFMNetworkExtractor {
|
|||
Stop maisonBlanche = ligne_7.stopsMap.get("Maison Blanche");
|
||||
System.out.println(maisonBlanche.name);
|
||||
|
||||
for (BifStop nextEntry : maisonBlanche.connected) {
|
||||
for (BifStop nextEntry : maisonBlanche.connected.values()) {
|
||||
System.out.println(nextEntry.bifurc+ nextEntry.stop.name);
|
||||
}
|
||||
System.out.println("****** AFFICHAGE LIGNE ******");
|
||||
|
@ -135,7 +135,7 @@ public class IDFMNetworkExtractor {
|
|||
Stop corientin = ligne_7.stopsMap.get("Corentin Cariou");
|
||||
System.out.println(corientin.name);
|
||||
|
||||
for (BifStop nextEntry : corientin.connected) {
|
||||
for (BifStop nextEntry : corientin.connected.values()) {
|
||||
System.out.println(nextEntry.bifurc+ nextEntry.stop.name);
|
||||
}
|
||||
System.out.println("***************************");
|
||||
|
@ -154,9 +154,21 @@ public class IDFMNetworkExtractor {
|
|||
b54b.buildBifurcation();
|
||||
System.out.println(b54b.descriptions);
|
||||
System.out.println("******************Building bifurcations ************************");
|
||||
long startTime = System.currentTimeMillis();
|
||||
|
||||
for (Transport entry : transports.values()) {
|
||||
entry.buildBifurcation();
|
||||
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 ************************");
|
||||
// System.out.println("Transport size :"+transports.size());
|
||||
// System.out.println("Trace size :"+traces.size());
|
||||
|
|
|
@ -7,32 +7,46 @@ import java.util.HashMap;
|
|||
|
||||
public class Stop {
|
||||
|
||||
List<BifStop> connected = new ArrayList<>();
|
||||
Map<String, BifStop> connected = new HashMap<>();
|
||||
public String name;
|
||||
|
||||
public Stop(String n){
|
||||
name = n;
|
||||
}
|
||||
|
||||
// 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);
|
||||
// }
|
||||
public boolean isStopConnected(String stopName) {
|
||||
for (BifStop b : connected) {
|
||||
if (b.stop.name.equals(stopName)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return connected.containsKey(stopName);
|
||||
}
|
||||
|
||||
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;
|
||||
public void addConnectedStop(BifStop stop) {
|
||||
connected.put(stop.stop.name, stop);
|
||||
}
|
||||
|
||||
public BifStop getConnectedStop(String stopName) {
|
||||
return connected.get(stopName);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -2,14 +2,16 @@ package fr.u_paris.gla.project.idfm;
|
|||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.AbstractMap.SimpleEntry;
|
||||
|
||||
|
||||
public class Transport {
|
||||
Map<String, Stop> stopsMap = new LinkedHashMap<>();
|
||||
Map<String, Stop> stopsMap = new HashMap<>();
|
||||
public String name;
|
||||
public String type;
|
||||
List <TraceDescription> descriptions = new ArrayList<>();
|
||||
|
@ -38,6 +40,23 @@ public class Transport {
|
|||
// System.out.println("J'en ai trouvé "+found);
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
// System.out.println("J'en ai trouvé " + found);
|
||||
}
|
||||
|
||||
public boolean isTerminus(String stop){
|
||||
for(TraceDescription t: descriptions){
|
||||
if(stop.equals(t.first) || stop.equals(t.last))
|
||||
|
@ -61,7 +80,7 @@ public class Transport {
|
|||
|
||||
Stop current = stopsMap.get(currentStop);
|
||||
List <SimpleEntry<Boolean,List<Integer>> > solutions = new ArrayList<>();
|
||||
for(BifStop b: current.connected){
|
||||
for(BifStop b: current.connected.values()){
|
||||
if(!visitedCopy.contains(b.stop.name)){
|
||||
List<Integer> bifCopy = new ArrayList<>(bif);
|
||||
if(b.bifurc!= 0)
|
||||
|
@ -81,26 +100,75 @@ public class Transport {
|
|||
return new SimpleEntry<>(trouve,bifSol) ;
|
||||
}
|
||||
|
||||
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) );
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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<>(bif);
|
||||
if (b.bifurc != 0) {
|
||||
bifCopy.add(b.bifurc);
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
public void addStop(String start, String end, int bifurcation){
|
||||
Stop startStop = stopsMap.computeIfAbsent(start, Stop::new);
|
||||
Stop endStop = stopsMap.computeIfAbsent(end, Stop::new);
|
||||
|
||||
BifStop connectedStop = new BifStop(bifurcation, endStop);
|
||||
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) );
|
||||
|
||||
// }
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -121,17 +189,17 @@ public class Transport {
|
|||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
// 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);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
/**
|
||||
|
|
Reference in a new issue