use of org.onebusaway.utility.collections.TreeUnionFind.Sentry in project onebusaway-application-modules by camsys.
the class GtfsStopsForMergingMain method main.
public static void main(String[] args) throws IOException, ParseException {
Options options = new Options();
options.addOption(ARG_DISTANCE, true, "");
options.addOption(ARG_CONSOLIDATED, true, "");
Parser parser = new GnuParser();
CommandLine cli = parser.parse(options, args);
args = cli.getArgs();
if (args.length < 5) {
usage();
System.exit(-1);
}
double distanceThreshold = 20;
if (cli.hasOption(ARG_DISTANCE))
distanceThreshold = Double.parseDouble(cli.getOptionValue(ARG_DISTANCE));
TreeUnionFind<AgencyAndId> existingConsolidatedStops = new TreeUnionFind<AgencyAndId>();
if (cli.hasOption(ARG_CONSOLIDATED))
existingConsolidatedStops = loadExistingConsolidatedStops(cli.getOptionValue(ARG_CONSOLIDATED));
PrintWriter writer = getOutputAsWriter(args[args.length - 1]);
TreeUnionFind<AgencyAndId> union = new TreeUnionFind<AgencyAndId>();
List<Collection<Stop>> allStops = new ArrayList<Collection<Stop>>();
for (int i = 0; i < args.length - 1; i += 2) {
String path = args[i];
String agencyId = args[i + 1];
Collection<Stop> stops = readStopsFromGtfsPath(path, agencyId);
for (Collection<Stop> previousStops : allStops) {
for (Stop stopA : previousStops) {
for (Stop stopB : stops) {
double d = SphericalGeometryLibrary.distance(stopA.getLat(), stopA.getLon(), stopB.getLat(), stopB.getLon());
if (d < distanceThreshold && !existingConsolidatedStops.isSameSet(stopA.getId(), stopB.getId())) {
union.union(stopA.getId(), stopB.getId());
}
}
}
}
allStops.add(stops);
}
for (Set<AgencyAndId> set : union.getSetMembers()) {
Set<Sentry> existing = new HashSet<Sentry>();
boolean first = true;
for (AgencyAndId stopId : set) {
if (first)
first = false;
else
writer.print(' ');
if (existingConsolidatedStops.contains(stopId))
existing.add(existingConsolidatedStops.find(stopId));
writer.print(AgencyAndIdLibrary.convertToString(stopId));
}
writer.println();
for (Sentry sentry : existing) writer.println(" => " + existingConsolidatedStops.members(sentry));
writer.flush();
}
}
use of org.onebusaway.utility.collections.TreeUnionFind.Sentry in project onebusaway-application-modules by camsys.
the class StopConsolidationSuggestionsTask method run.
@Override
public void run() {
try {
double distanceThreshold = 20;
_log.info("begin stop consolidation suggestions with distanceThreshold=" + distanceThreshold);
TreeUnionFind<AgencyAndId> existingConsolidatedStops = new TreeUnionFind<AgencyAndId>();
existingConsolidatedStops = loadExistingConsolidatedStops(CONSOLIDATED_URL);
TreeUnionFind<AgencyAndId> union = new TreeUnionFind<AgencyAndId>();
List<Collection<Stop>> allStops = new ArrayList<Collection<Stop>>();
for (Agency agency : _dao.getAllAgencies()) {
Collection<Stop> stops = getStopsForAgency(_dao, agency);
for (Collection<Stop> previousStops : allStops) {
for (Stop stopA : previousStops) {
for (Stop stopB : stops) {
double d = SphericalGeometryLibrary.distance(stopA.getLat(), stopA.getLon(), stopB.getLat(), stopB.getLon());
if (d < distanceThreshold && !existingConsolidatedStops.isSameSet(stopA.getId(), stopB.getId())) {
union.union(stopA.getId(), stopB.getId());
}
}
}
}
allStops.add(stops);
}
PrintWriter writer = new PrintWriter(new OutputStreamWriter(System.out));
_logger.header("stop_consolidation_suggestions.csv", "new_stops,existing_stops");
for (Set<AgencyAndId> set : union.getSetMembers()) {
StringBuffer newStopBuffer = new StringBuffer();
StringBuffer existingStopBuffer = new StringBuffer();
Set<Sentry> existing = new HashSet<Sentry>();
boolean first = true;
for (AgencyAndId stopId : set) {
if (first)
first = false;
else {
writer.print(' ');
newStopBuffer.append(" ");
}
if (existingConsolidatedStops.contains(stopId)) {
existing.add(existingConsolidatedStops.find(stopId));
}
writer.print(AgencyAndIdLibrary.convertToString(stopId));
newStopBuffer.append(AgencyAndIdLibrary.convertToString(stopId));
}
writer.println();
for (Sentry sentry : existing) {
writer.println(" => " + existingConsolidatedStops.members(sentry));
existingStopBuffer.append(existingConsolidatedStops.members(sentry));
}
_logger.log("stop_consolidation_suggestions.csv", newStopBuffer.toString(), existingStopBuffer.toString());
writer.flush();
}
_log.info("end stop consolidation suggestions");
} catch (Exception any) {
_log.error("exception:", any);
}
}
Aggregations