void TraineeWalker::computeWalkerPath() { _maxNeed = 0; // need of this trainee in buildings Propagator pathPropagator; pathPropagator.init(*_originBuilding); pathPropagator.propagate(_maxDistance); for (std::list<BuildingType>::iterator itType = _buildingNeed.begin(); itType != _buildingNeed.end(); ++itType) { BuildingType buildingType = *itType; checkDestination(buildingType, pathPropagator); } if (_destinationBuilding != NULL) { // some building needs that trainee! // std::cout << "trainee sent!" << std::endl; PathWay pathWay; pathPropagator.getPath(*_destinationBuilding, pathWay); setPathWay(pathWay); setIJ(_pathWay.getOrigin().getI(), _pathWay.getOrigin().getJ()); Scenario::instance().getCity().getWalkerList().push_back(this); _destinationBuilding->reserveTrainee(_traineeType); } else { // nobody needs him... // std::cout << "trainee suicide!" << std::endl; _isDeleted = true; } }
bool Engine::propagate() { if (async_fail) { async_fail = false; assert(!so.lazy || sat.confl); return false; } last_prop = NULL; WakeUp: if (!sat.consistent() && !sat.propagate()) return false; for (int i = 0; i < v_queue.size(); i++) { v_queue[i]->wakePropagators(); } v_queue.clear(); if (sat.confl) return false; last_prop = NULL; for (int i = 0; i < num_queues; i++) { if (p_queue[i].size()) { Propagator *p = p_queue[i].last(); p_queue[i].pop(); propagations++; bool ok = p->propagate(); p->clearPropState(); if (!ok) return false; goto WakeUp; } } return true; }
void TraineeWalker::computeWalkerPath() { _maxNeed = 0; // need of this trainee in buildings Propagator pathPropagator; pathPropagator.init( *_originBuilding.object() ); pathPropagator.propagate(_maxDistance); for (std::list<BuildingType>::iterator itType = _buildingNeed.begin(); itType != _buildingNeed.end(); ++itType) { BuildingType buildingType = *itType; checkDestination(buildingType, pathPropagator); } if( _destinationBuilding != NULL ) { // some building needs that trainee! // std::cout << "trainee sent!" << std::endl; PathWay pathWay; pathPropagator.getPath( _destinationBuilding, pathWay); setPathWay( pathWay ); setIJ( _pathWay.getOrigin().getIJ() ); } else { // nobody needs him... // std::cout << "trainee suicide!" << std::endl; deleteLater(); } }
void Emigrant::assignPath( const Road& startPoint ) { std::list<PathWay> pathWayList; std::list<LandOverlay*> houses = Scenario::instance().getCity().getBuildingList(B_HOUSE); House* blankHouse = 0; for( std::list<LandOverlay*>::iterator itHouse = houses.begin(); itHouse != houses.end(); ++itHouse ) { if( House* house = dynamic_cast<House*>(*itHouse) ) { if( house->getNbHabitants() < house->getMaxHabitants() ) { blankHouse = house; _d->destination = house->getTile().getIJ(); break; } } } Propagator pathfinder; PathWay pathWay; pathfinder.init( const_cast< Road& >( startPoint ) ); bool findPath = pathfinder.getPath( *blankHouse, pathWay ); if( findPath ) { setPathWay( pathWay ); setIJ(_pathWay.getOrigin().getI(), _pathWay.getOrigin().getJ()); } }
void ServiceWalker::computeWalkerPath() { std::list<PathWay> pathWayList; Propagator pathPropagator; pathPropagator.init(*_building); pathPropagator.getAllPaths(_maxDistance, pathWayList); float maxPathValue = 0.0; PathWay* bestPath = NULL; for (std::list<PathWay>::iterator itPath = pathWayList.begin(); itPath != pathWayList.end(); ++itPath) { PathWay &path = *itPath; float pathValue = evaluatePath(path); if (pathValue > maxPathValue) { bestPath = &path; maxPathValue = pathValue; } } if (bestPath == NULL) { // no good path _isDeleted = true; return; } reservePath(*bestPath); setPathWay(*bestPath); setIJ(_pathWay.getOrigin().getI(), _pathWay.getOrigin().getJ()); Scenario::instance().getCity().getWalkerList().push_back(this); }
void Roads::Impl::updateRoadsAround( Propagator& propagator, UpdateInfo info ) { propagator.init( info.first ); PathwayList pathWayList = propagator.getWays( info.second ); for( auto& path : pathWayList ) { RoadList roads = path->allTiles().overlays<Road>(); for( auto road : roads ) road->appendPaved( paved.increase ); } }
BuildingPtr CartPusher::getWalkerDestination_factory(Propagator &pathPropagator, PathWay &oPathWay) { BuildingPtr res; GoodType goodType = _d->stock._goodType; BuildingType buildingType = BuildingDataHolder::instance().getBuildingTypeByInGood(goodType); if (buildingType == B_NONE) { // no factory can use this good return NULL; } Propagator::ReachedBuldings pathWayList; pathPropagator.getReachedBuildings(buildingType, pathWayList); for( Propagator::ReachedBuldings::iterator pathWayIt= pathWayList.begin(); pathWayIt != pathWayList.end(); ++pathWayIt) { // for every factory within range BuildingPtr building= pathWayIt->first; PathWay& pathWay= pathWayIt->second; SmartPtr<Factory> factory = building.as<Factory>(); _d->reservationID = factory->getGoodStore().reserveStorage(_d->stock); if (_d->reservationID != 0) { res = factory.as<Building>(); oPathWay = pathWay; break; } } return res; }
double Kernel:: Compute(Propagator & propagator) const { if(0 == propagator.GetNUpwindNeighbors()) return infinity; return DoCompute(propagator); }
Propagator::DirectRoute getWarehouse4Buys( Propagator &pathPropagator, SimpleGoodStore& basket ) { Propagator::Routes pathWayList = pathPropagator.getRoutes( building::warehouse ); std::map< int, Propagator::DirectRoute > warehouseRating; // select the warehouse with the max quantity of requested goods Propagator::Routes::iterator pathWayIt = pathWayList.begin(); while( pathWayIt != pathWayList.end() ) { // for every warehouse within range WarehousePtr warehouse= pathWayIt->first.as< Warehouse >(); int rating = 0; for( int i=Good::wheat; i<Good::goodCount; i++ ) { Good::Type gtype = Good::Type(i); int qty = warehouse->getGoodStore().getMaxRetrieve( gtype ); int need = basket.getFreeQty( gtype ); rating = need > 0 ? ( qty ) : 0; } rating = math::clamp( rating - pathWayIt->second.getLength(), 0, 999 ); warehouseRating[ rating ] = *pathWayIt; pathWayIt++; } //have only available warehouses, find nearest of it return warehouseRating.size() > 0 ? warehouseRating.rbegin()->second : Propagator::DirectRoute(); }
BuildingPtr CartPusher::getWalkerDestination_granary(Propagator &pathPropagator, PathWay &oPathWay) { BuildingPtr res; GoodType goodType = _d->stock._goodType; if (!(goodType == G_WHEAT || goodType == G_FISH || goodType == G_MEAT || goodType == G_FRUIT || goodType == G_VEGETABLE)) { // this good cannot be stored in a granary return NULL; } Propagator::ReachedBuldings pathWayList; pathPropagator.getReachedBuildings( B_GRANARY, pathWayList); // find a granary with enough storage for( Propagator::ReachedBuldings::iterator pathWayIt= pathWayList.begin(); pathWayIt != pathWayList.end(); ++pathWayIt) { // for every granary within range BuildingPtr building= pathWayIt->first; PathWay& pathWay= pathWayIt->second; SmartPtr<Granary> granary= building.as<Granary>(); _d->reservationID = granary->getGoodStore().reserveStorage(_d->stock); if (_d->reservationID != 0) { res = granary.as<Building>(); oPathWay = pathWay; break; } } return res; }
BuildingPtr CartPusher::getWalkerDestination_warehouse(Propagator &pathPropagator, PathWay &oPathWay) { BuildingPtr res; Propagator::ReachedBuldings pathWayList; pathPropagator.getReachedBuildings(B_WAREHOUSE, pathWayList); for( Propagator::ReachedBuldings::iterator pathWayIt= pathWayList.begin(); pathWayIt != pathWayList.end(); ++pathWayIt) { // for every warehouse within range BuildingPtr building= pathWayIt->first; PathWay& pathWay= pathWayIt->second; SmartPtr<Warehouse> warehouse= building.as<Warehouse>(); _d->reservationID = warehouse->getGoodStore().reserveStorage(_d->stock); if (_d->reservationID != 0) { res = warehouse.as<Building>(); oPathWay = pathWay; break; } } return res; }
void runGPU0(Int_t nthreads = 4, Bool_t graphics = false, // const char *geomfile="gexam1.root") const char *geomfile = "http://root.cern.ch/files/cms.root") { TFile::SetCacheFileDir("./files"); gSystem->Load("libPhysics"); gSystem->Load("libHist"); gSystem->Load("libThread"); gSystem->Load("libGeom"); gSystem->Load("libVMC"); gSystem->Load("libGeant_v"); gSystem->Load("libXsec"); // gSystem->Load("libGeantCuda"); Int_t ntotal = 20; // Number of events to be transported Int_t nbuffered = 10; // Number of buffered events Propagator *prop = Propagator::Instance(ntotal, nbuffered); WorkloadManager *wmgr = WorkloadManager::Instance(nthreads); wmgr->SetNminThreshold(5 * nthreads); // CoprocessorBroker *gpuBroker = new CoprocessorBroker(); // gpuBroker->CudaSetup(32,128,1); // wmgr->SetTaskBroker(gpuBroker); prop->fNaverage = 500; // Average number of tracks per event prop->fNperBasket = 32; prop->fEmin = 1.E-5; // [10KeV] energy cut prop->fEmax = 0.03; // [30MeV] used for now to select particle gun energy // prop->fEmax = 1.; // Create the tab. phys process. prop->fProcess = new TTabPhysProcess("tab_phys", "xsec_FTFP_BERT.root", "fstate_FTFP_BERT.root"); prop->fApplication = new MyApplication(); // gROOT->ProcessLine(".x factory.C+"); // prop->fUseDebug = true; // prop->fDebugTrk = 1; // prop->PropagatorGeom(geomfile, nthreads, graphics); // This sets gGeomManager and hence superseeds the filename. VP_SimpleECal(); prop->PropagatorGeom("", nthreads /* + 3 */, graphics); delete gGeoManager; }
void Roads::Impl::updateRoadsAround( Propagator& propagator, UpdateInfo info ) { propagator.init( info.first ); PathwayList pathWayList = propagator.getWays( info.second ); for( auto&& path : pathWayList ) { const TilesArray& tiles = path->allTiles(); for( auto tile : tiles ) { RoadPtr road = tile->overlay().as<Road>(); if( road.isValid() ) { road->appendPaved( defaultIncreasePaved ); } } } }
void CartPusher::computeWalkerDestination() { // get the list of buildings within reach PathWay pathWay; Propagator pathPropagator; _d->consumerBuilding = 0; pathPropagator.init( *_d->producerBuilding.object() ); pathPropagator.propagate(_d->maxDistance); BuildingPtr destBuilding; if (destBuilding == NULL) { // try send that good to a factory destBuilding = getWalkerDestination_factory(pathPropagator, pathWay); } if (destBuilding == NULL) { // try send that good to a granary destBuilding = getWalkerDestination_granary(pathPropagator, pathWay); } if (destBuilding == NULL) { // try send that good to a warehouse destBuilding = getWalkerDestination_warehouse( pathPropagator, pathWay ); } if( destBuilding != NULL) { //_isDeleted = true; // no destination! setConsumerBuilding( destBuilding ); setPathWay( pathWay ); setIJ( _pathWay.getOrigin().getIJ() ); setSpeed( 1 ); } else { _action._direction = D_NORTH; setSpeed( 0 ); setIJ( _d->producerBuilding->getAccessRoads().front()->getIJ() ); walk(); } }
BuildingPtr reserveShortestPath( const BuildingType buildingType, GoodStock& stock, long& reservationID, Propagator &pathPropagator, PathWay &oPathWay ) { BuildingPtr res; Propagator::Routes pathWayList; pathPropagator.getRoutes(buildingType, pathWayList); //remove factories with improrer storage Propagator::Routes::iterator pathWayIt= pathWayList.begin(); while( pathWayIt != pathWayList.end() ) { // for every factory within range SmartPtr<T> building = pathWayIt->first.as<T>(); if( stock._currentQty > building->getGoodStore().getMaxStore( stock.type() ) ) { pathWayList.erase( pathWayIt++ ); } else { pathWayIt++; } } //find shortest path int maxLength = 999; PathWay* shortestPath = 0; for( Propagator::Routes::iterator pathIt = pathWayList.begin(); pathIt != pathWayList.end(); pathIt++ ) { if( pathIt->second.getLength() < maxLength ) { shortestPath = &pathIt->second; maxLength = pathIt->second.getLength(); res = pathIt->first; } } if( res.isValid() ) { reservationID = res.as<T>()->getGoodStore().reserveStorage( stock ); if (reservationID != 0) { oPathWay = *shortestPath; } else { res = BuildingPtr(); } } return res; }
//------------------------------------------------------------------------------ DiagramTwoLoop::DiagramTwoLoop(std::vector<Line> lines, LabelMap<Vertex, VertexType> vertextypes, LabelMap<Vertex, KernelType> kerneltypes) : DiagramBase(lines, vertextypes, kerneltypes), _qmax(std::numeric_limits<double>::infinity()) { _order = Order::kTwoLoop; // check to ensure that the diagram is really two loop bool is2Loop = false; // find the nontrivial poles for (auto line : _lines) { // check if the line has the loop momentum in it // if so, it has an IR pole that must be regulated if it is away from 0 if (line.propagator.hasLabel(Momentum::q)) { is2Loop = true; _order = Order::kOneLoop; Propagator pole = line.propagator.IRpole(Momentum::q); if (!pole.isNull()) { _IRpoles.push_back(pole); } } } assert(is2Loop); }
Propagator::DirectRoute getWarehouse4Sells( Propagator &pathPropagator, SimpleGoodStore& basket ) { Propagator::Routes pathWayList = pathPropagator.getRoutes( building::warehouse ); // select the warehouse with the max quantity of requested goods Propagator::Routes::iterator pathWayIt = pathWayList.begin(); while( pathWayIt != pathWayList.end() ) { // for every warehouse within range WarehousePtr warehouse= pathWayIt->first.as< Warehouse >(); if( warehouse->getGoodStore().getFreeQty() == 0 ) { pathWayList.erase( pathWayIt++ );} else { pathWayIt++; } } //have only available warehouses, find nearest of it Propagator::DirectRoute shortest = pathPropagator.getShortestRoute( pathWayList ); return shortest; }
void Immigrant::assignPath( const Building& home ) { City& city = Scenario::instance().getCity(); Tile& exitTile = city.getTilemap().at( city.getRoadExitI(), city.getRoadExitJ() ); Road* exitRoad = dynamic_cast< Road* >( exitTile.get_terrain().getOverlay() ); if( exitRoad ) { Propagator pathfinder; PathWay pathWay; pathfinder.init( const_cast< Building& >( home ) ); bool findPath = pathfinder.getPath( *exitRoad, pathWay ); if( findPath ) { setPathWay( pathWay ); setIJ(_pathWay.getOrigin().getI(), _pathWay.getOrigin().getJ()); } } else _isDeleted = true; }
void TraineeWalker::_checkDestination(const object::Type buildingType, Propagator &pathPropagator) { DirectPRoutes pathWayList = pathPropagator.getRoutes( buildingType ); for( auto item : pathWayList ) { // for every building within range BuildingPtr building = item.first.as<Building>(); float need = building->evaluateTrainee( type() ); if (need > _d->maxNeed) { _d->maxNeed = need; _d->destLocation = building->pos(); } } }
void TraineeWalker::checkDestination(const BuildingType buildingType, Propagator &pathPropagator) { std::map<Building*, PathWay> pathWayList; pathPropagator.getReachedBuildings(buildingType, pathWayList); for (std::map<Building*, PathWay>::iterator pathWayIt= pathWayList.begin(); pathWayIt != pathWayList.end(); ++pathWayIt) { // for every building within range Building& building = *(pathWayIt->first); float need = building.evaluateTrainee(_traineeType); if (need > _maxNeed) { _maxNeed = need; _destinationBuilding = &building; } } }
TilePos getWalkerDestination2( Propagator &pathPropagator, const TileOverlayType type, MarketPtr market, SimpleGoodStore& basket, const Good::Type what, PathWay &oPathWay, long& reservId ) { SmartPtr< T > res; Propagator::Routes pathWayList; pathPropagator.getRoutes(type, pathWayList); int max_qty = 0; // select the warehouse with the max quantity of requested goods for( Propagator::Routes::iterator pathWayIt= pathWayList.begin(); pathWayIt != pathWayList.end(); ++pathWayIt) { // for every warehouse within range BuildingPtr building= pathWayIt->first; PathWay& pathWay= pathWayIt->second; SmartPtr< T > destBuilding = building.as< T >(); int qty = destBuilding->getGoodStore().getMaxRetrieve( what ); if( qty > max_qty ) { res = destBuilding; oPathWay = pathWay; max_qty = qty; } } if( res.isValid() ) { // a warehouse/granary has been found! // reserve some goods from that warehouse/granary int qty = std::min( max_qty, market->getGoodDemand( what ) ); qty = std::min(qty, basket.getMaxQty( what ) - basket.getCurrentQty( what )); // std::cout << "MarketLady reserves from warehouse, qty=" << qty << std::endl; GoodStock stock( what, qty, qty); reservId = res->getGoodStore().reserveRetrieval( stock ); return res->getTilePos(); } return TilePos(-1, -1); }
TilePos getSupplierDestination2( Propagator &pathPropagator, const TileOverlayType type, const Good::Type what, const int needQty, PathWay &oPathWay, long& reservId ) { SmartPtr< T > res; Propagator::Routes pathWayList; pathPropagator.getRoutes(type, pathWayList); int max_qty = 0; // select the warehouse with the max quantity of requested goods for( Propagator::Routes::iterator pathWayIt= pathWayList.begin(); pathWayIt != pathWayList.end(); ++pathWayIt) { // for every warehouse within range BuildingPtr building= pathWayIt->first; PathWay& pathWay= pathWayIt->second; SmartPtr< T > destBuilding = building.as< T >(); int qty = destBuilding->getGoodStore().getMaxRetrieve( what ); if( qty > max_qty ) { res = destBuilding; oPathWay = pathWay; max_qty = qty; } } if( res.isValid() ) { // a warehouse/granary has been found! // reserve some goods from that warehouse/granary int qty = math::clamp( needQty, 0, max_qty ); GoodStock tmpStock( what, qty, qty); reservId = res->getGoodStore().reserveRetrieval( tmpStock ); return res->getTilePos(); } else { return TilePos( -1, -1 ); } }
void TraineeWalker::checkDestination(const BuildingType buildingType, Propagator &pathPropagator) { Propagator::ReachedBuldings pathWayList; pathPropagator.getReachedBuildings(buildingType, pathWayList); for( Propagator::ReachedBuldings::iterator pathWayIt= pathWayList.begin(); pathWayIt != pathWayList.end(); ++pathWayIt) { // for every building within range BuildingPtr building = pathWayIt->first; float need = building->evaluateTrainee(_traineeType); if (need > _maxNeed) { _maxNeed = need; _destinationBuilding = building; } } }
SpaceStatus Space::status(StatusStatistics& stat) { SpaceStatus s = SS_FAILED; // Check whether space is failed if (failed()) { s = SS_FAILED; goto exit; } assert(pc.p.active <= &pc.p.queue[PropCost::AC_MAX+1]); // Check whether space is stable but not failed if (pc.p.active >= &pc.p.queue[0]) { Propagator* p; ModEventDelta med_o; goto unstable; execute: stat.propagate++; // Keep old modification event delta med_o = p->u.med; // Clear med but leave propagator in queue p->u.med = 0; switch (p->propagate(*this,med_o)) { case ES_FAILED: // Count failure if (afc_enabled()) gafc.fail(p->gafc); // Mark as failed fail(); s = SS_FAILED; goto exit; case ES_NOFIX: // Find next, if possible if (p->u.med != 0) { unstable: // There is at least one propagator in a queue do { assert(pc.p.active >= &pc.p.queue[0]); // First propagator or link back to queue ActorLink* fst = pc.p.active->next(); if (pc.p.active != fst) { p = Propagator::cast(fst); goto execute; } pc.p.active--; } while (true); GECODE_NEVER; } // Fall through case ES_FIX: // Clear med and put into idle queue p->u.med = 0; p->unlink(); pl.head(p); stable_or_unstable: // There might be a propagator in the queue do { assert(pc.p.active >= &pc.p.queue[0]); // First propagator or link back to queue ActorLink* fst = pc.p.active->next(); if (pc.p.active != fst) { p = Propagator::cast(fst); goto execute; } } while (--pc.p.active >= &pc.p.queue[0]); assert(pc.p.active < &pc.p.queue[0]); goto stable; case __ES_SUBSUMED: p->unlink(); rfree(p,p->u.size); goto stable_or_unstable; case __ES_PARTIAL: // Schedule propagator with specified propagator events assert(p->u.med != 0); enqueue(p); goto unstable; default: GECODE_NEVER; } } stable: /* * Find the next brancher that has still alternatives left * * It is important to note that branchers reporting to have no more * alternatives left cannot be deleted. They cannot be deleted * as there might be choices to be used in commit * that refer to one of these branchers. This e.g. happens when * we combine branch-and-bound search with adaptive recomputation: during * recomputation, a copy is constrained to be better than the currently * best solution, then the first half of the choices are posted, * and a fixpoint computed (for storing in the middle of the path). Then * the remaining choices are posted, and because of the additional * constraints that the space must be better than the previous solution, * the corresponding Branchers may already have no alternatives left. * * The same situation may arise due to weakly monotonic propagators. * * A brancher reporting that no more alternatives exist is exhausted. * All exhausted branchers will be left of the current pointer b_status. * Only when it is known that no more choices * can be used for commit an exhausted brancher can actually be deleted. * This becomes known when choice is called. */ while (b_status != Brancher::cast(&bl)) if (b_status->status(*this)) { // Brancher still has choices to generate s = SS_BRANCH; goto exit; } else { // Brancher is exhausted b_status = Brancher::cast(b_status->next()); } // No brancher with alternatives left, space is solved s = SS_SOLVED; exit: stat.wmp = (wmp() > 0U); if (wmp() == 1U) wmp(0U); return s; }