Ejemplo n.º 1
0
	virtual Action ChooseAction( const State& state, const ActionList& actions )
	{
		std::vector<double> weights( actions.size() );
		double maxReward = -std::numeric_limits<double>::infinity();
		double minReward = std::numeric_limits<double>::infinity();
		for( unsigned int i = 0; i < actions.size(); i++ )
		{
			weights[i] = rewardFunc->CalculateReward( state, actions[i] );
			if( weights[i] < minReward ) { minReward = weights[i]; }
			if( weights[i] > maxReward ) { maxReward = weights[i]; }
		}

		double rewardRange = maxReward - minReward;
		if( rewardRange < 1E-6 ) { rewardRange = 1.0; }
		double k = scaling / ( rewardRange );
		// Normalize the exponents by making sure the min raw weight is 0 and the max weight is 1
		for( unsigned int i = 0; i < actions.size(); i++ )
		  {
		    weights[i] = std::exp( k * ( weights[i] - minReward ) );
			std::cout << "Action: " << actions[i] << " weight: " << weights[i] << std::endl;
		  }
		std::vector<unsigned int> inds;
		argus::NaiveWeightedSample( weights, 1, inds, generator );
		
		return actions[ inds[0] ];
	}
Ejemplo n.º 2
0
bool CKeyBindings::RemoveCommandFromList(ActionList& al, const string& command)
{
	bool success = false;
	for (int i = 0; i < (int)al.size(); ++i) {
		if (al[i].command == command) {
			success = true;
			for (int j = (i + 1); j < (int)al.size(); ++j) {
				al[j - 1] = al[j];
			}
			al.resize(al.size() - 1);
		}
	}
	return success;
}
Ejemplo n.º 3
0
ActionList make_actions(boost::program_options::variables_map & po) {
	using std::string;
	ActionList ret;

	if (po.count("exec")) {
		string t = po["exec"].as<string>();
		boost::regex e("^(.*)(\\;|\\+)$");
		boost::smatch s;

		if (regex_match(t, s, e)) {
			
			string text = string(s[1].first, s[1].second);
			string action = string(s[2].first, s[2].second);

			if (action == ";") ret.push_back(new ExecAction(text));
			else ret.push_back(new ExecAllAction(text));
		} 
		else throw std::invalid_argument("Invalid exec argument: " + t);
		
		}
	if (po.count("print") || (ret.size() == 0)) {
		ret.push_back(new PrintAction);
	}

	return ret;
}
Ejemplo n.º 4
0
 void clear()
 {
     for(unsigned int k=0; k<actions.size();k++)
     {
         ActionItem *ret=actions.at(k);
         delete ret;
      }
     actions.clear();
 }
