Package ptolemy.graph

Examples of ptolemy.graph.Edge


                // FIXME: why call new Schedule here?
                /*Schedule schedule = */new Schedule();

                // Expand the super node with adjacent nodes contained
                // within it.
                Edge edge = (Edge) childGraph.edges().iterator().next();
                ptolemy.graph.Node source = edge.source();
                ptolemy.graph.Node sink = edge.sink();
                SymbolicScheduleElement first = _expandAPGAN(childGraph,
                        source, strategy);
                SymbolicScheduleElement second = _expandAPGAN(childGraph, sink,
                        strategy);

                // Determine the iteration counts of the source and
                // sink clusters.
                String producedExpression = strategy.producedExpression(edge);
                String consumedExpression = strategy.consumedExpression(edge);

                // These errors should not occur.
                if (producedExpression == null) {
                    throw new RuntimeException("Internal error: null "
                            + "production rate expression. The offending edge "
                            + "follows.\n" + edge);
                } else if (consumedExpression == null) {
                    throw new RuntimeException(
                            "Internal error: null "
                                    + "consumption rate expression. The offending edge "
                                    + "follows.\n" + edge);
                }

                String denominator = PSDFGraphs.gcdExpression(
                        producedExpression, consumedExpression);
                String firstIterations = "(" + consumedExpression + ") / ("
                        + denominator + ")";
                String secondIterations = "(" + producedExpression + ") / ("
                        + denominator + ")";

                first.setIterationCount(firstIterations);
                second.setIterationCount(secondIterations);

                SymbolicSchedule symbolicSchedule = new SymbolicSchedule("1");
                symbolicSchedule.add((ScheduleElement) first);
                symbolicSchedule.add((ScheduleElement) second);

                // Compute buffer sizes and associate them with the
                // corresponding relations.
                Iterator edges = childGraph.edges().iterator();

                while (edges.hasNext()) {
                    Edge nextEdge = (Edge) edges.next();
                    PSDFEdgeWeight weight = (PSDFEdgeWeight) nextEdge
                            .getWeight();
                    IOPort sourcePort = weight.getSourcePort();
                    List relationList = sourcePort.linkedRelationList();

                    if (relationList.size() != 1) {
View Full Code Here


                        if (_debug) {
                            System.out.println("Adding edge from " + source
                                    + " to " + sink);
                        }

                        Edge newEdge = graph.addEdge((Node) (_actorMap
                                .get(source)), (Node) (_actorMap.get(sink)),
                                _computeEdgeWeight(outPort, inPort));
                        _processNewEdge(graph, newEdge, outPort, inPort);
                    }
                }
View Full Code Here

                    Collection edgeCollection = graph.predecessorEdges(v, u);
                    Iterator edges = edgeCollection.iterator();
                    double connectingEdgeCost = -Double.MAX_VALUE;

                    while (edges.hasNext()) {
                        Edge edge = (Edge) edges.next();

                        if (_edgeLengths.toDouble(edge) > connectingEdgeCost) {
                            connectingEdgeCost = _edgeLengths.toDouble(edge);
                        }
                    }
