Package ptolemy.kernel

Examples of ptolemy.kernel.Relation


         */
        public void setHead(final Object edge, final Object newArcHead) {
            final Arc link = (Arc) edge;
            NamedObj linkHead = (NamedObj) link.getHead();
            NamedObj linkTail = (NamedObj) link.getTail();
            Relation linkRelation = link.getRelation();

            // This moml is parsed to execute the change
            final StringBuffer moml = new StringBuffer();

            // This moml is parsed in case the change fails.
View Full Code Here


         */
        public void setTail(final Object edge, final Object newArcTail) {
            final Arc link = (Arc) edge;
            NamedObj linkHead = (NamedObj) link.getHead();
            NamedObj linkTail = (NamedObj) link.getTail();
            Relation linkRelation = link.getRelation();

            // This moml is parsed to execute the change
            final StringBuffer moml = new StringBuffer();

            // This moml is parsed in case the change fails.
View Full Code Here

                // created by it remains after it is deleted, so there is a
                // relation that has no match in the match result.
                // Needs to fix this in ptolemy.actor.lib.Publisher.
                if (hostLinkedObject != null
                        && !hostLinkdList.contains(hostLinkedObject)) {
                    Relation relation = (hostLinkedObject instanceof Relation) ? (Relation) hostLinkedObject
                            : (Relation) host;

                    NamedObj hostContainer = relation.getContainer();
                    String moml;
                    if (relation == hostLinkedObject) {
                        moml = _getLinkMoML(host, relation);
                    } else {
                        moml = _getLinkMoML(hostLinkedObject, relation);
                    }
                    MoMLChangeRequest request = new MoMLChangeRequest(this,
                            hostContainer, moml);
                    request.execute();
                }
            }

            if (replacement instanceof ComponentPort
                    && host instanceof ComponentPort) {
                ComponentPort replacementComponentPort = (ComponentPort) replacement;
                ComponentPort hostComponentPort = (ComponentPort) host;
                for (Object replacementRelationObject : replacementComponentPort
                        .insideRelationList()) {
                    Relation replacementRelation = (Relation) replacementRelationObject;
                    Relation hostRelation = (Relation) _replacementToHost
                            .get(replacementRelation);
                    if (!hostComponentPort.insideRelationList().contains(
                            hostRelation)) {
                        // There is no link between hostPort and hostRelation,
                        // so create a new link.
                        NamedObj hostContainer = hostRelation.getContainer();
                        String moml = _getLinkMoML(host, hostRelation);
                        MoMLChangeRequest request = new MoMLChangeRequest(this,
                                hostContainer, moml);
                        request.execute();
                    }
View Full Code Here

        if (relationHiding) {
            // Remove dangling relations.
            Collection<?> relations = GTTools.getChildren(host, false, false,
                    false, true);
            for (Object relationObject : relations) {
                Relation relation = (Relation) relationObject;
                List<?> linkedObjects = relation.linkedObjectsList();
                if (linkedObjects.size() == 1) {
                    String moml = "<deleteRelation name=\""
                            + relation.getName() + "\"/>";
                    MoMLChangeRequest request = new MoMLChangeRequest(this,
                            relation.getContainer(), moml);
                    request.execute();
                }
            }

            // Combine relations if possible.
            relations = GTTools.getChildren(host, false, false, false, true);
            for (Object relationObject : relations) {
                Relation relation = (Relation) relationObject;
                List<?> vertices = relation.attributeList(Vertex.class);
                if (vertices.isEmpty()) {
                    List<?> linkedObjects = relation.linkedObjectsList();
                    if (linkedObjects.size() == 2) {
                        NamedObj head = (NamedObj) linkedObjects.get(0);
                        NamedObj tail = (NamedObj) linkedObjects.get(1);
                        if (head instanceof Relation
                                || tail instanceof Relation) {
                            String moml = "<deleteRelation name=\""
                                    + relation.getName() + "\"/>";
                            MoMLChangeRequest request = new MoMLChangeRequest(
                                    this, relation.getContainer(), moml);
                            request.execute();

                            if (tail instanceof Relation) {
                                moml = _getLinkMoML(head, (Relation) tail);
                                request = new MoMLChangeRequest(this, tail
                                        .getContainer(), moml);
                                request.execute();
                            } else {
                                moml = _getLinkMoML(tail, (Relation) head);
                                request = new MoMLChangeRequest(this, head
                                        .getContainer(), moml);
                                request.execute();
                            }
                        }
                    } else if (linkedObjects.size() > 2) {
                        double[] location = _getBestLocation(relation
                                .linkedObjectsList());
                        String moml = "<group name=\"auto\">"
                                + "<vertex name=\"vertex\" value=\"["
                                + location[0] + ", " + location[1] + "]\"/>"
                                + "</group>";
View Full Code Here

        // CT Connections
        ctsub.connect(time.output, scale3.input);
        ctsub.connect(scale3.output, trigFunction.input);

        Relation cr0 = ctsub.connect(trigFunction.output, scale0.input, "CR0");
        ctsub.connect(scale0.output, add1.plus, "CR1");
        ctsub.connect(add1.output, intgl1.input, "CR2");

        Relation cr3 = ctsub.connect(intgl1.output, intgl2.input, "CR3");
        Relation cr4 = ctsub.connect(intgl2.output, ctPlot.input, "CR4");
        scale1.input.link(cr3);
        scale2.input.link(cr4);
        ctSampler.input.link(cr4);

        TypedIORelation cr5 = new TypedIORelation(ctsub, "CR5");
        ctSampler.output.link(cr5);
        subout.link(cr5);
        ctsub.connect(scale1.output, add1.plus, "CR6");
        ctsub.connect(scale2.output, add1.plus, "CR7");
        ctsub.connect(scale4.output, add1.plus, "CR8");

        TypedIORelation cr9 = new TypedIORelation(ctsub, "CR9");
        hold.input.link(cr9);
        subin.link(cr9);

        Relation cr10 = ctsub.connect(hold.output, scale4.input, "CR10");
        ctPlot.input.link(cr0);
        ctPlot.input.link(cr10);

        // DE System
        ptolemy.domains.de.lib.TimedDelay delay = new ptolemy.domains.de.lib.TimedDelay(
                this, "delay");
        delay.delay.setToken(new DoubleToken(0.02));

        FIR fir = new FIR(this, "fir");
        fir.taps.setExpression("{0.7, 0.3}");

        Quantizer quan = new Quantizer(this, "Quantizer");
        Average accumulator = new Average(this, "accumulator");
        Sampler sampler = new Sampler(this, "sampler");
        Clock clk = new Clock(this, "ADClock");
        clk.offsets.setExpression("{0.0}");
        clk.period.setToken(new DoubleToken(1.0));
        clk.values.setExpression("{true}");

        TimedPlotter dePlot = new TimedPlotter(this, "DEPlot");
        Plot newPlot = new Plot();
        dePlot.plot = newPlot;
        newPlot.setGrid(true);
        newPlot.setXRange(0.0, stopT);
        newPlot.setYRange(-1.0, 1.0);
        newPlot.setSize(500, 180);
        newPlot.setConnected(false);
        newPlot.setImpulses(true);
        newPlot.setMarksStyle("dots");
        newPlot.addLegend(0, "Accum");
        newPlot.addLegend(1, "Quantize");

        FIR mav = new FIR(this, "MAV");
        mav.taps.setExpression("{0.1, 0.1, 0.1, 0.1, 0.1, 0.05, 0.05, 0.05, "
                + "0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05}");

        // DE connections.
        connect(subout, delay.input);
        connect(delay.output, fir.input);
        connect(fir.output, quan.input);

        Relation dr3 = connect(quan.output, subin);
        mav.input.link(dr3);
        connect(mav.output, accumulator.input);

        Relation dr4 = connect(clk.output, sampler.trigger);
        accumulator.reset.link(dr4);
        connect(accumulator.output, sampler.input);
        connect(sampler.output, dePlot.input);
        dePlot.input.link(dr3);
View Full Code Here

    private void _removeLinks(CompositeEntity pattern) {
        Collection<?> relations = GTTools.getChildren(pattern, false, false,
                false, true);
        Set<Pair<Relation, Object>> linksToRemove = new HashSet<Pair<Relation, Object>>();
        for (Object relationObject : relations) {
            Relation relation = (Relation) relationObject;
            Relation replacementRelation = (Relation) _patternToReplacement
                    .get(relation);
            if (replacementRelation == null) {
                continue;
            }

            List<?> linkedObjectList = relation.linkedObjectsList();
            for (Object linkedObject : linkedObjectList) {
                Object replacementLinkedObject = _patternToReplacement
                        .get(linkedObject);
                if (replacementLinkedObject == null) {
                    continue;
                }

                boolean linkRemoved;
                if (replacementLinkedObject instanceof Port) {
                    linkRemoved = !((Port) replacementLinkedObject)
                            .isLinked(replacementRelation);
                } else {
                    linkRemoved = !replacementRelation.linkedObjectsList()
                            .contains(replacementLinkedObject);
                }

                if (linkRemoved) {
                    linksToRemove.add(new Pair<Relation, Object>(relation,
                            linkedObject));
                }
            }
        }

        for (Pair<Relation, Object> link : linksToRemove) {
            Relation hostRelation = (Relation) _matchResult
                    .get(link.getFirst());
            if (hostRelation == null) {
                continue;
            }
            Object hostObject = _matchResult.get(link.getSecond());
            if (hostObject == null) {
                continue;
            }

            String name;
            if (hostObject instanceof Port) {
                Port port = (Port) hostObject;
                name = port.getContainer().getName() + "." + port.getName();
            } else {
                name = ((Relation) hostObject).getName();
            }

            String moml = "<unlink port=\"" + name + "\" relation=\""
                    + hostRelation.getName() + "\"/>";
            MoMLChangeRequest request = new MoMLChangeRequest(this,
                    hostRelation.getContainer(), moml);
            request.execute();
        }

        Collection<?> entities = GTTools.getChildren(pattern, false, false,
                true, false);
View Full Code Here

            for (Map.Entry<Port, List<Object>> entry : portLinks.entrySet()) {
                Port port = entry.getKey();
                List<Object> linkedRelations = entry.getValue();
                int width = 1;
                for (Object relationObject : linkedRelations) {
                    Relation relation = (Relation) relationObject;
                    Parameter widthParameter = (Parameter) relation
                            .getAttribute("width");
                    if (widthParameter != null) {
                        try {
                            int thisWidth = ((IntToken) widthParameter
                                    .getToken()).intValue();
                            if (thisWidth > width) {
                                width = thisWidth;
                            }
                        } catch (IllegalActionException e) {
                            throw new TransformationException("Cannot get "
                                    + "width of relation " + relation.getName()
                                    + ".", e);
                        }
                    }
                }

                String moml = "<group name=\"auto\">"
                        + "<relation name=\"relation\" "
                        + "  class=\"ptolemy.actor.TypedIORelation\">"
                        + "</relation>" + "</group>";
                request = new MoMLChangeRequest(this, container, moml);
                request.execute();
                Relation newRelation = (Relation) _getNewlyAddedObject(
                        container, Relation.class);

                entityMap.put(port, newRelation);
            }

            // Fix the connections between the moved entities and relations.
            for (Map.Entry<NamedObj, NamedObj> entry : entityMap.entrySet()) {
                NamedObj originalObject = entry.getKey();
                NamedObj newObject = entry.getValue();
                if (originalObject instanceof Relation
                        || originalObject instanceof Port
                        && newObject instanceof Relation) {
                    List<?> linkedObjectList;
                    if (originalObject instanceof Relation) {
                        linkedObjectList = ((Relation) originalObject)
                                .linkedObjectsList();
                    } else {
                        linkedObjectList = portLinks.get(originalObject);
                    }
                    Relation relation2 = (Relation) newObject;
                    for (Object linkedObject : linkedObjectList) {
                        if (linkedObject instanceof Relation) {
                            Relation relation1 = (Relation) entityMap
                                    .get(linkedObject);
                            if (relation1 == null) {
                                relation1 = (Relation) linkedObject;
                            }
                            String moml = _getLinkMoML(relation1, relation2);
View Full Code Here

                        // Next check transitions.
                        Iterator transitions = master.relationList().iterator();

                        while (removeIt && transitions.hasNext()) {
                            Relation transition = (Relation) transitions.next();

                            if (!(transition instanceof Transition)) {
                                continue;
                            }
View Full Code Here

        // relation.  This replaces any previous table, so we first remove
        // the receivers that are currently in the table.
        if (_localReceiversTable != null) {
            Iterator relations = _localReceiversTable.keySet().iterator();
            while (relations.hasNext()) {
                Relation relation = (Relation) relations.next();
                _removeReceivers(relation);
            }
        }
        _localReceiversTable = new HashMap();
        // Make sure _localReceivers is updated next time it is accessed.
        _localReceiversVersion = -1;
        _insideReceiversVersion = -1;

        boolean input = isInput();
        boolean output = isOutput();

        if (input) {
            Iterator outsideRelations = linkedRelationList().iterator();

            int myWidth = getWidth();
            boolean madeOne = false;

            while (outsideRelations.hasNext()) {
                IORelation relation = (IORelation) outsideRelations.next();

                // A null link which can be created using insertLink()
                // with an index might result in an null relation.
                if (relation != null) {
                    int width = relation.getWidth();

                    if (!madeOne && (myWidth == 1) && (width > 1)) {
                        width = 1;
                    }

                    Receiver[][] result = new Receiver[width][1];

                    for (int i = 0; i < width; i++) {
                        // This throws an exception if there is no director.
                        result[i][0] = _newReceiver();
                        madeOne = true;
                    }

                    // Save it.  If we have previously seen this relation,
                    // then we simply add the new array to the list
                    // of occurrences for this relation.  Otherwise,
                    // we create a new list with one element.
                    // EAL 7/30/99.
                    if (_localReceiversTable.containsKey(relation)) {
                        List occurrences = (List) (_localReceiversTable
                                .get(relation));
                        occurrences.add(result);
                    } else {
                        List occurrences = new LinkedList();
                        occurrences.add(result);
                        _localReceiversTable.put(relation, occurrences);
                    }

                    if ((myWidth == 1) && madeOne) {
                        // Made the one receiver we need. Nothing more to do.
                        break;
                    }
                }
            }
        }

        if (output) {
            Iterator insideRelations = insideRelationList().iterator();

            while (insideRelations.hasNext()) {
                IORelation relation = (IORelation) insideRelations.next();
                int width = relation.getWidth();

                Receiver[][] result = new Receiver[width][1];

                // Inside links need to have receivers compatible
                // with the local director.  We need to create those
View Full Code Here

    public void unlink(int index) {
        // Override the base class to update _localReceiversTable.
        try {
            _workspace.getWriteAccess();

            Relation toDelete = (Relation) _relationsList.get(index);

            if ((toDelete != null) && (_localReceiversTable != null)) {
                _removeReceivers(toDelete);
                _localReceiversTable.remove(toDelete);
                _localReceiversVersion = -1;
View Full Code Here

TOP

Related Classes of ptolemy.kernel.Relation

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.