de.saar.chorus.domgraph.chart
Class Chart

Object
  extended by Chart
All Implemented Interfaces:
Cloneable

public class Chart
extends Object
implements Cloneable

A chart for storing intermediate results of the graph-chart solver. This data structure assigns to a weakly connected subgraph G of the original dominance graph a list of splits for G. A split records the choice of a fragment F of G as the root fragment of a solved form of G, and how the other fragments of G must be distributed over the holes of F. That is, it splits G into a root fragment F and the weakly connected components that remain after F is removed.

This class supports the dynamic addition and removal of splits and subgraphs, and maintains the invariant that all subgraphs and splits in the chart can be used in some solved form -- if they can't, they are removed from the chart. It uses reference counters to keep track of this; to initialise them, the user must specify one or more subgraphs as "top-level" subgraphs, which receive a reference count of 1. One important limitation is that it is not allowed to delete a subgraph (or the last split in the subgraph) if this subgraph is still referenced from elsewhere. The relevant methods throw an UnsupportedOperationException if you attempt this.

Author:
Alexander Koller

Constructor Summary
Chart()
          The constructor.
 
Method Summary
 void addSplit(Set<String> subgraph, Split split)
          Adds a split for the given subgraph.
 void addToplevelSubgraph(Set<String> subgraph)
          Adds a top-level subgraph.
 Object clone()
          Computes a clone of the chart.
 boolean containsSplitFor(Set<String> subgraph)
          Checks whether the chart contains a split for the given subgraph.
 BigInteger countSolvedForms()
          Returns the number of solved forms represented by this chart.
 BigInteger countSolvedFormsFor(Set<String> subgraph)
           
 int countSubgraphs()
           
 void deleteSubgraph(Set<String> subgraph)
          Deletes a subgraph and all of its splits from the chart.
 List<Split> getSplitsFor(Set<String> subgraph)
          Returns the list of all splits for the given subgraph.
 List<Set<String>> getToplevelSubgraphs()
          Returns the list of all top-level subgraphs.
 void setSplitsForSubgraph(Set<String> subgraph, List<Split> splits)
          Sets the splits for a given subgraph.
 int size()
          Returns the number of splits in the entire chart.
 String toString()
          Returns a string representation of the chart.
 
Methods inherited from class Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Chart

public Chart()
The constructor.

Method Detail

addSplit

public void addSplit(Set<String> subgraph,
                     Split split)
Adds a split for the given subgraph.

Parameters:
subgraph - a subgraph of some dominance graph
split - a split of this subgraph

countSubgraphs

public int countSubgraphs()

setSplitsForSubgraph

public void setSplitsForSubgraph(Set<String> subgraph,
                                 List<Split> splits)
Sets the splits for a given subgraph. If the subgraph already had splits, these are deleted first.

Parameters:
subgraph - a subgraph
splits - the new splits for this subgraph
Throws:
UnsupportedOperationException - - if you try to delete all splits of a subgraph that is still referenced from some other split. If this happens, the chart remains unchanged.

deleteSubgraph

public void deleteSubgraph(Set<String> subgraph)
Deletes a subgraph and all of its splits from the chart. This method updates the reference counts, and recursively deletes all other subgraphs that become unreachable.

Parameters:
subgraph - a subgraph
Throws:
UnsupportedOperationException - - if you try to delete a subgraph that is still referenced from some split. If this happens, the chart remains unchanged.

getSplitsFor

public List<Split> getSplitsFor(Set<String> subgraph)
Returns the list of all splits for the given subgraph.

Parameters:
subgraph - a subgraph
Returns:
the list of splits for this subgraph.

containsSplitFor

public boolean containsSplitFor(Set<String> subgraph)
Checks whether the chart contains a split for the given subgraph.

Parameters:
subgraph - a subgraph
Returns:
true iff the chart contains any splits for this subgraph.

size

public int size()
Returns the number of splits in the entire chart.

Returns:
the number of splits

toString

public String toString()
Returns a string representation of the chart.

Overrides:
toString in class Object

getToplevelSubgraphs

public List<Set<String>> getToplevelSubgraphs()
Returns the list of all top-level subgraphs.

Returns:
the top-level subgraphs.

addToplevelSubgraph

public void addToplevelSubgraph(Set<String> subgraph)
Adds a top-level subgraph. This should be one of the maximal weakly connected subgraphs of the dominance graph; if the entire graph is connected, then this should be the set of all nodes of the dominance graph.

Parameters:
subgraph - a weakly connected subgraph.

countSolvedForms

public BigInteger countSolvedForms()
Returns the number of solved forms represented by this chart. This method doesn't compute the solved forms themselves (and is much faster than that), but it can take a few hundred milliseconds for a large chart.

The method assumes that the chart belongs to a solvable dominance graph, i.e. that it represents any solved forms in the first place. You can assume this for all charts that were generated by ChartSolver#solve with a return value of true.

Returns:
the number of solved forms

countSolvedFormsFor

public BigInteger countSolvedFormsFor(Set<String> subgraph)

clone

public Object clone()
Computes a clone of the chart. Splits and subgraphs can be added and deleted, and toplevel subgraphs changed, on the clone without affecting the original chart object. However, the clone contains referneces to the same individual subgraphs and splits as the original chart, so be sure not to modify the subgraphs and splits themselves. (This would be a bad idea anyway.)

Overrides:
clone in class Object
Returns:
a Chart object which is a clone of the current chart