Calling an element inside a collection(Demand) of collection class ArrayList and Element class shop - simulation

There are 4 main Agents: Distributors-Shops-Trucks-Orders
We have 4 distributors- 145 shops- N Trucks
I added an event to generate demand of constant amount(2 pallets).
The max capacity of the Truck is 20 ("center" parameter is of type Distributor \ see the image below)
I want to make multiple deliveries for several neighbor retailers using one Truck, so the truck will start from the distributor, the truck has to know which retailers to visit to know which pallets should be loaded.
So I need a way to find the group or sequence of retailers that the trucks has to deliver to based on DistanceByRoute() in order to decrease the number of Travelsenter image description here
I was trying to generate random orders inside the shop agent with amount 2
ProductOrder order= new ProductOrder(2,this); // "this" refers to the shop
I added this to a collection called Demand
Demand.add(this);
I wanted to make a loop, while Truck.load<20 .... I get from the collection(Demand) the Nearest shop by Route, like this I load and sequence the orders in an area, and I send the truck.
I cant find the Demand collection when trying to call it (Demand is a collection in shop agent).
Any ideas?
Also I appreciate notes about the algorithm/way of grouping the retailers orders in one Truck.

Related

Access paramters of Anylogic agent population created from db

OK... let me retry the question.
I'll just walk through the steps I (wrongly) assumed would work.
Create a data table in excel with passenger info (id, flight_time, type, class, qty...), note that the table is sorted by id... not flight_time.
Import this database into anylogic.
Create a population of agents (Passenger/Passengers) from the data table (one/row).
Create a schedule that addresses the Start Column as flight_time and Value column as qty (for this job I'm only sending one passenger at a time therefore qty = 1 for each row).
Set the pedSource to arrive according to schedule and to use the Passenger Agent as the New pedestrian.
So here is where I'm losing it. When I run this model the new Passengers do not have any parameters associated from the data table. The pedestrian id is some weird number (say 3000 or so). I can click on the Passengers icon during run time and scroll through the created agents (all of the parameter data is there and correctly assigned), but I'm not sure how to associate the new Agents in the run-time model with the population of Passengers agents.
Am I missing a step here? I was thinking that if I import a population of agents from a data table and then have each show up at a particular time in the model that I could then do some calculations with regard to each such as ped.exitTime = time() - ped.flightTime - ped.bufferTime.
I'm just not understanding why the table data is not available for use during run-time through ped? Is there another mapping step that must be performed to push the data to the ped agnets?
I'm at an impasse at this point. I hope this question is described more clearly and your feedback is appreciated.
Several things are wrong here.
You do not create agents in a pop first and then try to reuse them in a PedSource. The latter creates agents itself.
You don't seem to create pedestrians but just agents
you are not mapping the data to parameters
Quick guide to help:
create custom agent type "MyPed" . Make sure its "use in flowchart" property is set to "Pedestrian"
add 1 param into "MyPed" for each dbase table column
set your PedSource to "calls of inject()" function for its arrivals
delete your schedule, you cannot get the data you need
USe a DynamicEvent. Include 1 parameter argument for each dbase column. On Startup of main, loop across all dbase entries and create a dynamic event with the current row-data.
in the action of the DynEvent, call myPedSource.inject(1) and then manually fill that ped with the data from the arguments
This is not straightforward, especially the DynEvent stuff. So do more research in the AL help to understand these and how they work, check example models...

What type of event or tool should I use to model customer orders using pre-existing data?

I am building a model where trucks leave main distributor to make deliveries to several customers along a route before returning back to the distributor when it is empty. I have been given pre-existing data in the form of a CSV of the exact location of all of the orders, the order weight, and how many orders there were at that location -- therefore, it's not a stochastic process that I'm modeling. My goal is to see how many deliveries the truck can make within 300 miles and a 20-hour round trip driving time, with the truck's total weight being decremented by the order weight at each stop. The initial truck capacity was 40,000 pounds.
Currently, I've created a standard "order" event, though I'm concerned my code is not correctly doing what I want it to. My order trigger type is "Timeout," mode is "cyclic," the first occurrence is 0.999 days, and the recurrence time is every 1 days. Below is my code on the "Action" module:
for( Truck truck: main.trucks){
double freeCapacity = truck.truckMaxCapacity - truck.truckCapacity;
if( distanceTo(truck, MILE) < 300 && totalWeight < freeCapacity && findFirst(main.trucks, tr->tr.customers.contains(this)) == null){
truck.customers.add(this);
truck.truckCapacity += totalWeight;
}
}
Since I'm not passing in the direct parameters of the orders in my code, I'm concerned the code I've written so far is generating orders rather than using what I already have. I have the order identification number, weight, and location all loaded in from a database within my "Customer" agent, which is also where the "order" event is located.
I'm new to StackOverflow, so thanks in advance for any help.

Assign value to entities - Anylogic

I am just starting with Anylogic & Java. Could you please help me with my simple issue?
I have two windows: Main & Trucks
The trucks are entities generated on my model using a "source" within "Main".
I asked the model to create 10 trucks at the same time. It creates the trucks and then they move to another defined point at different speeds. When they arrive at the final point I want to know which truck arrived first (1, 2, ... or 10).
So... I am assuming that there is a way to assign a number to each truck when they are created. And I am also assuming I can read this number at the final point to know which one arrived first.
How can I do this?
Yes it is possible. Use a parameter. Truck is an agent and it can have multiple parameters. The easiest way to use parameters is to drag them from the Agent pallet into the Truck window. You define its name and type (in your case will be integer). When the truck is generated at the source you can give the parameter the value you want. If you want to have a sequential number, create a variable in your main window called ID with initial value 1 and then, in the source object, on the On Exit code area you type something like:
Agent.parameter = ID++;
Note that "parameter" should be the name of the parameter you created in Truck window.
Hope that helps.

Mahout: Recommending Items for a user in particular product category

What do we have as of now? - We are using Mahout's GenericItemBasedRecommender to get a list of recommended products for a user using TanimotoCoefficientSimilarity as ItemSimilarity.
Where do we want to go from here? - The above works fine when we don't care about product category but what we want to know is the Product Category specific recommendations i.e. Say if a user has been buying, browsing, liking etc. specifically more in Men's and Gadgets category, I would then want to show this user recommendation in that specific category saying Recommended for you in [X] where X would be replaced by Mens or Gadgets in this case. We are thinking about a couple of options below to achieve this and we need some leads/opinion/feedback etc. so as to make sure we are going in the right direction. Options:
Firstly we'll have to move to a non-tanimoto version for calculating item similarity so that we account for users buying, liking, etc and not only view/browsing data.
Figuring out product category for a particular user (this is where we need direction) - Our product category hierarchy is basically a tree and we need to know which top 4 nodes (with best recommendations) in tree we would show to the user. Also if we are saying that node X is a category which we are showing to the user and node Y is a parent of node X we then don't want show user products in category Y or any parent for that matter. Couple of ways achieving this:
For every user calculate SUM of similarity scores values of items for a nodes at leaf level and recursively calculate for parent node till the root. Now at each node we have A = SUM of similarity scores & B = Number of Items Recommended so we also have A/B=Value (V) at each node. Now we pick the top 4 V values from the tree and recommend that to the user. The challenge here is that if we try to calculate this online during the request it we would tough to limit this under 150 ms for the entire request. An Example:
Root Level - Category12 (A=11, B=4) (category1 + category2)
|
_____________________|_________________________
/ \
/ \
Leaf Level - category1 (A=6, B=2) category2 (A=5, B=2)
Recommended products in Category 1: Item1 (score = 2), Item2 (score = 4)
Recommended products in Category 2: Item3 (score = 1), Item4 (score = 4)
Second option: For every category create a cluster of users based on their behaviour (likes, buying, viewing etc.) and then figure out the top 4 categories to which the user belongs. Not sure if we can achieve this using clustering in Mahout but I think we can do this offline.
Please provide your feedback/suggestions/leads/thoughts.
Thanks in advance!
If you want to model more than one thing in your data, I would suggest to use the SVD recommender instead with the ALSWR factorizer set to implicit feedback. With that done you can have user,item,preference in your data and the preference value would be how strongly associated your user is to the item. You can play with the numbers, for example a purchase is a 20 and a view is just a 2. I'm just throwing numbers here, I wouldn't know what will work best for your data, because you can also model things proportionally, as in if a purchase is 30 times less likely to happen than a view, then a purchase should be 30 times stronger than a view.
Mahout provides a way to influence the recommendations through the IDRescorer. You implement your own logic here and decide how to affect the recommendations. For example, the IDRescorer would check if a recommendation candidate belongs to the same category and if it does, boost the score by X. There's an example here (link) from the Mahout in Action Book (which you should definitely read), showing a rescorer.
Hope this helps

Need a good database design for this situation

I am making an application for a restaurant.
For some food items, there are some add-ons available - e.g. Toppings for Pizza.
My current design for Order Table-
FoodId || AddOnId
If a customer opts for multiple addons for a single food item (say Topping and Cheese Dip for a Pizza), how am I gonna manage?
Solutions I thought of -
Ids separated by commas in AddOnId column (Bad idea i guess)
Saving Combinations of all addon as a different addon in Addon Master Table.
Making another Trans table for only Addon for ordered food item.
Please suggest.
PS - I searched a lot for a similar question but cudnt find one.
Your relationship works like this:
(1 Order) has (1 or more Food Items) which have (0 or more toppings).
The most detailed structure for this will be 3 tables (in addition to Food Item and Topping):
Order
Order to Food Item
Order to Food Item to Topping
Now, for some additional details. Let's start flushing out the tables with some fields...
Order
OrderId
Cashier
Server
OrderTime
Order to Food Item
OrderToFoodItemId
OrderId
FoodItemId
Size
BaseCost
Order to Food Item to Topping
OrderToFoodItemId
ToppingId
LeftRightOrWhole
Notice how much information you can now store about an order that is not dependent on anything except that particular order?
While it may appear to be more work to maintain more tables, the truth is that it structures your data, allowing you many added advantages... not the least of which is being able to more easily compose sophisticated reports.
You want to model two many-to-many realtionships by the sound of it.
i.e. Many products (food items) can belong to many orders, and many addons can belong to many products:
Orders
Id
Products
Id
OrderLines
Id
OrderId
ProductId
Addons
Id
ProductAddons
Id
ProductId
AddonId
Option 1 is certainly a bad idea as it breaks even first normal form.
why dont you go for many-to-many relationship.
situation: one food can have many toppings, and one toppings can be in many food.
you have a food table and a toppings table and another FoodToppings bridge table.
this is just a brief idea. expand the database with your requirement
You're right, first one is a bad idea, because it is not compliant with normal form of tables and it would be hard to maintain it (e.g. if you remove some addon you would need to parse strings to remove ids from each row - really slow).
Having table you have already there is nothing wrong, but the primary key of that table will be (foodId, addonId) and not foodId itself.
Alternatively you can add another "id" not to use compound primary key.