Bas Lindeboom
Bas Lindeboom

Reputation: 91

Dynamic resource pool for parcel delivery Anylogic

I am trying to compose an Anylogic based simulation for the multi-depot vehicle routing problem with heterogeneous fleet (9 types). I have found an example on fleet delivery optimization (https://www.anylogic.com/resources/educational-videos/delivery-fleet-optimization-with-gis/), however, this example uses only a single type of truck. Does anybody how to make a resource pool with dynamic vehicle agents?

The alternative is to make 9 resource pools and to define the number of vehicles used per vehicle. I want to make the model more widely applicable however through the inclusion of a data set with vehicle specifications.

Upvotes: 2

Views: 326

Answers (2)

Stuart Rossiter
Stuart Rossiter

Reputation: 2517

You don't need to do anything different conceptually here (like multiple agent types, multiple resource pools, or use of agent inheritance), and don't need the resource pool to be "dynamic" (in either the sense of dynamically adding resources to it and/or it including multiple types of agent). [All those things are possible but not necessary here, and how resource pools work add some complexities if you go those routes.]

Just have a Vehicle agent type with attributes (via parameters) that cover the relevant differences between your different vehicle types (which might just boil down to a single parameter of some Option List type which says which type of vehicle this is, or might relate to loads of other things such as fuel capacity/type, loading capacity, etc.).

Then your model inputs (e.g. via model parameters or Excel imported into the Database) would specify how many vehicles of each 'sub-type' you need. Initialise the resource pool with size equal to the sum of these (and ensure the pool adds them to a custom population of type Vehicle so you can access / loop through them explicitly). Then, as part of model initialisation (e.g., in on-startup actions of Main), set each of them up with the appropriate sub-type-specific attribute values. [There are other ways to do this initialisation; see for example this question, where my answer expands a fair bit on the other answers.]

Exactly how you do this depends on what your vehicle parameters are and how you define the input data that controls them. Say you define

  • An Option List VehicleType with values TYPE_A, TYPE_B and TYPE_C
  • Model parameters numTypeA, numTypeB and numTypeC which define how many of each you want
  • Vehicle agent type that just has a single parameter type of data type VehicleType

Then some initialisation logic (which has to set type for all the vehicles in your custom population allVehicles) might look like the below. (This could be written more elegantly, but the below is easier to understand.)

// Set up type A vehicles in population (using relevant indices)
for (int i = 0; i < numTypeA; i++) {
   allVehicles.get(i).type = VehicleType.TYPE_A;
}

// Set up type B vehicles in population (using relevant indices)
for (int i = numTypeA; i < numTypeA + numTypeB; i++) {
   allVehicles.get(i).type = VehicleType.TYPE_B;
}

// Set up type C vehicles in population (using relevant indices)
for (int i = numTypeA + numTypeB; i < numTypeA + numTypeB + numTypeC; i++) {
   allVehicles.get(i).type = VehicleType.TYPE_C;
}

In the model logic, where you need to distinguish between them in terms of which resources to seize, use the 'Resource choice condition' option of the Seize/Service blocks in question. This works by evaluating your resource choice condition for each available resource in turn (the current one being accesssible via the unit keyword): if it returns true that resource will be seized. Obviously the condition will depend on how your model needs to work (and will probably depend on attributes of the agent doing the seizing, accessible via the agent keyword), so could be something like

agent.weight > 40 ? unit.type == VehicleType.TYPE_A : unit.type == VehicleType.B

(If the agents doing the seizing have weights and you want to use type A vehicles for agents with weight > 40 and type B otherwise for this particular seize operation.) In general, this would be a function returning a boolean which accepted the agent doing the seizing and the current unit (vehicle) as arguments and does whatever logic is needed to determine if this vehicle is to be chosen. It may be that your choosing logic can't easily work on a say-yes-or-no-for-each-individual-resource basis; for example, if your criteria is 'choose the vehicle that has the most time since it last carried something' which means knowing this for all the vehicles to make a choice. Such logic can still be made to work, but this is more complicated.

If you want the vehicle types themselves to be data-driven (i.e., you don't want to 'hardcode' into the model — e.g., via an Option List — what vehicle types can exist), that's much more complex (because you also have to make all the logic on which type is used when generic as well) but doable.

NB: It may be that all you actually need is for the vehicles in your fleet to be distinguished in some ways (e.g., different loading capacities) without having to explicitly specify or care about what 'type' the vehicle is. This doesn't change any of the above, except you don't need an explicit attribute (parameter) of the Vehicle to say what sub-type it is.

Upvotes: 1

Yashar Ahmadov
Yashar Ahmadov

Reputation: 1636

In this type of situations, I create separate agents for different vehicle types.

enter image description here

If you need, create a collection of those resources so that you can access the one you need by index.

In fact, ResourcePool does allow you to add multiple resources. If you switch to dynamic editor, you can do this:

enter image description here

Upvotes: 1

Related Questions