QVariant PlaceListModel::data (const QModelIndex &index, int role) const { int idx = index.row (); if (idx < 0 || m_data.count () <= idx) return QVariant(); Place *place = m_data[idx]; switch (role) { case NAME: return place->name (); case PUBKEY: return place->pubKeyString (); case TYPE: return place->type (); case DESC: return place->desc (); case THREADS: return &m_threads[idx]; default: return QVariant(); } }
Place* PNP::addTimedAction(string name, Place *p0, int timevalue, Place **p0action) { // fork transition Transition *tf = addTransition("[]"); tf->setX(p0->getX()+1); tf->setY(p0->getY()); connect(p0,tf); // initial places of actions Place *pi1 = addPlace("X",-1); pi1->setX(tf->getX()+1); pi1->setY(tf->getY()-1); connect(tf,pi1); Place *pf1 = addAction(name,pi1); // actions Place *pi2 = addPlace("X",-1); pi2->setX(tf->getX()+1); pi2->setY(tf->getY()+1); connect(tf,pi2); stringstream ss; ss << "wait_" << timevalue; Place *pf2 = addAction(ss.str(),pi2); // join transition Transition *tj = addTransition("[]"); tj->setX(pf1->getX()+1); tj->setY(pf1->getY()+1); connect(pf1,tj); connect(pf2,tj); // interrupt Transition *ti = addTransition(name+".interrupt []"); ti->setX(tj->getX()); ti->setY(tj->getY()+1); connect(next(next(pi1)),ti); connect(pf2,ti); // final place Place *po = addPlace("X",-1); po->setX(tj->getX()+1); po->setY(tj->getY()); connect(tj,po); connect(ti,po); nactions+=2; *p0action = pi1; // initial place of action return po; }
void TypeNodeCodeGen::visit(MethodCall* m) { Place* self = getSelf(m); if ( const ScalarType* from = m->expr_->get().type_->cast<ScalarType>() ) { Value* val = self->getScalar(builder_); const ScalarType* to = cast<ScalarType>( m->memberFct_->sig_.out_[0]->getType() ); const llvm::Type* llvmTo = to->getLLVMType(ctxt_->module_); const llvm::Type* llvmFrom = from->getLLVMType(ctxt_->module_); if ( m->id()->find("bitcast") != std::string::npos ) val = builder_.CreateBitCast(val, llvmTo); else // -> assumes that r is a normal cast { if ( llvmTo == llvmFrom ) { setResult(m, new Scalar(val)); return; } llvm::StringRef name = val->getName(); if ( from->isInteger() && to->isInteger() ) { if ( from->sizeOf() > to->sizeOf() ) val = builder_.CreateTrunc(val, llvmTo, name); else { // -> sizeof(from) < sizeof(to) if ( from->isUnsigned() ) val = builder_.CreateZExt(val, llvmTo, name); else val = builder_.CreateSExt(val, llvmTo, name); } } else if ( from->isFloat() && to->isSigned() ) // fp -> si val = builder_.CreateFPToSI(val, llvmTo, name); else if ( from->isFloat() && to->isUnsigned() ) // fp -> ui val = builder_.CreateFPToUI(val, llvmTo, name); else if ( from->isSigned() && to->isFloat() ) // si -> fp val = builder_.CreateSIToFP(val, llvmTo, name); else if ( from->isUnsigned() && to->isFloat() ) // ui -> fp val = builder_.CreateUIToFP(val, llvmTo, name); else { swiftAssert( from->isFloat() && to->isFloat(), "must both be floats" ); if ( from->sizeOf() > to->sizeOf() ) val = builder_.CreateFPTrunc(val, llvmTo, name); else // -> sizeof(from) < sizeof(to) val = builder_.CreateFPExt(val, llvmTo, name); } } setResult( m, new Scalar(val) ); } else emitCall(m, self); }
void AttackAction::execute(Player *player, Command *command, Game *game) { Place *location = player->getLocation(); BeingListCItPair beings = location->getBeingsByName(command->getDirectObject()); if (beings.begin == beings.end) { player->out("display") << "There is no " << command->getDirectObject() << " here!" << endl; return; } try { string weaponName = command->getIndirectObject(); Object *weapon = 0; Being *defender = Entity::clarifyEntity<BeingListCItPair, BeingListCIt, Being *>(beings, player); if (weaponName.length() > 0) { ObjectListCItPair items = player->getInventoryObjectsByName(weaponName); if (items.begin == items.end) { player->out("display") << "You don't have a " << weaponName << "!" << endl; return; } try { weapon = Entity::clarifyEntity<ObjectListCItPair, ObjectListCIt, Object *>(items, player); // TODO: this check should be made inside Being (we'd have an // exception to catch) if (!weapon->isWeapon()) { player->out("display") << "The " << weaponName << " isn't a weapon!" << endl; return; } } catch (string name) { player->out("display") << "You don't have a " << weaponName << "!" << endl; return; } } player->attack(defender, weapon); } catch (string name) { player->out("display") << "There is no " << name << " here!" << endl; } }
Place * Place::create(const QString &name, const QString &city, const QString &type, QObject *parent) { Place * returned = new Place(parent); returned->d_func()->name = name; returned->d_func()->city = city; returned->d_func()->type = typeFromString(type); returned->d_func()->typeString = type; return returned; }
int main() { string input_in_form = "London"; string input_in_Place = "Eugene"; form_mesto z = form_mesto(input_in_form); Place x = Place(input_in_Place); x.add_place(z); std::ofstream ofs("save.dat", std::ios::binary); boost::archive::binary_oarchive oa(ofs); oa << x; }
void SimbaNonsearchAllplacesGetResponse::parseNormalResponse() { parseError(); if (responseParser->hasName("place_list")) { QList<Parser *> listParser = responseParser->getListObjectParser("place_list"); Parser *parser; foreach (parser, listParser) { Place tmp; tmp.setParser(parser); tmp.parseResponse(); placeList.append(tmp); }
Place::Place(const Place& place) { name = NULL; sign = NULL; x = 0; y = 0; if (place.name && place.sign) { set_place(place.get_x(), place.get_y(), place.get_name(), place.get_sign()); } else { cout << "Cannot copy NULL pointer!!" << endl; } }
void LookAction::execute(Player *player, Command *command, Game *game) { string object = command->getDirectObject(); if (object.length() == 0) { object = command->getIndirectObject(); } if (object.length() == 0) { player->getLocation()->observe(player, true, true); } else { Place *location = player->getLocation(); // Note: I can't use list.merge(), because ObjectList and ThingList are // of different types :'( ThingList items; // consider matching inventory items, if there are any ObjectListCItPair invItems = player->getInventoryObjectsByName(object); for (ObjectListCIt i = invItems.begin; i != invItems.end; i++) { items.push_front(*i); } // also consider matching items in the room, if there are any ThingListCItPair roomItems = location->getThingsByName(object); for (ThingListCIt i = roomItems.begin; i != roomItems.end; i++) { items.push_front(*i); } if (0 == items.size()) { player->out("display") << "There is no " << object << " here!" << endl; return; } ThingListCItPair itemsIt; itemsIt.begin = items.begin(); itemsIt.end = items.end(); try { Thing *thing = Entity::clarifyEntity<ThingListCItPair, ThingListCIt, Thing *>(itemsIt, player); thing->observe(player, true, true); } catch (string name) { player->out("display") << "There is no " << name << " here!" << endl; } } }
Place* Place::create(const Vec2& pos) { Place *ret = new (std::nothrow) Place(); if (ret && ret->initWithPosition(pos)) { ret->autorelease(); return ret; } CC_SAFE_DELETE(ret); return nullptr; }
Place* Place::create(const Point& pos) { Place *pRet = new Place(); if (pRet && pRet->initWithPosition(pos)) { pRet->autorelease(); return pRet; } CC_SAFE_DELETE(pRet); return NULL; }
void TreeCorrelator::createPlace(std::map<std::string, std::string>& params, bool verbose) { bool replace = false; if (params["replace"] != "") replace = strings::to_bool(params["replace"]); vector<string> names = split_names(params["name"]); for (vector<string>::iterator it = names.begin(); it != names.end(); ++it) { if (params["type"] != "") { if (replace) { if (places_.count((*it)) != 1) { stringstream ss; ss << "TreeCorrelator: cannot replace Place " << (*it) << ", it doesn't exist"; throw TreeCorrelatorException(ss.str()); } delete places_[(*it)]; if (verbose) { Messenger m; stringstream ss; ss << "Replacing place " << (*it); m.detail(ss.str(), 1); } } else { if (places_.count((*it)) == 1) { stringstream ss; ss << "TreeCorrelator: place" << (*it) << " already exists"; throw TreeCorrelatorException(ss.str()); } if (verbose) { Messenger m; stringstream ss; ss << "Creating place " << (*it); m.detail(ss.str(), 1); } } Place* current = builder.create(params, verbose); places_[(*it)] = current; if (strings::to_bool(params["init"])) current->activate(0.0); } if (params["parent"] != "root") { bool coincidence = strings::to_bool(params["coincidence"]); addChild(params["parent"], (*it), coincidence, verbose); } } }
vector<Place> PlacesManager::findRandom(unsigned int limit) { vector<Place> places; ResultSet &rs = Database::getInstance().execute("SELECT id, name FROM place ORDER BY RANDOM() LIMIT %d", limit); while (rs.hasNext()) { Place place; place.setId(rs.getInt(0)); place.setName(rs.getString(1)); places.push_back(place); } return places; }
void previewPlace(Place& place) { { const TexMng::tex_ptr texture = texmng_.get(tex_name_l_); const Vec2<int>& ts = texture->size(); GrpSprite obj; obj.size(size_.x / 2.0f, size_.y); obj.center(size_.x / 2.0f, size_.y / 2.0); obj.texture(texture); obj.uv(0, 0, ts.x, ts.y); obj.col(1.0, 1.0, 1.0); obj.draw(); // 左側 } { const TexMng::tex_ptr texture = texmng_.get(tex_name_r_); const Vec2<int>& ts = texture->size(); GrpSprite obj; obj.size(size_.x / 2.0f, size_.y); obj.center(0, size_.y / 2.0); obj.texture(texture); obj.uv(0, 0, ts.x, ts.y); obj.col(1.0, 1.0, 1.0); obj.draw(); // 右側 } glScalef(size_.x / 2.0, size_.y / 2.0, 1.0); place.draw(); }
bool BoardQObjectAbstraction::selectSquare(int column, int row) { bool moveAccepted = false; Place * tempPlace = selectedPlace; if(this->board != nullptr) { selectedPlace = board->getPlaceByCoord(column, row); if( (tempPlace != nullptr) &&(tempPlace->getOccupyingPiece() != nullptr)) { moveAccepted = board->movePiece(tempPlace, this->selectedPlace); } if( (selectedPlace->getOccupyingPiece() == nullptr) ||(moveAccepted == true)) { selectedPlace = nullptr; } } return moveAccepted; }
/**Operational method for the class; * Called to prompt the user to specificy the Place Object's attribute they wish to change, and * the value to set it to. * * @return Returns a pointer to itself (this) */ ModifyPlacesView* ModifyPlacesView::start() { Place* place = getPlace(rootPlace); string opts[3] = {"Name", "Longitude", "Latitude"}; OptionsView<string> view(opts, 3); int menuSelection = 0; do { cout << LF << "\tWhat would you like to modify?" << LF; switch (menuSelection = view.display()->getOption()) { case 0: place->setName(getAddress(1, "Please enter the name")); break; case 1: place->setLongitude(inputFloat("Please enter the longitude")); break; case 2: place->setLatitude(inputFloat("Please enter the latitude")); break; } } while (menuSelection != 3); return this; }
/*! From QAbstractListModel. Returns data from model by \a index by \a role. */ QVariant PlacesModel::data(const QModelIndex &index, int role /* Qt::DisplayRole */) const { if (!index.isValid()) { return QVariant(); } const int itemIndex(index.row()); const int placesCount(mPlaces.count()); int virtualIndex(0); Place *place = 0; // Skip all invisible places for (int i = 0; i < placesCount; ++i) { if (mPlaces[i]->visible()) { if (itemIndex == virtualIndex) { place = mPlaces[i]; break; } else { virtualIndex++; } } } if (!place) { return QVariant(); } QVariant value = QVariant(); switch (role) { case NameRole: value = QVariant::fromValue(place->name()); break; case StreetAddressRole: value = QVariant::fromValue(place->address().street()); break; case LatitudeRole: value = QVariant::fromValue(place->coordinate().latitude()); break; case LongitudeRole: value = QVariant::fromValue(place->coordinate().longitude()); break; case IconUrlRole: value = QVariant::fromValue(place->iconUrl()); break; case PlaceObjectRole: value = QVariant::fromValue((QObject*)place); break; default: break; } return value; }
Place* PNP::addAction(string name, Node *p0) { Transition *ts = addTransition(name+".start"); Place *pe = addPlace(name+".exec"); Transition *te = addTransition(name+".end"); Place *pf = addPlace("X",-1); ts->setY(p0->getY()); pe->setY(p0->getY()); // same line as p0 te->setY(p0->getY()); pf->setY(p0->getY()); ts->setX(p0->getX()+1); pe->setX(p0->getX()+2); // X pos after p0 te->setX(p0->getX()+3); pf->setX(p0->getX()+4); connect(p0,ts); connect(ts,pe); connect(pe,te); connect(te,pf); nactions++; return pf; }
void Database::addPlace(Place place) { int sizex,i; string name; name=place.getPlaceName(); //getting place name sizex=places.size(); //getting size of place vector try{ for(i=0; i<sizex; i++) //searching place entries { if(places[i].getPlaceName()==name) throw (SystemError) 0; //if place exists, return error messages } places.push_back(place); //if no error messages received add place entry. } catch(SystemError x) { cout << "ERR_PLACE_EXISTS"<<endl; } }
vector<Place*> PNP::addSensingAction(string name, Place* p0, vector<string> outcomes) { vector<Place *> v; Transition *ts = addTransition(name+".start"); Place *pe = addPlace(name+".exec"); ts->setY(p0->getY()); pe->setY(p0->getY()); // same line as p0 ts->setX(p0->getX()+1); pe->setX(p0->getX()+2); // X pos after p0 connect(p0,ts); connect(ts,pe); int k=0; for (vector<string>::iterator it = outcomes.begin(); it!=outcomes.end(); it++, k++) { Transition *te = addTransition("["+(*it)+"] "+name+".end"); Place *pf = addPlace("X",-1); te->setY(p0->getY()+k); pf->setY(p0->getY()+k); te->setX(p0->getX()+3); pf->setX(p0->getX()+4); connect(pe,te); connect(te,pf); v.push_back(pf); } nactions++; return v; }
PageEntryDialog::PageEntryDialog(int pageset,QWidget * parent) : QDialog(parent) { QLOG_DEBUG() << Q_FUNC_INFO; QSqlQuery p(QSqlDatabase::database("notesdb")); if (! p.prepare(SQL_PAGESET_DETAIL)) { QLOG_WARN() << QString(tr("Prepare failed for SQL_PAGESET_DETAIL query:%1")).arg(p.lastError().text()); } /// we shouldn't have sql errors, but this should fail gracefully p.bindValue(0,pageset); p.exec(); int page = 0; QVBoxLayout * layout = new QVBoxLayout; QMap<int,QString> hm; QStringList cols; cols << tr("Select") << tr("Node") << tr("Root") << tr("Headword") << tr("Volume/Page") << tr("Id"); m_pages = new ColumnarTableWidget(cols); m_pages->setKey(ColumnarTableWidget::STATE,SID_PAGESET_PAGEENTRY_STATE); m_pages->setSelectionMode(QAbstractItemView::SingleSelection); m_pages->verticalHeader()->setVisible(false); QString html; QLabel * label; while(p.next()) { Place n = Place::fromString(p.record().value("place").toString()); if (n.isValid()) { page = m_pages->rowCount(); m_pages->insertRow(page); m_pages->setItem(page,PAGE_NODE_COLUMN,new QTableWidgetItem(n.m_node)); m_pages->item(page,PAGE_NODE_COLUMN)->setTextAlignment(Qt::AlignCenter); html = qobject_cast<Lexicon *>(qApp)->scanAndStyle(n.m_root,"pageset"); label = new QLabel(html);; label->setAlignment(Qt::AlignCenter); m_pages->setCellWidget(page,PAGE_ROOT_COLUMN,label); html = qobject_cast<Lexicon *>(qApp)->scanAndStyle(n.m_word,"pageset"); label = new QLabel(html);; label->setAlignment(Qt::AlignCenter); m_pages->setCellWidget(page,PAGE_WORD_COLUMN,label); m_pages->setCellWidget(page,PAGE_LOAD_COLUMN,new CenteredCheckBox); m_pages->setItem(page,PAGE_VOLUME_COLUMN,new QTableWidgetItem(n.format("%V/%P"))); m_pages->item(page,PAGE_VOLUME_COLUMN)->setTextAlignment(Qt::AlignCenter); m_pages->setItem(page,PAGE_ID_COLUMN,new QTableWidgetItem(p.record().value("id").toString())); } } int rows = m_pages->rowCount(); if (m_pages->rowCount() == 0) { m_pages->clear(); m_pages->insertRow(0); m_pages->setColumnCount(1); m_pages->setHorizontalHeaderLabels(QStringList() << ""); m_pages->horizontalHeader()->setStretchLastSection(true); QLabel * m = new QLabel(tr("<em>No pages found</em>")); m->setAlignment(Qt::AlignCenter); m_pages->setCellWidget(0,0,m); } else { QTableWidgetItem * item; QList<int> cols; cols << PAGE_NODE_COLUMN << PAGE_VOLUME_COLUMN << PAGE_ID_COLUMN; for(int i=0;i < m_pages->rowCount();i++) { for(int j=0;j < cols.size();j++) { item = m_pages->item(i,cols[j]); item->setFlags(item->flags() ^ Qt::ItemIsEditable); } } } m_pages->hideColumn(PAGE_ID_COLUMN); m_pages->resizeColumnsToContents(); layout->addWidget(m_pages); QDialogButtonBox * buttonBox; if (rows > 0) { buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); QPushButton * btn1 = new QPushButton(tr("Select all")); buttonBox->addButton(btn1,QDialogButtonBox::ActionRole); connect(btn1,SIGNAL(clicked()),this,SLOT(onSelectAll())); QPushButton * btn2 = new QPushButton(tr("Clear Selections")); buttonBox->addButton(btn2,QDialogButtonBox::ActionRole); connect(btn2,SIGNAL(clicked()),this,SLOT(onClearSelections())); } else { buttonBox = new QDialogButtonBox(QDialogButtonBox::Cancel); } connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept())); connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); layout->addWidget(buttonBox); setLayout(layout); /// SETTINGS settings.beginGroup("PageSets"); m_pages->readConfiguration(settings); }
bool PNPGenerator::genFromPolicy(Policy &p) { bool _error = false; // check if errors occur during generation // Map of visited states (with associated places) std::map<string,Place*> visited; cout << "Init: " << p.initial_state << endl; string current_state = p.initial_state; // add a first fixed transition from the init place to the initial state pair<Transition*,Place*> pa = pnp.addCondition("[]",pnp.pinit); Place *p1 = pa.second; p1->setName(current_state); // put place for initial state visited[p.initial_state]=p1; cout << "Final: " << p.final_state << endl; //string final_state_str = transformState(final_state); // Initialization of the stack stack< pair<string, Place*> > SK; SK.push(make_pair(current_state,p1)); while (!SK.empty()) { // get top element from stack current_state=SK.top().first; Place* current_place = SK.top().second; SK.pop(); std::cout << "PNPgen:: " << current_state << " : "; string action = p.getActionForState(current_state); if (action=="") { if (current_state!=p.final_state) std::cerr << "PNPgen Warning: No action found for state " << current_state << std::endl; continue; } std::cout << action << " -> "; vector<StateOutcome> vo = p.getOutcomes(current_state,action); if (vo.size()==0) { std::cerr << "PNPgen ERROR: No successor state found for state " << current_state << " and action " << action << std::endl; _error = true; break; } Place *pe = addAction(action,current_place); // pe: end place of action // y coordinate of Petri Net layout int dy=0; vector<StateOutcome>::iterator io; for (io = vo.begin(); io!=vo.end(); io++) { string succ_state = io->successor; string cond = io->observation; if (cond[0]!='[') cond = "["+cond+"]"; cout << cond << " " << succ_state << " "; Place *ps = visited[succ_state]; // check if succ_state is already visited if (ps==NULL) { // if not visited pair<Transition*,Place*> pa = pnp.addCondition(cond,pe,dy); dy++; Place* pc = pa.second; SK.push(make_pair(succ_state,pc)); visited[succ_state]=pc; pc->setName(succ_state); if (succ_state==p.final_state) pc->setName("goal"); } else { // if already visited pnp.addConditionBack(cond,pe, ps, dy); dy++; } } // for io std::cout << std::endl; } return !_error; }
void Transition::crossTransition(bool mustChangeTokenValue, unsigned int newTokenValue) { if (!areAllInGoingArcsActive()) { throw IncoherentStateException(); } arcList inGoingArc = inGoingArcsOf(); arcList outGoingArc = outGoingArcsOf(); resetBitArray(); set<Transition*> transitionsToReset; unsigned int tokenValue = 0; for (unsigned int i = 0 ; i < inGoingArc.size() ; ++i) { tokenValue = inGoingArc[i]->consumeTokenInFrom(); if (isStatic()) { tokenValue -= inGoingArc[i]->getRelativeMinValue().getValue(); } else { tokenValue -= inGoingArc[i]->getRelativeMaxValue().getValue(); } if (inGoingArc[i]->haveEnoughTokensInFrom()) { setArcAsActive(inGoingArc[i], 0, false); } else { Place* place = (Place*) inGoingArc[i]->getFrom(); petriNetNodeList nodeList = place->returnSuccessors(); if (nodeList.size() > 1) { for (unsigned int i = 0 ; i < nodeList.size() ; ++i) { if (nodeList[i] != this) { transitionsToReset.insert((Transition*) nodeList[i]); } } } } } if (mustChangeTokenValue) { tokenValue = newTokenValue; } transitionList transitionsToResetList(transitionsToReset.begin(), transitionsToReset.end()); for (unsigned int i = 0 ; i < transitionsToResetList.size() ; ++i) { transitionsToResetList[i]->resetBitArray(); transitionsToResetList[i]->resetIncomingArcsState(); } if (m_externActions.size() > 0) { for (unsigned int i = 0 ; i < m_externActions.size() ; ++i) { m_externActions[i]->m_transitionAction(m_externActions[i]->m_transitionActionArgument); } } for (unsigned int i = 0 ; i < outGoingArc.size() ; ++i) { outGoingArc[i]->produceTokenInTo(tokenValue); } }
void PNPGenerator::applySocialRules() { pair<string, Place*> current; Place* noplace=NULL; while (!ASS.empty()) { current=ASS.top(); ASS.pop(); string current_action_param = current.first; vector<string> tk; boost::split(tk,current_action_param,boost::is_any_of("_")); string current_action = tk[0]; // current action (without parameters) Place* current_place = current.second; // init place of this action // before vector<pair<string,string> >::iterator sit = socialrules.begin(); while (sit!=socialrules.end()) { string a = sit->first, b = sit->second; sit++; vector<string> tk; boost::split(tk,a,boost::is_any_of(" ")); if (tk[0]=="before" && tk[1]==current_action) { current_place=add_before(pnp,b,current_action,current_place); /* - Execution rules if (b=="approach") pnp.addInterrupt(current_place,"not humanDetected",pnp.pinit); if (b=="explain_approach") pnp.addInterrupt(current_place,"not humanDetected",pnp.pinit); */ } } // after sit = socialrules.end(); while (sit!=socialrules.begin()) { sit--; string a = sit->first, b = sit->second; vector<string> tk; boost::split(tk,a,boost::is_any_of(" ")); if (tk[0]=="after" && tk[1]==current_action) { Place *pp = add_after(pnp,b,current_action,current_place); /* - Execution rules if (b=="approach") pnp.addInterrupt(pp,"not humanDetected",pnp.pinit); // not humanDetected if (b=="explain_approach") pnp.addInterrupt(current_place,"not humanDetected",pnp.pinit); */ } } // during sit = socialrules.begin(); while (sit!=socialrules.end()) { string a = sit->first, b = sit->second; sit++; vector<string> tk; boost::split(tk,a,boost::is_any_of(" ")); if (tk[0]=="during" && tk[1]==current_action) { // add b during this action //cout << "-- add " << b << " in parallel with " << current_action << endl; // search for action after place current_place // it may be different when after and before add actions around... Node* nn = current_place; bool found=false; while (!found) { string naction = pnp.next(nn)->getName(); found = naction.substr(0,current_action.size())==current_action; // cout << naction << "=" << current_action << " " << found << endl; if (!found) nn = pnp.next(nn); } Node* t1 = pnp.disconnect(nn); Transition* tf = pnp.addTransition(" "); tf->setX(nn->getX()+1); tf->setY(nn->getY()); pnp.connect(nn,tf); Place* p1 = pnp.addPlace("YA",-1); p1->setX(tf->getX()+1); p1->setY(tf->getY()); pnp.connect(tf,p1); pnp.connect(p1,t1); current_place=p1; Place* p2 = pnp.addPlace("YB",-1); p2->setX(tf->getX()+1); p2->setY(tf->getY()+1); pnp.connect(tf,p2); Place* p2e = pnp.addAction(b,p2); addActionToStacks(b,p2); // new action (b, p2) to be analyzed Transition* tj = pnp.addTransition(" "); tj->setX(p2e->getX()+1); tj->setY(p2e->getY()); pnp.connect(p2e,tj); for (int k=0; k<3; k++) t1 = pnp.next(t1); Node* t3 = pnp.disconnect(t1); pnp.connect(t1,tj); Place *po = pnp.addPlace("Z",-1); po->setX(tj->getX()+2); po->setY(tj->getY()); pnp.connect(tj,po); pnp.connect(po,t3); } } } }
void PNPGenerator::applyExecutionRules() { pair<string, Place*> current; Place* noplace=NULL; while (!ASE.empty()) { current=ASE.top(); ASE.pop(); string current_action_param = current.first; vector<string> tk; boost::split(tk,current_action_param,boost::is_any_of("_")); string current_action = tk[0]; // current action (without parameters) Place* current_place = current.second; // init place of this action cout << "Applying execution rules for action " << current_action << endl; vector<TExecutionRule>::iterator eit; eit = executionrules.v.begin(); while (eit!=executionrules.v.end()) { if (eit->action==current_action) { cout << " " << eit->condition << " -> " << eit->recoveryplan << endl; boost::trim(eit->recoveryplan); vector<string> v; boost::split(v,eit->recoveryplan,boost::is_any_of("; "),boost::token_compress_on); Place *po = NULL; string R=""; Place *pi = pnp.addPlace("I",-1); pi->setY(current_place->getY()-1); pi->setX(current_place->getX()+3); if (v.size()>1) { // build actual plan without recovery specification string plan = ""; int i=0; for (i=0; i<v.size()-2; i++) plan = plan + v[i] + ";"; plan = plan + v[i]; //cout << "-- recovery plan " << plan << endl; po = genLinearPlan(pi,plan,false); // output place of linear plan R = v[v.size()-1]; } else { R = eit->recoveryplan; po = pi; } pnp.addInterrupt(current_place,eit->condition,pi); if (R=="fail_plan") { po->setName("fail"); } else if (R=="restart_plan") { pnp.connectPlaces(po,pnp.pinit); } else if (R=="restart_action") { pnp.connectPlaces(po,current_place); } else if (R=="skip_action") { pnp.connectPlaces(po,pnp.endPlaceOf(current_place)); } } eit++; } } }
void PNPGenerator::genHumanAction(string say_ask, string say_do, string action_do, string say_dont, string condition) { Place *p1 = pnp.addAction("findHuman",pnp.pinit); addActionToStacks("findHuman",pnp.pinit); Place *p2 = pnp.addAction(say_ask,p1); addActionToStacks(say_ask,p1); pair<Transition*,Place*> ptg = pnp.addCondition(" ",p2); Place *p = ptg.second; Transition* t1 = pnp.addTransition("["+condition+"]"); t1->setY(p->getY()-1); t1->setX(p->getX()+1); Transition* t2 = pnp.addTransition("[saidYes]"); t2->setY(p->getY()+0); t2->setX(p->getX()+1); Transition* t3 = pnp.addTransition("[saidNo]"); t3->setY(p->getY()+1); t3->setX(p->getX()+1); Transition* t4 = pnp.addTransition("[timeout]"); t4->setY(p->getY()+2); t4->setX(p->getX()+1); pnp.connect(p,t1); pnp.connect(p,t2); pnp.connect(p,t3); pnp.connect(p,t4); Place *py = pnp.addPlace("Y",-1); py->setY(t2->getY()); py->setX(t2->getX()+1); pnp.connect(t2,py); Place *pn = pnp.addPlace("N",-1); pn->setY(t3->getY()); pn->setX(t3->getX()+1); pnp.connect(t3,pn); // say_do, action_do Place *pd1 = pnp.addAction(say_do,py); addActionToStacks(say_do,py); Place *pd2 = pnp.addAction(action_do,pd1); addActionToStacks(action_do,pd1); ptg = pnp.addCondition("["+condition+"]",pd2); Place *pg = ptg.second; pg->setName("goal"); // say_dont Place *pf1 = pnp.addAction(say_dont,pn); addActionToStacks(say_dont,pn); Transition* tf1 = pnp.addTransition("[not humanDetected]"); tf1->setY(pf1->getY()); tf1->setX(pf1->getX()+1); pnp.connect(pf1,tf1); pnp.connect(tf1,pnp.pinit); pnp.connect(t1,pg); pnp.connect(t4,pnp.pinit); pnp.addInterrupt(pnp.pinit, condition, pg); }
void PNPGenerator::setMainLinearPlan(string plan) { Place *p = genLinearPlan(pnp.pinit,plan); p->setName("goal"); }
void TypeNodeCodeGen::emitCall(MemberFctCall* call, Place* self) { Values args; MemberFct* fct = call->getMemberFct(); call->exprList_->accept(this); TypeList& out = fct->sig_.outTypes_; /* * prepare arguments */ if (self) args.push_back( self->getAddr(builder_) ); Values perRefRetValues; // append return-value arguments for (size_t i = 0; i < out.size(); ++i) { const Type* type = out[i]; if ( type->perRef() ) { int simdLength = call->simd_ ? 4 : 0; // HACK const llvm::Type* llvmType = type->getRawLLVMType(ctxt_->module_, simdLength); // do return value optimization or create temporary Place* place = 0; if ( call->initPlaces_ && (*call->initPlaces_)[i] ) place = (*call->initPlaces_)[i]; Value* arg = place ? place->getAddr(builder_) : createEntryAlloca(builder_, llvmType); args.push_back(arg); perRefRetValues.push_back(arg); } } // append regular arguments call->exprList_->getArgs(builder_, args); llvm::Function* llvmFct = call->simd_ ? fct->simdFct_ : fct->llvmFct_; swiftAssert(llvmFct, "must exist"); // create actual call llvm::CallInst* callInst = llvm::CallInst::Create( llvmFct, args.begin(), args.end() ); callInst->setCallingConv(llvm::CallingConv::Fast); Value* retValue = builder_.Insert(callInst); /* * write results back */ swiftAssert( call->numResults() == out.size(), "sizes must match" ); size_t idxRetType = 0; size_t idxPerRef = 0; for (size_t i = 0; i < out.size(); ++i) { call->set(i).place_ = out[i]->perRef() ? (Place*) new Addr( perRefRetValues[idxPerRef++] ) : (Place*) new Scalar( builder_.CreateExtractValue(retValue, idxRetType++) ); } }
void startInteractiveTest() { float l, w, d, h; int mD; cout << "\tQuadtree testing - Interactive test" << endl << endl << "Enter parameters for new tree (left, width, down, height, max depth)" << endl; cin >> l >> w >> d >> h >> mD; { Quadtree testTree(l, w, d, h, mD); map<string, Place *> places; int testOpt; CLEAR_SCR(); try { do { cout << "\tQuadtree testing - Interactive test" << endl << endl << "1. Print testing tree" << endl << "2. Add new place" << endl << "3. Remove place" << endl << "4. Move place" << endl << "5. Print places" << endl << "6. Get place at coordinate" << endl << "7. Get places in area" << endl << endl << "0. Exit interactive test" << endl << endl << "Enter option: "; cin >> testOpt; CLEAR_SCR(); switch (testOpt) { case PRINT_TREE: { cout << testTree; PAUSE(); PAUSE(); //Needs two since "\n" is still in cin. break; } case PRINT_PLACES: { cout << "Allocated places:" << endl; for (map<string, Place *>::iterator it = places.begin(); it != places.end(); it++) { cout << "\t" << (*it).second->getName() << "\t(" << (*it).second->getX() << ", " << (*it).second->getY() << ")" << endl; } PAUSE(); PAUSE(); break; } case ADD_PLACE: { float x, y; string name; cout << "Enter name: "; cin >> name; cout << "Coordinate: "; cin >> x >> y; Place *newPlace = new Place(x, y, name); testTree.addPos(newPlace); places[name] = newPlace; PAUSE(); PAUSE(); break; } case REMOVE_PLACE: { string name; Place *place; cout << "Enter name: "; cin >> name; place = places[name]; testTree.removePos(place); places.erase(name); PAUSE(); PAUSE(); break; } case MOVE_PLACE: { string name; Place *place; float x, y; cout << "Enter name: "; cin >> name; cout << "Enter new coordinate: "; cin >> x >> y; place = places[name]; place->setX(x); place->setY(y); testTree.updatePos(place); PAUSE(); PAUSE(); break; } case GET_AT: { float x, y; cout << "Enter coordinate: "; cin >> x >> y; vector<IRO_Point2D *> points; points = testTree.getContentAt(x, y); cout << "Found: " << points.size() << " places." << endl; for (vector<IRO_Point2D *>::iterator it = points.begin(); it != points.end(); it++) { cout << static_cast<Place *>(*it)->getName() << " "; } PAUSE(); PAUSE(); break; } case GET_IN_RECT: { float x1, y1, x2, y2; vector<IRO_Point2D *> placesInRect; cout << "Enter rectangle (left, down, right, up): "; cin >> x1 >> y1 >> x2 >> y2; placesInRect = testTree.getContentInRect(x1, y1, x2, y2); cout << "Found: " << placesInRect.size() << " places." << endl; for (vector<IRO_Point2D *>::iterator it = placesInRect.begin(); it != placesInRect.end(); it++) { cout << static_cast<Place *>(*it)->getName() << " "; } PAUSE(); PAUSE(); break; } } CLEAR_SCR(); } while (testOpt != EXIT_TEST); } catch (exception &e) { cout << e.what() << endl; PAUSE(); PAUSE(); } for (map<string, Place *>::iterator it = places.begin(); it != places.end(); it++) { delete (*it).second; } places.clear(); } PAUSE(); }
bool Oca::loadXml(string _xmlConfigFile){ bool loaded = false; ofxXmlSettings XML; if (XML.loadFile(_xmlConfigFile)){ places.clear(); players.clear(); // Places ( casilleros ) // int totalPatchs = XML.getNumTags("place"); for(int i = 0; i < totalPatchs ; i++){ XML.pushTag("place", i); Place *newPlace = new Place( XML.getValue("id", -1) ); newPlace->angle = XML.getValue("angle", 0.0); newPlace->message = XML.getValue("message", "NULL"); // Load the mask path if ( XML.pushTag("mask") ){ int totalMaskCorners = XML.getNumTags("point"); if (totalMaskCorners > 0){ newPlace->clear(); } for(int i = 0; i < totalMaskCorners; i++){ XML.pushTag("point",i); newPlace->addVertex( space.x + XML.getValue("x", 0.0) * space.width, space.y + XML.getValue("y", 0.0)*space.height); XML.popTag(); } XML.popTag(); // Pop "mask" } newPlace->scale = scaleFactor; newPlace->bLoop = XML.getValue("loop", false); newPlace->lockUntil = XML.getValue("lock", -1); if ( XML.tagExists("link")){ if ( XML.pushTag("link") ){ int totalLinks = XML.getNumTags("id"); for(int i = 0; i < totalLinks; i++){ int linkId = XML.getValue("id", i); newPlace->linked.push_back(linkId); } XML.popTag(); // Pop "link" } } newPlace->setImage( XML.getValue("baseImage", "00.png") ); newPlace->bColored = XML.getValue("colored", false); places.push_back(newPlace); XML.popTag(); // Pop "place" } // Players ( fichas ) // int totalPlayer = XML.getNumTags("player"); for(int i = 0; i < totalPlayer ; i++){ XML.pushTag("player", i); Player newPlayer = Player(i); newPlayer.x = XML.getValue("pos:x", 0.0); newPlayer.y = XML.getValue("pos:y", 0.0); newPlayer.color.set(XML.getValue("color:r", 255), XML.getValue("color:g", 255), XML.getValue("color:b", 255), 100); newPlayer.img.loadImage( XML.getValue("image", "player01.png") ); players.push_back(newPlayer); XML.popTag(); // Pop "player" } for (int i = 0; i < players.size(); i++){ ofAddListener( players[i].arriveToPlace, this, &Oca::playerArriveToPlace); } } else ofLog(OF_LOG_ERROR,"Oca: loading file " + _xmlConfigFile ); return loaded; }