@@ -4,36 +4,43 @@ use clap::{arg, Parser};
44use tracing:: info;
55
66use rust_q_sim:: simulation:: config:: { MetisOptions , PartitionMethod } ;
7+ use rust_q_sim:: simulation:: id;
78use rust_q_sim:: simulation:: network:: global_network:: Network ;
89
910fn main ( ) {
1011 rust_q_sim:: simulation:: logging:: init_std_out_logging ( ) ;
1112 let args = InputArgs :: parse ( ) ;
1213
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
1622 . file_name ( )
1723 . unwrap ( )
1824 . to_str ( )
1925 . unwrap ( )
2026 . split ( '.' )
2127 . collect ( ) ;
2228 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 ( ) ) ;
2430 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);
2935
3036 info ! (
3137 "Partition network: {} into {} parts" ,
32- args. in_path, args. num_parts
38+ args. net_path. to_str( ) . unwrap( ) ,
39+ args. num_parts
3340 ) ;
3441
35- let net1 = Network :: from_file (
36- & args. in_path ,
42+ let net1 = Network :: from_file_path (
43+ & args. net_path ,
3744 args. num_parts ,
3845 PartitionMethod :: Metis ( MetisOptions :: default ( ) ) ,
3946 ) ;
@@ -44,70 +51,16 @@ fn main() {
4451 ) ;
4552
4653 net1. to_file ( & out_path) ;
47- //to_file_internal_ids(&net1, &out_path_internal);
4854
4955 info ! ( "Finished partitioning Network." )
5056}
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- };
8657
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- */
10758#[ derive( Parser , Debug ) ]
10859struct InputArgs {
10960 #[ arg( short, long) ]
110- pub in_path : String ,
61+ pub net_path : PathBuf ,
62+ #[ arg( short, long) ]
63+ pub id_path : Option < PathBuf > ,
11164 #[ arg( long) ]
11265 pub num_parts : u32 ,
11366}
0 commit comments