@@ -18,46 +18,51 @@ use webgraph::{
18
18
} ;
19
19
use webgraph_algo:: distances:: hyperball:: HyperBallBuilder ;
20
20
21
- #[ derive( Args , Debug , Clone , Copy ) ]
21
+ #[ derive( Args , Debug , Clone ) ]
22
22
#[ clap( group = ArgGroup :: new( "centralities" ) ) ]
23
23
/// Centralities that can be computed with hyperball.
24
- /// The output files will be named BASENAME.<centrality_name>.
24
+ /// To compress the result you can use named pipes or process substitution
25
+ /// like `--harmonic=>(zstd > harmonic.zstd)`.
25
26
pub struct Centralities {
26
27
/// How all the centralities will be stored.
27
28
#[ clap( long, value_enum, default_value_t = FloatVectorFormat :: Ascii ) ]
28
29
pub fmt : FloatVectorFormat ,
30
+ #[ clap( long) ]
29
31
/// How many decimal digits will be used to store centralities in text formats.
30
32
pub precision : Option < usize > ,
31
33
32
- /// Compute the approximate sum of distances and save them as BASENAME.sum_of_distances
34
+ /// Compute the approximate sum of distances and save them as at the given path.
35
+ #[ clap( long) ]
36
+ pub sum_of_distances : Option < PathBuf > ,
37
+ /// Compute the approximate number of reachable nodes and save them as at the given path.
33
38
#[ clap( long) ]
34
- pub sum_of_distances : bool ,
35
- /// Compute the approximate number of reachable nodes and save them as BASENAME.reachable_nodes
39
+ pub reachable_nodes : Option < PathBuf > ,
40
+ /// Compute the approximate harmonic centralities and save them as at the given path.
36
41
#[ clap( long) ]
37
- pub reachable_nodes : bool ,
38
- /// Compute the approximate harmonic centralities and save them as BASENAME.harmonic
42
+ pub harmonic : Option < PathBuf > ,
43
+ /// Compute the approximate closeness centralities and save them as at the given path.
39
44
#[ clap( long) ]
40
- pub harmonic : bool ,
41
- /// Compute the approximate closeness centralities and save them as BASENAME.closeness
45
+ pub closeness : Option < PathBuf > ,
42
46
#[ clap( long) ]
43
- pub closeness : bool ,
44
- // TODO!: discounted ?
45
- // TODO!: neighborhood_function ?
47
+ /// Compute the approximate neighborhood function and save it as at the given path.
48
+ /// This is at most as big as the graph diameter and stores the number of
49
+ /// paths of length 1, 2, ..., d.
50
+ pub neighborhood_function : Option < PathBuf > ,
46
51
}
47
52
48
53
impl Centralities {
49
54
pub fn should_compute_sum_of_distances ( & self ) -> bool {
50
- self . sum_of_distances || self . closeness
55
+ self . sum_of_distances . is_some ( ) || self . closeness . is_some ( )
51
56
}
52
57
pub fn should_compute_sum_of_inverse_distances ( & self ) -> bool {
53
- self . harmonic
58
+ self . harmonic . is_some ( )
54
59
}
55
60
}
56
61
57
62
#[ derive( Parser , Debug ) ]
58
63
#[ command(
59
64
name = "hyperball" ,
60
- about = "Use hyperball to compute centralities. (WORK IN PROGRESS) " ,
65
+ about = "Use hyperball to compute centralities." ,
61
66
long_about = ""
62
67
) ]
63
68
pub struct CliArgs {
@@ -176,9 +181,8 @@ pub fn hyperball<E: Endianness>(global_args: GlobalArgs, args: CliArgs) -> Resul
176
181
/// here we use a macro to avoid duplicating the code, it can't be a function
177
182
/// because different centralities have different return types
178
183
macro_rules! store_centrality {
179
- ( $flag: ident, $method: ident, $extension: literal, $description: expr) => { {
180
- if args. centralities. $flag {
181
- let path = args. basename. with_extension( $extension) ;
184
+ ( $flag: ident, $method: ident, $description: expr) => { {
185
+ if let Some ( path) = args. centralities. $flag {
182
186
log:: info!( "Saving {} to {}" , $description, path. display( ) ) ;
183
187
let value = hb. $method( ) ?;
184
188
args. centralities
@@ -188,31 +192,14 @@ pub fn hyperball<E: Endianness>(global_args: GlobalArgs, args: CliArgs) -> Resul
188
192
} } ;
189
193
}
190
194
191
- // TODO: store neighborhood function
192
-
193
- store_centrality ! (
194
- sum_of_distances,
195
- sum_of_distances,
196
- "sum_of_distances" ,
197
- "sum of distances"
198
- ) ;
199
- store_centrality ! (
200
- harmonic,
201
- harmonic_centralities,
202
- "harmonic" ,
203
- "harmonic centralities"
204
- ) ;
205
- store_centrality ! (
206
- closeness,
207
- closeness_centrality,
208
- "closeness" ,
209
- "closeness centralities"
210
- ) ;
195
+ store_centrality ! ( sum_of_distances, sum_of_distances, "sum of distances" ) ;
196
+ store_centrality ! ( harmonic, harmonic_centralities, "harmonic centralities" ) ;
197
+ store_centrality ! ( closeness, closeness_centrality, "closeness centralities" ) ;
198
+ store_centrality ! ( reachable_nodes, reachable_nodes, "reachable nodes" ) ;
211
199
store_centrality ! (
212
- reachable_nodes,
213
- reachable_nodes,
214
- "reachable_nodes" ,
215
- "reachable nodes"
200
+ neighborhood_function,
201
+ neighborhood_function,
202
+ "neighborhood function"
216
203
) ;
217
204
218
205
Ok ( ( ) )
0 commit comments