InjectActivityReactor::InjectActivityReactor(Activity::Ptr _a, CustomerLocation::Ptr _l) :
	Activity::Notifiee(_a.ptr()),
	activity_(_a),
	transferRate_(0),
	shipmentSize_(0),
	source_(_l),
	destination_(NULL) {}
void FleetRepReactor::onAttributeIs() {
	
	// Create scheduleChanges activity
	if(scheduleReactor_)
		activityManagerInstance()->activityDel("schedule");
	Activity::Ptr scheduleChanges = activityManagerInstance()->activityNew("schedule");
	scheduleReactor_ = new ScheduleChangesReactor(scheduleChanges.ptr(), fleet_, scheduledAttrs_);
	scheduleChanges->nextTimeIs(currentTimeRoundedDownTo24() + scheduledAttrs_.startTime.value());
	scheduleChanges->lastNotifieeIs(scheduleReactor_.ptr());
	scheduleChanges->statusIs(Activity::queued);
	
	// Create unscheduleChanges activity
	if(unscheduleReactor_)
		activityManagerInstance()->activityDel("unschedule");
	Activity::Ptr unscheduleChanges = activityManagerInstance()->activityNew("unschedule");
	unscheduleReactor_ = new UnscheduleChangesReactor(unscheduleChanges.ptr(), fleet_, scheduledAttrs_);
	unscheduleChanges->nextTimeIs(currentTimeRoundedDownTo24() + scheduledAttrs_.endTime.value());
	unscheduleChanges->lastNotifieeIs(unscheduleReactor_.ptr());
	unscheduleChanges->statusIs(Activity::queued);

}
示例#3
0
void Segment::readyForShipmentIs(bool b) {
	if (b == false || shipmentQ_.empty()) return;
	
	Activity::Manager::Ptr manager = activityManagerInstance();
	string name = "forward shipment #";
	ostringstream oss;
	oss << rand() << rand() << rand();
	name.append(oss.str());
	Activity::Ptr fwd = manager->activityNew(name);

	ShipmentQueue shipments;
	NumVehicles currentVehicles(capacity());
    Fleet::Ptr fleet = engine_->fleet();
	NumPackages vehicleCapacity(fleet->capacity(mode()).value());
	NumPackages totalCapacity(
		currentVehicles.value() * vehicleCapacity.value());
	NumPackages packageCount(0);

	NumVehicles vehicles(0);
    Dollar costPerTrip = this->length().value()*this->difficulty().value()*fleet->speed(mode()).value();

	for (Shipment::Ptr s = shipmentQ_.front(); !shipmentQ_.empty() && packageCount < totalCapacity; ) {
		NumPackages load = s->load();
		if (load.value() > totalCapacity.value()) { // split shipment
			++shipmentsFragmented_;
			s->loadIs(load.value() - totalCapacity.value());
			load = totalCapacity;
			shipmentQ_.push_front( Shipment::ShipmentNew( s->name(), s->source(), s->destination(), s->origSize(), load, s->timeShipped() ));
		}
		// now we're guaranteed to have at least one shipment at the
		// front of the queue that we can send off
        Shipment::Ptr shipment = shipmentQ_.front();
        shipment->costIs(shipment->cost().value() + costPerTrip.value());
		shipments.push_front(shipment);
		shipmentQ_.pop_front();
		packageCount = packageCount.value() + load.value();
		totalCapacity = totalCapacity.value() - load.value();
	}

	vehicles = packageCount.value() / vehicleCapacity.value() +
		((packageCount.value() % vehicleCapacity.value() > 0) ? 1 : 0);
    capacity_ = capacity_.value() - vehicles.value();

	fwd->lastNotifieeIs(new ForwardShipmentReactor(manager,
								fwd.ptr(), 0, this, shipments, vehicles)); 
	Time timeTaken = this->length().value() / fleet->speed(mode()).value();
	fwd->nextTimeIs(manager->now().value() + timeTaken.value());
	fwd->statusIs(Activity::nextTimeScheduled);
}
示例#4
0
void BooksimWrapper::coreInterfaceIs(CoreInterface* iface, int idx){
  if(_coreInterfaces[idx]!=NULL){
    throw Fwk::ConstraintException("Interface for index %d already exists in NetworkSim::coreInterfaceIs", idx);
  }
  _coreInterfaces[idx]=iface;

  //create activities/reactors not sure if any of these is actually used
  CoreInterfaceReactor::Ptr lr = new CoreInterfaceReactor(iface, this);
  iface->msgInjectionNotifieeIs(lr.ptr());
  Activity::Ptr act = _actMgr->activityNew(iface->name()+"Activity", _ifacePriority+_basePriority);
  InterfaceActivityReactor::Ptr lar= new InterfaceActivityReactor(_actMgr.ptr(), act.ptr(), iface, this);
  _coreIfaceReactors[iface] = lr;
  _ifaceActivities[iface] = act;
  _ifaceActivityReactors[iface] = lar;

  act->statusIs(Activity::free);
}
示例#5
0
void CustomerReactor::injectActivityChk() {
	if(transferRateSet_ && shipmentSizeSet_ && destinationSet_ ) {

		Activity::Manager::Ptr manager = activityManagerInstance();
		Activity::Ptr inject = manager->activityNew("activity"+this->notifier()->name());
		double rate = 24 / this->notifier()->transferRate().value();
		inject->lastNotifieeIs(new InjectActivityReactor(manager,
					inject.ptr(), 
					rate,
					engine_,
					this->notifier()->name(), 
					this->notifier()->destination(),
					this->notifier()->shipmentSize()));
		inject->statusIs(Activity::nextTimeScheduled);

		//cout << "Inject activity!" << this->notifier()->shipmentSize().value() << endl;
		transferRateSet_=false;
		shipmentSizeSet_=false;
		destinationSet_=false;
	} else { return; }
}