Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Promote PtNetworkSimplifier to org.matsim package #2149

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@

package org.matsim.core.network.algorithms;

import org.apache.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.matsim.api.core.v01.Id;
import org.matsim.api.core.v01.Scenario;
import org.matsim.api.core.v01.network.Link;
Expand Down Expand Up @@ -61,7 +62,7 @@
*/
public final class NetworkSimplifier {

private static final Logger log = Logger.getLogger(NetworkSimplifier.class);
private static final Logger LOG = LogManager.getLogger(NetworkSimplifier.class);
private boolean mergeLinksWithDifferentAttributes = false;
private Collection<Integer> nodeTopoToMerge = Arrays.asList( NetworkCalcTopoType.PASS1WAY , NetworkCalcTopoType.PASS2WAY );

Expand Down Expand Up @@ -133,11 +134,11 @@ private void run(final Network network, double thresholdLength, ThresholdExceede
private void run(final Network network, double thresholdLength, ThresholdExceeded type,
final BiPredicate<Link, Link> isMergeable, final BiConsumer<Tuple<Link, Link>, Link> transferAttributes) {

if(this.nodeTopoToMerge.size() == 0){
if(this.nodeTopoToMerge.isEmpty()){
throw new RuntimeException("No types of node specified. Please use setNodesToMerge to specify which nodes should be merged");
}

log.info("running " + this.getClass().getName() + " algorithm...");
LOG.info("running {} algorithm...", this.getClass().getName());

NetworkCalcTopoType nodeTopo = new NetworkCalcTopoType();
nodeTopo.run(network);
Expand Down Expand Up @@ -258,9 +259,9 @@ private void run(final Network network, double thresholdLength, ThresholdExceede
}
}

log.info(" resulting network contains " + network.getNodes().size() + " nodes and " +
network.getLinks().size() + " links.");
log.info("done.");
LOG.info(" resulting network contains {} nodes and {} links.", network.getNodes().size(),
network.getLinks().size());
LOG.info("done.");

// writes stats as a side effect
nodeTopo = new NetworkCalcTopoType();
Expand Down Expand Up @@ -359,7 +360,7 @@ private boolean eitherLinkIsShorterThanThreshold(Link linkA, Link linkB, double
/**
* Compare link attributes. Return whether they are the same or not.
*/
private boolean bothLinksHaveSameLinkStats(Link linkA, Link linkB){
public static boolean bothLinksHaveSameLinkStats(Link linkA, Link linkB) {

boolean bothLinksHaveSameLinkStats = true;

Expand All @@ -375,6 +376,10 @@ private boolean bothLinksHaveSameLinkStats(Link linkA, Link linkB){
}

public static void main(String[] args) {
if (args.length < 2) {
LOG.error("Required arguments: inNetworkFile outNetworkFile");
return;
}
final String inNetworkFile = args[ 0 ];
final String outNetworkFile = args[ 1 ];

Expand Down