get horraire done

This commit is contained in:
AngeHerman 2024-03-25 17:52:35 +01:00
parent 16c875bb68
commit 2e42d7f7e5
8 changed files with 34423 additions and 35052 deletions

69235
prof.csv

File diff suppressed because it is too large Load diff

View file

@ -5,6 +5,7 @@ package fr.u_paris.gla.project.idfm;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.text.NumberFormat; import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
@ -44,6 +45,8 @@ public final class CSVStreamProvider {
Map<StopEntry, Set<StopEntry>> lineSegments = new HashMap<>(); Map<StopEntry, Set<StopEntry>> lineSegments = new HashMap<>();
// The transport id with its value // The transport id with its value
private Map<String, Transport> transports; private Map<String, Transport> transports;
List <TraceDescription> descriptions = new ArrayList<>();
private StopEntry start = null; private StopEntry start = null;
private StopEntry end = null; private StopEntry end = null;
@ -107,6 +110,8 @@ public final class CSVStreamProvider {
} }
TraceEntry trace = this.currentTrace.next(); TraceEntry trace = this.currentTrace.next();
id = trace.id; id = trace.id;
descriptions.clear();
descriptions.addAll(trace.descriptions);
this.currentPath = trace.getPaths().iterator(); this.currentPath = trace.getPaths().iterator();
this.line[NetworkFormat.LINE_INDEX] = trace.lname; this.line[NetworkFormat.LINE_INDEX] = trace.lname;
this.lineSegments.clear(); this.lineSegments.clear();
@ -183,6 +188,9 @@ public final class CSVStreamProvider {
transp = transports.get(id); transp = transports.get(id);
} }
transp.addStop(start_p, end_p, bifurcation); transp.addStop(start_p, end_p, bifurcation);
if(transp.descriptions.isEmpty()){
transp.addDescriptions(descriptions);
}
} }

View file