View Full Code Here

        if (!_maximumAnalysis) {
            weight = Double.MAX_VALUE;
        }

        while (edges.hasNext()) {
            Edge edge = (Edge) edges.next();

            if (_maximumAnalysis) {
                double nextWeight = _edgeLengths.toDouble(edge);

                if (nextWeight > weight) {
View Full Code Here

        // create new edges for the mirror
        Iterator edges = graph().edges().iterator();

        while (edges.hasNext()) {
            Edge edge = (Edge) edges.next();
            Edge mirrorEdge = null;
            Node mirrorSource = (Node) _transformedVersion.get(edge.source());
            Node mirrorSink = (Node) _transformedVersion.get(edge.sink());

            if (!edge.hasWeight()) {
                mirrorEdge = new Edge(mirrorSource, mirrorSink);
            } else {
                Object mirrorWeight = null;

                try {
                    // Clone weights of any type of object.
                    if (_cloneWeights) {
                        Object oldWeight = edge.getWeight();

                        if (oldWeight instanceof Cloneable) {
                            /* Since clone() of Object is protected, it can't
                             be called publicly. The class Method is used
                             here to call public clone(). */
                            Class[] argumentTypes = {};
                            Method method = oldWeight.getClass().getMethod(
                                    nameClone, argumentTypes);

                            // Cast to (Object []) so as to avoid varargs call.
                            mirrorWeight = method.invoke(oldWeight,
                                    (Object[]) null);
                        } else {
                            throw new RuntimeException();
                        }
                    } else {
                        mirrorWeight = edge.getWeight();
                    }
                } catch (Throwable throwable) {
                    /* Exception due to non-Cloneable weights or
                     weights without public clone(). */
                    throw new RuntimeException(
                            "Can not clone the edge weight.\n", throwable);
                }

                mirrorEdge = new Edge(mirrorSource, mirrorSink, mirrorWeight);
            }

            mirrorGraph.addEdge(mirrorEdge);
            _originalVersion.put(mirrorEdge, edge);
            _transformedVersion.put(edge, mirrorEdge);
View Full Code Here

                .cloneAs(new DirectedGraph());
        Object[] edges = graphPlusDelaysAsNodes.edges().toArray();
        HashMap edgeProfitsMap = new HashMap();

        for (int j = 0; j < edges.length; j++) {
            Edge edge = (Edge) edges[j];
            Node source = edge.source();
            Node sink = edge.sink();

            //_edgeCostsMap.put(edge, _edgeCosts.toInt());
            // For all the edges that have at least one delay
            if (_edgeCosts.toInt(edge) != 0) {
                graphPlusDelaysAsNodes.removeEdge(edge);

                int delays = _edgeCosts.toInt(edge);

                for (int i = 0; i < delays; i++) {
                    Node addedNode = graphPlusDelaysAsNodes.addNodeWeight("D"
                            + j + i);
                    _delayNodeList.add(addedNode);

                    Edge addedEdge = graphPlusDelaysAsNodes.addEdge(source,
                            addedNode);
                    edgeProfitsMap.put(addedEdge, Double.valueOf(0.0));
                    source = addedNode;
                }

                Edge lastAddedEdge = graphPlusDelaysAsNodes.addEdge(source,
                        sink);
                edgeProfitsMap.put(lastAddedEdge, Double.valueOf(_edgeProfits
                        .toDouble(edge)));
            } else {
                edgeProfitsMap.put(edge, Double.valueOf(_edgeProfits
                        .toDouble(edge)));
            }
        }

        HashMap D = new HashMap(_delayNodeList.size());
        edges = graphPlusDelaysAsNodes.edges().toArray();

        // compute the first order longest path matrix
        HashMap predecessorMap = new HashMap();

        for (Iterator delayNodes = _delayNodeList.iterator(); delayNodes
                .hasNext();) {
            Node delayNode = (Node) delayNodes.next();
            DirectedGraph thisRoundGraph = (DirectedGraph) graphPlusDelaysAsNodes
                    .clone();
            HashMap delayGraphProfitMap = new HashMap();

            for (int j = 0; j < edges.length; j++) {
                Edge edge = (Edge) edges[j];
                Node source = edge.source();
                Node sink = edge.sink();

                if (sink == delayNode) {
                    predecessorMap.put(delayNode, source);
                }

                if (_delayNodeList.contains(source)
                        || _delayNodeList.contains(sink)) {
                    if (source == delayNode) {
                        delayGraphProfitMap.put(edge, edgeProfitsMap.get(edge));
                    }

                    if (sink == delayNode) {
                        thisRoundGraph.removeEdge(edge);
                    }

                    if ((source != delayNode) && (sink != delayNode)) {
                        if (_delayNodeList.contains(source)) {
                            thisRoundGraph.removeEdge(edge);
                        } else {
                            delayGraphProfitMap.put(edge, edgeProfitsMap
                                    .get(edge));
                        }
                    }
                } else {
                    delayGraphProfitMap.put(edge, edgeProfitsMap.get(edge));
                }
            }

            SingleSourceLongestPathAnalysis longestPath = null;
            longestPath = new SingleSourceLongestPathAnalysis(thisRoundGraph,
                    delayNode, new ToDoubleMapMapping(delayGraphProfitMap));
            D.put(delayNode, longestPath);
        }

        _makeFirstOrderLongestPathMatrix(D, graphPlusDelaysAsNodes,
                predecessorMap);

        // create the delay graph on which the maximum cycle mean is going to
        // be executed.
        DirectedGraph delayGraph = new DirectedGraph();
        HashMap delayGraphEdgeProfits = new HashMap();

        for (int i = 0; i < _delayNodeList.size(); i++) {
            delayGraph.addNode((Node) _delayNodeList.get(i));
        }

        for (int i = 0; i < _delayNodeList.size(); i++) {
            for (int j = 0; j < _delayNodeList.size(); j++) {
                Node source = (Node) _delayNodeList.get(i);
                Node sink = (Node) _delayNodeList.get(j);

                if (_firstOrderLongestPathMatrix[i][j] >= 0) {
                    if (!((source == sink) && (_firstOrderLongestPathMatrix[i][j] == 0))) {
                        Edge addedEdge = delayGraph.addEdge(source, sink);
                        delayGraphEdgeProfits.put(addedEdge, Double
                                .valueOf(_firstOrderLongestPathMatrix[i][j]));
                    }
                }
            }
View Full Code Here

    protected Object _compute() {
        ArrayList selfLoopEdges = new ArrayList();
        Iterator edges = graph().edges().iterator();

        while (edges.hasNext()) {
            Edge edge = (Edge) edges.next();

            if (edge.isSelfLoop()) {
                selfLoopEdges.add(edge);
            }
        }

        return selfLoopEdges;
View Full Code Here

        // Remove all edges that are inside the induced subgraph.
        Iterator edges = graph.edges().iterator();
        ArrayList removeList = new ArrayList();

        while (edges.hasNext()) {
            Edge edge = (Edge) (edges.next());

            if (nodesToRemove.contains(edge.source())
                    && nodesToRemove.contains(edge.sink())) {
                removeList.add(edge);
            }
        }

        Iterator edgesToRemove = removeList.iterator();

        while (edgesToRemove.hasNext()) {
            graph.removeEdge((Edge) edgesToRemove.next());
        }

        // For each edge that connects a node Z outside the induced subgraph
        // to a node inside the subgraph, replace the edge that connects
        // Z to the super node.
        removeList.clear();

        ArrayList addList = new ArrayList();
        edges = graph.edges().iterator();

        while (edges.hasNext()) {
            Edge edge = (Edge) edges.next();
            Edge newEdge = null;

            if (nodesToRemove.contains(edge.source())) {
                if (edge.hasWeight()) {
                    newEdge = new Edge(_superNode, edge.sink(), edge
                            .getWeight());
                } else {
                    newEdge = new Edge(_superNode, edge.sink());
                }
            } else if (nodesToRemove.contains(edge.sink())) {
                if (edge.hasWeight()) {
                    newEdge = new Edge(edge.source(), _superNode, edge
                            .getWeight());
                } else {
                    newEdge = new Edge(edge.source(), _superNode);
                }
            }

            if (newEdge != null) {
                removeList.add(edge);
View Full Code Here

        // returns an unmodifiableList. The removeEdge() method will cause
        // a concurrentModification exception.
        Object[] edges = dependencyGraph.edges().toArray();

        for (int i = 0; i < edges.length; i++) {
            Edge edge = (Edge) edges[i];

            if (edge.source().getWeight().equals(inputPort)
                    && edge.sink().getWeight().equals(outputPort)) {
                dependencyGraph.removeEdge(edge);
            }
        }
    }
View Full Code Here

            Node node = graph().node(i);
            Iterator outputEdges = ((DirectedGraph) graph()).outputEdges(node)
                    .iterator();

            while (outputEdges.hasNext()) {
                Edge edge = (Edge) outputEdges.next();
                int sinkLabel = ((DirectedGraph) graph())
                        .nodeLabel(edge.sink());

                if (_allPairShortestPath[0][i][sinkLabel] > _edgeLengths
                        .toDouble(edge)) {
                    _allPairShortestPath[0][i][sinkLabel] = _edgeLengths
                            .toDouble(edge);
View Full Code Here

TOP

Related Classes of ptolemy.graph.Edge

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.