void ContainerItemModel::removeItem (const ItemStack& item, size_t count) { int toRemove = count; for (std::vector<MWWorld::Ptr>::iterator source = mItemSources.begin(); source != mItemSources.end(); ++source) { MWWorld::ContainerStore& store = MWWorld::Class::get(*source).getContainerStore(*source); for (MWWorld::ContainerStoreIterator it = store.begin(); it != store.end(); ++it) { if (stacks(*it, item.mBase)) { toRemove -= store.remove(*it, toRemove, *source); if (toRemove <= 0) return; } } } for (std::vector<MWWorld::Ptr>::iterator source = mWorldItems.begin(); source != mWorldItems.end(); ++source) { if (stacks(*source, item.mBase)) { int refCount = source->getRefData().getCount(); if (refCount - toRemove <= 0) MWBase::Environment::get().getWorld()->deleteObject(*source); else source->getRefData().setCount(std::max(0, refCount - toRemove)); toRemove -= refCount; if (toRemove <= 0) return; } } throw std::runtime_error("Not enough items to remove could be found"); }
void ContainerItemModel::update() { mItems.clear(); for (std::vector<MWWorld::Ptr>::iterator source = mItemSources.begin(); source != mItemSources.end(); ++source) { MWWorld::ContainerStore& store = MWWorld::Class::get(*source).getContainerStore(*source); for (MWWorld::ContainerStoreIterator it = store.begin(); it != store.end(); ++it) { std::vector<ItemStack>::iterator itemStack = mItems.begin(); for (; itemStack != mItems.end(); ++itemStack) { if (stacks(*it, itemStack->mBase)) { // we already have an item stack of this kind, add to it itemStack->mCount += it->getRefData().getCount(); break; } } if (itemStack == mItems.end()) { // no stack yet, create one ItemStack newItem (*it, this, it->getRefData().getCount()); mItems.push_back(newItem); } } } for (std::vector<MWWorld::Ptr>::iterator source = mWorldItems.begin(); source != mWorldItems.end(); ++source) { std::vector<ItemStack>::iterator itemStack = mItems.begin(); for (; itemStack != mItems.end(); ++itemStack) { if (stacks(*source, itemStack->mBase)) { // we already have an item stack of this kind, add to it itemStack->mCount += source->getRefData().getCount(); break; } } if (itemStack == mItems.end()) { // no stack yet, create one ItemStack newItem (*source, this, source->getRefData().getCount()); mItems.push_back(newItem); } } }
MWWorld::ContainerStoreIterator MWWorld::InventoryStore::unequipItemQuantity(const Ptr& item, const Ptr& actor, int count) { if (!isEquipped(item)) throw std::runtime_error ("attempt to unequip an item that is not currently equipped"); if (count <= 0) throw std::runtime_error ("attempt to unequip nothing (count <= 0)"); if (count > item.getRefData().getCount()) throw std::runtime_error ("attempt to unequip more items than equipped"); if (count == item.getRefData().getCount()) return unequipItem(item, actor); // Move items to an existing stack if possible, otherwise split count items out into a new stack. // Moving counts manually here, since ContainerStore's restack can't target unequipped stacks. for (MWWorld::ContainerStoreIterator iter (begin()); iter != end(); ++iter) { if (stacks(*iter, item) && !isEquipped(*iter)) { iter->getRefData().setCount(iter->getRefData().getCount() + count); item.getRefData().setCount(item.getRefData().getCount() - count); return iter; } } return unstack(item, actor, item.getRefData().getCount() - count); }
void individualMove(struct board_position pos, int i, int j, int turn, int *nc, char *child_ptr) { struct board_position p; if (pos.board[i][j] != WPAWN) { p = pos; if (leftDown(p.board, i, j)) { insert_into_array(p, *nc, child_ptr); (*nc)++; } p = pos; if (rightDown(p.board, i, j)) { insert_into_array(p, *nc, child_ptr); (*nc)++; } } if (pos.board[i][j] != BPAWN) { p = pos; if (leftUp(p.board, i, j)) { insert_into_array(p, *nc, child_ptr); (*nc)++; } p = pos; if (rightUp(p.board, i, j)) { insert_into_array(p, *nc, child_ptr); (*nc)++; } } stacks(pos, i, j, turn, nc, child_ptr); }
MWWorld::ContainerStoreIterator MWWorld::ContainerStore::restack(const MWWorld::Ptr& item) { MWWorld::ContainerStoreIterator retval = end(); for (MWWorld::ContainerStoreIterator iter (begin()); iter != end(); ++iter) { if (item == *iter) { retval = iter; break; } } if (retval == end()) throw std::runtime_error("item is not from this container"); for (MWWorld::ContainerStoreIterator iter (begin()); iter != end(); ++iter) { if (stacks(*iter, item)) { iter->getRefData().setCount(iter->getRefData().getCount() + item.getRefData().getCount()); item.getRefData().setCount(0); retval = iter; break; } } return retval; }
std::string Sphere::toLua(std::ostream & outStream) const { Object::toLua(outStream); outStream << name() << ":" << "setRadius(" << radius() << ");\n"; outStream << name() << ":" << "setSlices(" << slices() << ");\n"; outStream << name() << ":" << "setStacks(" << stacks() << ");\n"; return name(); }
MWWorld::ContainerStoreIterator MWWorld::ContainerStore::add (const Ptr& ptr) { int type = getType(ptr); const MWWorld::ESMStore &esmStore = MWBase::Environment::get().getWorld()->getStore(); // gold needs special handling: when it is inserted into a container, the base object automatically becomes Gold_001 // this ensures that gold piles of different sizes stack with each other (also, several scripts rely on Gold_001 for detecting player gold) if (MWWorld::Class::get(ptr).getName(ptr) == esmStore.get<ESM::GameSetting>().find("sGold")->getString()) { MWWorld::LiveCellRef<ESM::Miscellaneous> *gold = ptr.get<ESM::Miscellaneous>(); if (compare_string_ci(gold->mRef.mRefID, "gold_001") || compare_string_ci(gold->mRef.mRefID, "gold_005") || compare_string_ci(gold->mRef.mRefID, "gold_010") || compare_string_ci(gold->mRef.mRefID, "gold_025") || compare_string_ci(gold->mRef.mRefID, "gold_100")) { MWWorld::ManualRef ref(esmStore, "Gold_001"); int count = (ptr.getRefData().getCount() == 1) ? gold->mBase->mData.mValue : ptr.getRefData().getCount(); ref.getPtr().getRefData().setCount(count); for (MWWorld::ContainerStoreIterator iter (begin(type)); iter!=end(); ++iter) { if (compare_string_ci((*iter).get<ESM::Miscellaneous>()->mRef.mRefID, "gold_001")) { (*iter).getRefData().setCount( (*iter).getRefData().getCount() + count); flagAsModified(); return iter; } } return addImpl(ref.getPtr()); } } // determine whether to stack or not for (MWWorld::ContainerStoreIterator iter (begin(type)); iter!=end(); ++iter) { if (stacks(*iter, ptr)) { // stack iter->getRefData().setCount( iter->getRefData().getCount() + ptr.getRefData().getCount() ); flagAsModified(); return iter; } } // if we got here, this means no stacking return addImpl(ptr); }
MWWorld::ContainerStoreIterator MWWorld::InventoryStore::unequipSlot(int slot, const MWWorld::Ptr& actor) { ContainerStoreIterator it = mSlots[slot]; if (it != end()) { ContainerStoreIterator retval = it; // empty this slot mSlots[slot] = end(); // restack the previously equipped item with other (non-equipped) items for (MWWorld::ContainerStoreIterator iter (begin()); iter != end(); ++iter) { if (stacks(*iter, *it)) { iter->getRefData().setCount(iter->getRefData().getCount() + it->getRefData().getCount()); it->getRefData().setCount(0); retval = iter; break; } } if (actor.getRefData().getHandle() == "player") { // Unset OnPCEquip Variable on item's script, if it has a script with that variable declared const std::string& script = Class::get(*it).getScript(*it); if (script != "") (*it).getRefData().getLocals().setVarByInt(script, "onpcequip", 0); // Update HUD icon when removing player weapon or selected enchanted item. // We have to check for both as the weapon could also be the enchanted item. if (slot == MWWorld::InventoryStore::Slot_CarriedRight) { // weapon MWBase::Environment::get().getWindowManager()->unsetSelectedWeapon(); } if ((mSelectedEnchantItem != end()) && (mSelectedEnchantItem == it)) { // enchanted item mSelectedEnchantItem = end(); MWBase::Environment::get().getWindowManager()->unsetSelectedSpell(); } } fireEquipmentChangedEvent(); updateMagicEffects(actor); return retval; } return it; }
// Creates an array to respond to the Xenon PHP extension; // builds the data into the format neeeded. Array XenonRequestLocalData::createResponse() { PackedArrayInit stacks(m_stackSnapshots.size()); for (ArrayIter it(m_stackSnapshots); it; ++it) { const auto& frame = it.second().toArray(); stacks.append(make_map_array( s_time, frame[s_time], s_stack, frame[s_stack].toArray(), s_phpStack, parsePhpStack(frame[s_stack].toArray()), s_isWait, frame[s_isWait] )); } return stacks.toArray(); }
void UndoGroup::checkAllCleanStates() { bool clean = true; foreach(QUndoStack* stack, stacks()) { if(!stack->isClean()) { clean = false; break; } } //TODO: don't emit on every entry only when the state changes. emit isModified(!clean); }
int main() { SetOfStacks stacks(2); stacks.push(3); stacks.push(5); stacks.push(6); stacks.push(7); stacks.push(8); stacks.push(9); stacks.push(10); stacks.push(11); stacks.printStacks(); stacks.popAt(0); stacks.printStacks(); }
int stacks_dcmd(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) { int rval = stacks(addr, flags, argc, argv); /* * For the user-level variant of ::stacks, we don't bother caching * state, as even a very large program is unlikely to compare to the * kernel in terms of number of threads. (And if you find yourself * here in anger, frustrated about how long ::stacks is running on * your galactically complicated zillion-thread program, hopefully * you will find some solace in the irony. Okay, probably not...) */ stacks_cleanup(B_TRUE); return (rval); }
MWWorld::ContainerStoreIterator MWWorld::ContainerStore::addImp (const Ptr& ptr, int count) { int type = getType(ptr); const MWWorld::ESMStore &esmStore = MWBase::Environment::get().getWorld()->getStore(); // gold needs special handling: when it is inserted into a container, the base object automatically becomes Gold_001 // this ensures that gold piles of different sizes stack with each other (also, several scripts rely on Gold_001 for detecting player gold) if(ptr.getClass().isGold(ptr)) { int realCount = count * ptr.getClass().getValue(ptr); for (MWWorld::ContainerStoreIterator iter (begin(type)); iter!=end(); ++iter) { if (Misc::StringUtils::ciEqual((*iter).getCellRef().getRefId(), MWWorld::ContainerStore::sGoldId)) { iter->getRefData().setCount(iter->getRefData().getCount() + realCount); flagAsModified(); return iter; } } MWWorld::ManualRef ref(esmStore, MWWorld::ContainerStore::sGoldId, realCount); return addNewStack(ref.getPtr(), realCount); } // determine whether to stack or not for (MWWorld::ContainerStoreIterator iter (begin(type)); iter!=end(); ++iter) { if (stacks(*iter, ptr)) { // stack iter->getRefData().setCount( iter->getRefData().getCount() + count ); flagAsModified(); return iter; } } // if we got here, this means no stacking return addNewStack(ptr, count); }
void RadixSort<VAL>::sort(Vector<VAL> & vec) { Vector<List<VAL> > stacks(10); for (int i = 1; i < 9; i++) { trace("Radical " << i << endl) for (int j = 0; j < vec.getSize(); j++) { vec[j]>vec[j]; // TODO: esto stacks[(int(vec[j])%int(pow(10,i)))/int(pow(10,i-1))].snoc(vec[j]); } for (int z = 0; z < stacks.getSize(); z++) { trace("By number " << z << ": "<< stacks[z] << endl); } int ixV = 0; for (int t = 0; t < stacks.getSize(); t++) { while (!stacks[t].isEmpty()) { vec[ixV] = stacks[t].popFront(); ixV++; } } trace("Vector: " << vec << endl); } }
int main(int argc, char* argv[]) { unsigned num_replicas = 8; bool verbose = false; // bool out_of_place = false; bool batched_plan = false; int num_threads = 0; std::string cpu_name; int num_repeats = 5; std::string stack_dims = ""; po::options_description desc("Allowed options"); //clang-format off desc.add_options() // ("help,h", "produce help message") // ("verbose,v", "print lots of information in between") // ("header-only,H", "print header of stats only") // // ("stack_dimensions,s", // po::value<std::string>(&stack_dims)->default_value("64x64x64"), // "HxWxD of synthetic stacks to generate") // // ("repeats,r", // po::value<int>(&num_repeats)->default_value(10), // "number of repetitions per measurement") // // ("num_replicas,n", // po::value<unsigned>(&num_replicas)->default_value(8), // "number of replicas to use for batched processing") // // ("num_threads,t", // po::value<int>(&num_threads)->default_value(1), // "number of threads to use") // // ("cpu_name,c", // po::value<std::string>(&cpu_name)->default_value("i7-3520M"), // "cpu name to use in output") // ; // //clang-format on po::variables_map vm; po::store(po::parse_command_line(argc, argv, desc), vm); po::notify(vm); if (vm.count("help")) { std::cout << desc << "\n"; return 1; } if (vm.count("header-only")) { print_header(); return 0; } static const int max_threads = boost::thread::hardware_concurrency(); if(num_threads > max_threads) num_threads = max_threads; verbose = vm.count("verbose"); // out_of_place = vm.count("out-of-place"); batched_plan = vm.count("batched_plan"); std::vector<unsigned> numeric_stack_dims; split<'x'>(stack_dims, numeric_stack_dims); if (verbose) { std::cout << "received " << numeric_stack_dims.size() << " dimensions: "; for (unsigned i = 0; i < numeric_stack_dims.size(); ++i) { std::cout << numeric_stack_dims[i] << " "; } std::cout << "\n"; } if (numeric_stack_dims.size() != 3) { std::cerr << ">> " << numeric_stack_dims.size() << "-D data, not supported yet!\n"; return 1; } unsigned long data_size_byte = std::accumulate(numeric_stack_dims.begin(), numeric_stack_dims.end(), 1u, std::multiplies<unsigned long>()) * sizeof(float); unsigned long memory_available = data_size_byte; // later float exp_mem_mb = (data_size_byte) / float(1 << 20); exp_mem_mb *= num_replicas; float av_mem_mb = memory_available / float(1 << 20); // if(exp_mem_mb>av_mem_mb){ // std::cerr << "not enough memory available on device, needed " << // exp_mem_mb // <<" MB), available: " << av_mem_mb << " MB\n"; // return 1; // } else { if (verbose) std::cout << "[NOT IMPLEMENTED YET] memory estimate: needed " << exp_mem_mb << " MB), available: " << av_mem_mb << " MB\n"; // } std::vector<unsigned> reshaped(numeric_stack_dims); reshaped.back() = (reshaped.back() / 2 + 1) * 2; multiviewnative::image_kernel_data raw(numeric_stack_dims); multiviewnative::image_kernel_data reference = raw; inplace_cpu_convolution(reference.stack_.data(), &reference.stack_shape_[0], reference.kernel_.data(), &reference.kernel_shape_[0], num_threads); std::vector<multiviewnative::image_kernel_data> stacks(num_replicas,raw); if (verbose) { std::cout << "[config]\t" << "\n" << "num_replicas\t:\t" << num_replicas << "\nnumeric size\t:\t"; std::copy(numeric_stack_dims.begin(), numeric_stack_dims.end(), std::ostream_iterator<unsigned>(std::cout, " ")); std::cout << "\nfftw size\t:\t"; std::copy(reshaped.begin(), reshaped.end(), std::ostream_iterator<unsigned>(std::cout, " ")); std::cout << "\n"; } stacks[0] = raw; //start measurement std::vector<ns_t> durations(num_repeats); ns_t time_ns = ns_t(0); tp_t start, end; for (int r = 0; r < num_repeats; ++r) { for ( multiviewnative::image_kernel_data& s : stacks ){ s.stack_ = raw.stack_; s.kernel_ = raw.kernel_; } start = boost::chrono::high_resolution_clock::now(); //batched fold comes here if (num_threads == 1) inplace_cpu_batched_fold<mvn::cpu::serial_tag>(stacks); else{ convolve<mvn::cpu::parallel_tag>::transform_type::set_n_threads(num_threads); inplace_cpu_batched_fold<mvn::cpu::parallel_tag>(stacks); } end = boost::chrono::high_resolution_clock::now(); durations[r] = boost::chrono::duration_cast<ns_t>(end - start); time_ns += boost::chrono::duration_cast<ns_t>(end - start); if (verbose) { std::cout << r << "\t" << boost::chrono::duration_cast<ns_t>(durations[r]).count() / double(1e6) << " ms\n"; } } bool data_valid = std::equal(reference.stack_.data(), reference.stack_.data() + reference.stack_.num_elements(), stacks[0].stack_.data()); std::string implementation_name = __FILE__; std::string comments = "global_plan"; if(data_valid) comments += ",OK"; else comments += ",NA"; if(batched_plan) comments += ",batched"; if(verbose) print_header(); print_info(num_threads, implementation_name, cpu_name, num_repeats, time_ns.count() / double(1e6), numeric_stack_dims, sizeof(float), comments ); return 0; }
int main() { // Test variable size stack implementation Stack3 stacks(5); stacks.Push(0,1); stacks.Push(0,2); stacks.Push(1,10); stacks.Push(2,20); stacks.Push(2,21); std::cout << "**** Test variable size stack ****\n"; std::cout << "Total array is full? " << stacks.IsFull() << "\n"; int value[5]; value[0] = stacks.Top(0); stacks.Pop(0); value[1] = stacks.Top(0); stacks.Pop(0); value[2] = stacks.Top(1); stacks.Pop(1); value[3] = stacks.Top(2); stacks.Pop(2); value[4] = stacks.Top(2); stacks.Pop(2); std::cout << "1st stack: top-->" << value[0] << "-->" << value[1] << "\n"; std::cout << "2nd stack: top-->" << value[2] << "\n"; std::cout << "3rd stack: top-->" << value[3] << "-->" << value[4] << "\n"; std::cout << "1st stack is empty? " << stacks.IsEmpty(0) << "\n"; std::cout << "2nd stack is empty? " << stacks.IsEmpty(1) << "\n"; std::cout << "3rd stack is empty? " << stacks.IsEmpty(2) << "\n"; std::cout << "Total array is full? " << stacks.IsFull() << "\n"; // Test equal sized stack implementation Stack3Equal stacks2(2); stacks2.Push(0,1); stacks2.Push(0,2); stacks2.Push(1,10); stacks2.Push(1,11); stacks2.Push(2,20); stacks2.Push(2,21); std::cout << "\n**** Test equal sized stack ****\n"; std::cout << "1st stack is full? " << stacks2.IsFull(0) << "\n"; std::cout << "2nd stack is full? " << stacks2.IsFull(1) << "\n"; std::cout << "3rd stack is full? " << stacks2.IsFull(2) << "\n"; int value2[6]; value2[0] = stacks2.Top(0); stacks2.Pop(0); value2[1] = stacks2.Top(0); stacks2.Pop(0); value2[2] = stacks2.Top(1); stacks2.Pop(1); value2[3] = stacks2.Top(1); stacks2.Pop(1); value2[4] = stacks2.Top(2); stacks2.Pop(2); value2[5] = stacks2.Top(2); stacks2.Pop(2); std::cout << "1st stack: top-->" << value2[0] << "-->" << value2[1] << "\n"; std::cout << "2nd stack: top-->" << value2[2] << "-->" << value2[3] << "\n"; std::cout << "3rd stack: top-->" << value2[4] << "-->" << value2[5] << "\n"; std::cout << "1st stack is empty? " << stacks2.IsEmpty(0) << "\n"; std::cout << "2nd stack is empty? " << stacks2.IsEmpty(1) << "\n"; std::cout << "3rd stack is empty? " << stacks2.IsEmpty(2) << "\n"; }
int main( int argc, char *argv[] ) { if ( argc < 3 ) { std::cout << "Usage: ./compileSHE <domain.pddl> <task.pddl>\n"; std::cout << "Writes domain file to standard output and instance file to standard error\n"; exit( 1 ); } d = new Domain( argv[1] ); ins = new Instance( *d, argv[2] ); // Generate dependency graph among actions and identify durations and depths graph g( d->actions.size() ); for ( unsigned i = 0; i < d->actions.size(); ++i ) { for ( unsigned j = 0; j < d->actions.size(); ++j ) if ( i != j ) detectDependency( i, j, g ); } g.computeDurations(); g.computeDepths(); // Identify contexts that are threatened by contents // RIGHT NOW PRE & EFF ASSUME POSITIVE PRECONDITIONS !!! int maxCount = 0; for ( unsigned i = 0; i < d->actions.size(); ++i ) { maxCount = MAX( maxCount, *g.depths[i].rbegin() ); for ( unsigned j = 0; j < get( i )->pre_o->conds.size(); ++j ) { Ground * pre = dynamic_cast< Ground * >( get( i )->pre_o->conds[j] ); if ( pre ) { int k = d->preds.index( pre->name ); if ( k >= 0 && isPre( i, k, g ) ) pres.insert( k ); } } } // Create classical domain cd = new Domain; cd->name = d->name; cd->equality = d->equality; cd->condeffects = cd->typed = true; cd->cons = d->cons || ( maxCount && pres.size() ) || g.subtractionPairs.size(); cd->equality = d->equality; // Add types cd->setTypes( d->copyTypes() ); if ( maxCount && pres.size() ) cd->createType( "COUNT" ); if ( g.subtractionPairs.size() ) cd->createType( "TIME" ); // Add constants StringVec counts; for ( int i = 0; maxCount && pres.size() && i <= maxCount; ++i ) { std::stringstream ss; ss << "COUNT" << i; counts.push_back( ss.str() ); cd->createConstant( counts[i], "COUNT" ); } StringVec times; for ( unsigned i = 0; g.subtractionPairs.size() && i < g.durationMap.size(); ++i ) { std::stringstream ss; ss << "TIME" << i; times.push_back( ss.str() ); cd->createConstant( times[i], "TIME" ); } // Add predicates for ( unsigned i = 0; i < d->preds.size(); ++i ) { StringVec pars = d->typeList( d->preds[i] ); cd->createPredicate( d->preds[i]->name, pars ); if ( pres.find( i ) != pres.end() ) { pars.push_back( "COUNT" ); cd->createPredicate( "COUNT-" + d->preds[i]->name, pars ); } } StringVec stacks( 1, "EMPTYSTACK" ); cd->createPredicate( stacks[0] ); for ( int i = 1; i <= maxCount; ++i ) { std::stringstream ss; ss << "STACK" << i; stacks.push_back( ss.str() ); cd->createPredicate( stacks[i] ); cd->createPredicate( stacks[i] + "-REMAINING", StringVec( 1, "TIME" ) ); cd->createPredicate( stacks[i] + "-INCREASE", StringVec( 1, "TIME" ) ); cd->createPredicate( stacks[i] + "-DECREASE" ); cd->createPredicate( stacks[i] + "-CONTINUE", StringVec( 1, "TIME" ) ); } for ( unsigned i = 0; i < d->actions.size(); ++i ) for ( IntSet::iterator j = g.depths[i].begin(); g.outgoing( i ) && j != g.depths[i].end(); ++j ) { std::stringstream ss; ss << "STACK" << *j + 1 << "-" << d->actions[i]->name; cd->createPredicate( ss.str(), d->typeList( d->actions[i] ) ); } if ( counts.size() ) cd->createPredicate( "CONSECUTIVE", StringVec( 2, "COUNT" ) ); if ( times.size() ) cd->createPredicate( "SUBTRACT", StringVec( 3, "TIME" ) ); // Currently does NOT add functions // for ( unsigned i = 0; i < d->funcs.size(); ++i ) // cd->createFunction( d->funcs[i]->name, d->funcs[i]->returnType, d->typeList( d->funcs[i] ) ); // Add actions for ( unsigned i = 0; i < d->actions.size(); ++i ) // DOES NOT CURRENTLY IMPLEMENT COUNT MECHANISM !!! for ( IntSet::iterator j = g.depths[i].begin(); j != g.depths[i].end(); ++j ) if ( g.outgoing( i ) ) { // Action is an envelope: compile into push and pop action // Push action std::string name = "PUSH-" + d->actions[i]->name; unsigned size = d->actions[i]->params.size(); Action * push = cd->createAction( name, d->typeList( d->actions[i] ) ); //std::cout << "Creating action " << name << "\n"; // ONLY DEALS WITH POSITIVE PRECONDITIONS HERE !!! cd->setPre( name, d->actions[i]->pre ); for ( unsigned k = 0; k < get( i )->pre_o->conds.size(); ++k ) { Ground * pre = dynamic_cast< Ground * >( get( i )->pre_o->conds[k] ); if ( pre && !includes( 0, pre, ( And * )get( i )->pre ) && !includes( 0, pre, ( And * )get( i )->eff ) ) cd->addPre( 0, name, pre->name, pre->params ); // if precon is not positive, just copy it if ( !pre ) ( ( And * )push->pre )->add( get( i )->pre_o->conds[k]->copy( *cd ) ); } cd->addPre( 0, name, stacks[*j] ); cd->setEff( name, d->actions[i]->eff ); cd->addEff( 1, name, stacks[*j] ); if ( *j ) cd->addEff( 0, name, stacks[*j] + "-INCREASE", IntVec( 1, cd->constantIndex( times[g.durationMap[d->actions[i]->duration()]], "TIME" ) ) ); else cd->addEff( 0, name, stacks[1] ); cd->addEff( 0, name, stacks[*j + 1] + "-" + d->actions[i]->name, incvec( 0, size ) ); cd->addEff( 0, name, stacks[*j + 1] + "-REMAINING", IntVec( 1, cd->constantIndex( times[g.durationMap[d->actions[i]->duration()]], "TIME" ) ) ); // Pop action name = "POP-" + d->actions[i]->name; cd->createAction( name, d->typeList( d->actions[i] ) ); //std::cout << "Creating action " << name << "\n"; // ONLY DEALS WITH POSITIVE PRECONDITIONS HERE !!! cd->setPre( name, get( i )->pre_e ); for ( unsigned k = 0; k < get( i )->pre_o->conds.size(); ++k ) { Ground * h = dynamic_cast< Ground * >( get( i )->pre_o->conds[k] ); if ( h && !includes( 0, h, get( i )->pre_e ) ) cd->addPre( 0, name, h->name, h->params ); } cd->addPre( 0, name, stacks[*j + 1] ); cd->addPre( 0, name, stacks[*j + 1] + "-" + d->actions[i]->name, incvec( 0, size ) ); cd->setEff( name, get( i )->eff_e ); cd->addEff( 0, name, stacks[*j + 1] + "-DECREASE" ); cd->addEff( 1, name, stacks[*j + 1] ); cd->addEff( 1, name, stacks[*j + 1] + "-" + d->actions[i]->name, incvec( 0, size ) ); } else { // Action is not an envelope: compile into compressed action std::string name = "DO-" + d->actions[i]->name; Action * doit = cd->createAction( name, d->typeList( d->actions[i] ) ); //std::cout << "Creating action " << name << "\n"; // ONLY DEALS WITH POSITIVE PRECONDITIONS HERE !!! cd->setPre( name, d->actions[i]->pre ); for ( unsigned k = 0; k < get( i )->pre_o->conds.size(); ++k ) { Ground * pre = dynamic_cast< Ground * >( get( i )->pre_o->conds[k] ); if ( pre && !includes( 0, pre, ( And * )get( i )->pre ) && !includes( 0, pre, ( And * )get( i )->eff ) ) cd->addPre( 0, name, pre->name, pre->params ); // if precon is not positive, just copy it if ( !pre ) ( ( And * )doit->pre )->add( get( i )->pre_o->conds[k]->copy( *cd ) ); } for ( unsigned k = 0; k < get( i )->pre_e->conds.size(); ++k ) { Ground * h = ( Ground * )get( i )->pre_e->conds[k]; if ( !includes( 0, h, ( And * )get( i )->pre ) && !includes( 0, h, ( And * )get( i )->eff ) ) cd->addPre( 0, name, h->name, h->params ); } cd->addPre( 0, name, stacks[*j] ); cd->setEff( name, get( i )->eff_e ); GroundVec add = get( i )->addEffects(); for ( unsigned k = 0; k < add.size(); ++k ) if ( !includes( 1, add[k], get( i )->eff_e ) ) cd->addEff( 0, name, add[k]->name, add[k]->params ); GroundVec del = get( i )->deleteEffects(); for ( unsigned k = 0; k < del.size(); ++k ) if ( !includes( 0, del[k], get( i )->eff_e ) ) cd->addEff( 1, name, del[k]->name, del[k]->params ); if ( *j ) { cd->addEff( 1, name, stacks[*j] ); cd->addEff( 0, name, stacks[*j] + "-CONTINUE", IntVec( 1, cd->constantIndex( times[g.durationMap[d->actions[i]->duration()]], "TIME" ) ) ); } } for ( int i = 1; i <= maxCount; ++i ) { if ( i < maxCount ) { // Increase action std::stringstream ss; ss << "INCREASE" << i; std::string name = ss.str(); cd->createAction( name, StringVec( 3, "TIME" ) ); cd->addPre( 0, name, stacks[i] + "-REMAINING", incvec( 0, 1 ) ); cd->addPre( 0, name, stacks[i] + "-INCREASE", incvec( 2, 3 ) ); cd->addPre( 0, name, "SUBTRACT", incvec( 0, 3 ) ); cd->addEff( 0, name, stacks[i + 1] ); cd->addEff( 1, name, stacks[i] + "-REMAINING", incvec( 0, 1 ) ); cd->addEff( 0, name, stacks[i] + "-REMAINING", incvec( 1, 2 ) ); cd->addEff( 1, name, stacks[i] + "-INCREASE", incvec( 2, 3 ) ); } // Decrease action std::stringstream ss; ss << "DECREASE" << i; std::string name = ss.str(); cd->createAction( name, StringVec( 1, "TIME" ) ); cd->addPre( 0, name, stacks[i] + "-REMAINING", incvec( 0, 1 ) ); cd->addPre( 0, name, stacks[i] + "-DECREASE" ); cd->addEff( 0, name, stacks[i - 1] ); cd->addEff( 1, name, stacks[i] + "-REMAINING", incvec( 0, 1 ) ); cd->addEff( 1, name, stacks[i] + "-DECREASE" ); // Continue action std::stringstream ss2; ss2 << "CONTINUE" << i; name = ss2.str(); cd->createAction( name, StringVec( 3, "TIME" ) ); cd->addPre( 0, name, stacks[i] + "-REMAINING", incvec( 0, 1 ) ); cd->addPre( 0, name, stacks[i] + "-CONTINUE", incvec( 2, 3 ) ); cd->addPre( 0, name, "SUBTRACT", incvec( 0, 3 ) ); cd->addEff( 0, name, stacks[i] ); cd->addEff( 1, name, stacks[i] + "-REMAINING", incvec( 0, 1 ) ); cd->addEff( 0, name, stacks[i] + "-REMAINING", incvec( 1, 2 ) ); cd->addEff( 1, name, stacks[i] + "-CONTINUE", incvec( 2, 3 ) ); } cd->PDDLPrint( std::cout ); cins = new Instance( *cd ); cins->name = ins->name; // create initial state for ( unsigned i = 0; i < ins->init.size(); ++i ) if ( d->preds.index( ins->init[i]->name ) >= 0 ) cins->addInit( ins->init[i]->name, d->objectList( ins->init[i] ) ); cins->addInit( stacks[0] ); for ( unsigned i = 1; i < counts.size(); ++i ) { StringVec pars( 1, counts[i - 1] ); pars.push_back( counts[i] ); cins->addInit( "CONSECUTIVE", pars ); } for ( DoublePairSet::iterator i = g.subtractionPairs.begin(); i != g.subtractionPairs.end(); ++i ) { StringVec pars( 1, times[g.durationMap[i->first]] ); pars.push_back( times[g.durationMap[i->first - i->second]] ); pars.push_back( times[g.durationMap[i->second]] ); cins->addInit( "SUBTRACT", pars ); } // create goal state for ( unsigned i = 0; i < ins->goal.size(); ++i ) cins->addGoal( ins->goal[i]->name, d->objectList( ins->goal[i] ) ); cins->addGoal( stacks[0] ); cins->PDDLPrint( std::cerr ); delete cins; delete cd; delete ins; delete d; }