Skip to content

9.6 Condense groups of your own choice

You divide the nodes into groups you choose, and get the condensed graph between the groups.

You have put the nodes of a graph into groups of your own and want the graph between the groups, for example: which package calls which, or which data center talks to which. Such a division into groups is called a partition. The graph between the groups is called the condensed graph. The groups can be:

  • methods grouped by class or package, for the calls between packages;
  • servers grouped by data center, for the traffic between data centers;
  • tasks grouped by team, for the work that passes from one team to another.

The example graph calls models the calls between the ten methods of a small program. It has an edge from each method to each method it calls. The program has eight packages: app, cli, ui, service, model, storage, json and util. Every method belongs to one of the first six, so json and util have no methods. The array packageOfpackage_ofpackageOfpackageOf holds the package of each method. Which package calls which? The picture before frames the methods by package. The picture after shows the condensed graph, which holds the calls between the packages:

The calls, grouped by package
The calls between the packages
0: main2: run1: parseArgs5: show3: load4: save6: parse7: format8: read9: writestoragemodelserviceuicliapp
0: app1: cli2: ui3: service4: model5: storage6: json7: util
Input
  • Methods of a package
Output
  • Package with its group ID
  • From a package to a package it calls
NodePartition byPackage = NodePartition.of(calls, packageOf, 8);
// 8 - json and util are empty
int groupCount = byPackage.groupCount();
int sizeOfService = byPackage.sizeOf(service); // 2
// [3, 4] - load and save
SortedIntView methodsOfService = byPackage.nodesOf(service);
// The calls between packages: an edge wherever a method of one calls a method of
// another.
Graph packageCalls = byPackage.condense();
// packageCalls: app -> [cli, ui, service], ui -> [model], service -> [model, storage]
Full example
let by_package = NodePartition::of(&calls, &package_of, 8)?;
let group_count = by_package.group_count(); // 8 - json and util are empty
let size_of_service = by_package.size_of(service); // 2
let methods_of_service = by_package.nodes_of(service); // [3, 4] - load and save
// The calls between packages: an edge wherever a method of one calls a method of
// another.
let package_calls = by_package.condense();
// package_calls: app -> [cli, ui, service], ui -> [model],
// service -> [model, storage]
Full example
const byPackage = NodePartition.of(calls, packageOf, 8);
const groupCount = byPackage.groupCount; // 8 - json and util are empty
const sizeOfService = byPackage.sizeOf(service); // 2
const methodsOfService = byPackage.nodesOf(service); // [3, 4] - load and save
// The calls between packages: an edge wherever a method of one calls a method of
// another.
const packageCalls = byPackage.condense();
// packageCalls: app -> [cli, ui, service], ui -> [model], service -> [model, storage]
Full example
NodePartition byPackage = NodePartition.Of(calls, packageOf, 8);
// 8 - json and util are empty
int groupCount = byPackage.GroupCount;
int sizeOfService = byPackage.SizeOf(service); // 2
// [3, 4] - load and save
SortedIntView methodsOfService = byPackage.NodesOf(service);
// The calls between packages: an edge wherever a method of one calls a method of
// another.
Graph packageCalls = byPackage.Condense();
// packageCalls: app -> [cli, ui, service], ui -> [model],
// service -> [model, storage]
Full example

The condensed graph packageCallspackage_callspackageCallspackageCalls has a node for each group, with the group IDs as node IDs. That makes one node for each of the eight packages. json and util have no methods and stay without edges. Calls within a package, such as main -> run, are left out. The two calls from service to model are load -> parse and save -> format. They become one edge, as in the picture after.