本文整理汇总了Java中com.martiansoftware.jsap.Switch类的典型用法代码示例。如果您正苦于以下问题:Java Switch类的具体用法?Java Switch怎么用?Java Switch使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Switch类属于com.martiansoftware.jsap包,在下文中一共展示了Switch类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import com.martiansoftware.jsap.Switch; //导入依赖的package包/类
public static void main(final String[] arguments)
{
try
{
final SimpleJSAP jsap = new SimpleJSAP(
"Main Application",
"Demonstrate JSAP",
new Parameter[]
{new FlaggedOption("file", STRING_PARSER, NO_DEFAULT, REQUIRED, 'f', "file", "File path/name."),
new Switch("verbose", 'v', "verbose", "Requests verbose output." )});
final JSAPResult parsedResult = jsap.parse(arguments);
if (jsap.messagePrinted())
{
out.println(jsap.getHelp());
System.exit( -1 );
}
out.println("File path/name is '" + parsedResult.getString("file") + "'.");
out.println("Verbosity level is " + parsedResult.getBoolean("verbose"));
}
catch (JSAPException jsapException)
{
out.println("Exception encountered during parsing command line arguments - " + jsapException);
}
}
示例2: main
import com.martiansoftware.jsap.Switch; //导入依赖的package包/类
public static void main(String[] args) throws IOException, JSAPException {
SimpleJSAP jsap = new SimpleJSAP(GZIPArchiveReader.class.getName(), "Writes some random records on disk.",
new Parameter[] {
new Switch("fully", 'f', "fully",
"Whether to read fully the record (and do a minimal cosnsistency check)."),
new UnflaggedOption("path", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, JSAP.NOT_GREEDY,
"The path to read from."), });
JSAPResult jsapResult = jsap.parse(args);
if (jsap.messagePrinted())
System.exit(1);
final boolean fully = jsapResult.getBoolean("fully");
GZIPArchiveReader gzar = new GZIPArchiveReader(new FileInputStream(jsapResult.getString("path")));
for (;;) {
ReadEntry e = gzar.getEntry();
if (e == null)
break;
InputStream inflater = e.lazyInflater.get();
if (fully)
ByteStreams.toByteArray(inflater);
e.lazyInflater.consume();
System.out.println(e);
}
}
示例3: main
import com.martiansoftware.jsap.Switch; //导入依赖的package包/类
public static void main( final String[] arg ) throws IOException, JSAPException {
final SimpleJSAP simpleJSAP = new SimpleJSAP( JungAdapter.class.getName(), "Reads a graph with a given basename, optionally its transpose, and writes it on standard output in Pajek format.",
new Parameter[] {
new Switch( "offline", 'o', "offline", "Use the offline load method to reduce memory consumption. It usually works, but your mileage may vary." ),
new UnflaggedOption( "basename", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, JSAP.NOT_GREEDY, "The basename of the source graph." ),
new UnflaggedOption( "transpose", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.NOT_REQUIRED, JSAP.NOT_GREEDY, "The basename of the transpose. If unspecified, the JungAdapter constructor will be provided with null as a parameter. This usually works, but your mileage may vary." )
});
final JSAPResult jsapResult = simpleJSAP.parse( arg );
if ( simpleJSAP.messagePrinted() ) System.exit( 1 );
final boolean offline = jsapResult.userSpecified( "offline" );
final ImmutableGraph graph = offline ? ImmutableGraph.loadOffline( jsapResult.getString( "basename" ) ) : ImmutableGraph.load( jsapResult.getString( "basename" ) );
final ImmutableGraph transpose = jsapResult.userSpecified( "transpose" ) ? ( offline ? ImmutableGraph.loadOffline( jsapResult.getString( "transpose" ) ) : ImmutableGraph.load( jsapResult.getString( "transpose" ) ) ) : null;
final PrintWriter printWriter = new PrintWriter( System.out );
new PajekNetWriter<Integer, Long>().save( new JungAdapter( graph, transpose ), printWriter );
printWriter.flush();
}
示例4: main
import com.martiansoftware.jsap.Switch; //导入依赖的package包/类
public static void main( String arg[] ) throws IOException, JSAPException, IllegalArgumentException, ClassNotFoundException, IllegalAccessException, InvocationTargetException, InstantiationException, NoSuchMethodException {
SimpleJSAP jsap = new SimpleJSAP( SequentialHyperBall.class.getName(), "Prints an approximation of the neighbourhood function.",
new Parameter[] {
new FlaggedOption( "log2m", JSAP.INTEGER_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, 'l', "log2m", "The logarithm of the number of registers." ),
new FlaggedOption( "upperBound", JSAP.LONGSIZE_PARSER, Long.toString( Long.MAX_VALUE ), JSAP.NOT_REQUIRED, 'u', "upper-bound", "An upper bound to the number of iteration (default: the graph size)." ),
new FlaggedOption( "threshold", JSAP.DOUBLE_PARSER, Double.toString( 1E-3 ), JSAP.NOT_REQUIRED, 't', "threshould", "A threshould that will be used to stop the computation by absolute or relative increment." ),
new Switch( "spec", 's', "spec", "The source is not a basename but rather a specification of the form <ImmutableGraphImplementation>(arg,arg,...)." ),
new UnflaggedOption( "basename", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, JSAP.NOT_GREEDY, "The basename of the graph." ),
}
);
JSAPResult jsapResult = jsap.parse( arg );
if ( jsap.messagePrinted() ) System.exit( 1 );
final boolean spec = jsapResult.getBoolean( "spec" );
final String basename = jsapResult.getString( "basename" );
final ProgressLogger pl = new ProgressLogger( LOGGER );
final int log2m = jsapResult.getInt( "log2m" );
final ImmutableGraph graph = spec ? ObjectParser.fromSpec( basename, ImmutableGraph.class, GraphClassParser.PACKAGE ) : ImmutableGraph.loadOffline( basename );
SequentialHyperBall shb = new SequentialHyperBall( graph, log2m, pl, Util.randomSeed() );
TextIO.storeDoubles( shb.approximateNeighbourhoodFunction( jsapResult.getLong( "upperBound" ), jsapResult.getDouble( "threshold" ) ), System.out );
shb.close();
}
示例5: main
import com.martiansoftware.jsap.Switch; //导入依赖的package包/类
public static void main( String arg[] ) throws IOException, JSAPException, IllegalArgumentException, ClassNotFoundException, IllegalAccessException, InvocationTargetException, InstantiationException, NoSuchMethodException {
SimpleJSAP jsap = new SimpleJSAP( ExactNeighbourhoodFunction.class.getName(), "Prints the neighbourhood function.",
new Parameter[] {
new Switch( "spec", 's', "spec", "The source is not a basename but rather a specification of the form <ImmutableGraphImplementation>(arg,arg,...)." ),
new UnflaggedOption( "basename", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, JSAP.NOT_GREEDY, "The basename of the graph." ),
}
);
JSAPResult jsapResult = jsap.parse( arg );
if ( jsap.messagePrinted() ) System.exit( 1 );
final boolean spec = jsapResult.getBoolean( "spec" );
final String basename = jsapResult.getString( "basename" );
final ProgressLogger pl = new ProgressLogger( LOGGER );
final ImmutableGraph graph = spec ? ObjectParser.fromSpec( basename, ImmutableGraph.class, GraphClassParser.PACKAGE ) : ImmutableGraph.loadOffline( basename );
final ExactNeighbourhoodFunction neighbourhoodFunction = new ExactNeighbourhoodFunction( graph, pl );
pl.start( "Computing..." );
TextIO.storeDoubles( neighbourhoodFunction.neighbourhoodFunction(), System.out );
pl.done();
}
示例6: getContext
import com.martiansoftware.jsap.Switch; //导入依赖的package包/类
public VelocityContext getContext() {
VelocityContext vc = new VelocityContext();
Iterator it = params.iterator();
while(it.hasNext()) {
Object cur = it.next();
if(cur instanceof Switch) {
Switch sw = (Switch)cur;
if(result.getBoolean(sw.getID())) {
vc.put(sw.getID(), Boolean.TRUE);
}
} else {
Option param = (Option)cur;
if(param.isList()) {
Object[] paramResult = result.getObjectArray(param.getID());
if(paramResult.length > 0) {
vc.put(param.getID(), paramResult);
}
} else if (result.getObject(param.getID()) != null) {
vc.put(param.getID(), result.getObject(param.getID()));
}
}
}
return vc;
}
示例7: main
import com.martiansoftware.jsap.Switch; //导入依赖的package包/类
public static void main(final String arg[]) throws Exception {
final SimpleJSAP jsap = new SimpleJSAP(Agent.class.getName(), "Starts a BUbiNG agent (note that you must enable JMX by means of the standard Java system properties).",
new Parameter[] {
new FlaggedOption("weight", JSAP.INTEGER_PARSER, "1", JSAP.NOT_REQUIRED, 'w', "weight", "The agent weight."),
new FlaggedOption("group", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, 'g', "group", "The JGroups group identifier (must be the same for all cooperating agents)."),
new FlaggedOption("jmxHost", JSAP.STRING_PARSER, InetAddress.getLocalHost().getHostAddress(), JSAP.REQUIRED, 'h', "jmx-host", "The IP address (possibly specified by a host name) that will be used to expose the JMX RMI connector to other agents."),
new FlaggedOption("rootDir", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.NOT_REQUIRED, 'r', "root-dir", "The root directory."),
new Switch("new", 'n', "new", "Start a new crawl"),
new FlaggedOption("properties", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, 'P', "properties", "The properties used to configure the agent."),
new UnflaggedOption("name", JSAP.STRING_PARSER, JSAP.REQUIRED, "The agent name (an identifier that must be unique across the group).")
});
final JSAPResult jsapResult = jsap.parse(arg);
if (jsap.messagePrinted()) System.exit(1);
// JMX *must* be set up.
final String portProperty = System.getProperty(JMX_REMOTE_PORT_SYSTEM_PROPERTY);
if (portProperty == null) throw new IllegalArgumentException("You must specify a JMX service port using the property " + JMX_REMOTE_PORT_SYSTEM_PROPERTY);
final String name = jsapResult.getString("name");
final int weight = jsapResult.getInt("weight");
final String group = jsapResult.getString("group");
final String host = jsapResult.getString("jmxHost");
final int port = Integer.parseInt(portProperty);
final BaseConfiguration additional = new BaseConfiguration();
additional.addProperty("name", name);
additional.addProperty("group", group);
additional.addProperty("weight", Integer.toString(weight));
additional.addProperty("crawlIsNew", Boolean.valueOf(jsapResult.getBoolean("new")));
if (jsapResult.userSpecified("rootDir")) additional.addProperty("rootDir", jsapResult.getString("rootDir"));
new Agent(host, port, new RuntimeConfiguration(new StartupConfiguration(jsapResult.getString("properties"), additional)));
System.exit(0); // Kills remaining FetchingThread instances, if any.
}
示例8: main
import com.martiansoftware.jsap.Switch; //导入依赖的package包/类
public static void main(String[] args) throws JSAPException, IOException, InterruptedException {
final SimpleJSAP jsap = new SimpleJSAP(RandomReadWritesTest.class.getName(), "Writes some random records on disk.",
new Parameter[] {
new FlaggedOption("random", JSAP.INTEGER_PARSER, "100", JSAP.NOT_REQUIRED, 'r', "random", "The number of random record to sample from."),
new FlaggedOption("body", JSAP.INTSIZE_PARSER, "4K", JSAP.NOT_REQUIRED, 'b', "body", "The maximum size of the random generated body (in bytes)."),
new Switch("fully", 'f', "fully", "Whether to read fully the record (and do a minimal sequential cosnsistency check)."),
new Switch("writeonly", 'w', "writeonly", "Whether to skip the read part (if present, 'fully' will be ignored."),
new UnflaggedOption("path", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, JSAP.NOT_GREEDY, "The path to write to."),
new UnflaggedOption("records", JSAP.INTSIZE_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, JSAP.NOT_GREEDY, "The numer of records to write."),
});
final JSAPResult jsapResult = jsap.parse(args);
if (jsap.messagePrinted()) System.exit(1);
final String path = jsapResult.getString("path");
final boolean compress = path.endsWith(".gz");
final boolean fully = jsapResult.getBoolean("fully");
final int parallel = compress ? 1 : 0;
final int body = jsapResult.getInt("body");
final WarcRecord[] rnd = prepareRndRecords(jsapResult.getInt("random"), RESPONSE_PROBABILITY, MAX_NUMBER_OF_HEADERS, MAX_LENGTH_OF_HEADER, body);
final int[] sequence = writeRecords(path, jsapResult.getInt("records"), rnd, parallel);
if (! jsapResult.getBoolean("writeonly"))
readRecords(path, sequence, body, fully, compress);
}
示例9: main
import com.martiansoftware.jsap.Switch; //导入依赖的package包/类
public static void main(String[] rawArguments) throws Exception {
SimpleJSAP jsap = new SimpleJSAP(
WikipediaTextArchiveProducer.class.getName(),
"Build wikipedia graph.",
new Parameter[] {
new UnflaggedOption( "input", JSAP.STRING_PARSER, JSAP.REQUIRED,
"The pages-articles.xml input file, from Wikipedia." ),
new Switch("bzip", 'z', "bzip", "Interpret the input file as bzipped"),
new UnflaggedOption( "resolver", JSAP.STRING_PARSER, JSAP.REQUIRED,
"resolver" ),
new UnflaggedOption( "output", JSAP.STRING_PARSER, JSAP.REQUIRED,
"output graph basename" )
});
JSAPResult args = jsap.parse( rawArguments );
if ( jsap.messagePrinted() ) System.exit( 1 );
WikipediaDocumentSequence wikipediaDocumentSequence = new WikipediaDocumentSequence(
args.getString("input"),
args.getBoolean("bzip"),
"http://en.wikipedia.org/wiki/",
true, // parse text article
false // do not keep all namespaces
);
DocumentSequenceImmutableGraph g = new DocumentSequenceImmutableGraph(
wikipediaDocumentSequence,
8, // should be the anchor field
(VirtualDocumentResolver) SerializationUtils.read(args.getString("resolver"))
);
BVGraph.store(g, args.getString("output"));
}
示例10: main
import com.martiansoftware.jsap.Switch; //导入依赖的package包/类
public static void main(String[] rawArguments) throws Exception {
SimpleJSAP jsap = new SimpleJSAP(
WikipediaCategoryProducer.class.getName(),
"Read a wikipedia dump and produces 3 files with " +
"serialized Java objects: \n" +
" * pageId2Name.ser, an Int2ObjectMap from page ids to " +
"wikipedia page names \n" +
" * catName2Id.ser, an Object2IntMap from category ids to " +
"category names \n" +
" * page2cat.ser, an Int2ObjectMap from page ids to an IntSet" +
"of category ids",
new Parameter[] {
new UnflaggedOption( "input", JSAP.STRING_PARSER, JSAP.REQUIRED,
"The pages-articles.xml input file, from Wikipedia." ),
new UnflaggedOption( "basename", JSAP.STRING_PARSER, JSAP.REQUIRED,
"The basename of the output files (p.e. a Directory with / in the end)" ),
new Switch("bzip", 'z', "bzip", "Interpret the input file as bzipped"),
new Switch("verbose", 'v', "verbose", "Print every category found to StdErr")
});
// Initializing input read
JSAPResult args = jsap.parse( rawArguments );
if ( jsap.messagePrinted() ) System.exit( 1 );
WikipediaDocumentSequence wikipediaDocumentSequence = new WikipediaDocumentSequence(
args.getString("input"),
args.getBoolean("bzip"),
"http://en.wikipedia.org/wiki/", true,
true // keep all namespaces
);
WikipediaCategoryProducer reader =
new WikipediaCategoryProducer(wikipediaDocumentSequence);
reader.setPlainUrisFile(args.getString("basename") + "pages.uris");
reader.extractAllData();
reader.saveAllTo(args.getString("basename"));
}
示例11: main
import com.martiansoftware.jsap.Switch; //导入依赖的package包/类
public static void main(final String[] arg) throws IOException, JSAPException, ClassNotFoundException {
final SimpleJSAP jsap = new SimpleJSAP(ListSpeedTest.class.getName(), "Test the speed of a list",
new Parameter[] {
new Switch("random", 'r', "random", "Do a random test on at most 1 million strings."),
new UnflaggedOption("list", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, JSAP.NOT_GREEDY, "The filename for the serialised list.")
});
JSAPResult jsapResult = jsap.parse(arg);
if (jsap.messagePrinted()) return;
final String listName = jsapResult.getString("list");
final LongList list = (LongList)BinIO.loadObject(listName);
long total = 0;
int n = list.size();
for(int k = 13; k-- != 0;) {
long time = -System.currentTimeMillis();
for(int i = 0; i < n; i++) {
list.getLong(i);
if (i++ % 100000 == 0) System.out.print('.');
}
System.out.println();
time += System.currentTimeMillis();
if (k < 10) total += time;
System.out.println(time / 1E3 + "s, " + (time * 1E3) / n + " \u00b5s/item");
}
System.out.println("Average: " + Util.format(total / 10E3) + "s, " + Util.format((total * 1E3) / (10 * n)) + " \u00b5s/item");
}
示例12: main
import com.martiansoftware.jsap.Switch; //导入依赖的package包/类
public static void main( String arg[] ) throws IOException, JSAPException {
SimpleJSAP jsap = new SimpleJSAP( ErdosRenyiGraph.class.getName(), "Generates an Erd\u0151s-R\u00E9nyi random graph and stores it as a BVGraph.",
new Parameter[] {
new Switch( "loops", 'l', "loops", "Whether the graph should include self-loops." ),
new FlaggedOption( "p", JSAP.DOUBLE_PARSER, JSAP.NO_DEFAULT, JSAP.NOT_REQUIRED, 'p', "The probability of generating an arc." ),
new FlaggedOption( "m", JSAP.LONGSIZE_PARSER, JSAP.NO_DEFAULT, JSAP.NOT_REQUIRED, 'm', "The expected number of arcs." ),
new UnflaggedOption( "basename", JSAP.STRING_PARSER, JSAP.REQUIRED, "The basename of the output graph file." ),
new UnflaggedOption( "n", JSAP.INTEGER_PARSER, JSAP.REQUIRED, "The number of nodes." ),
});
JSAPResult jsapResult = jsap.parse( arg );
if ( jsap.messagePrinted() ) System.exit( 1 );
final String baseName = jsapResult.getString( "basename" );
final int n = jsapResult.getInt( "n" );
final boolean loops = jsapResult.getBoolean( "loops" );
if ( jsapResult.userSpecified( "p" ) && jsapResult.userSpecified( "m" ) ) {
System.err.println( "Options p and m cannot be specified together" );
System.exit( 1 );
}
if ( ! jsapResult.userSpecified( "p" ) && ! jsapResult.userSpecified( "m" ) ) {
System.err.println( "Exactly one of the options p and m must be specified" );
System.exit( 1 );
}
BVGraph.store( ( jsapResult.userSpecified( "p" ) ? new ErdosRenyiGraph( n, jsapResult.getDouble( "p" ), loops ) : new ErdosRenyiGraph( n, jsapResult.getLong( "m" ), loops ) ), baseName, new ProgressLogger() );
}
示例13: main
import com.martiansoftware.jsap.Switch; //导入依赖的package包/类
public static void main( String arg[] ) throws IOException, JSAPException {
SimpleJSAP jsap = new SimpleJSAP( NeighbourhoodFunction.class.getName(),
"Prints the neighbourhood function of a graph, computing it via breadth-first visits.",
new Parameter[] {
new FlaggedOption( "logInterval", JSAP.LONG_PARSER, Long.toString( ProgressLogger.DEFAULT_LOG_INTERVAL ), JSAP.NOT_REQUIRED, 'l', "log-interval", "The minimum time interval between activity logs in milliseconds." ),
new Switch( "expand", 'e', "expand", "Expand the graph to increase speed (no compression)." ),
new FlaggedOption( "threads", JSAP.INTSIZE_PARSER, "0", JSAP.NOT_REQUIRED, 'T', "threads", "The number of threads to be used. If 0, the number will be estimated automatically." ),
new UnflaggedOption( "basename", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, JSAP.NOT_GREEDY, "The basename of the graph." ),
}
);
JSAPResult jsapResult = jsap.parse( arg );
if ( jsap.messagePrinted() ) System.exit( 1 );
final String basename = jsapResult.getString( "basename" );
final int threads = jsapResult.getInt( "threads" );
ProgressLogger pl = new ProgressLogger( LOGGER, jsapResult.getLong( "logInterval" ), TimeUnit.MILLISECONDS );
ImmutableGraph g =ImmutableGraph.load( basename );
if ( jsapResult.userSpecified( "expand" ) ) g = new ArrayListMutableGraph( g ).immutableView();
TextIO.storeLongs( computeExact( g, threads, pl ), System.out );
}
示例14: main
import com.martiansoftware.jsap.Switch; //导入依赖的package包/类
public static void main( String arg[] ) throws IOException, JSAPException {
SimpleJSAP jsap = new SimpleJSAP( ConnectedComponents.class.getName(),
"Computes the connected components of a symmetric graph of given basename. The resulting data is saved " +
"in files stemmed from the given basename with extension .wcc (a list of binary integers specifying the " +
"component of each node) and .wccsizes (a list of binary integer specifying the size of each component). " +
"The symmetric graph can also be specified using a generic (non-symmetric) graph and its transpose.",
new Parameter[] {
new Switch( "sizes", 's', "sizes", "Compute component sizes." ),
new Switch( "renumber", 'r', "renumber", "Renumber components in decreasing-size order." ),
new FlaggedOption( "logInterval", JSAP.LONG_PARSER, Long.toString( ProgressLogger.DEFAULT_LOG_INTERVAL ), JSAP.NOT_REQUIRED, 'l', "log-interval", "The minimum time interval between activity logs in milliseconds." ),
new Switch( "mapped", 'm', "mapped", "Do not load the graph in main memory, but rather memory-map it." ),
new FlaggedOption( "threads", JSAP.INTSIZE_PARSER, "0", JSAP.NOT_REQUIRED, 'T', "threads", "The number of threads to be used. If 0, the number will be estimated automatically." ),
new FlaggedOption( "basenamet", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.NOT_REQUIRED, 't', "transpose", "The basename of the transpose, in case the graph is not symmetric." ),
new UnflaggedOption( "basename", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, JSAP.NOT_GREEDY, "The basename of a symmetric graph (or of a generic graph, if the transpose is provided, too)." ),
new UnflaggedOption( "resultsBasename", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.NOT_REQUIRED, JSAP.NOT_GREEDY, "The basename of the resulting files." ),
}
);
JSAPResult jsapResult = jsap.parse( arg );
if ( jsap.messagePrinted() ) System.exit( 1 );
final String basename = jsapResult.getString( "basename" );
final String basenamet = jsapResult.getString( "basenamet" );
final String resultsBasename = jsapResult.getString( "resultsBasename", basename );
final int threads = jsapResult.getInt( "threads" );
ProgressLogger pl = new ProgressLogger( LOGGER, jsapResult.getLong( "logInterval" ), TimeUnit.MILLISECONDS );
ImmutableGraph graph = jsapResult.userSpecified( "mapped" ) ? ImmutableGraph.loadMapped( basename ) : ImmutableGraph.load( basename, pl );
ImmutableGraph grapht = basenamet == null ? null : jsapResult.userSpecified( "mapped" ) ? ImmutableGraph.loadMapped( basenamet ) : ImmutableGraph.load( basenamet, pl );
final ConnectedComponents components = ConnectedComponents.compute( basenamet != null ? new UnionImmutableGraph( graph, grapht ) : graph, threads, pl );
if ( jsapResult.getBoolean( "sizes" ) || jsapResult.getBoolean( "renumber" ) ) {
final int size[] = components.computeSizes();
if ( jsapResult.getBoolean( "renumber" ) ) components.sortBySize( size );
if ( jsapResult.getBoolean( "sizes" ) ) BinIO.storeInts( size, resultsBasename + ".wccsizes" );
}
BinIO.storeInts( components.component, resultsBasename + ".wcc" );
}
示例15: main
import com.martiansoftware.jsap.Switch; //导入依赖的package包/类
public static void main( String arg[] ) throws IOException, JSAPException {
SimpleJSAP jsap = new SimpleJSAP( StronglyConnectedComponents.class.getName(),
"Computes the strongly connected components (and optionally the buckets) of a graph of given basename. The resulting data is saved " +
"in files stemmed from the given basename with extension .scc (a list of binary integers specifying the " +
"component of each node), .sccsizes (a list of binary integer specifying the size of each component) and .buckets " +
" (a serialised LongArrayBigVector specifying buckets). Please use suitable JVM options to set a large stack size.",
new Parameter[] {
new Switch( "sizes", 's', "sizes", "Compute component sizes." ),
new Switch( "renumber", 'r', "renumber", "Renumber components in decreasing-size order." ),
new Switch( "buckets", 'b', "buckets", "Compute buckets (nodes belonging to a bucket component, i.e., a terminal nondangling component)." ),
new FlaggedOption( "filter", new ObjectParser( LabelledArcFilter.class, GraphClassParser.PACKAGE ), JSAP.NO_DEFAULT, JSAP.NOT_REQUIRED, 'f', "filter", "A filter for labelled arcs; requires the provided graph to be arc labelled." ),
new FlaggedOption( "logInterval", JSAP.LONG_PARSER, Long.toString( ProgressLogger.DEFAULT_LOG_INTERVAL ), JSAP.NOT_REQUIRED, 'l', "log-interval", "The minimum time interval between activity logs in milliseconds." ),
new UnflaggedOption( "basename", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, JSAP.NOT_GREEDY, "The basename of the graph." ),
new UnflaggedOption( "resultsBasename", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.NOT_REQUIRED, JSAP.NOT_GREEDY, "The basename of the resulting files." ),
}
);
JSAPResult jsapResult = jsap.parse( arg );
if ( jsap.messagePrinted() ) System.exit( 1 );
final String basename = jsapResult.getString( "basename" );
final String resultsBasename = jsapResult.getString( "resultsBasename", basename );
final LabelledArcFilter filter = (LabelledArcFilter)jsapResult.getObject( "filter" );
ProgressLogger pl = new ProgressLogger( LOGGER, jsapResult.getLong( "logInterval" ), TimeUnit.MILLISECONDS );
final StronglyConnectedComponents components =
filter != null ? StronglyConnectedComponents.compute( ArcLabelledImmutableGraph.load( basename ), filter, jsapResult.getBoolean( "buckets" ), pl )
: StronglyConnectedComponents.compute( ImmutableGraph.load( basename ), jsapResult.getBoolean( "buckets" ), pl );
if ( jsapResult.getBoolean( "sizes" ) || jsapResult.getBoolean( "renumber" ) ) {
final int size[] = components.computeSizes();
if ( jsapResult.getBoolean( "renumber" ) ) components.sortBySize( size );
if ( jsapResult.getBoolean( "sizes" ) ) BinIO.storeInts( size, resultsBasename + ".sccsizes" );
}
BinIO.storeInts( components.component, resultsBasename + ".scc" );
if ( components.buckets != null ) BinIO.storeObject( components.buckets, resultsBasename + ".buckets" );
}