@ -1,5 +1,6 @@
package fr.u_paris.gla.project.idfm; package fr.u_paris.gla.project.idfm;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Iterator; import java.util.Iterator;
@ -28,6 +29,7 @@ public class CSVStreamSchedulesProvider {
private Iterator<StopEntry> currentSegmentEnd = Collections.emptyIterator(); private Iterator<StopEntry> currentSegmentEnd = Collections.emptyIterator();
Map<StopEntry, Set<StopEntry>> lineSegments = new HashMap<>(); Map<StopEntry, Set<StopEntry>> lineSegments = new HashMap<>();
private StopEntry start = null; private StopEntry start = null;
private StopEntry end = null; private StopEntry end = null;

View file

@ -120,6 +120,8 @@ public class IDFMNetworkExtractor {
System.out.println(transports.get("IDFM:C02060").name); System.out.println(transports.get("IDFM:C02060").name);
// Transport ligne_1 = transports.get("IDFM:C01371"); // Transport ligne_1 = transports.get("IDFM:C01371");
Transport ligne_7 = transports.get("IDFM:C01377"); Transport ligne_7 = transports.get("IDFM:C01377");
Transport rerd = transports.get("IDFM:C01728");
System.out.println("****** AFFICHAGE LIGNE ******"); System.out.println("****** AFFICHAGE LIGNE ******");
Stop maisonBlanche = ligne_7.stopsMap.get("Maison Blanche"); Stop maisonBlanche = ligne_7.stopsMap.get("Maison Blanche");
@ -128,9 +130,16 @@ public class IDFMNetworkExtractor {
for (Stop nextEntry : maisonBlanche.connected) { for (Stop nextEntry : maisonBlanche.connected) {
System.out.println(nextEntry.name); System.out.println(nextEntry.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 ***********************");
ligne_7.buildBifurcation();
rerd.buildBifurcation();
System.out.println("******************Derniere description ***********************");
System.out.println(rerd.descriptions);
} }
@ -175,6 +184,16 @@ public class IDFMNetworkExtractor {
Double.parseDouble(line[IDFM_STOPS_LAT_INDEX])); Double.parseDouble(line[IDFM_STOPS_LAT_INDEX]));
String rid = line[IDFM_STOPS_RID_INDEX]; String rid = line[IDFM_STOPS_RID_INDEX];
//Add traces description if it's empty
if (traces.keySet().contains(rid)) {
TraceEntry tmp = traces.get(rid);
if (tmp.isDescriptionEmpty()){
List<TraceDescription> descriptions = extractDescription(line[IDFM_STOPS_SCHEDULES_INDEX]);
tmp.addDescriptions(descriptions);
}
}
// Add terminus to the traces // Add terminus to the traces
if (traces.keySet().contains(rid)) { if (traces.keySet().contains(rid)) {
extractTerminus(line[IDFM_STOPS_SCHEDULES_INDEX]).forEach(t -> traces.get(rid).addTerminus(t)); extractTerminus(line[IDFM_STOPS_SCHEDULES_INDEX]).forEach(t -> traces.get(rid).addTerminus(t));
@ -257,4 +276,27 @@ public class IDFMNetworkExtractor {
return all; return all;
} }
private static List<TraceDescription> extractDescription(String JSON) {
List<TraceDescription> all = new ArrayList<>();
try {
JSONArray schedules = new JSONArray(JSON);
for (int i = 0; i < schedules.length(); i++) {
JSONObject stop = schedules.getJSONObject(i);
String from = stop.getString("from");
String to = stop.getString("to");
String first = stop.getString("first");
String last = stop.getString("last");
//We skip the lines where from equals to
// if(from.compareTo(to) != 0){
all.add(new TraceDescription(from, to, first, last));
// }
}
} catch (JSONException e) {
// Ignoring invalid element!
// e.printStackTrace();
}
return all;
}
} }

View file

@ -5,15 +5,35 @@ import java.util.Map;
import java.util.ArrayList; 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> next = new HashMap<>();
Map<String, Stop> previous = new HashMap<>(); Map<String, Stop> previous = new HashMap<>();
List<Stop> connected = new ArrayList<>(); List<Stop> connected = new ArrayList<>();
public String name; public String name;
public Stop(String n){ public Stop(String n){
name = n; name = n;
} }
public boolean isStopConnected(String stopName) {
for (Stop stop : connected) {
if (stop.name.equals(stopName)) {
return true;
} }
}
return false;
}
public Stop getStop(String stopName) {
if (this.name.equals(stopName)) {
return this;
}
for (Stop stop : connected) {
if (stop.name.equals(stopName)) {
return stop;
}
}
return null;
}
}

View file

@ -0,0 +1,24 @@
package fr.u_paris.gla.project.idfm;
import java.util.List;
import java.util.ArrayList;
public class TraceDescription {
public String from;
public String to;
public String first;
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;
}
@Override
public String toString() {
return "From: " + from + ", To: " + to + ", First: " + first + ", Last: " + last + ", Bifurcation: " + bifurcation;
}
}

View file

@ -18,6 +18,7 @@ public final class TraceEntry {
private List<String> terminus = new ArrayList<>(); private List<String> terminus = new ArrayList<>();
private List<List<StopEntry>> paths = new ArrayList<>(); private List<List<StopEntry>> paths = new ArrayList<>();
List <TraceDescription> descriptions = new ArrayList<>();
/** /**
@ -50,4 +51,16 @@ public final class TraceEntry {
public void addTerminus(String term) { public void addTerminus(String term) {
terminus.add(term); terminus.add(term);
} }
public boolean isDescriptionEmpty(){
return descriptions.isEmpty();
}
/**
* Add all the description to the current one
* @param desctipt
*/
public void addDescriptions(List<TraceDescription> desctipt){
descriptions.addAll(desctipt);
}
} }

View file

