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 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; }
}
Beispiel #3
0
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;
}
int main(int argc, char *argv[]) {
    try
    {
        Ptr<Instance::Manager> manager = shippingInstanceManager();

        Ptr<Instance> fleet = manager->instanceNew("fleet", "Fleet");
        fleet->attributeIs("Truck, speed", "50");
        fleet->attributeIs("Truck, cost", "1");
        fleet->attributeIs("Truck, capacity", "50");

        fleet->attributeIs("Plane, speed", "100");
        fleet->attributeIs("Plane, cost", "2.0");
        fleet->attributeIs("Plane, capacity", "100");

        /********************************************************
        ******************* | NETWORK SETUP | ******************
        ********************************************************/

        Ptr<Instance> source = manager->instanceNew("source", "Customer");
        Ptr<Instance> otherCustomer = manager->instanceNew("other", "Customer");
        Ptr<Instance> dest = manager->instanceNew("dest", "Customer");
        source->attributeIs("Destination", "dest");
        Ptr<Instance> truckT = manager->instanceNew("truckT", "Truck terminal");
        Ptr<Instance> planeT = manager->instanceNew("planeT", "Plane terminal");

        // source <-seg1-> truck terminal <-seg2-> dest
        Ptr<Instance> seg1 = manager->instanceNew("seg1", "Truck segment");
        Ptr<Instance> rseg1 = manager->instanceNew("rseg1", "Truck segment");
        seg1->attributeIs("source", "source");
        rseg1->attributeIs("source", "truckT");
        seg1->attributeIs("return segment", "rseg1");
        Ptr<Instance> seg2 = manager->instanceNew("seg2", "Truck segment");
        Ptr<Instance> rseg2 = manager->instanceNew("rseg2", "Truck segment");
        seg2->attributeIs("source", "truckT");
        rseg2->attributeIs("source", "dest");
        seg2->attributeIs("return segment", "rseg2");
        seg1->attributeIs( "length", "400");
        rseg1->attributeIs("length", "400");
        seg2->attributeIs( "length", "400");
        rseg2->attributeIs("length", "400");

        // source <-seg3-> port terminal <-seg4-> dest 
        Ptr<Instance> seg3 = manager->instanceNew("seg3", "Plane segment");
        Ptr<Instance> rseg3 = manager->instanceNew("rseg3", "Plane segment");
        seg3->attributeIs("source", "source");
        rseg3->attributeIs("source", "planeT");
        seg3->attributeIs("return segment", "rseg3");
        Ptr<Instance> seg4 = manager->instanceNew("seg4", "Plane segment");
        Ptr<Instance> rseg4 = manager->instanceNew("rseg4", "Plane segment");
        seg4->attributeIs("source", "planeT");
        rseg4->attributeIs("source", "dest");
        seg4->attributeIs("return segment", "rseg4");
        seg3->attributeIs("length", "400");
        rseg3->attributeIs("length", "400");
        seg4->attributeIs("length", "400");
        rseg4->attributeIs("length", "400");

        //source <-seg5-> other customer <-seg6-> dest
        //to verify customers do not get routed to
        Ptr<Instance> seg5 = manager->instanceNew("seg5", "Plane segment");
        Ptr<Instance> rseg5 = manager->instanceNew("rseg5", "Plane segment");
        seg5->attributeIs("source", "source");
        rseg5->attributeIs("source", "other");
        seg5->attributeIs("return segment", "rseg5");
        Ptr<Instance> seg6 = manager->instanceNew("seg6", "Plane segment");
        Ptr<Instance> rseg6 = manager->instanceNew("rseg6", "Plane segment");
        seg6->attributeIs("return segment", "rseg6");
        seg6->attributeIs("source", "other");
        rseg6->attributeIs("source", "dest");

        seg5->attributeIs("length", "200");
        rseg5->attributeIs("length", "200");
        seg6->attributeIs("length", "200");
        rseg6->attributeIs("length", "200");

        /********************************************************
        ****************| END NETWORK SETUP | ******************
        ********************************************************/

        // TRUCK SEGMENTS
        seg1->attributeIs( "Capacity", CAPACITY_TRUCK);
        rseg1->attributeIs("Capacity", CAPACITY_TRUCK);
        seg2->attributeIs( "Capacity", CAPACITY_TRUCK);
        rseg2->attributeIs("Capacity", CAPACITY_TRUCK);

        // PLANE SEGMENTS
        seg3->attributeIs( "Capacity", CAPACITY_PLANE);
        rseg3->attributeIs("Capacity", CAPACITY_PLANE);
        seg4->attributeIs( "Capacity", CAPACITY_PLANE);
        rseg4->attributeIs("Capacity", CAPACITY_PLANE);

        //OTHER ATTRIBUTES 
        source->attributeIs("Transfer Rate", TRANSFER_RATE);
        source->attributeIs("Shipment Size", SHIPMENT_SIZE);

        Activity::Manager::Ptr activityManager = activityManagerInstance();
        // RealTimeManager::Ptr realTimeManager = realTimeManagerInstance();

        for ( int i = 1; i <= STEPS; i++){
            activityManager->nowIs(TIME_STEP * i);
            // realTimeManager->realTimePassedIs(TIME_STEP);

            cout << "AT TIME: " << TIME_STEP * i << endl;
            cout << "SOURCE->TRUCK: Capacity " << seg1->attribute("Capacity") << 
                "    recieved " << seg1->attribute("Shipments Received") << 
                "    refused " << seg1->attribute("Shipments Refused") << endl;
            cout << "TRUCK->DEST : Capacity " << seg2->attribute("Capacity") <<
                "    recieved " << seg2->attribute("Shipments Received") << 
                "    refused " << seg2->attribute("Shipments Refused") << endl;
            cout << "SOURCE->PLANE: Capacity " << seg3->attribute("Capacity") <<
                "    recieved " << seg3->attribute("Shipments Received") << 
                "    refused " << seg3->attribute("Shipments Refused") << endl;
            cout << "PLANE->DEST: Capacity " << seg4->attribute("Capacity") <<
                "    recieved " << seg4->attribute("Shipments Received") << 
                "    refused " << seg4->attribute("Shipments Refused") << endl << endl;

            cout << "DESTINATION: " << endl << 
                "   Recieved Shipments:" << dest->attribute("Shipments Received") << 
                "   Average latency: " << dest->attribute("Average Latency") << 
                "   Total cost: " << dest->attribute("Total Cost") << endl;
            cout << endl << endl;;
        }

    }
    catch(Exception e)
    {
        cout << e.what() << endl;
    }
    catch(...)
    {
    }

    return 0;
}