icentral_graph/insert_edge_and_update_muc.rs
1/// His disciples asked him: "What should we do for our work to be perfect?"
2///
3/// The master said to them: "be ready in every circumstance. Blessed are they
4/// who have found the strife, and who have seen the struggle with their eyes.
5///
6/// They have not killed, nor have they been killed, but they have emerged
7/// victorious."
8///
9/// Judas asked "Tell me, master, what is the beginning of the way?"
10///
11/// He said to them "Love, and goodness. If one of these had existed among the
12/// rulers, wickedness would never have come to be."
13///
14/// Matthew said "you have spoken of the end of the universe with no difficulty"
15///
16/// The master said "you have understood all things I have said to you, and you
17/// have accepted them in faith. If you know them, they are yours. If not, they
18/// are not yours.
19///
20/// They asked him "to what place are we going?"
21///
22/// He said "stand in the place you can reach."
23///
24/// If you have understood everything I have told you, you will become immortal.
25/// For you... everything.
26///
27/// - the dialogue of the savior.
28///
29crate::ix!();
30
31impl<GH> InsertEdgeUpdateMuc for Graph<GH>
32where GH
33: GraphHashMucInterface
34+ ClearMucs
35+ CreateNamedEmpty
36+ ExtendWith<GH,Error=BetweennessCentralityError>
37+ GetConnectedComponentSizes
38+ GetNeighborsForNode
39+ GetNodeIdRange
40+ IsValid
41{
42 /// case 1: both @src and @dst are in the same
43 /// muc
44 ///
45 /// then just update the graph and the
46 /// muc graph
47 ///
48 /// just update the muc and the graph
49 ///
50 fn insert_edge_and_update_muc_when_full_edge_contained_in_muc(&mut self,
51 edge: &Edge,
52 src_muc_id: MinimumUnionCycleId)
53 {
54 debug!("full edge is contained in muc");
55
56 self.mucs[src_muc_id.val()].insert_edge(&edge);
57
58 self.insert_edge(&edge);
59 }
60
61 /// case 2: @src and @dst are not in the same
62 /// muc
63 ///
64 fn insert_edge_and_update_muc_when_we_are_not_in_the_same_muc(
65 &mut self,
66 edge: &Edge,
67 src_muc_id: MinimumUnionCycleId,
68 dst_muc_id: MinimumUnionCycleId)
69 -> Result<(),BetweennessCentralityError>
70 {
71 debug!("we will insert_edge and update_muc, but we are not in the same muc");
72
73 let mut shortest_path = self.get_shortest_path(
74 edge.src,
75 edge.dst
76 )?;
77
78 let id = self.create_and_push_new_muc(
79 &shortest_path,
80 edge,
81 src_muc_id,
82 dst_muc_id
83 )?;
84
85 self.insert_edge(&edge);
86
87 // TODO updating the connection
88 // vertices must be done in a much
89 // faster way!
90 //
91 self.find_conn_verts();;
92
93 self.find_muc_subgraphs(id);
94
95 Ok(())
96 }
97
98 fn insert_edge_update_muc(&mut self, edge: &Edge) {
99
100 let src_muc_id: MinimumUnionCycleId = self.nodes_to_mucs.mucid_for_node(edge.src);
101 let dst_muc_id: MinimumUnionCycleId = self.nodes_to_mucs.mucid_for_node(edge.dst);
102
103 debug!("insert_edge_update_muc with src_muc_id={}, dst_muc_id={}", src_muc_id, dst_muc_id);
104
105 if src_muc_id == dst_muc_id {
106
107 self.insert_edge_and_update_muc_when_full_edge_contained_in_muc(
108 edge,
109 src_muc_id
110 );
111
112 } else {
113
114 self.insert_edge_and_update_muc_when_we_are_not_in_the_same_muc(
115 edge,
116 src_muc_id,
117 dst_muc_id
118 );
119 }
120 }
121}