@ -2,23 +2,86 @@ package fr.u_paris.gla.project.idfm;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
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;
private boolean goingNext = true; List <TraceDescription> descriptions = new ArrayList<>();
public Transport(String n){ public Transport(String n){
name = n; name = n;
} }
public void buildBifurcation(){
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);
SimpleEntry<Boolean,List<Integer> > sol = roadToLast(debut.name, debut.name, fin.name, new ArrayList<String>(), 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))
return true;
}
return false;
}
public SimpleEntry<Boolean,List<Integer> > roadToLast(String currentStop,String first, String last, List<String> alreadyVisited, List<Integer> bif){
if(currentStop.equals(last)){
return new SimpleEntry<>(true,bif);
}
//Checker L'arrivéé a un terminus
if(isTerminus(currentStop)){
return new SimpleEntry<>(false,bif);
}
List<String> visitedCopy = new ArrayList<>(alreadyVisited);
visitedCopy.add(currentStop);
Stop current = stopsMap.get(currentStop);
int i = 1;
List <SimpleEntry<Boolean,List<Integer>> > solutions = new ArrayList<>();
for(Stop s: current.connected){
if(visitedCopy.contains(s.name)){
i--;
}else{
List<Integer> bifCopy = new ArrayList<>(bif);
if(current.connected.size() > 2)
bifCopy.add(i);
solutions.add(roadToLast(s.name, first, last, visitedCopy, bifCopy));
}
i++;
}
List<Integer> bifSol = new ArrayList<>();
boolean trouve = false;
for(SimpleEntry<Boolean,List<Integer>> se: solutions){
if(se.getKey()){
trouve = true;
bifSol = se.getValue();
}
}
return new SimpleEntry<>(trouve,bifSol) ;
}
public void addStop(String start,String end,String bifurcation){ public void addStop(String start,String end,String bifurcation){
// String saveLastEndStop = lastStop;
// if(stopsMap.size() == 0){
// stopsMap.put(start, new Stop(start));
Stop start_stop; Stop start_stop;
Stop end_stop; Stop end_stop;
if (!stopsMap.containsKey(start)){ if (!stopsMap.containsKey(start)){
@ -35,48 +98,6 @@ public class Transport {
end_stop = stopsMap.get(end); end_stop = stopsMap.get(end);
} }
start_stop.connected.add( end_stop); start_stop.connected.add( end_stop);
if(start.equals("Maison Blanche") && end.equals("Tolbiac")){
System.out.println("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$");
for (Stop nextEntry : start_stop.connected) {
System.out.println(nextEntry.name);
}
}
if(start.equals("Tolbiac") && end.equals("Maison Blanche")){
System.out.println("!!!!!!!!!!!!!!!!!!!!!!!$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$");
}
// if(stopsMap.size() == 0){
// start_stop.next.put(bifurcation, end_stop);
// }else{
// if(goingNext){
// if(start.equals("Porte Maillot") && end.equals("Les Sablons")){
// System.out.println("<<<<<<<<<<<<<<<Arrivé au probleme<<<<<<<<<<<<<<<<<<");
// System.out.println(startBeforeEnd(end, start));
// System.out.println(startBeforeEnd(start, end));
// System.out.println(end_stop.next.containsValue(start_stop));
// for (Map.Entry<String, Stop> nextEntry : end_stop.next.entrySet()) {
// System.out.println(nextEntry.getKey() + ": " + nextEntry.getValue().name);
// }
// }
// if( startBeforeEnd(start, end)){
// start_stop.next.put(bifurcation, end_stop);
// }else{
// if(end_stop.next.containsValue(start_stop)){
// goingNext = false;
// start_stop.previous.put(bifurcation, end_stop);
// }else{ //Probleme de la zone artisanale (ligne 20 du bus 56)
// start_stop.next.put(bifurcation, end_stop);
// }
// }
// }else{
// start_stop.previous.put(bifurcation, end_stop);
// }
// }
} }
@ -125,5 +146,13 @@ public class Transport {
} }
} }
/**
* Add all the description to the current one
* @param desctipt
*/
public void addDescriptions(List<TraceDescription> desctipt){
descriptions.addAll(desctipt);
}
} }