Example #1
0
Parameters ActionNode::_paramsSendSignal(map<string, shared_ptr<InstanceSpecification> > affectations)
{
	shared_ptr<SendSignalAction> action = shared_dynamic_cast<SendSignalAction>(_action);

//	if (!(shared_dynamic_cast<SendSignalAction>(_action))->getTarget()) // FIXME
	{
		vector< shared_ptr<ActivityEdge> > edges = getOutgoing();
		for (size_t i = 0; i < edges.size() ; i++)
		{
			if (edges[i]->getTarget()->getKind() == "object")
			{
				map<string, shared_ptr<InstanceSpecification> >::iterator it = affectations.find(edges[i]->getTarget()->getName());
				if (it != affectations.end())
				{
					action->setTarget(it->second);
				}
				else
				{
					cerr << "affectation of " << edges[i]->getTarget()->getName() << "not found"<<endl;
					cerr << "affectations:"<<endl;
					map<string, shared_ptr<InstanceSpecification> >::iterator it = affectations.begin();
					while(it != affectations.end())
					{
						cerr << "  "<<it->first<<"="<<it->second->getName()<<endl;
						it++;
					}
				}
			}
		}
	}

	return Parameters();
}
Example #2
0
		double operator()(Random& random, size_t& idx) const {
			/* Get random number */
			double chi = random.uniform();
			/* Sample the bin on the cumulative */
			idx = std::upper_bound(cdf.begin(), cdf.end(), chi) - cdf.begin() - 1;
			/* Return outgoing value */
			return getOutgoing(chi, idx);
		}