Ejemplo n.º 5
0
void ActionEditor::deleteActions(QDesignerFormWindowInterface *fw, const ActionList &actions)
{
    // We need a macro even in the case of single action because the commands might cause the
    // scheduling of other commands (signal slots connections)
    const QString description = actions.size() == 1 ?
        tr("Remove action '%1'").arg(actions.front()->objectName()) : tr("Remove actions");
    fw->beginCommand(description);
    foreach(QAction *action, actions) {
        RemoveActionCommand *cmd = new RemoveActionCommand(fw);
        cmd->init(action);
        fw->commandHistory()->push(cmd);
    }
Ejemplo n.º 6
0
bool ActionMenu::constructMenu(Entity *entity){
	dprintf(("entered Interface::constructActionMenu()\n"));

	if(!initialized) return false;

	//destroyActionMenu(); // kill any old action menu	
	release();

	ActionList actions = entity->getActionList();
			
	if(actions.size() <= 0){
		dprintf(("  size <= 0\n"));
		return false;
	}		
				
	width = ACTION_BUTTON_WIDTH;
	height = actions.size()*ACTION_BUTTON_HEIGHT;
	if(!createOffScreenSurface(image, width, height )) return false;
	//if(!createOffScreenSurface(image, ACTION_BUTTON_WIDTH, 
		//actions.size()*ACTION_BUTTON_HEIGHT)) return false;		
	if(image== NULL) dprintf(("  surface == NULL\n"));

	ActionList::iterator i;	
	int j;		
	for(j=0, i=actions.begin(); j<actions.size(); i++, j++){			
		//ActionType type = (*i)->getType();
		ActionType type = (*i)->type;
		int srcX = ((type%ACTION_BUTTON_FILE_COLUMNS)*(ACTION_BUTTON_WIDTH+1))+1;
		int srcY = ((type/ACTION_BUTTON_FILE_ROWS)*(ACTION_BUTTON_HEIGHT+1))+1;			
		if(!bmp->drawRectTo(0, j*ACTION_BUTTON_HEIGHT, image, srcX, srcY, 
			ACTION_BUTTON_WIDTH, ACTION_BUTTON_HEIGHT)){
			dprintf(("  problem drawing action button %d, type: %d\n", j, type));
			//destroyActionMenu();
			return false;
		}
	}

	actionReciever = entity;
	return true;
}
Ejemplo n.º 7
0
/** \fn KeyBindings::GetKeyContexts(const QString &) const
 *  \brief Get the context names in which a key is bound.
 *  \return A list of context names in which a key is bound.
 */
QStringList KeyBindings::GetKeyContexts(const QString &key) const
{
    ActionList actions = m_actionSet.GetActions(key);
    QStringList contexts;

    for (int i = 0; i < actions.size(); i++)
    {
        QString context = actions[i].GetContext();
        if (!contexts.contains(context))
            contexts.push_back(context);
    }

    return contexts;
}
Ejemplo n.º 8
0
void PrintDeviceInfo(Device *dev, int indent)
{
	string indentStr;
	GetIndentString(indent, indentStr);
	const char *devName = dev->getFriendlyName();
	cout << indentStr << devName << endl;

	int i, n, j;
	ServiceList *serviceList = dev->getServiceList();
	int serviceCnt = serviceList->size();
	for (n=0; n<serviceCnt; n++) {
		Service *service = serviceList->getService(n);
		cout << indentStr << " service[" << n << "] = "<< service->getServiceType() << endl;
		ActionList *actionList = service->getActionList();
		int actionCnt = actionList->size();
		for (i=0; i<actionCnt; i++) {
			Action *action = actionList->getAction(i);
			cout << indentStr << "  action[" << i << "] = "<< action->getName() << endl;
			ArgumentList *argList = action->getArgumentList();
			int argCnt = argList->size();
			for (j=0; j<argCnt; j++) {
					Argument *arg = argList->getArgument(j);
					cout << indentStr << "    arg[" << j << "] = " << arg->getName() << "("  << arg->getDirection() << ")";
					StateVariable *stateVar = arg->getRelatedStateVariable();
					if (stateVar != NULL)
						cout << " - " << stateVar->getName();
					cout << endl;
			}
		}
		ServiceStateTable *stateTable = service->getServiceStateTable();
		int varCnt = stateTable->size();
		for (i=0; i<varCnt; i++) {
			StateVariable *stateVar = stateTable->getStateVariable(i);
			cout << indentStr << "  stateVar[" << i << "] = " << stateVar->getName() << endl;
			AllowedValueList *valueList = stateVar->getAllowedValueList();
			int valueListCnt = valueList->size();
			if (0 < valueListCnt) {
				for (j=0; j<valueListCnt; j++)
					cout << indentStr << "    AllowedValueList[" << j << "] = " << valueList->getAllowedValue(j) << endl;
			}
			AllowedValueRange *valueRange = stateVar->getAllowedValueRange();
			if (valueRange != NULL) {
					cout << indentStr << "    AllowedRange[minimum] = " << valueRange->getMinimum() << endl;
					cout << indentStr << "    AllowedRange[maximum] = " << valueRange->getMaximum() << endl;
					cout << indentStr << "    AllowedRange[step] = " << valueRange->getStep() << endl;
			}
		}
	}
}
Ejemplo n.º 9
0
void PromotionTaskMenu::addActions(QDesignerFormWindowInterface *fw, unsigned flags,
                                   ActionList &actionList)
{
    Q_ASSERT(m_widget);
    const int previousSize = actionList.size();
    const PromotionState promotionState = createPromotionActions(fw);

    // Promotion candidates/demote
    actionList += m_promotionActions;

    // Edit action depending on context
    switch (promotionState) {
    case  CanPromote:
        actionList += m_EditPromoteToAction;
        break;
    case CanDemote:
        if (!(flags & SuppressGlobalEdit))
            actionList += m_globalEditAction;
        if (!languageExtension(fw->core())) {
            actionList += separatorAction(this);
            actionList += m_EditSignalsSlotsAction;
        }
        break;
    default:
        if (!(flags & SuppressGlobalEdit))
            actionList += m_globalEditAction;
        break;
    }
    // Add separators if required
    if (actionList.size() > previousSize) {
        if (flags &  LeadingSeparator)
            actionList.insert(previousSize, separatorAction(this));
        if (flags & TrailingSeparator)
            actionList += separatorAction(this);
    }
}
Ejemplo n.º 10
0
void ToolBarEventFilter::startDrag(const QPoint &pos, Qt::KeyboardModifiers modifiers)
{
    const int index = actionIndexAt(m_toolBar, pos, m_toolBar->orientation());
    if (index == - 1)
        return;

    const ActionList actions = m_toolBar->actions();
    QAction *action = actions.at(index);
    QDesignerFormWindowInterface *fw = formWindow();

    const Qt::DropAction dropAction = (modifiers & Qt::ControlModifier) ? Qt::CopyAction : Qt::MoveAction;
    if (dropAction == Qt::MoveAction) {
        RemoveActionFromCommand *cmd = new RemoveActionFromCommand(fw);
        const int nextIndex = index + 1;
        QAction *nextAction = nextIndex < actions.size() ? actions.at(nextIndex) : 0;
        cmd->init(m_toolBar, action, nextAction);
        fw->commandHistory()->push(cmd);
    }

    QDrag *drag = new QDrag(m_toolBar);
    drag->setPixmap(ActionRepositoryMimeData::actionDragPixmap( action));
    drag->setMimeData(new ActionRepositoryMimeData(action, dropAction));

    if (drag->start(dropAction) == Qt::IgnoreAction) {
        hideDragIndicator();
        if (dropAction == Qt::MoveAction) {
            const ActionList currentActions = m_toolBar->actions();
            QAction *previous = 0;
            if (index >= 0 && index < currentActions.size())
                previous = currentActions.at(index);
            InsertActionIntoCommand *cmd = new InsertActionIntoCommand(fw);
            cmd->init(m_toolBar, action, previous);
            fw->commandHistory()->push(cmd);
        }
    }
}
Ejemplo n.º 11
0
/** \fn KeyBindings::CommitChanges(void)
 *  \brief Commit all changes made to the keybindings.
 *
 *   This method will write the changes to the database, unbind %MythTV's
 *   current bindings for those actions that changed, and setup the
 *   new bindings.
 */
void KeyBindings::CommitChanges(void)
{
    ActionList modified = m_actionSet.GetModified();

    while (modified.size() > 0)
    {
        ActionID id = modified.front();

        // commit either a jumppoint or an action
        if (id.GetContext() == ActionSet::kJumpContext)
            CommitJumppoint(id);
        else
            CommitAction(id);

        // tell the action set that the action is no longer modified
        m_actionSet.SetModifiedFlag(id, false);

        modified.pop_front();
    }
}
Ejemplo n.º 12
0
void Driver::BuildUniversalActions(const ArgList &Args, 
                                   ActionList &Actions) const {
  llvm::PrettyStackTraceString CrashInfo("Building actions for universal build");
  // Collect the list of architectures. Duplicates are allowed, but
  // should only be handled once (in the order seen).
  llvm::StringSet<> ArchNames;
  llvm::SmallVector<const char *, 4> Archs;
  for (ArgList::const_iterator it = Args.begin(), ie = Args.end(); 
       it != ie; ++it) {
    Arg *A = *it;

    if (A->getOption().getId() == options::OPT_arch) {
      const char *Name = A->getValue(Args);

      // FIXME: We need to handle canonicalization of the specified
      // arch?

      A->claim();
      if (ArchNames.insert(Name))
        Archs.push_back(Name);
    }
  }

  // When there is no explicit arch for this platform, make sure we
  // still bind the architecture (to the default) so that -Xarch_ is
  // handled correctly.
  if (!Archs.size())
    Archs.push_back(0);

  // FIXME: We killed off some others but these aren't yet detected in
  // a functional manner. If we added information to jobs about which
  // "auxiliary" files they wrote then we could detect the conflict
  // these cause downstream.
  if (Archs.size() > 1) {
    // No recovery needed, the point of this is just to prevent
    // overwriting the same files.
    if (const Arg *A = Args.getLastArg(options::OPT_save_temps))
      Diag(clang::diag::err_drv_invalid_opt_with_multiple_archs) 
        << A->getAsString(Args);
  }

  ActionList SingleActions;
  BuildActions(Args, SingleActions);

  // Add in arch binding and lipo (if necessary) for every top level
  // action.
  for (unsigned i = 0, e = SingleActions.size(); i != e; ++i) {
    Action *Act = SingleActions[i];

    // Make sure we can lipo this kind of output. If not (and it is an
    // actual output) then we disallow, since we can't create an
    // output file with the right name without overwriting it. We
    // could remove this oddity by just changing the output names to
    // include the arch, which would also fix
    // -save-temps. Compatibility wins for now.

    if (Archs.size() > 1 && !types::canLipoType(Act->getType()))
      Diag(clang::diag::err_drv_invalid_output_with_multiple_archs)
        << types::getTypeName(Act->getType());

    ActionList Inputs;
    for (unsigned i = 0, e = Archs.size(); i != e; ++i)
      Inputs.push_back(new BindArchAction(Act, Archs[i]));

    // Lipo if necessary, We do it this way because we need to set the
    // arch flag so that -Xarch_ gets overwritten.
    if (Inputs.size() == 1 || Act->getType() == types::TY_Nothing)
      Actions.append(Inputs.begin(), Inputs.end());
    else
      Actions.push_back(new LipoJobAction(Inputs, Act->getType()));
  }
}
Ejemplo n.º 13
0
 int size()
 {
     return actions.size();
 }