Esempio n. 1
0
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -    
void SourceFacility::generateMaterial(int curr_time) {
  int time_change = curr_time - prev_time_;
  prev_time_ = curr_time;

  // if there's room in the inventory, process material at capacity
  double empty_space = inventory_.space();
  if (empty_space < EPS_KG) {return;}

  IsoVector temp = recipe_;
  if (capacity_ * recipe_.mass() * time_change <= empty_space) {
    // add a material the size of the capacity to the inventory
    temp.multBy(capacity_ * time_change);
  } else {
    // add a material that fills the inventory
    temp.setMass(empty_space);
  }
  mat_rsrc_ptr newMat = mat_rsrc_ptr(new Material(temp));
  newMat->setOriginatorID( this->ID() );
  inventory_.pushOne(newMat);
}
Esempio n. 2
0
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -    
void SourceFacility::handleTock(int time){

  // if there's room in the inventory, process material at capacity
  double space = inventory_size_ - this->checkInventory(); 
  if (capacity_ * recipe_.mass() <= space) {
    // add a material the size of the capacity to the inventory
    IsoVector temp = recipe_;
    temp.multBy(capacity_);
    Material* newMat = new Material(temp);

    LOG(LEV_DEBUG2) << facName() << ", handling the tock, has created a material:";
    newMat->print();
    inventory_.push_front(newMat);
  } else if (space < capacity_*recipe_.mass() && space > 0) {
    // add a material that fills the inventory
    IsoVector temp = recipe_;
    temp.setMass(space);
    Material* newMat = new Material(temp);
    LOG(LEV_DEBUG2) << facName() << ", handling the tock, has created a material:";
    newMat->print();
    inventory_.push_front(newMat);
  }
  // check what orders are waiting,
  // send material if you have it now
  while (!ordersWaiting_.empty()) {
    msg_ptr order = ordersWaiting_.front();
    order->approveTransfer();
    ordersWaiting_.pop_front();
  }
  // For now, lets just print out what we have at each timestep.
  LOG(LEV_DEBUG2) << "SourceFacility " << this->ID()
                  << " is holding " << this->checkInventory()
                  << " units of material at the close of month " << time
                  << ".";

  // call the facility model's handle tock last 
  // to check for decommissioning
  FacilityModel::handleTock(time);
}