Package ptolemy.actor

Examples of ptolemy.actor.IOPort


        LinkedList newRelationList = new LinkedList();
        Iterator outputPorts = transition.outputPortList().iterator();

        while (outputPorts.hasNext()) {
            IOPort outPort = (IOPort) outputPorts.next();
            newRelationList.addAll(outPort.linkedRelationList());
        }

        LinkedList temporaryDestinationPortList = new LinkedList();

        while (newRelationList.size() > 0) {
            IORelation weights = (IORelation) newRelationList.getFirst();

            if (weights != null) {
                Iterator weightPorts = weights.linkedDestinationPortList()
                        .iterator();

                while (weightPorts.hasNext()) {
                    IOPort weightPort = (IOPort) weightPorts.next();

                    if (!temporaryDestinationPortList.contains(weightPort)) {
                        temporaryDestinationPortList.add(weightPort);

                        Nameable weightPlace = weightPort.getContainer();

                        if (weightPlace instanceof PetriNetActor) {
                            if (weightPort.isOutput()) {
                                newRelationList.addAll(weightPort
                                        .linkedRelationList());
                            } else if (weightPort.isInput()) {
                                newRelationList.addAll(weightPort
                                        .insideRelationList());
                            }
                        } else if (weightPlace instanceof Place) {
                            // Don't do anything for Place
                        } else {
                            _debug("something wrong "
                                    + weightPlace.getFullName());
                        }
                    }
                }

                int weightNumber = _getWeightNumber(weights);
                LinkedList forwardConnectedPlaces = _findForwardConnectedPlaces(weights);
                Iterator forwardConnectedPlace = forwardConnectedPlaces
                        .iterator();
                int itemCount = 0;

                while (forwardConnectedPlace.hasNext()) {
                    Place forwardPlace = (Place) forwardConnectedPlace.next();
                    itemCount++;

                    int oldToken = forwardPlace.getMarking();
                    forwardPlace.increaseMarking(weightNumber);

                    if (_debugging) {
                        _debug("              the " + itemCount + " place is "
                                + forwardPlace.getFullName() + " old  "
                                + oldToken + " new "
                                + forwardPlace.getMarking());
                    }
                }
            }

            newRelationList.remove(weights);
        }

        LinkedList backRelationList = new LinkedList();
        Iterator inputPorts = transition.inputPortList().iterator();

        while (inputPorts.hasNext()) {
            IOPort inPort = (IOPort) inputPorts.next();
            backRelationList.addAll(inPort.linkedRelationList());
        }

        LinkedList temporarySourcePortList = new LinkedList();

        while (backRelationList.size() > 0) {
            IORelation weights = (IORelation) backRelationList.getFirst();

            if (weights != null) {
                Iterator weightPorts = weights.linkedSourcePortList()
                        .iterator();

                while (weightPorts.hasNext()) {
                    IOPort weightPort = (IOPort) weightPorts.next();

                    if (!temporarySourcePortList.contains(weightPort)) {
                        temporarySourcePortList.add(weightPort);

                        Nameable weightPlace = weightPort.getContainer();

                        if (weightPlace instanceof PetriNetActor) {
                            if (weightPort.isOutput()) {
                                backRelationList.addAll(weightPort
                                        .insideRelationList());
                            } else if (weightPort.isInput()) {
                                backRelationList.addAll(weightPort
                                        .linkedRelationList());
                            }
                        }
                    }
                }
View Full Code Here


            IORelation weights = (IORelation) newRelationList.getFirst();
            Iterator weightPorts = weights.linkedDestinationPortList()
                    .iterator();

            while (weightPorts.hasNext()) {
                IOPort weightPort = (IOPort) weightPorts.next();

                if (!temporaryDestinationPortList.contains(weightPort)) {
                    temporaryDestinationPortList.add(weightPort);

                    Nameable weightPlace = weightPort.getContainer();

                    if (weightPlace instanceof PetriNetActor) {
                        if (weightPort.isOutput()) {
                            newRelationList.addAll(weightPort
                                    .linkedRelationList());
                        } else if (weightPort.isInput()) {
                            newRelationList.addAll(weightPort
                                    .insideRelationList());
                        }
                    } else if (weightPlace instanceof Place) {
                        temporaryPlaceList.add(weightPlace);
                    } else {
                        _debug("------found no place/PetriNetActor"
                                + weightPort.getFullName());
                    }
                }
            }

            newRelationList.remove(weights);
View Full Code Here

        while (newRelationList.size() > 0) {
            IORelation weights = (IORelation) newRelationList.getFirst();
            Iterator weightPorts = weights.linkedSourcePortList().iterator();

            while (weightPorts.hasNext()) {
                IOPort weightPort = (IOPort) weightPorts.next();

                if (!temporarySourcePortList.contains(weightPort)) {
                    temporarySourcePortList.add(weightPort);

                    Nameable weightPlace = weightPort.getContainer();

                    if (weightPlace instanceof PetriNetActor) {
                        if (weightPort.isOutput()) {
                            newRelationList.addAll(weightPort
                                    .insideRelationList());
                        } else if (weightPort.isInput()) {
                            newRelationList.addAll(weightPort
                                    .linkedRelationList());
                        }
                    } else if (weightPlace instanceof Place) {
                        temporaryPlaceList.add(weightPlace);
                    } else {
                        _debug("-------found no place/PetriNetActor  "
                                + weightPort.getFullName());
                    }
                }
            }

            newRelationList.remove(weights);
View Full Code Here

        LinkedList newRelationList = new LinkedList();

        Iterator inputPorts = transition.inputPortList().iterator();

        while (inputPorts.hasNext()) {
            IOPort inPort = (IOPort) inputPorts.next();
            newRelationList.addAll(inPort.linkedRelationList());
        }

        LinkedList temporaryPlaceList = new LinkedList();

        while (newRelationList.size() > 0) {
View Full Code Here

                // the class mechanism.
                if (port instanceof IOPort) {
                    String direction = (String) _attributes.get("direction");

                    if (direction != null) {
                        IOPort ioport = (IOPort) port;
                        boolean isOutput = direction.equals("output")
                                || direction.equals("both");
                        boolean isInput = direction.equals("input")
                                || direction.equals("both");

                        // If this object is a derived object, then its I/O status
                        // cannot be changed.
                        if (alreadyExisted
                                && (ioport.getDerivedLevel() < Integer.MAX_VALUE)) {
                            if ((ioport.isInput() != isInput)
                                    || (ioport.isOutput() != isOutput)) {
                                throw new IllegalActionException(
                                        ioport,
                                        "Cannot change whether this port is "
                                                + "an input or output. That property is "
                                                + "fixed by the class definition.");
                            }
                        }

                        ioport.setOutput(isOutput);
                        ioport.setInput(isInput);
                    }
                }

                //////////////////////////////////////////////////////////////
                //// property
View Full Code Here

    public void sendOutNullTokens(DDEReceiver receiver) {
        Iterator ports = _actor.outputPortList().iterator();
        Time time = getModelTime();

        while (ports.hasNext()) {
            IOPort port = (IOPort) ports.next();
            Receiver[][] receivers = port.getRemoteReceivers();

            for (int i = 0; i < receivers.length; i++) {
                for (int j = 0; j < receivers[i].length; j++) {
                    if (time
                            .compareTo(((DDEReceiver) receivers[i][j])._lastTime) > 0) {
View Full Code Here

        //
        int cnt = 0;
        int currentPriority = 0;

        while (cnt < listOfPorts.size()) {
            IOPort port = (IOPort) listOfPorts.get(cnt);
            Receiver[][] receivers = port.getReceivers();

            for (int i = 0; i < receivers.length; i++) {
                for (int j = 0; j < receivers[i].length; j++) {
                    ((DDEReceiver) receivers[i][j])._priority = currentPriority;
View Full Code Here

            Actor[] actors = currentState.getRefinement();
            getRefinementReferredInputPorts(currentState);

            // Transfer additional inputs needed by the refinement.
            for (int i = 0; i < inputPortList.size(); i++) {
                IOPort port = (IOPort) inputPortList.get(i);

                if (_refinementReferredInputPorts.contains(port)
                        && !_referredInputPorts.contains(port)) {
                    super.transferInputs(port);
                    controller.readInputs();
                    _referredInputPorts.add(port);
                }
            }

            // Fire the refinement.
            if (actors != null) {
                for (int i = 0; i < actors.length; ++i) {
                    if (_stopRequested) {
                        break;
                    }

                    if (actors[i].prefire()) {
                        actors[i].fire();
                        actors[i].postfire();
                    }
                }
            }

            controller.readOutputsFromRefinement();

            // Get inputs needed by the nonpreemptive transitions.
            getNonpreemptiveTransitionsReferredInputPorts(currentState);

            // Transfer additional inputs needed by the refinement.
            for (int i = 0; i < inputPortList.size(); i++) {
                IOPort port = (IOPort) inputPortList.get(i);

                if (_nonpreemptiveTransitionsInputs.contains(port)
                        && !_referredInputPorts.contains(port)) {
                    super.transferInputs(port);
                    controller.readInputs();
                    _referredInputPorts.add(port);
                }
            }

            // Choose a nonpreemptive transition.
            enabledTransitions = controller.enabledTransitions(currentState
                    .nonpreemptiveTransitionList());

            // Ensure that if there are multiple enabled transitions, all of them
            // must be nondeterministic.
            if (enabledTransitions.size() > 1) {
                Iterator transitions = enabledTransitions.iterator();

                while (transitions.hasNext()) {
                    Transition transition = (Transition) transitions.next();

                    if (!transition.isNondeterministic()) {
                        throw new MultipleEnabledTransitionsException(
                                controller.currentState(),
                                "Multiple enabled transitions found but "
                                        + transition.getName()
                                        + " is deterministic.");
                    }
                }
            }

            // Randomly choose one transition from the list of the
            // enabled trnasitions.
            length = enabledTransitions.size();

            if (length != 0) {
                // Since the size of the list of enabled transitions usually (almost
                // always) is less than the maximum value of integer. We can safely
                // do the cast from long to int in the following statement.
                int randomChoice = (int) Math.floor(Math.random() * length);

                // There is tiny chance that randomChoice equals length.
                // When this happens, we deduct 1 from the randomChoice.
                if (randomChoice == length) {
                    randomChoice--;
                }

                enabledTransition = (Transition) enabledTransitions
                        .get(randomChoice);
            }

            _enabledTransition = enabledTransition;
        }

        if (enabledTransition != null) {
            // Get additional inputs needed for output actions and set actions
            // of the enabled transition.
            getOutputActionsReferredInputPorts(enabledTransition);
            getSetActionsReferredInputPorts(enabledTransition);

            for (int i = 0; i < inputPortList.size(); i++) {
                IOPort port = (IOPort) inputPortList.get(i);

                if (_outputActionReferredInputPorts.contains(port)
                        && !_referredInputPorts.contains(port)) {
                    super.transferInputs(port);
                    controller.readInputs();
                    _referredInputPorts.add(port);
                }
            }

            controller.readInputs();

            // execute output actions.
            Iterator actions = enabledTransition.choiceActionList().iterator();

            while (actions.hasNext()) {
                Action action = (Action) actions.next();
                action.execute();
            }

            // Get additional input ports needed by set actions of
            // the enabeld transition.
            for (int i = 0; i < inputPortList.size(); i++) {
                IOPort port = (IOPort) inputPortList.get(i);

                if (_setActionReferredInputPorts.contains(port)
                        && !_referredInputPorts.contains(port)) {
                    super.transferInputs(port);
                    controller.readInputs();
View Full Code Here

    public void getReferredInputPorts(Set portSet, Set referredInputPorts) {
        CompositeActor container = (CompositeActor) getContainer();
        List inputPortList = container.inputPortList();

        for (int i = 0; i < inputPortList.size(); i++) {
            IOPort inputPort = (IOPort) inputPortList.get(i);

            if (portSet.contains(inputPort.getName())) {
                referredInputPorts.add(inputPort);
            }
        }
    }
View Full Code Here

        Iterator outputPorts = actor.outputPortList().iterator();
        double endTime = PrioritizedTimedQueue.INACTIVE;

        if (outputPorts != null) {
            while (outputPorts.hasNext()) {
                IOPort port = (IOPort) outputPorts.next();
                Receiver[][] receivers = port.getRemoteReceivers();

                if (receivers == null) {
                    break;
                }
View Full Code Here

TOP

Related Classes of ptolemy.actor.IOPort

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.