Search in sources :

Example 11 with Edge

use of cbit.util.graph.Edge in project vcell by virtualcell.

the class MathSystemHash method getDependencyGraph.

/**
 * Insert the method's description here.
 * Creation date: (4/12/2002 3:45:17 PM)
 * @return cbit.vcell.math.Variable[]
 * @param variables cbit.vcell.math.Variable[]
 */
public Graph getDependencyGraph(Symbol[] symbols) throws MathSystemHash.UnresolvedException {
    // 
    // add the nodes for each "Symbol"
    // 
    Graph graph = new Graph();
    for (int i = 0; i < symbols.length; i++) {
        Node node = new Node(symbols[i].getName(), symbols[i]);
        graph.addNode(node);
    }
    // 
    // add an edge for each dependency of a Symbol (due to it's associated expression implied equation ... e.g. Rate, IC).
    // 
    Node[] nodes = graph.getNodes();
    for (int i = 0; i < nodes.length; i++) {
        Symbol symbol = (Symbol) nodes[i].getData();
        if (symbol.getExpression() != null) {
            String[] symbolNames = symbol.getExpression().getSymbols();
            for (int j = 0; symbolNames != null && j < symbolNames.length; j++) {
                // 
                // find node that this symbol references
                // 
                Node symbolNode = graph.getNode(symbolNames[j]);
                if (symbolNode == null) {
                    throw new RuntimeException("symbol " + symbol.getName() + " references unknown symbol '" + symbolNames[j] + "'");
                }
                Edge dependency = new Edge(nodes[i], symbolNode, symbol.getName() + "->" + ((Symbol) symbolNode.getData()).getName());
                graph.addEdge(dependency);
            }
        }
        if (symbol instanceof VariableReference) {
            VariableReference varRef = (VariableReference) symbol;
            Node referencingVarNode = graph.getNode(varRef.variable.getName());
            if (referencingVarNode == null) {
                throw new RuntimeException("symbol " + symbol.getName() + " references unknown variable '" + varRef.variable.getName() + "'");
            }
            Edge dependency = new Edge(referencingVarNode, nodes[i], varRef.variable.getName() + "->" + symbol.getName());
            graph.addEdge(dependency);
        }
    }
    return graph;
}
Also used : Graph(cbit.util.graph.Graph) Node(cbit.util.graph.Node) Edge(cbit.util.graph.Edge)

Aggregations

Edge (cbit.util.graph.Edge)11 Graph (cbit.util.graph.Graph)10 Node (cbit.util.graph.Node)9 Tree (cbit.util.graph.Tree)3 Expression (cbit.vcell.parser.Expression)3 Path (cbit.util.graph.Path)2 Feature (cbit.vcell.model.Feature)2 Membrane (cbit.vcell.model.Membrane)2 Model (cbit.vcell.model.Model)2 ElectricalTopology (cbit.vcell.model.Model.ElectricalTopology)2 Structure (cbit.vcell.model.Structure)2 SymbolTableEntry (cbit.vcell.parser.SymbolTableEntry)2 ArrayList (java.util.ArrayList)2 BitSet (java.util.BitSet)2 VCImageUncompressed (cbit.image.VCImageUncompressed)1 Geometry (cbit.vcell.geometry.Geometry)1 CurrentDensityClampStimulus (cbit.vcell.mapping.CurrentDensityClampStimulus)1 ElectricalStimulus (cbit.vcell.mapping.ElectricalStimulus)1 Electrode (cbit.vcell.mapping.Electrode)1 MappingException (cbit.vcell.mapping.MappingException)1