@@ -4,36 +4,43 @@ use clap::{arg, Parser};
4
4
use tracing:: info;
5
5
6
6
use rust_q_sim:: simulation:: config:: { MetisOptions , PartitionMethod } ;
7
+ use rust_q_sim:: simulation:: id;
7
8
use rust_q_sim:: simulation:: network:: global_network:: Network ;
8
9
9
10
fn main ( ) {
10
11
rust_q_sim:: simulation:: logging:: init_std_out_logging ( ) ;
11
12
let args = InputArgs :: parse ( ) ;
12
13
13
- let input_path = PathBuf :: from ( & args. in_path ) ;
14
- let folder = input_path. parent ( ) . unwrap ( ) ;
15
- let mut name_parts: Vec < & str > = input_path
14
+ if let Some ( id_path) = args. id_path {
15
+ id:: load_from_file ( & id_path) ;
16
+ }
17
+
18
+ //let input_path = PathBuf::from(&args.in_path);
19
+ let folder = args. net_path . parent ( ) . unwrap ( ) ;
20
+ let mut name_parts: Vec < & str > = args
21
+ . net_path
16
22
. file_name ( )
17
23
. unwrap ( )
18
24
. to_str ( )
19
25
. unwrap ( )
20
26
. split ( '.' )
21
27
. collect ( ) ;
22
28
let num_parts_string = args. num_parts . to_string ( ) ;
23
- name_parts. insert ( name_parts. len ( ) - 2 , num_parts_string. as_str ( ) ) ;
29
+ name_parts. insert ( name_parts. len ( ) - 1 , num_parts_string. as_str ( ) ) ;
24
30
let out_path = folder. join ( name_parts. join ( "." ) ) ;
25
- info ! ( "Writing to {:?}" , out_path) ;
26
- name_parts. insert ( name_parts. len ( ) - 3 , "internal-ids" ) ;
27
- let out_path_internal = folder. join ( name_parts. join ( "." ) ) ;
28
- info ! ( "Writing to {:?}" , out_path_internal) ;
31
+ // info!("Writing to {:?}", out_path);
32
+ // name_parts.insert(name_parts.len() - 3, "internal-ids");
33
+ // let out_path_internal = folder.join(name_parts.join("."));
34
+ // info!("Writing to {:?}", out_path_internal);
29
35
30
36
info ! (
31
37
"Partition network: {} into {} parts" ,
32
- args. in_path, args. num_parts
38
+ args. net_path. to_str( ) . unwrap( ) ,
39
+ args. num_parts
33
40
) ;
34
41
35
- let net1 = Network :: from_file (
36
- & args. in_path ,
42
+ let net1 = Network :: from_file_path (
43
+ & args. net_path ,
37
44
args. num_parts ,
38
45
PartitionMethod :: Metis ( MetisOptions :: default ( ) ) ,
39
46
) ;
@@ -44,70 +51,16 @@ fn main() {
44
51
) ;
45
52
46
53
net1. to_file ( & out_path) ;
47
- //to_file_internal_ids(&net1, &out_path_internal);
48
54
49
55
info ! ( "Finished partitioning Network." )
50
56
}
51
- /*
52
- fn to_file_internal_ids(network: &Network, file_path: &Path) {
53
- let mut result = IONetwork::new(None);
54
-
55
- for node in &network.nodes {
56
- let attributes = Attrs {
57
- attributes: vec![Attr {
58
- name: String::from("partition"),
59
- value: node.partition.to_string(),
60
- class: String::from("java.lang.Integer"),
61
- }],
62
- };
63
- let io_node = IONode {
64
- id: node.id.internal().to_string(),
65
- x: node.x,
66
- y: node.y,
67
- attributes: Some(attributes),
68
- };
69
- result.nodes_mut().push(io_node);
70
- }
71
-
72
- for link in &network.links {
73
- let modes = link
74
- .modes
75
- .iter()
76
- .map(|m| m.external().to_string())
77
- .reduce(|modes, mode| format!("{modes},{mode}"))
78
- .unwrap();
79
- let attributes = Attrs {
80
- attributes: vec![Attr {
81
- name: String::from("partition"),
82
- value: link.partition.to_string(),
83
- class: String::from("java.lang.Integer"),
84
- }],
85
- };
86
57
87
- let io_link = IOLink {
88
- id: link.id.internal().to_string(),
89
- from: link.from.internal().to_string(),
90
- to: link.to.external().to_string(),
91
- length: link.length,
92
- capacity: link.capacity,
93
- freespeed: link.freespeed,
94
- permlanes: link.permlanes,
95
- modes,
96
- attributes: Some(attributes),
97
- };
98
- result.links.effective_cell_size = Some(network.effective_cell_size);
99
- result.links_mut().push(io_link);
100
- }
101
-
102
- result.to_file(file_path);
103
-
104
-
105
- }
106
- */
107
58
#[ derive( Parser , Debug ) ]
108
59
struct InputArgs {
109
60
#[ arg( short, long) ]
110
- pub in_path : String ,
61
+ pub net_path : PathBuf ,
62
+ #[ arg( short, long) ]
63
+ pub id_path : Option < PathBuf > ,
111
64
#[ arg( long) ]
112
65
pub num_parts : u32 ,
113
66
}
0 commit comments