How Do We Keep HyperEdge Structures Up-To-Date?

The Problem

Using Event callbacks to monitor the hiding of GraphObjects can lead to IllegalStateExceptions. We can cause IllegalStateExceptions in FGraphPerspective by indirectly fully hiding objects we are in the middle of hiding.

For example, assume we have a HyperEdge with ConnectorNode cn1. This HyperEdge has edge e1 to node P and edge e2 to node M (see diagram). Notice that if we hide any edge, the HyperEdge will be hidden causing e1-e2, and cn1 to be hidden.

  e2    e1
M----o---->P
    cn1

Now assume a user selects e1 and does 'Edit->Delete Selected Nodes and Edges'. The call chain looks something like:

...
cytoscape.editor.actions.DeleteAction.actionPerformed()
  fing.model.FGraphPerspective.hideEdges()
    fing.model.FGraphPerspective$GraphWeeder.hideEdges()
       <HyperEdgeManager callback called with e1>
    fing.model.FGraphPerspective$GraphWeeder.actuallyHideEdge()
    ...

The current HyperEdgeManager event callback will take the edge (e1) and carefully remove HyperEdge bookkeeping information about this edge--without deleting it. However, removing e1 from the HyperEdge implies that the whole HyperEdge must be removed. So, e2 and cn1 are hidden. When cn1 is really hidden by FGraphPerspective, it will first hide its edges, namely e1 will be fully hidden. However, notice that we are in the process of hiding e1--we are in the event call back for it being hidden. So, after our event callback completes, FGraphPerspective.actuallyHideEdge() will get an IllegalStateException since e2 is been hidden out from underneath it (for all the gory details, see Details of Simple Example, below).

Rehiding versus Recursively Hiding

Notice that rehiding and recursively hiding a GraphObject are different issues. Rehiding a CyNode or CyEdge is attempting to hide it again after fully hiding it already. Fing is fairly robust here, since it already has to deal with these situations (see Rehiding CyNodes and CyEdges in Fing, below). However, where Fing is inflexible is in recursively hiding a GraphObject.

How to Solve This Problem

Before looking at temporary solutions, notice that this problem goes away if (when) HyperEdge is placed in Cytoscape core. At this time, then event callbacks will no longer be needed to track deletions but instead the real HyperEdge API deletion methods would be invoked directly.

To temporarily solve this problem, we need to follow the rule:

Other Strategies Considered

  1. Just catch IllegalStateException checking that error is the 'internal error - couldn't hide xxx' and continue. Besides being an incredible hack and possibly catching other unwanted errors, it isn't clear where the catching could be done so that we could continue. The RootGraph may also be in a corrupted state.

  2. When a hiding callback starts, track all items given in the list of items to hide and ensure that HyperEdge operations don't actually hide any of these items. This was attempted, passing in a BookkeepingItem that contains all GraphObjects to ignore as far as hiding. Although this catches potential problems with rehiding objects (which doesn't look like it's a problem anyway), it does not deal with recursive hiding.

Rehiding CyNodes and CyEdges in Fing

!FGraphPerspective.hideEdges() must already be somewhat flexible to handle simple hidings. For example, the code for Edit-->"Delete Selected Nodes and Edges", in cytoscape.editor.actions.DeleteAction.actionPerformed(), performs the following steps:

   ...
   cyNet.hideNodes(nodes);
   cyNet.hideEdges(edges);
   ...

If we select a CyNode and its CyEdges and hide them, then by the time cyNet.hideEdges() is called, 'edges' will be hidden.

More Complex Example

Assume we have two HyperEdges he1 and he2 with ConnectorNodes cn1 and cn2 respectively. he1 has edge e2 to cn2 and edge e1 to node A. he2 has edge e2 to cn1 and edge e3 to B (see diagram). Notice that if we hide any edge or any node, both hyperedges will be deleted causing e1-e3, cn1, and cn2 to be hidden.

  e1
A---->o
      |
      |e2
      |
      v
B---->o
  e3

Now assume a user selects e1,e2,e3 and does 'Edit->Delete Selected Nodes and Edges'. The call chain looks something like:

...
cytoscape.editor.actions.DeleteAction.actionPerformed()
  fing.model.FGraphPerspective.hideEdges()
    fing.model.FGraphPerspective$GraphWeeder.hideEdges()
       <HyperEdgeManager callback called with e1,e2,e3>
    fing.model.FGraphPerspective$GraphWeeder.actuallyHideEdge()
    ...

Details of Simple Example

cytoscape.editor.actions.DeleteAction.actionPerformed()
  fing.model.FGraphPerspective.hideEdges()
    fing.model.FGraphPerspective$GraphWeeder.hideEdges()
       [HyperEdgeManager callback called with e1]
         save e1 on toIgnoreList
         HE.removeEdgeBookkeeping()
           HE.primDestroy() -- not enough egdes remain
             HE.primRemoveNode(M)
               HE.primRemoveEdge(e2)
                 HE.removeUnderlyingEdge (e2)
                   since e2 is not on toIgnoreList, really hide
                   CyNet.removeEdge (e2)
                     [HyperEdgeManager callback with e2--immediate return
                      since we are in an internal operation]
                      E2 REALLY REMOVED BY FGraphPerspective
             HE.primRemoveNode(P)
               HE.primRemoveEdge (e1)
                 HE.removeUnderlyingEdge (e1)
                   since e1 is on the toIgnoreList, NO deletion
             HE.removeConnectorNodeAndAttributes()
               HE.removeUnderlyingNode (cn1)
                 HEM.removeNodeFromNet (cn1)
                   since cn1 is NOT on ignore list-hide
                   CyNet.removeNode (cn1)
                     [HyperEdgeManager callback with cn1--immediate return
                      since we are in an internal operation]
                     [HyperEdgeManager callback with e1--immediate return
                      since we are in an internal operation]
                      E1 REALLY REMOVED By FGraphPerspective
                      We are screwed at this point because E1 was
                      hidden while hiding E1.
    fing.model.FGraphPerspective$GraphWeeder.actuallyHideEdge(e1)
       IllegalStateException--internal error: couldn't hide edge -3.

HyperEdgeUpdating (last edited 2009-02-12 01:03:51 by localhost)

Funding for Cytoscape is provided by a federal grant from the U.S. National Institute of General Medical Sciences (NIGMS) of the Na tional Institutes of Health (NIH) under award number GM070743-01. Corporate funding is provided through a contract from Unilever PLC.

MoinMoin Appliance - Powered by TurnKey Linux