Bifurcation refaite

This commit is contained in:
AngeHerman 2024-03-28 20:08:39 +01:00
parent c1c69963c8
commit 682fca4f9c
7 changed files with 77640 additions and 52 deletions

77572
prof.csv Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,11 @@
package fr.u_paris.gla.project.idfm;
public class BifStop {
public int bifurc;
public Stop stop;
public BifStop(int bif, Stop s){
bifurc = bif;
stop = s;
}
}

View file

@ -54,7 +54,9 @@ public final class CSVStreamProvider {
private boolean hasNext = false; private boolean hasNext = false;
private boolean onNext = false; private boolean onNext = false;
private String id = ""; private String traceId = "";
private String traceType = "";
/** Create the stream provider */ /** Create the stream provider */
public CSVStreamProvider(Iterator<TraceEntry> traces, Map<String, Transport> t) { public CSVStreamProvider(Iterator<TraceEntry> traces, Map<String, Transport> t) {
this.currentTrace = traces; this.currentTrace = traces;
@ -109,7 +111,8 @@ public final class CSVStreamProvider {
return; return;
} }
TraceEntry trace = this.currentTrace.next(); TraceEntry trace = this.currentTrace.next();
id = trace.id; traceId = trace.id;
traceType = trace.type;
descriptions.clear(); descriptions.clear();
descriptions.addAll(trace.descriptions); descriptions.addAll(trace.descriptions);
this.currentPath = trace.getPaths().iterator(); this.currentPath = trace.getPaths().iterator();
@ -139,9 +142,10 @@ public final class CSVStreamProvider {
.format(distance); .format(distance);
this.line[NetworkFormat.DURATION_INDEX] = formatTime( this.line[NetworkFormat.DURATION_INDEX] = formatTime(
(long) Math.ceil(distanceToTime(distance) * SECONDS_IN_HOURS)); (long) Math.ceil(distanceToTime(distance) * SECONDS_IN_HOURS));
int bifurcation = this.lineSegments.get(this.start).size() - 1;
this.line[NetworkFormat.VARIANT_INDEX] = Integer this.line[NetworkFormat.VARIANT_INDEX] = Integer
.toString(this.lineSegments.get(this.start).size() - 1); .toString(bifurcation);
fillTransports(); fillTransports(bifurcation);
return Arrays.copyOf(this.line, this.line.length); return Arrays.copyOf(this.line, this.line.length);
} }
@ -175,19 +179,19 @@ public final class CSVStreamProvider {
+ Math.pow(Math.min(distance, TWO_ACCELERATION_DISTANCE) / MAX_SPEED, 2); + Math.pow(Math.min(distance, TWO_ACCELERATION_DISTANCE) / MAX_SPEED, 2);
} }
private void fillTransports() { private void fillTransports(int bif) {
String nameTransport = this.line[NetworkFormat.LINE_INDEX]; String nameTransport = this.line[NetworkFormat.LINE_INDEX];
String start_p = this.line[NetworkFormat.START_INDEX]; String start_p = this.line[NetworkFormat.START_INDEX];
String end_p = this.line[NetworkFormat.STOP_INDEX]; String end_p = this.line[NetworkFormat.STOP_INDEX];
String bifurcation = this.line[NetworkFormat.VARIANT_INDEX]; // String bifurcation = this.line[NetworkFormat.VARIANT_INDEX];
Transport transp = null; Transport transp = null;
if(!transports.containsKey(id)){ if(!transports.containsKey(traceId)){
transp = new Transport(nameTransport); transp = new Transport(nameTransport,traceType);
transports.put(id, transp); transports.put(traceId, transp);
}else{ }else{
transp = transports.get(id); transp = transports.get(traceId);
} }
transp.addStop(start_p, end_p, bifurcation); transp.addStop(start_p, end_p, bif);
if(transp.descriptions.isEmpty()){ if(transp.descriptions.isEmpty()){
transp.addDescriptions(descriptions); transp.addDescriptions(descriptions);
} }

View file

@ -38,6 +38,7 @@ public class IDFMNetworkExtractor {
private static final int IDFM_TRACE_ID_INDEX = 0; private static final int IDFM_TRACE_ID_INDEX = 0;
private static final int IDFM_TRACE_SNAME_INDEX = 1; private static final int IDFM_TRACE_SNAME_INDEX = 1;
private static final int IDFM_TRACE_SHAPE_INDEX = 6; private static final int IDFM_TRACE_SHAPE_INDEX = 6;
private static final int IDFM_TRACE_TYPE_INDEX = 3;
private static final int IDFM_STOPS_RID_INDEX = 0; private static final int IDFM_STOPS_RID_INDEX = 0;
private static final int IDFM_STOPS_SCHEDULES_INDEX = 3; private static final int IDFM_STOPS_SCHEDULES_INDEX = 3;
@ -124,8 +125,16 @@ public class IDFMNetworkExtractor {
Stop maisonBlanche = ligne_7.stopsMap.get("Maison Blanche"); Stop maisonBlanche = ligne_7.stopsMap.get("Maison Blanche");
System.out.println(maisonBlanche.name); System.out.println(maisonBlanche.name);
for (Stop nextEntry : maisonBlanche.connected) { for (BifStop nextEntry : maisonBlanche.connected) {
System.out.println(nextEntry.name); 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) {
System.out.println(nextEntry.bifurc+ nextEntry.stop.name);
} }
System.out.println("***************************"); System.out.println("***************************");
// System.out.println("****** AFFICHAGE Description ******"); // System.out.println("****** AFFICHAGE Description ******");
@ -133,10 +142,12 @@ public class IDFMNetworkExtractor {
// System.out.println("****** AFFICHAGE Description False ******"); // System.out.println("****** AFFICHAGE Description False ******");
// System.out.println(ligne_7.descriptions); // System.out.println(ligne_7.descriptions);
System.out.println("****************** Build la path ***********************"); System.out.println("****************** Build la path ***********************");
System.out.println(ligne_7.type);
System.out.println(rerd.type);
ligne_7.buildBifurcation(); ligne_7.buildBifurcation();
rerd.buildBifurcation(); rerd.buildBifurcation();
System.out.println("******************Derniere description ***********************"); System.out.println("******************Derniere description ***********************");
System.out.println(rerd.descriptions); System.out.println(ligne_7.descriptions);
// Write into args[1] // Write into args[1]
CSVStreamSchedulesProvider providerschedules = new CSVStreamSchedulesProvider(traces.values().iterator(), transports); CSVStreamSchedulesProvider providerschedules = new CSVStreamSchedulesProvider(traces.values().iterator(), transports);
@ -212,7 +223,7 @@ public class IDFMNetworkExtractor {
} }
private static void addLine(String[] line, Map<String, TraceEntry> traces) { private static void addLine(String[] line, Map<String, TraceEntry> traces) {
TraceEntry entry = new TraceEntry(line[IDFM_TRACE_SNAME_INDEX], line[IDFM_TRACE_ID_INDEX]); TraceEntry entry = new TraceEntry(line[IDFM_TRACE_SNAME_INDEX], line[IDFM_TRACE_ID_INDEX],line[IDFM_TRACE_TYPE_INDEX]);
List<List<StopEntry>> buildPaths = buildPaths(line[IDFM_TRACE_SHAPE_INDEX]); List<List<StopEntry>> buildPaths = buildPaths(line[IDFM_TRACE_SHAPE_INDEX]);
entry.getPaths().addAll(buildPaths); entry.getPaths().addAll(buildPaths);
if (buildPaths.isEmpty()) { if (buildPaths.isEmpty()) {

View file

@ -6,9 +6,8 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
public class Stop { public class Stop {
Map<String, Stop> next = new HashMap<>();
Map<String, Stop> previous = new HashMap<>(); List<BifStop> connected = new ArrayList<>();
List<Stop> connected = new ArrayList<>();
public String name; public String name;
public Stop(String n){ public Stop(String n){
@ -16,8 +15,8 @@ public class Stop {
} }
public boolean isStopConnected(String stopName) { public boolean isStopConnected(String stopName) {
for (Stop stop : connected) { for (BifStop b : connected) {
if (stop.name.equals(stopName)) { if (b.stop.name.equals(stopName)) {
return true; return true;
} }
} }
@ -28,9 +27,9 @@ public class Stop {
if (this.name.equals(stopName)) { if (this.name.equals(stopName)) {
return this; return this;
} }
for (Stop stop : connected) { for (BifStop b : connected) {
if (stop.name.equals(stopName)) { if (b.stop.name.equals(stopName)) {
return stop; return b.stop;
} }
} }
return null; return null;

View file

@ -14,6 +14,9 @@ import java.util.List;
public final class TraceEntry { public final class TraceEntry {
public final String lname; public final String lname;
public final String id; public final String id;
public final String type;
private List<String> terminus = new ArrayList<>(); private List<String> terminus = new ArrayList<>();
@ -26,10 +29,11 @@ public final class TraceEntry {
* *
* @param lname the name of the line * @param lname the name of the line
*/ */
public TraceEntry(String lname,String ident) { public TraceEntry(String lname,String ident,String t_type) {
super(); super();
this.lname = lname; this.lname = lname;
this.id = ident; this.id = ident;
this.type = t_type;
} }
// FIXME list of lists are bad practice in direct access... // FIXME list of lists are bad practice in direct access...

View file

@ -11,11 +11,13 @@ import java.util.AbstractMap.SimpleEntry;
public class Transport { public class Transport {
Map<String, Stop> stopsMap = new LinkedHashMap<>(); Map<String, Stop> stopsMap = new LinkedHashMap<>();
public String name; public String name;
public String type;
List <TraceDescription> descriptions = new ArrayList<>(); List <TraceDescription> descriptions = new ArrayList<>();
public Transport(String n){ public Transport(String n,String t_type){
name = n; name = n;
type = t_type;
} }
public void buildBifurcation(){ public void buildBifurcation(){
@ -50,7 +52,7 @@ public class Transport {
return new SimpleEntry<>(true,bif); return new SimpleEntry<>(true,bif);
} }
//Checker L'arrivéé a un 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,bif);
} }
@ -58,19 +60,16 @@ public class Transport {
visitedCopy.add(currentStop); visitedCopy.add(currentStop);
Stop current = stopsMap.get(currentStop); Stop current = stopsMap.get(currentStop);
int i = 1;
List <SimpleEntry<Boolean,List<Integer>> > solutions = new ArrayList<>(); List <SimpleEntry<Boolean,List<Integer>> > solutions = new ArrayList<>();
for(Stop s: current.connected){ for(BifStop b: current.connected){
if(visitedCopy.contains(s.name)){ if(!visitedCopy.contains(b.stop.name)){
i--;
}else{
List<Integer> bifCopy = new ArrayList<>(bif); List<Integer> bifCopy = new ArrayList<>(bif);
if(current.connected.size() > 2) if(b.bifurc!= 0)
bifCopy.add(i); bifCopy.add(b.bifurc);
solutions.add(roadToLast(s.name, first, last, visitedCopy, bifCopy)); solutions.add(roadToLast(b.stop.name, first, last, visitedCopy, bifCopy));
} }
i++;
} }
//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){
@ -82,7 +81,7 @@ public class Transport {
return new SimpleEntry<>(trouve,bifSol) ; return new SimpleEntry<>(trouve,bifSol) ;
} }
public void addStop(String start,String end,String bifurcation){ public void addStop(String start,String end,int bifurcation){
Stop start_stop; Stop start_stop;
Stop end_stop; Stop end_stop;
if (!stopsMap.containsKey(start)){ if (!stopsMap.containsKey(start)){
@ -98,7 +97,7 @@ public class Transport {
}else{ }else{
end_stop = stopsMap.get(end); end_stop = stopsMap.get(end);
} }
start_stop.connected.add( end_stop); start_stop.connected.add( new BifStop(bifurcation,end_stop) );
} }
@ -122,30 +121,18 @@ public class Transport {
return false; return false;
} }
public void printAllNextStops() { public void printAllConnectionStops() {
System.out.println("Affichage des couples (stop, next du stop):"); System.out.println("Affichage des couples (stop, next du stop):");
for (Map.Entry<String, Stop> entry : stopsMap.entrySet()) { for (Map.Entry<String, Stop> entry : stopsMap.entrySet()) {
Stop stop = entry.getValue(); Stop stop = entry.getValue();
System.out.println("Stop: " + stop.name); System.out.println("Stop: " + stop.name);
System.out.println("Next:"); System.out.println("Next:");
for (Map.Entry<String, Stop> nextEntry : stop.next.entrySet()) { for (BifStop nextEntry : stop.connected) {
System.out.println(nextEntry.getKey() + ": " + nextEntry.getValue().name); System.out.println(nextEntry.bifurc + ": " + nextEntry.stop.name);
} }
} }
} }
// Méthode pour afficher tous les couples (stop, previous du stop)
public void printAllPreviousStops() {
System.out.println("Affichage des couples (stop, previous du stop):");
for (Map.Entry<String, Stop> entry : stopsMap.entrySet()) {
Stop stop = entry.getValue();
System.out.println("Stop: " + stop.name);
System.out.println("Previous:");
for (Map.Entry<String, Stop> prevEntry : stop.previous.entrySet()) {
System.out.println(prevEntry.getKey() + ": " + prevEntry.getValue().name);
}
}
}
/** /**
* Add all the description to the current one * Add all the description to the current one