예제 #1
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);
}
InjectActivityReactor::InjectActivityReactor(Activity::Ptr _a, CustomerLocation::Ptr _l) :
	Activity::Notifiee(_a.ptr()),
	activity_(_a),
	transferRate_(0),
	shipmentSize_(0),
	source_(_l),
	destination_(NULL) {}
예제 #3
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);
}
예제 #4
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; }
}
예제 #5
0
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);

}
예제 #6
0
    void ManagerImpl::nowIs(Time t) {
	//find the most recent activites to run and run them in order
	while (!scheduledActivities_.empty()) {
	    
	    //figure out the next activity to run
	    Activity::Ptr nextToRun = scheduledActivities_.top();

	    //if the next time is greater than the specified time, break
	    //the loop
	    if (nextToRun->nextTime().value() > t.value()) {
		break;
	    }
	    
	    //calculate amount of time to sleep
	    Time diff = Time(nextToRun->nextTime().value() - now_.value());
	    
	    //sleep 100ms (100,000 microseconds) for every unit of time
	    //Sleep only for the real time activity manager
	    if(realTime_){
	    	usleep(( ((int)diff.value()) * 100000));
	    }
	    
	    now_ = nextToRun->nextTime();

	    //run the minimum time activity and remove it from the queue
	    scheduledActivities_.pop();

	    if(nextToRun->status() != Activity::deleted)
	    	nextToRun->statusIs(Activity::executing);

	    if(nextToRun->status() != Activity::deleted && nextToRun->status() != Activity::waiting){
	    	nextToRun->statusIs(Activity::free);
	    }
	}

	//syncrhonize the time
	now_ = t;
    }
예제 #7
0
	void ManagerImpl::nowIs(Time t) {
		static bool beenHere = false;

		if (!beenHere) {
			beenHere = true;
			//cout <<__FILE__<<":"<< __LINE__<< " doing preprocess" << endl;
			
			//cout << "network=" << network.ptr() << endl;
			//cout << "conn=" << network->connectivity().ptr() << endl;
			Shipping::Connectivity::Ptr c = const_cast<Shipping::Connectivity*>(network_->connectivity().ptr());
			c->simulationStatusIs(Shipping::Connectivity::running());
			//cout <<__FILE__<<":"<< __LINE__<< " end preprocess" << endl;
		}

		if (t < now_) return;
		cout << "Time is " << t.value() << endl;
		
		//find the most recent activites to run and run them in order
		while (!scheduledActivities_.empty()) {
			
			//figure out the next activity to run
			Activity::Ptr nextToRun = scheduledActivities_.top();

			//if the next time is greater than the specified time, break
			//the loop
			if (nextToRun->nextTime() > t) {
				break;
			}
			
			//calculate amount of time to sleep
			Time diff = Time(nextToRun->nextTime().value() - now_.value());
			
			if (managerType() == ManagerImpl::realtime()) {
				//cout << "going to sleep" << endl;
				//sleep 1s (1,000,000 microseconds) for every unit of time
				usleep(( (diff.value()) * 200000 ));
			}
			
			now_ = nextToRun->nextTime();

			//run the minimum time activity and remove it from the queue
			scheduledActivities_.pop();

			nextToRun->statusIs(Activity::executing);
			nextToRun->statusIs(Activity::free);

		}
		
		//syncrhonize the time
		now_ = t;
	}