Example #1
0
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -    
vector<Resource*> SourceFacility::removeResource(msg_ptr msg) {
  Transaction trans = msg->trans();
  double sent_amt = 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() > (sent_amt+EPS_KG) && !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() - sent_amt)) {
      sent_amt += m->quantity();
      toSend.push_back(m);
      inventory_.pop_front();
      LOG(LEV_DEBUG2) <<"SourceFacility "<< ID()
        <<"  has decided not to split the object with size :  "<< m->quantity();
    } else if (m->quantity() > (trans.resource->quantity() - sent_amt)) { 
      // if the inventory obj is larger than the remaining need, split it.
      Material* mat_to_send = m->extract(trans.resource->quantity() - sent_amt);
      sent_amt += mat_to_send->quantity();
      LOG(LEV_DEBUG2) <<"SourceFacility "<< ID()
        <<"  has decided to split the object to size :  "<< mat_to_send->quantity();
      toSend.push_back(mat_to_send);
      printSent(mat_to_send);
    }
  }    
  return toSend;
}
 FakeConverterMarket() : ConverterMarket() {
   string kg = "kg";
   string qual = "qual";
   gen_rsrc_ptr res = gen_rsrc_ptr(new GenericResource(kg, qual, 1));
   Transaction trans(this, OFFER);
   msg_ = msg_ptr(new Message(this, this, trans));
   msg_->trans().setResource(res);
 }