Example #3
0
vector<shared_ptr<ActionNode> > ChoiceNode::getOutgoingActionNodeByPartition(const string& partitionName)
{
	vector<shared_ptr<ActionNode> > nodes;
	vector<shared_ptr<ActivityEdge> > edges = getOutgoing();
	for (size_t i=0; i<edges.size(); i++)
	{
		if(edges[i]->getTarget()->getPartition()[0]->getName() == partitionName)
		{
			if (edges[i]->getGuard())
			{
				bool eval;
				if (edges[i]->getGuard()->getSpecification()->getBoolValue(eval))
				{
					if(eval)
					{
						if(edges[i]->getTarget()->getKind() == "action")
						{
							nodes.push_back(shared_dynamic_cast<ActionNode>(edges[i]->getTarget()));
						}
						else
						{
							vector<shared_ptr<ActionNode> > actions=edges[i]->getTarget()->getOutgoingActionNodeByPartition(partitionName);
							for(size_t i=0;i<actions.size();i++)
								nodes.push_back(actions[i]);
						}
					}
				}
				else
				{
					cerr << "FAILED eval Expression!!!"<< endl;
				}
			}
			else
			{
				if(edges[i]->getTarget()->getPartition()[0]->getName() == partitionName)
				{
					if(edges[i]->getTarget()->getKind() == "action")
					{
						nodes.push_back(shared_dynamic_cast<ActionNode>(edges[i]->getTarget()));
					}
					else
					{
						vector<shared_ptr<ActionNode> > actions=edges[i]->getTarget()->getOutgoingActionNodeByPartition(partitionName);
						for(size_t i=0;i<actions.size();i++)
							nodes.push_back(actions[i]);
					}
				}
			}
		}
	}
	return nodes;
}
Example #4
0
void HypNode::setEnabledOutgoing(int on, int descend) {
  //  if (!bEnabled) return;
  for (int j = 0; j < getOutgoingCount(); j++) {
    HypLink *l = getOutgoing(j);
    HypNode *n = l->getChild();
    l->setDesired(on);
    // if other end is disabled don't turn it on
    if ( (on && getEnabled() && n->getEnabled()) || !on)
      l->setEnabled(on);
  }
  if (descend) 
    for (int i = 0; i < getChildCount(); i++)
      children[i]->setEnabledOutgoing(on, descend);
}
Example #5
0
vector<shared_ptr<ActionNode> > ChoiceNode::getOutgoingActionNode()
{
	vector<shared_ptr<ActionNode> > nodes;
	vector<shared_ptr<ActivityEdge> > edges = getOutgoing();
	for (size_t i=0; i<edges.size(); i++)
	{
		if (edges[i]->getGuard())
		{
			cerr << "eval "<<shared_dynamic_cast<Expression>(edges[i]->getGuard()->getSpecification())->getExpression()<<endl;
			bool eval=edges[i]->getGuard()->eval(_activity.lock()->getContext());
			if(eval)
			{
				if(edges[i]->getTarget()->getKind() == "action")
				{
					nodes.push_back(shared_dynamic_cast<ActionNode>(edges[i]->getTarget()));
					break;
				}
				else
				{
					vector<shared_ptr<ActionNode> > actions=edges[i]->getTarget()->getOutgoingActionNode();
					for(size_t i=0;i<actions.size();i++)
					{
						nodes.push_back(actions[i]);
					}
					if(actions.size())
						break;
				}
			}
		}
		else
		{
			if(edges[i]->getTarget()->getKind() == "action")
			{
				nodes.push_back(shared_dynamic_cast<ActionNode>(edges[i]->getTarget()));
				break;
			}
			else
			{
				vector<shared_ptr<ActionNode> > actions=edges[i]->getTarget()->getOutgoingActionNode();
				for(size_t i=0;i<actions.size();i++)
				{
					nodes.push_back(actions[i]);
				}
				if(actions.size())
					break;
			}
		}
	}
	return nodes;
}
Example #6
0
void HypNode::markEnable(int on, int descend) {
  int j;
  int wanted, value;
  HypLink *l;
  HypNode *n;
  setEnabled(on);
  for (j = 0; j < getChildCount(); j++) {
    l = getChildLink(j);
    n = l->getChild();
    wanted = l->getDesired();
    value = 0;
    if (n != (HypNode *)0 && on && getEnabled() && n->getEnabled() && wanted)
      value = 1;
    l->setEnabled(value);
  }
  l = getParentLink();
  if (l) {
    n = l->getParent();
    wanted = l->getDesired();
    value = 0;
    if (n != (HypNode *)0 && on && getEnabled() && n->getEnabled() && wanted)
      value = 1;
    l->setEnabled(value);
  }
  for (j = 0; j < getOutgoingCount(); j++) {
    l = getOutgoing(j);
    n = l->getChild();
    wanted = l->getDesired();
    value = 0;
    if (n != (HypNode *)0 && on && getEnabled() && n->getEnabled() && wanted)
      value = 1;
    l->setEnabled(value);
  }
  for (j = 0; j < getIncomingCount(); j++) {
    l = getIncoming(j);
    n = l->getParent();
    wanted = l->getDesired();
    value = 0;
    if (n != (HypNode *)0 && on && getEnabled() && n->getEnabled() && wanted)
      value = 1;
    l->setEnabled(value);
  }
  if (descend) 
    for (j = 0; j < getChildCount(); j++) {
      children[j]->markEnable(on, descend);
    }
}
Example #7
0
vector<shared_ptr<ActionNode> > ChoiceNode::getPossibleOutgoingActionNode()
{
	vector<shared_ptr<ActionNode> > nodes;
	vector<shared_ptr<ActivityEdge> > edges = getOutgoing();
	for (size_t i=0; i<edges.size(); i++)
	{
		if (edges[i]->getGuard())
		{
			bool eval=edges[i]->getGuard()->eval(_activity.lock()->getContext());
			if(eval)
			{
				if(edges[i]->getTarget()->getKind() == "action")
				{
					nodes.push_back(shared_dynamic_cast<ActionNode>(edges[i]->getTarget()));
				}
				else
				{
					vector<shared_ptr<ActionNode> > actions=edges[i]->getTarget()->getPossibleOutgoingActionNode();
					for(size_t i=0;i<actions.size();i++)
					{
						nodes.push_back(actions[i]);
					}
				}
			}
		}
		else
		{
			if(edges[i]->getTarget()->getKind() == "action")
			{
				nodes.push_back(shared_dynamic_cast<ActionNode>(edges[i]->getTarget()));
			}
			else
			{
				vector<shared_ptr<ActionNode> > actions=edges[i]->getTarget()->getPossibleOutgoingActionNode();
				for(size_t i=0;i<actions.size();i++)
				{
					nodes.push_back(actions[i]);
				}
			}
		}
	}
	return nodes;
}