Beispiel #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);
}
Beispiel #2
0
void Conn::onLocationShipmentNew(Location::PtrConst _cur,
    Shipment::Ptr _shipment) {
        FWK_DEBUG("Conn::onLocationShipmentNew() with name: " << _cur->name());

        Location::PtrConst next =
            routeTable_->nextLocation(_cur, _shipment->destination());
        Segment::Ptr out;
        Location::OutSegmentIteratorConst it = _cur->outSegmenterIterConst();
        for (int i =0; i < _cur->outSegments(); ++i, ++it) {
            Segment::PtrConst r = graphSegment_.at((*it)->returnSegment());
            if (r->source() == next->name()){
                out = *it;
                break;
            }
        }
        //Segment * s = const_cast<Segment *> (out.ptr());
        Location::Ptr p =  const_cast<Location *>(next.ptr());
        out->shipmentEnq(_shipment,p);
};