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); }
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; } }
int main(int argc, char *argv[]) { Activity::Manager::Ptr activityManager = activityManagerInstance(); Activity::Ptr loc1 = activityManager->activityNew("location 1"); //loc1->lastNotifieeIs(new InjectActivityReactor(activityManager, loc1.ptr(), 2)); loc1->statusIs(Activity::nextTimeScheduled); Ptr<Instance::Manager> manager = shippingInstanceManager(); Ptr<Instance> stats = manager->instanceNew("myStats", "Stats"); Ptr<Instance> fleet = manager->instanceNew("myFleet", "Fleet"); fleet->attributeIs("Boat, speed", "1"); fleet->attributeIs("Truck, speed", "2"); fleet->attributeIs("Plane, speed", "4"); fleet->attributeIs("Truck, capacity", "50"); fleet->attributeIs("Plane, cost", "1"); Ptr<Instance> customer1 = manager->instanceNew("customer1", "Customer"); Ptr<Instance> customer2 = manager->instanceNew("customer2", "Customer"); Ptr<Instance> boatSeg1 = manager->instanceNew("boatSeg1", "Boat segment"); Ptr<Instance> boatSeg2 = manager->instanceNew("boatSeg2", "Boat segment"); boatSeg1->attributeIs("source", "customer1"); boatSeg2->attributeIs("source", "customer2"); boatSeg1->attributeIs("return segment", "boatSeg2"); // Example using customer reactor customer1->attributeIs("Shipment Size", "3"); customer1->attributeIs("Transfer Rate", "3"); customer1->attributeIs("Destination", "customer2"); activityManager->nowIs(6.0); cout << "Done!" << endl; return 0; }