Search code examples
exceldatabaseanylogicinode

How to use an Anylogic Object (INode) as a Type when using Databases


The Problem: I have database tables (imported excel) with orders and locations. The orders have a column called "destination" that is cross referenced (using "Foreign Key" to reference locations.location) to the location column locations table which is supposed to represent the actual INode. How do i specify this address say in a moveTo block?

  1. I dont see an option where i can specify INode as the type in the Database table. I get a permission error if i choose Other as type and try to write INode.
  2. How do i effect this cross reference in code or in the Actions line? Its already set up with a foreign key in the agent table/parameters.

Solution

  • you cannot represent AnyLogic objects like INode as database entries. Instead, you can store characteristics about the node and create nodes programmatically at the model start.

    So store things like X/Y coordinates, etc.

    Below is an example for GIS points to show you the approach. You need to do something similar for INodes (check the AnyLogic help for INode API to learn how to create them).

    I store the location name as a string in the dbase: enter image description here

    On the model startup, I programmatically create GISPoint elements from the data (assumes I have a GIS map called map):

    List<Tuple> rows = selectFrom(routes)
    .list();
    
    for (Tuple row : rows) {
            GISPoint locationFrom = map.searchFirst(row.get( routes.location_from ));
            GISPoint locationTo = map.searchFirst(row.get( routes.location_to ));
            map.add(locationFrom);
            map.add(locationTo);
            GISRoute route = map.getRoute(locationFrom.getLatitude(), locationFrom.getLongitude(), 
                 locationTo.getLatitude(), locationTo.getLongitude());
            route.setLineColor( spectrumColor(uniform_discr(1,10), 10) );
    }