Example #3
0
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -    
void BatchReactor::receiveMessage(msg_ptr msg) {
  // is this a message from on high? 
  if(msg->trans().supplier()==this){
    // file the order
    ordersWaiting_.push_front(msg);
    LOG(LEV_INFO5, "BReact") << name() << " just received an order.";
  }
  else {
    throw CycException("BatchReactor is not the supplier of this msg.");
  }
}
Example #4
0
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -    
void RecipeReactor::addResource(msg_ptr msg, vector<rsrc_ptr> manifest) {
  // grab each material object off of the manifest
  // and move it into the stocks.
  for (vector<rsrc_ptr>::iterator thisMat=manifest.begin();
       thisMat != manifest.end();
       thisMat++) {
    LOG(LEV_DEBUG2, "RReact") <<"RecipeReactor " << ID() << " is receiving material with mass "
        << (*thisMat)->quantity();
    stocks_.push_front(make_pair(msg->trans().commod, boost::dynamic_pointer_cast<Material>(*thisMat)));
  }
}
Example #5
0
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void ConditioningFacility::addResource(msg_ptr msg, vector<rsrc_ptr> manifest) {
  // Put the material received in the stocks
  // grab each material object off of the manifest
  // and move it into the stocks.
  for (vector<rsrc_ptr>::iterator thisMat=manifest.begin();
       thisMat != manifest.end();
       thisMat++) {
    LOG(LEV_DEBUG2, "none!") <<"ConditiondingFacility " << ID() << " is receiving material with mass "
        << (*thisMat)->quantity();

    mat_rsrc_ptr mat = boost::dynamic_pointer_cast<Material>(*thisMat);
    stocks_.push_front(make_pair(msg->trans().commod, mat));
  } 
};
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void SeparationsMatrixFacility::addResource(msg_ptr msg,
                                            vector<Resource*> manifest) {  
  LOG(LEV_DEBUG2) << "Entered the addResource file ";

  // grab each material object off of the manifest
  // and move it into the stocks.
  for (vector<Resource*>::iterator thisMat=manifest.begin();
      thisMat != manifest.end();
      thisMat++) {
    LOG(LEV_DEBUG2) <<"SeparationsFacility " << ID() << " is receiving material with mass "
      << (*thisMat)->quantity();
    stocks_.push_back(make_pair(msg->trans().commod, dynamic_cast<Material*>(*thisMat)));
  }
}
Example #7
0
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
vector<rsrc_ptr> ConditioningFacility::removeResource(msg_ptr order) {
  vector<rsrc_ptr> toRet = vector<rsrc_ptr>() ;
  Transaction trans = order->trans();
  double order_amount = trans.resource->quantity()*trans.minfrac;
  if (remaining_capacity_ >= order_amount){
    toRet = processOrder(order);
  } else { 
    string msg;
    msg += "The ConditioningFacility has run out of processing capacity. ";
    msg += "The order requested by ";
    msg += order->requester()->name();
    msg += " will not be sent.";
    LOG(LEV_DEBUG2, "none!") << msg;
    gen_rsrc_ptr empty = gen_rsrc_ptr(new GenericResource("kg","kg",0));
    toRet.push_back(empty);
  }
  return toRet;
}
Example #8
0
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -    
vector<rsrc_ptr> RecipeReactor::removeResource(msg_ptr msg) {
  Transaction trans = msg->trans();

  double newAmt = 0;

  mat_rsrc_ptr m;
  mat_rsrc_ptr newMat;
  mat_rsrc_ptr toAbsorb;

  // start with an empty manifest
  vector<rsrc_ptr> toSend;

  // pull materials off of the inventory stack until you get the trans amount
  while (trans.resource->quantity() > newAmt && !inventory_.empty() ) {
    for (deque<Fuel>::iterator iter = inventory_.begin(); 
        iter != inventory_.end(); 
        iter ++){
      // be sure to get the right commodity
      if (iter->first == trans.commod) {
        m = iter->second;

        // start with an empty material
        newMat = mat_rsrc_ptr(new Material());

        // 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();
          newMat->absorb(m);
          inventory_.pop_front();
        } else { 
          // if the inventory obj is larger than the remaining need, split it.
          toAbsorb = m->extract(trans.resource->quantity() - newAmt);
          newAmt += toAbsorb->quantity();
          newMat->absorb(toAbsorb);
        }
        toSend.push_back(newMat);
        LOG(LEV_DEBUG2, "RReact") <<"RecipeReactor "<< ID()
          <<"  is sending a mat with mass: "<< newMat->quantity();
      }
    }
  }    
  return toSend;
}
Example #9
0
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -    
vector<rsrc_ptr> StorageFacility::removeResource(msg_ptr order) {
  Transaction trans = order->trans();
  // it should be of incommod Commodity type
  if(trans.commod != incommod_){
    throw CycException("StorageFacility can only send incommodity type materials.");
  }
  // pull materials off of the inventory_ stack until you get the trans amount
  Mass complete = 0;

  // start with an empty manifest
  vector<rsrc_ptr> toSend;

  while(trans.amount > complete && !inventory_.empty() ){
    mat_rsrc_ptr m = inventory_.front();

    // if the inventory_ obj isn't larger than the remaining need, send it as is.
    if(m->quantity() <= (capacity_ - complete)){
      complete += m->quantity();
      toSend.push_back(m);
      LOG(LEV_DEBUG2, "none!") <<"StorageFacility "<< getSN()
        <<"  is sending a mat with mass: "<< m->quantity();
      inventory_.pop_front();
    } else { 
      // if the inventory_ obj is larger than the remaining need, split it.
      // start with an empty material
      mat_rsrc_ptr newMat = mat_rsrc_ptr(new Material(CompMap(), 
          m->getUnits(),
          m->getName(), 
          0, ATOMBASED);
      mat_rsrc_ptr toAbsorb = m->extractMass(capacity_ - complete);
      complete += toAbsorb->quantity();
      newMat->absorb(toAbsorb);
      toSend.push_back(newMat);
      LOG(LEV_DEBUG2, "none!") <<"StorageFacility "<< getSN()
        <<"  is sending a mat with mass: "<< newMat->quantity();
    }
  }    
  return toSend;
}
Example #10
0
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
std::vector<Resource*> SeparationsMatrixFacility::removeResource(msg_ptr msg) {
  Transaction trans = msg->trans();

  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() ){
    for (deque<InSep>::iterator iter = inventory_.begin(); 
        iter != inventory_.end(); 
        iter ++){
      Material* m = inventory_.front().second;

      // start with an empty material
      Material* newMat = new Material();

      // 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();
        newMat->absorb(m);
        inventory_.pop_front();
      }
      else{ 
        // if the inventory obj is larger than the remaining need, split it.
        Material* toAbsorb = m->extract(trans.resource->quantity() - newAmt);
        newAmt += toAbsorb->quantity();
        newMat->absorb(toAbsorb);
      }

      toSend.push_back(newMat);
      LOG(LEV_DEBUG2) <<"SeparationsMatrixFacility "<< ID()
        <<"  is sending a mat with mass: "<< newMat->quantity();
    }    
  }
  return toSend;
}
Example #11
0
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
vector<rsrc_ptr> ConditioningFacility::processOrder(msg_ptr order) {
 // Send material from inventory to fulfill transactions

  Transaction trans = order->trans();

  double newAmt = 0;

  // pull materials off of the inventory stack until you get the transaction amount

  // start with an empty manifest
  vector<rsrc_ptr> toSend;

  while(trans.resource->quantity() > newAmt && !inventory_.empty() ) {
    mat_rsrc_ptr m = inventory_.front().second;

    // start with an empty material
    mat_rsrc_ptr newMat = mat_rsrc_ptr(new Material());

    // 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();
      newMat->absorb(m);
      inventory_.pop_front();
      remaining_capacity_ = remaining_capacity_ - newAmt;
    } else { 
      // if the inventory obj is larger than the remaining need, split it.
      mat_rsrc_ptr toAbsorb = m->extract(trans.resource->quantity() - newAmt);
      newMat->absorb(toAbsorb);
      newAmt += toAbsorb->quantity();
      remaining_capacity_ = remaining_capacity_ - newAmt;
    }

    toSend.push_back(newMat);
    LOG(LEV_DEBUG2, "none!") <<"ConditioningFacility "<< ID()
      <<"  is sending a mat with mass: "<< newMat->quantity();
  }    
  return toSend;
};
Example #12
0
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -    
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;
}
Example #13
0
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -    
vector<rsrc_ptr> SourceFacility::removeResource(msg_ptr msg) {
  Transaction trans = msg->trans();
  return ResourceBuff::toRes(inventory_.popQty(trans.resource->quantity()));
}