//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void NullFacility::receiveMessage(msg_ptr msg) { // is this a message from on high? if (msg->supplier()==this) { // file the order ordersWaiting_.push_front(msg); } else { throw CycException("NullFacility is not the supplier of this msg."); } }
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void SeparationsMatrixFacility::separate() { // Get iterators that define the boundaries of the ordersExecuting_ that are // currently ready.~ int time = TI->time(); pair<ProcessLine::iterator, ProcessLine::iterator> iters; iters = ordersExecuting_.equal_range(time); ProcessLine::iterator curr, omega; curr = iters.first; omega = iters.second; // Create and send Materials corresponding to each order that's ready to go. while (curr != omega) { // Get the info we need to make the separated Material. msg_ptr mess = (curr->second).first; Material* mat = (curr->second).second; // Find out what we're trying to make. try { IsoVector vecToMake = dynamic_cast<Material*>(mess->resource())->isoVector(); } catch (exception& e) { string err = "The Resource sent to the SeparationsMatrixFacility \ must be a Material type Resource" ; throw CycException(err); } ordersExecuting_.erase(time); } /* * The section below is currently under development. Its purpose is to do the * actual separations of the isotopes based on the string information. */ // This loop will cycle through each element and then it will find out if // there is anything in the stream that needs to be added to the material //for separation. /* for(stream_set_.second.first::iterator iter = stream_set_.begin(); !iter = stream_set_.end(); iter++){ firstpair = inventory_.pop_front(); string firstcommodity = firstpair.first(); Material* firstmaterial = firstpair.second(); // Multiply Amount of Element by Separation Efficieny and then add // it to the stock of material for that Element stocks_.second((*stream_set_).first) = firstmaterial((*stream_set_).first)*((*stream_set_).second).second ++; } */ }
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - std::vector<Resource*> NullFacility::removeResource(msg_ptr order) { Transaction trans = order->trans(); // it should be of out_commod_ commodity type if (trans.commod != out_commod_) { std::string err_msg = "NullFacility can only send '" + out_commod_ ; err_msg += + "' materials."; throw CycException(err_msg); } double newAmt = 0; // pull materials off of the inventory stack until you get the trans amount // start with an empty manifest vector<Resource*> toSend; while (trans.resource->quantity() > newAmt && !inventory_.empty() ) { Material* m = inventory_.front(); // if the inventory obj isn't larger than the remaining need, send it as is. if (m->quantity() <= (trans.resource->quantity() - newAmt)) { newAmt += m->quantity(); inventory_.pop_front(); } else { // if the inventory obj is larger than the remaining need, split it. Material* leftover = m->extract(trans.resource->quantity() - newAmt); newAmt += m->quantity(); inventory_.pop_front(); inventory_.push_back(leftover); } toSend.push_back(m); LOG(LEV_DEBUG2) <<"NullFacility "<< ID() <<" is sending a mat with mass: "<< m->quantity(); } return toSend; }
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void CapacityRegion::handleTick(int time) { // Overwriting RegionModel's handleTick // We loop through each facility that exists in the to_build_map_ map <string, queue <pair <int,int> > >::iterator fac; for (fac = to_build_map_.begin(); fac != to_build_map_.end(); ++fac){ // Define a few parameters /* !!!! This method is not full proof... what if multiple facilities need to be built and some fail and some succeed...? !!!! */ bool built = false; string fac_name = fac->first; queue<pair <int,int> > fac_build_queue = fac->second; pair<int,int> next_fac_build = fac_build_queue.front(); int next_build_time = next_fac_build.first; // Continue to loop until the facility is built while (built!=true){ // If the current time = the next build time for a facility, // build said facility if (time == next_build_time) { Model* inst; Model* fac_to_build = Model::getModelByName(fac_name); int num_facs_to_build = next_fac_build.second; int i; // Build the prescribed number of facilities for this time step for (i=0;i!=num_facs_to_build;i++){ inst = chooseInstToBuildFac(); built = requestBuild(fac_to_build,dynamic_cast<InstModel*>(inst)); } } // If there is nothing to build at this time, consider 0 facilities built else { built=true; } // For now, catch any situation for which no facility is built. // ************* This should eventually be changed if (built!=true){ std::stringstream ss1, ss2; ss1 << fac_name; ss2 << time; throw CycException("Facility " + ss1.str() + " could not be built at time " + ss2.str() + "."); } } // end build loop } // end facility loop // check current capacity for (int i=0;i<nCapacities();i++){ bool build_facility = true; bool built = false; while (build_facility){ double current_capacity = checkCurrentCapcity(capacity_type(i)); build_facility = current_capacity < nominal_value(i); Model* fac_to_build; if (build_facility){ Model* inst = chooseInstToBuildFac(); fac_to_build = chooseFacToBuild( allReplacementFacs_[i] ); built = requestBuild(fac_to_build,dynamic_cast<InstModel*>(inst)); } // For now, catch any situation for which no facility is built. // ************* This should eventually be changed if (build_facility && !built){ string fac_name = (dynamic_cast<FacilityModel*>(fac_to_build))->facName(); std::stringstream ss1, ss2; ss1 << fac_name; ss2 << time; throw CycException("Facility " + ss1.str() + " could not be built at time " + ss2.str() + "."); } } } // After we finish building, call the normal handleTick for a region RegionModel::handleTick(time); }