Esempio n. 1
0
Place::Place(PetriNet* petriNet)
: PetriNetNode(petriNet) {
	m_childPetriNet = NULL;

	int nbColors = getPetriNet()->nbOfPossibleColors();

	m_tokenByColor.resize(nbColors);
}
Esempio n. 2
0
void Place::merge(Place* placeToMerge) // CB copie améliorée de Transition::merge, à descendre dans PetriNetNode ?
{
    arcList mergeInGoingArcs = placeToMerge->inGoingArcsOf(); // CB vector
    arcList mergeOutGoingArcs = placeToMerge->outGoingArcsOf(); // CB vector
    
    for (arcList::iterator it = mergeInGoingArcs.begin() ; it != mergeInGoingArcs.end() ; it++) {
        PetriNetArc* newArc = getPetriNet()->createArc(dynamic_cast<Transition*>((*it)->getFrom()), this); // CB uncheck cast
        newArc->changeAbsoluteTime((*it)->getAbsoluteMinValue(), (*it)->getAbsoluteMaxValue());
        newArc->changeRelativeTime((*it)->getRelativeMinValue(), (*it)->getRelativeMaxValue());
        getPetriNet()->deleteArc((*it)->getFrom(), placeToMerge);
    } // CB Arc::Arc adds the arc in the nodes' lists
    
    for (arcList::iterator it = mergeOutGoingArcs.begin() ; it != mergeOutGoingArcs.end() ; it++) {
        PetriNetArc* newArc = getPetriNet()->createArc(this, dynamic_cast<Transition*>((*it)->getTo()));
        newArc->changeAbsoluteTime((*it)->getAbsoluteMinValue(), (*it)->getAbsoluteMaxValue());
        newArc->changeRelativeTime((*it)->getRelativeMinValue(), (*it)->getRelativeMaxValue());
        getPetriNet()->deleteArc(placeToMerge, (*it)->getTo());
    } // CB Arc::Arc adds the arc in the nodes' lists
}
Esempio n. 3
0
void Place::produceTokens(unsigned int nbOfTokens, unsigned int colorLabel, int tokensTime)
{
	unsigned int oldNumberOfTokens = getNbOfTokens(colorLabel);

	for (unsigned int i = 0; i < nbOfTokens; ++i) {
        Token token(tokensTime);
		m_tokenByColor[colorLabel - 1].push_back(token);
	}

//    if(tokensTime < 0){tokensTime = 0;} // CB incompatible with deactivation (tokenTime = -1)

	if ((oldNumberOfTokens < NB_OF_TOKEN_TO_ACTIVE_ARC) && (getNbOfTokens(colorLabel) >= NB_OF_TOKEN_TO_ACTIVE_ARC)) { // CB WTF : Si un token et deux arcs sortant, bug ?
		arcList outGoingArcs = outGoingArcsOf(colorLabel);
		for (unsigned int i = 0 ; i < outGoingArcs.size() ; ++i) {
			PetriNetArc* arc = outGoingArcs[i];
            
//            if (!arc->getCondition()) { // CB check if the arc can be activated
//                continue;
//            }

            Transition* transitionTo = dynamic_cast<Transition*>(arc->getTo());
            
			if (!transitionTo) {
				throw IncoherentStateException();
			}

			transitionTo->setArcAsActive(arc, tokensTime, true);

			if (transitionTo->isStatic()) {
				if(arc->getRelativeMinValue().getValue() < (int) tokensTime) {
					getPetriNet()->pushTransitionToCrossWhenAcceleration(transitionTo);
				}
			} else {
				if(arc->getRelativeMaxValue().getValue() < (int) tokensTime) {
					getPetriNet()->pushTransitionToCrossWhenAcceleration(transitionTo);
				}
			}
		}
	}
}
Esempio n. 4
0
void Place::produceTokens(unsigned int nbOfTokens, unsigned int colorLabel, unsigned int tokensTime) {
	unsigned int oldNumberOfTokens = getNbOfTokens(colorLabel);

	for (unsigned int i = 0; i < nbOfTokens; ++i) {
		Token token;
		token.setRemainingTime(tokensTime);
		m_tokenByColor[colorLabel - 1].push_back(token);
	}

	if ((oldNumberOfTokens < NB_OF_TOKEN_TO_ACTIVE_ARC) && (getNbOfTokens(colorLabel) >= NB_OF_TOKEN_TO_ACTIVE_ARC)) {
		arcList outGoingArcs = outGoingArcsOf(colorLabel);
		for (unsigned int i = 0 ; i < outGoingArcs.size() ; ++i) {
			Arc* arc = outGoingArcs[i];

			if (!(dynamic_cast<Transition*>(arc->getTo()))) {
				throw IncoherentStateException();
			}

			Transition* transitionTo = ((Transition*) arc->getTo());

			transitionTo->setArcAsActive(arc, tokensTime, true);

			if (transitionTo->isStatic()) {
				if(arc->getRelativeMinValue().getValue() < (int) tokensTime) {
					getPetriNet()->pushTransitionToCrossWhenAcceleration(transitionTo);
				}
			} else {
				if(arc->getRelativeMaxValue().getValue() < (int) tokensTime) {
					getPetriNet()->pushTransitionToCrossWhenAcceleration(transitionTo);
				}
			}

		}
	}



}