Bifurcation refaite
This commit is contained in:
parent
c1c69963c8
commit
682fca4f9c
7 changed files with 77640 additions and 52 deletions
11
src/main/java/fr/u_paris/gla/project/idfm/BifStop.java
Normal file
11
src/main/java/fr/u_paris/gla/project/idfm/BifStop.java
Normal 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;
|
||||
}
|
||||
}
|
|
@ -54,7 +54,9 @@ public final class CSVStreamProvider {
|
|||
private boolean hasNext = false;
|
||||
private boolean onNext = false;
|
||||
|
||||
private String id = "";
|
||||
private String traceId = "";
|
||||
private String traceType = "";
|
||||
|
||||
/** Create the stream provider */
|
||||
public CSVStreamProvider(Iterator<TraceEntry> traces, Map<String, Transport> t) {
|
||||
this.currentTrace = traces;
|
||||
|
@ -109,7 +111,8 @@ public final class CSVStreamProvider {
|
|||
return;
|
||||
}
|
||||
TraceEntry trace = this.currentTrace.next();
|
||||
id = trace.id;
|
||||
traceId = trace.id;
|
||||
traceType = trace.type;
|
||||
descriptions.clear();
|
||||
descriptions.addAll(trace.descriptions);
|
||||
this.currentPath = trace.getPaths().iterator();
|
||||
|
@ -139,9 +142,10 @@ public final class CSVStreamProvider {
|
|||
.format(distance);
|
||||
this.line[NetworkFormat.DURATION_INDEX] = formatTime(
|
||||
(long) Math.ceil(distanceToTime(distance) * SECONDS_IN_HOURS));
|
||||
int bifurcation = this.lineSegments.get(this.start).size() - 1;
|
||||
this.line[NetworkFormat.VARIANT_INDEX] = Integer
|
||||
.toString(this.lineSegments.get(this.start).size() - 1);
|
||||
fillTransports();
|
||||
.toString(bifurcation);
|
||||
fillTransports(bifurcation);
|
||||
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);
|
||||
}
|
||||
|
||||
private void fillTransports() {
|
||||
private void fillTransports(int bif) {
|
||||
String nameTransport = this.line[NetworkFormat.LINE_INDEX];
|
||||
String start_p = this.line[NetworkFormat.START_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;
|
||||
if(!transports.containsKey(id)){
|
||||
transp = new Transport(nameTransport);
|
||||
transports.put(id, transp);
|
||||
if(!transports.containsKey(traceId)){
|
||||
transp = new Transport(nameTransport,traceType);
|
||||
transports.put(traceId, transp);
|
||||
}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()){
|
||||
transp.addDescriptions(descriptions);
|
||||
}
|
||||
|
|
|
@ -38,6 +38,7 @@ public class IDFMNetworkExtractor {
|
|||
private static final int IDFM_TRACE_ID_INDEX = 0;
|
||||
private static final int IDFM_TRACE_SNAME_INDEX = 1;
|
||||
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_SCHEDULES_INDEX = 3;
|
||||
|
@ -124,8 +125,16 @@ public class IDFMNetworkExtractor {
|
|||
Stop maisonBlanche = ligne_7.stopsMap.get("Maison Blanche");
|
||||
System.out.println(maisonBlanche.name);
|
||||
|
||||
for (Stop nextEntry : maisonBlanche.connected) {
|
||||
System.out.println(nextEntry.name);
|
||||
for (BifStop nextEntry : maisonBlanche.connected) {
|
||||
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("****** AFFICHAGE Description ******");
|
||||
|
@ -133,10 +142,12 @@ public class IDFMNetworkExtractor {
|
|||
// System.out.println("****** AFFICHAGE Description False ******");
|
||||
// System.out.println(ligne_7.descriptions);
|
||||
System.out.println("****************** Build la path ***********************");
|
||||
System.out.println(ligne_7.type);
|
||||
System.out.println(rerd.type);
|
||||
ligne_7.buildBifurcation();
|
||||
rerd.buildBifurcation();
|
||||
System.out.println("******************Derniere description ***********************");
|
||||
System.out.println(rerd.descriptions);
|
||||
System.out.println(ligne_7.descriptions);
|
||||
|
||||
// Write into args[1]
|
||||
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) {
|
||||
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]);
|
||||
entry.getPaths().addAll(buildPaths);
|
||||
if (buildPaths.isEmpty()) {
|
||||
|
|
|
@ -6,9 +6,8 @@ import java.util.ArrayList;
|
|||
import java.util.HashMap;
|
||||
|
||||
public class Stop {
|
||||
Map<String, Stop> next = new HashMap<>();
|
||||
Map<String, Stop> previous = new HashMap<>();
|
||||
List<Stop> connected = new ArrayList<>();
|
||||
|
||||
List<BifStop> connected = new ArrayList<>();
|
||||
public String name;
|
||||
|
||||
public Stop(String n){
|
||||
|
@ -16,8 +15,8 @@ public class Stop {
|
|||
}
|
||||
|
||||
public boolean isStopConnected(String stopName) {
|
||||
for (Stop stop : connected) {
|
||||
if (stop.name.equals(stopName)) {
|
||||
for (BifStop b : connected) {
|
||||
if (b.stop.name.equals(stopName)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -28,9 +27,9 @@ public class Stop {
|
|||
if (this.name.equals(stopName)) {
|
||||
return this;
|
||||
}
|
||||
for (Stop stop : connected) {
|
||||
if (stop.name.equals(stopName)) {
|
||||
return stop;
|
||||
for (BifStop b : connected) {
|
||||
if (b.stop.name.equals(stopName)) {
|
||||
return b.stop;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
|
|
@ -14,6 +14,9 @@ import java.util.List;
|
|||
public final class TraceEntry {
|
||||
public final String lname;
|
||||
public final String id;
|
||||
public final String type;
|
||||
|
||||
|
||||
|
||||
|
||||
private List<String> terminus = new ArrayList<>();
|
||||
|
@ -26,10 +29,11 @@ public final class TraceEntry {
|
|||
*
|
||||
* @param lname the name of the line
|
||||
*/
|
||||
public TraceEntry(String lname,String ident) {
|
||||
public TraceEntry(String lname,String ident,String t_type) {
|
||||
super();
|
||||
this.lname = lname;
|
||||
this.id = ident;
|
||||
this.type = t_type;
|
||||
}
|
||||
|
||||
// FIXME list of lists are bad practice in direct access...
|
||||
|
|
|
@ -11,11 +11,13 @@ import java.util.AbstractMap.SimpleEntry;
|
|||
public class Transport {
|
||||
Map<String, Stop> stopsMap = new LinkedHashMap<>();
|
||||
public String name;
|
||||
public String type;
|
||||
List <TraceDescription> descriptions = new ArrayList<>();
|
||||
|
||||
|
||||
public Transport(String n){
|
||||
public Transport(String n,String t_type){
|
||||
name = n;
|
||||
type = t_type;
|
||||
}
|
||||
|
||||
public void buildBifurcation(){
|
||||
|
@ -50,7 +52,7 @@ public class Transport {
|
|||
return new SimpleEntry<>(true,bif);
|
||||
}
|
||||
|
||||
//Checker L'arrivéé a un terminus
|
||||
//Checker if the current stop is the bad terminus
|
||||
if(isTerminus(currentStop)){
|
||||
return new SimpleEntry<>(false,bif);
|
||||
}
|
||||
|
@ -58,19 +60,16 @@ public class Transport {
|
|||
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{
|
||||
for(BifStop b: current.connected){
|
||||
if(!visitedCopy.contains(b.stop.name)){
|
||||
List<Integer> bifCopy = new ArrayList<>(bif);
|
||||
if(current.connected.size() > 2)
|
||||
bifCopy.add(i);
|
||||
solutions.add(roadToLast(s.name, first, last, visitedCopy, bifCopy));
|
||||
if(b.bifurc!= 0)
|
||||
bifCopy.add(b.bifurc);
|
||||
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<>();
|
||||
boolean trouve = false;
|
||||
for(SimpleEntry<Boolean,List<Integer>> se: solutions){
|
||||
|
@ -82,7 +81,7 @@ public class Transport {
|
|||
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 end_stop;
|
||||
if (!stopsMap.containsKey(start)){
|
||||
|
@ -98,7 +97,7 @@ public class Transport {
|
|||
}else{
|
||||
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;
|
||||
}
|
||||
|
||||
public void printAllNextStops() {
|
||||
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 (Map.Entry<String, Stop> nextEntry : stop.next.entrySet()) {
|
||||
System.out.println(nextEntry.getKey() + ": " + nextEntry.getValue().name);
|
||||
for (BifStop nextEntry : stop.connected) {
|
||||
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
|
||||
|
|
Reference in a new issue