1010package org .eclipse .elk .alg .layered .graph .transform ;
1111
1212import java .util .EnumSet ;
13+ import java .util .HashSet ;
1314import java .util .Iterator ;
1415import java .util .List ;
1516import java .util .Map ;
@@ -228,15 +229,24 @@ private void calculateMinimumGraphSize(final ElkNode elkgraph, final LGraph lgra
228229 private void importFlatGraph (final ElkNode elkgraph , final LGraph lgraph ) {
229230 // Transform the node's children, unless we're told not to
230231 int index = 0 ;
232+ HashSet <Integer > cbGroupModelOrders = new HashSet <>();
231233 for (ElkNode child : elkgraph .getChildren ()) {
232234 if (!child .getProperty (LayeredOptions .NO_LAYOUT )) {
233235 if (needsModelOrder (child )) {
234236 child .setProperty (InternalProperties .MODEL_ORDER , index );
235237 index ++;
238+ if (child .hasProperty (LayeredOptions .CONSIDER_MODEL_ORDER_GROUP_MODEL_ORDER_CYCLE_BREAKING_ID )) {
239+ cbGroupModelOrders .add (child .getProperty (LayeredOptions .CONSIDER_MODEL_ORDER_GROUP_MODEL_ORDER_CYCLE_BREAKING_ID ));
240+ }
236241 }
237242 transformNode (child , lgraph );
238243 }
239244 }
245+ // Save the maximum node model order.
246+ // This is relevant to create graph partitions based on model order and constraints.
247+ lgraph .setProperty (InternalProperties .MAX_MODEL_ORDER_NODES , index );
248+ // Save the number of model order groups.
249+ lgraph .setProperty (InternalProperties .CB_NUM_MODEL_ORDER_GROUPS , cbGroupModelOrders .size ());
240250
241251 // iterate the list of contained edges to preserve the 'input order' of the edges
242252 // (this is not part of the previous loop since all children must have already been transformed)
@@ -298,6 +308,7 @@ private void importHierarchicalGraph(final ElkNode elkgraph, final LGraph lgraph
298308
299309 // Model order index for nodes
300310 int index = 0 ;
311+ HashSet <Integer > cbGroupModelOrders = new HashSet <>();
301312 // Transform the node's children
302313 elkGraphQueue .addAll (elkgraph .getChildren ());
303314 while (!elkGraphQueue .isEmpty ()) {
@@ -306,6 +317,9 @@ private void importHierarchicalGraph(final ElkNode elkgraph, final LGraph lgraph
306317 if (needsModelOrder (elknode )) {
307318 // Assign a model order to the nodes as they are read
308319 elknode .setProperty (InternalProperties .MODEL_ORDER , index ++);
320+ if (elknode .hasProperty (LayeredOptions .CONSIDER_MODEL_ORDER_GROUP_MODEL_ORDER_CYCLE_BREAKING_ID )) {
321+ cbGroupModelOrders .add (elknode .getProperty (LayeredOptions .CONSIDER_MODEL_ORDER_GROUP_MODEL_ORDER_CYCLE_BREAKING_ID ));
322+ }
309323 }
310324
311325 // Check if the current node is to be laid out in the first place
@@ -358,6 +372,11 @@ private void importHierarchicalGraph(final ElkNode elkgraph, final LGraph lgraph
358372 }
359373 }
360374 }
375+ // Save the maximum node model order.
376+ // This is relevant to create graph partitions based on model order and constraints.
377+ lgraph .setProperty (InternalProperties .MAX_MODEL_ORDER_NODES , index );
378+ // Save the number of model order groups.
379+ lgraph .setProperty (InternalProperties .CB_NUM_MODEL_ORDER_GROUPS , cbGroupModelOrders .size ());
361380
362381 // Model order index for edges.
363382 index = 0 ;
@@ -458,22 +477,29 @@ private boolean needsModelOrder(final ElkNode child) {
458477 * @return True, if model order should be set.
459478 */
460479 private boolean needsModelOrderBasedOnParent (final ElkNode elkgraph ) {
461- return (elkgraph .getProperty (LayeredOptions .CONSIDER_MODEL_ORDER_STRATEGY ) != OrderingStrategy .NONE
462- || elkgraph .getProperty (LayeredOptions .CYCLE_BREAKING_STRATEGY ) == CycleBreakingStrategy .MODEL_ORDER
463- || elkgraph
464- .getProperty (LayeredOptions .CYCLE_BREAKING_STRATEGY ) == CycleBreakingStrategy .GREEDY_MODEL_ORDER
480+
481+ boolean modelOrderCycleBreaking = elkgraph .getProperty (LayeredOptions .CYCLE_BREAKING_STRATEGY ) == CycleBreakingStrategy .MODEL_ORDER
482+ || elkgraph .getProperty (LayeredOptions .CYCLE_BREAKING_STRATEGY ) == CycleBreakingStrategy .BFS_NODE_ORDER
483+ || elkgraph .getProperty (LayeredOptions .CYCLE_BREAKING_STRATEGY ) == CycleBreakingStrategy .DFS_NODE_ORDER
484+ || elkgraph .getProperty (LayeredOptions .CYCLE_BREAKING_STRATEGY ) == CycleBreakingStrategy .GREEDY_MODEL_ORDER
485+ || elkgraph .getProperty (LayeredOptions .CYCLE_BREAKING_STRATEGY ) == CycleBreakingStrategy .SCC_CONNECTIVITY
486+ || elkgraph .getProperty (LayeredOptions .CYCLE_BREAKING_STRATEGY ) == CycleBreakingStrategy .SCC_NODE_TYPE ;
487+ boolean modelOrderLayering = elkgraph .getProperty (LayeredOptions .LAYERING_STRATEGY ) == LayeringStrategy .BF_MODEL_ORDER
488+ || elkgraph .getProperty (LayeredOptions .LAYERING_STRATEGY ) == LayeringStrategy .DF_MODEL_ORDER
489+ || elkgraph .getProperty (LayeredOptions .LAYERING_NODE_PROMOTION_STRATEGY ) == NodePromotionStrategy .MODEL_ORDER_LEFT_TO_RIGHT
490+ || elkgraph .getProperty (LayeredOptions .LAYERING_NODE_PROMOTION_STRATEGY ) == NodePromotionStrategy .MODEL_ORDER_RIGHT_TO_LEFT ;
491+ boolean modelOrderCrossingMinimization =
492+ // Maybe add the explicit strategies here
493+ elkgraph .getProperty (LayeredOptions .CONSIDER_MODEL_ORDER_STRATEGY ) != OrderingStrategy .NONE
465494 || elkgraph .getProperty (LayeredOptions .CROSSING_MINIMIZATION_FORCE_NODE_MODEL_ORDER )
466- || elkgraph
467- .getProperty (LayeredOptions .CONSIDER_MODEL_ORDER_COMPONENTS ) != ComponentOrderingStrategy .NONE )
468- || elkgraph .getProperty (
469- LayeredOptions .LAYERING_NODE_PROMOTION_STRATEGY ) == NodePromotionStrategy .MODEL_ORDER_LEFT_TO_RIGHT
470- || elkgraph .getProperty (
471- LayeredOptions .LAYERING_NODE_PROMOTION_STRATEGY ) == NodePromotionStrategy .MODEL_ORDER_RIGHT_TO_LEFT
472- || elkgraph .getProperty (
473- LayeredOptions .LAYERING_STRATEGY ) == LayeringStrategy .BF_MODEL_ORDER
474- || elkgraph .getProperty (
475- LayeredOptions .LAYERING_STRATEGY ) == LayeringStrategy .DF_MODEL_ORDER ;
476- }
495+ // Maybe add the explicit strategies here
496+ || elkgraph .getProperty (LayeredOptions .CONSIDER_MODEL_ORDER_COMPONENTS ) != ComponentOrderingStrategy .NONE
497+
498+ || elkgraph .getProperty (LayeredOptions .CONSIDER_MODEL_ORDER_CROSSING_COUNTER_NODE_INFLUENCE ) != 0
499+ || elkgraph .getProperty (LayeredOptions .CONSIDER_MODEL_ORDER_CROSSING_COUNTER_PORT_INFLUENCE ) != 0 ;
500+ return modelOrderCycleBreaking || modelOrderLayering || modelOrderCrossingMinimization ;
501+ }
502+
477503
478504 /**
479505 * Checks if the given node has any inside self loops.
0 commit comments